Unit testing in PHPUnit with Twig installed

When I run PHPUnit, it tries to run test files in unexpected places, namely in the Twig installation directory, and tries to download Twig class files too many times. Does anyone know how to fix these problems?

Background

I use Twig (just Twig, not Symfony) in a web application, and Twig is installed through Composer. Composer and Twig are installed in user places, and my tests are in /test/, so I have the following simplified project structure:

/src/includes/vendor/
    autoload.php
    composer/
    twig/
        twig/
            lib/
            test/
/test/
    bootstrap.php
    (various files named, e.g., someClassTest.php)

My boot file ( /test/bootstrap.php) does nothing but load the Composer autoloader:

<?php
require_once dirname(__FILE__) . "/../src/includes/vendor/autoload.php";

My PHPUnit configuration file (phpunit.xml) looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
    <testsuites>
        <testsuite name="All Tests">
            <directory>./test/phpunit/</directory>
        </testsuite>
    </testsuites>
    <php>
        <ini name="xdebug.default_enable" value="0" />
        <ini name="xdebug.remote_autostart" value="0" />
        <ini name="xdebug.remote_enable" value="0" />
        <ini name="xdebug.overload_var_dump" value="0" />
        <ini name="xdebug.show_mem_delta" value="0" />
    </php>
</phpunit>

Problems

1. PHPUnit runs Twig's test tests /src/includes/vendor/composer/twig/twig/test/.

? , , /test . , Twig :

<exclude>./src/includes/vendor/</exclude>

, , . - ?

2. PHPUnit Twig, .

PHPUnit bootstrap.php, Composer , PHPUnit Twig.

, , :

Fatal error: Cannot redeclare class Twig_Node_Expression_Test in [path to project]\src\includes\vendor\twig\twig\lib\Twig\Node\Expression\Test.php on line 32

Call Stack:
    0.1630     223296   1. {main}() C:\Users\Ed\AppData\Local\Temp\ide-phpunit.php:0
    0.4280     857528   2. IDE_Base_PHPUnit_TextUI_Command::main() C:\Users\Ed\AppData\Local\Temp\ide-phpunit.php:552
    0.4280     864000   3. PHPUnit_TextUI_Command->run() C:\Users\Ed\AppData\Local\Temp\ide-phpunit.php:294
    1.8451    1338552   4. PHPUnit_Runner_BaseTestRunner->getTest() phar://C:/Users/Ed/Documents/Programming/phpunit-lts.phar/phpunit/TextUI/Command.php:150
  107.4751    1501304   5. PHPUnit_Framework_TestSuite->addTestFiles() phar://C:/Users/Ed/Documents/Programming/phpunit-lts.phar/phpunit/Runner/BaseTestRunner.php:96
  107.6552    1668912   6. PHPUnit_Framework_TestSuite->addTestFile() phar://C:/Users/Ed/Documents/Programming/phpunit-lts.phar/phpunit/Framework/TestSuite.php:416
  107.6572    1668888   7. PHPUnit_Util_Fileloader::checkAndLoad() phar://C:/Users/Ed/Documents/Programming/phpunit-lts.phar/phpunit/Framework/TestSuite.php:355
  107.6592    1669056   8. PHPUnit_Util_Fileloader::load() phar://C:/Users/Ed/Documents/Programming/phpunit-lts.phar/phpunit/Util/Fileloader.php:76

; .

, PHPStorm 9 (PS-141.1717), PHPUnit 3.7.37.

- ?


: , PHPStorm, :

C:\xampp\php\php.exe C:/Users/Ed/AppData/Local/Temp/ide-phpunit.php --bootstrap [ ]\test\phpunit\bootstrap.php --configuration [ ]\phpunit.xml [ ]

+4
2

, PHPStorm. "Run/Debug Configurations" "Directory" " ". " ".

PHPStorm Run / Debug Configuration dialog screenshot

PHPUnit /test/phpunit/, phpunit.xml. , Twig ( ), , . , PHPStorm, phpunit , , phpunit.xml.

, , - , Twig, "Can not redeclare class", .

0

PHPUnit [path to project] [path to project]/tests/phpunit .

0

All Articles