Enabling php-vcr in PHPUnit bootstrap file breaks the autoloading of class PHPUnit\Framework\ExceptionWrapper
I tried to downgrade PHPUnit to 7.x without success. Removing VCR from bootstrap solves the ExceptionWrapper issue
Here's the beginning of my bootstrap file
require_once __DIR__ . '/../vendor/autoload.php';
use VCR\VCR;
VCR::turnOn();
VCR::configure()->setMode('new_episodes');
PHPUnit configuration file
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
>
<php>
<ini name="error_reporting" value="-1" />
</php>
<testsuites>
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="integration">
<directory>tests/Integration</directory>
</testsuite>
<testsuite name="end2end">
<directory>tests/End2End</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
Expected: successful tests
Actual:
./vendor/bin/phpunit --color=always --verbose --testsuite=integration
PHPUnit 8.1.5 by Sebastian Bergmann and contributors.
Runtime: PHP 7.3.4 with Xdebug 2.7.2
Configuration: /var/www/project/phpunit.xml.dist
............................
Fatal error: Uncaught Error: Class 'PHPUnit\Framework\ExceptionWrapper' not found in /var/www/project/vendor/phpunit/phpunit/src/Framework/TestResult.php on line 732
Error: Class 'PHPUnit\Framework\ExceptionWrapper' not found in /var/www/project/vendor/phpunit/phpunit/src/Framework/TestResult.php on line 732
Call Stack:
0.0002 422288 1. {main}() /var/www/project/vendor/phpunit/phpunit/phpunit:0
0.0224 1925752 2. PHPUnit\TextUI\Command::main() /var/www/project/vendor/phpunit/phpunit/phpunit:61
0.0224 1925864 3. PHPUnit\TextUI\Command->run() /var/www/project/vendor/phpunit/phpunit/src/TextUI/Command.php:163
0.1295 6797680 4. PHPUnit\TextUI\TestRunner->doRun() /var/www/project/vendor/phpunit/phpunit/src/TextUI/Command.php:207
0.1456 7214088 5. PHPUnit\Framework\TestSuite->run() /var/www/project/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:613
0.1463 7214280 6. PHPUnit\Framework\TestSuite->run() /var/www/project/vendor/phpunit/phpunit/src/Framework/TestSuite.php:761
0.6619 12277352 7. PHPUnit\Framework\TestSuite->run() /var/www/project/vendor/phpunit/phpunit/src/Framework/TestSuite.php:761
0.6629 12277544 8. PHPUnit\Framework\DataProviderTestSuite->run() /var/www/project/vendor/phpunit/phpunit/src/Framework/TestSuite.php:761
0.8272 18014088 9. EasyWelfare\Tests\Integration\Routes\AvailabilityTest->run() /var/www/project/vendor/phpunit/phpunit/src/Framework/TestSuite.php:761
0.8272 18014088 10. PHPUnit\Framework\TestResult->run() /var/www/project/vendor/phpunit/phpunit/src/Framework/TestCase.php:808
Hint: the test that breaks involves SoapClient
Related
Ich checked on several sources on the network and also here on stack overflow but couldn't solve it so far.
Heres my config:
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.0/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="../../src/test.bootstrap.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
verbose="true"
>
<!--printerFile="vendor/whatthejeff/emoji-phpunit-resultprinter/src/Emoji/PHPUnit/ResultPrinter.php"-->
<!--printerClass="Emoji\PHPUnit\ResultPrinter"-->
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_DIR" value="src/" />
<env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="testing"/>
</php>
<loggin>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-crap4j" target="build/logs/crap4j.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</loggin>
<testsuites>
<testsuite name="Project Test Suite">
<directory>src/*/*Bundle/Tests</directory>
<directory>src/*/Bundle/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>../src</directory>
<exclude>
<directory>src/*/*Bundle/Resources</directory>
<directory>src/*/*Bundle/Tests</directory>
<directory>src/*/Bundle/*Bundle/Resources</directory>
<directory>src/*/Bundle/*Bundle/Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
Due to the Build Server limitations I need to call phpunit with the following command:
./build/bin/phpunit.phar -c build/config/phpunit.xml --coverage-clover build/logs/clover.xml --coverage-crap4j build/logs/crap4j.xml --coverage-html build/coverage --coverage-xml build/logs/coverage.xml --log-junit build/logs/junit.xml --testdox-html build/testdox/testdox.html --testdox-xml build/logs/testdox.xml src/ -v
Everything works except code coverage heres the Result Output:
PHPUnit 6.1.4 by Sebastian Bergmann and contributors.
Runtime: PHP 7.1.5-1+0~20170522123046.25+jessie~1.gbpb8686b with Xdebug 2.6.0-dev
Configuration: /home/testcase/build-directories/build/config/phpunit.xml
Error: Incorrect whitelist config, no code coverage will be generated.
.................. 18 / 18 (100%)
Time: 945 ms, Memory: 6.00MB
OK (18 tests, 68 assertions)
I'm a little bit irritated as unit tests itself are working.
The Reds Message can be ignored (Hope so) as the Redis server is not yet fully configured.
I'm using oh-unit 6.1.4
Please give me a clue where the error is in my configuration
Try to change the whitelist deirectory into you phpunit with this:
<whitelist>
<directory suffix=".php">./src</directory>
<exclude>
<directory>./src/*/*Bundle/Resources</directory>
<directory>./src/*/*Bundle/Tests</directory>
<directory>./src/*/Bundle/*Bundle/Resources</directory>
<directory>./src/*/Bundle/*Bundle/Tests</directory>
</exclude>
</whitelist>
The directory given in the filter/whitelist/directory XML node is relative to the directory that contains the phpunit configuration file.
I think you should use ../../src.
I have the same issue, so I have update the whitelist directory path in phpunit.xml
<whitelist>
<directory>./web/core/includes</directory>
<directory>./web/core/lib</directory>
<!-- Extensions can have their own test directories, so exclude those. -->
<directory>./web/core/modules</directory>
<exclude>
<directory>./web/core/modules/*/src/Tests</directory>
<directory>./web/core/modules/*/tests</directory>
</exclude>
<directory>./web/modules</directory>
<exclude>
<directory>./web/modules/*/src/Tests</directory>
<directory>./web/modules/*/tests</directory>
<directory>./web/modules/*/*/src/Tests</directory>
<directory>./web/modules/*/*/tests</directory>
</exclude>
<directory>./web/sites</directory>
</whitelist>
(I'm beginner in PHPUnit)
In Netbeans I try to code-coverage PHPUnit in Symfony2.8 project, but it throws error:
"C:\wamp\www\treningPHPUnitSymfony2.8\bin\phpunit.bat" "--colors" "--log-junit" "C:\Users\chiny\AppData\Local\Temp\nb-phpunit-log.xml" "--coverage-clover" "C:\Users\chiny\AppData\Local\Temp\nb-phpunit-coverage.xml" "C:\Program Files\NetBeans 8.1\php\phpunit\NetBeansSuite.php" "--" "--run=C:\wamp\www\treningPHPUnitSymfony2.8\src\TreningBundle\Tests\Utils\CalculatorTest.php"
PHPUnit 5.3.4 by Sebastian Bergmann and contributors.
Error: No whitelist configured, no code coverage will be generated
................I 17 / 17 (100%)
Time: 531 ms, Memory: 4.00MB
OK, but incomplete, skipped, or risky tests!
Tests: 17, Assertions: 16, Incomplete: 1.
Done.
But i have Symfony default app\phpunit.xml.dist with <whitelist> defined :
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<!--
<server name="KERNEL_DIR" value="/path/to/your/app/" />
-->
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
<directory>../src/*Bundle/Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>../src</directory>
<exclude>
<directory>../src/*Bundle/Resources</directory>
<directory>../src/*Bundle/Tests</directory>
<directory>../src/*/*Bundle/Resources</directory>
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*Bundle/Resources</directory>
<directory>../src/*/Bundle/*Bundle/Tests</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
I got:
Symfony2.8, PHPUnit5.3.4, Netbeans 8.1
edit
But in windows console command
phpunit -c app/ src/TreningBundle/ --coverage-html=cov/ works great, generate coverage.
Unfortunately the "No whitelist configured, no code coverage will be generated" message is also printed when the whitelist configuration is invalid, see https://github.com/sebastianbergmann/phpunit/issues/2049 for details.
I am running phpunit (composer provisioned and version 4.8) from PHPStorm 8. Usually it works fine but whenever I need to use the #runInSeparateProcess annotation it starts screaming this error:
Fatal error: Class 'PHPUnit_Util_Configuration' not found in - on line 334
Call Stack:
0.0013 395808 1. {main}() -:0
The PHPUnit configuration on the IDE is the following:
Language & Frameworks > PHP > PHPunit: custom autoloader pointing to codebase/vendor/autoload.php
Run/Debug Configuration: alternative configuration file which point to my local phpunit.xml
This is the content of the configuration:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.2/phpunit.xsd"
colors="true"
bootstrap="./vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="My Project">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
The tests run as expected from the command line with the same phpunit executable and the same configuration file.
Any suggestion?
Apparently removing all dependencies and re-installing phpunit from composer (phpunit 4.8.6) solved the problem.
A modification of the fix the folks over at Drupal are using (https://www.drupal.org/node/2597814)
Add to the top of your boostrap file:
if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/path/to/composer/vendors/dir/autoload.php');
}
I tried many other methods, including upgrading PHPStorm and up/down-grading PHPUnit. This works.
I get the message no tests executed when i try to do
phpunit
or
phpunit -c phpunit.xml
on the other hand, if i do
phpunit -c phpunit.xml ./tests
It works. But this is a problem considering that some tool that I'm using does not handle this well.
Directory structur
code
tests/
phpunit.xml
autoloader.php
And here is the config file
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="true"
bootstrap="./tests/bootstrap.php"
>
<testsuites>
<testsuite name="StdTestSuite">
<directory>
tests/
</directory>
</testsuite>
</testsuites>
</phpunit>
The problem was the stupidest thing ever.
You can't have whitespace inside the tag.
So what you need to have in you phpunit.xml file is this
...
<testsuite name="StdTestSuite">
<directory>tests/</directory>
</testsuite>
...
Then running
phpunit
Should work
PHP Fatal error: Class 'Symfony\Bundle\FrameworkBundle\Test\WebTestCase' not found in /home/manivasagam/projects/ProofCentral/src/ProofCentral/ServiceBundle/Tests/Services/AttachmentServiceTest.php on line 15
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP 4. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/php/PHPUnit/TextUI/Command.php:150
PHP 5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:104
PHP 6. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:168
PHP 7. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/php/PHPUnit/Runner/StandardTestSuiteLoader.php:77
PHP 8. PHPUnit_Util_Fileloader::load() /usr/share/php/PHPUnit/Util/Fileloader.php:76
PHP 9. include_once() /usr/share/php/PHPUnit/Util/Fileloader.php:92
The problem here is that you dont load bootstrap file
I put the configuration in the app/phpunit.xml
With following xml in it:
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap = "bootstrap.php.cache" >
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/*/*Bundle/Tests</directory>
<directory>../src/*/Bundle/*/Tests</directory>
</testsuite>
</testsuites>
<!--
<php>
<server name="KERNEL_DIR" value="/path/to/your/app/" />
</php>
-->
<filter>
<whitelist>
<directory>../src</directory>
<exclude>
<directory>../src/*/Bundle/*/Resources</directory>
<directory>../src/*/Bundle/*/Controller</directory>
<directory>../src/*/Bundle/*/Tests</directory>
<directory>../src/*/Bundle/*/DataFixtures</directory>
<directory>../src/*/Bundle/*/DependencyInjection</directory>
<directory>../src/*/Bundle/*/Form</directory>
<directory>../src/*/Bundle/*/Event*</directory>
<directory>../src/*/Bundle/*/Firewall</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
And then run the phpunit
phpunit --coverage-text app src/ProofCentral/ServiceBundle/Tests/Services/CalculatorTest.php --bootstrap path/to/your/app/bootstrap.php.cache