xdebug : Fatal error with phpunit for code coverage - phpunit

I wanna to test my code and coverage. I already install Xdebug extension and when I verify with php -v command, all i'ts good like that :
PHP 7.4.12 (cli) (built: Oct 27 2020 17:18:47) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v3.0.0RC1, Copyright (c) 2002-2020, by Derick Rethans
with Zend OPcache v7.4.12, Copyright (c), by Zend Technologies
However if I run phpunit i have a fatal error :
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
Fatal error: Uncaught SebastianBergmann\CodeCoverage\RuntimeException: xdebug.coverage_enable=On has to be set in php.ini in C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\.phpunit\phpunit-7.5-0\vendor\phpunit\php-code-coverage\src\Driver\Xdebug.php on line 42
SebastianBergmann\CodeCoverage\RuntimeException: xdebug.coverage_enable=On has to be set in php.ini in C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\.phpunit\phpunit-7.5-0\vendor\phpunit\php-code-coverage\src\Driver\Xdebug.php on line 42
Call Stack:
0.0005 402112 1. {main}() C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\phpunit:0
0.0027 477240 2. require('C:\Users\quent\Desktop\Github\quentingeeraert-website\vendor\symfony\phpunit-bridge\bin\simple-phpunit.php') C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\phpunit:13
0.2824 501760 3. include('C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\.phpunit\phpunit-7.5-0\phpunit') C:\Users\quent\Desktop\Github\quentingeeraert-website\vendor\symfony\phpunit-bridge\bin\simple-phpunit.php:405
0.2989 1149952 4. PHPUnit\TextUI\Command::main($exit = ???) C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\.phpunit\phpunit-7.5-0\phpunit:22
0.2989 1150064 5. Symfony\Bridge\PhpUnit\Legacy\CommandForV6->run($argv = [0 => 'bin\\phpunit', 1 => '--colors=always', 2 => '--stop-on-failure'], $exit = TRUE) C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\.phpunit\phpunit-7.5-0\src\TextUI\Command.php:162
I already add xdebug.coverage_enable = On in my php.ini file so I don't understand why the system say that :/
Maybe someone can help me ? Thank you a lot for help me !

I already add xdebug.coverage_enable = On in my php.ini file so I don't understand why the system say that :/
Xdebug v3.0.0RC1
PHPUnit 7.5.20
Either upgrade PHPUnit to the version that knows about Xdebug 3 ... or downgrade Xdebug to 2.x (2.9.8 is the latest).
Thing is: xdebug.coverage_enable is the Xdebug 2 option. That option does nothing in Xdebug 3 where you should use xdebug.mode = coverage instead.
Xdebug 3 uses different config options than v2 and your version of PHPUnit is simply not aware of that. Xdebug 3 will simply report an empty value/0 for no-longer-used Xdebug 2 options.
https://3.xdebug.org/docs/upgrade_guide#Changed-Configuration-Settings
P.S. You should see a warning when you run php -i with Xdebug 3 -- it should complain if such a wrong/outdated option is present in your php.ini (unless you have configured PHP to not to report any startup errors I guess).
In either case: run php -i and see the actual live values from Xdebug section: what value that option has.

Related

Trying to test the "Example 2.7 Using a data provider that returns an Iterator object" from PHPUnit online documentation but, it is not working

A PHPUnit example from the online documentation is not working for me! Please see below for more details.
Your help is appreciated. Thank you in advance!
I'm trying to run the example test below from online documentation but, it is not working for me!
Example 2.7 Using a data provider that returns an Iterator object
The result I'm getting is shown below:
..#VivoBook MINGW64 ~/PHPunit/test-project
$ ./vendor/bin/phpunit --testdox dataProviders
PHPUnit 8.5.32 by Sebastian Bergmann and contributors.
Warning Test Case (PHPUnit\Framework\WarningTestCase)
⚠ Warning
│
│ The data provider specified for DataTest::testAdd is invalid.
│ Error: Class 'CsvFileIterator' not found
│ ..\PHPunit\test-project\dataProviders\DataProviderTest.php:16
│
Time: 77 ms, Memory: 4.00 MB
WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.
PHP info:
..#VivoBook MINGW64 ~/PHPunit/test-project
$ php -v
PHP 7.2.28 (cli) (built: Feb 18 2020 12:54:18) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
The issue appeared because the class in use was not loaded. Loading the class 'CsvFileIterator' using require/require_once solved the issue.

Phpunit error "This build of PHPDBG does not support code coverage"

I'm getting error "This build of PHPDBG does not support code coverage" when try to run phpunit with coverage with phpdbg. I found in PHAR line which generate this error:
if (!\function_exists('PHPUnit\\phpdbg_start_oplog')) {
throw new \PHPUnit\SebastianBergmann\CodeCoverage\RuntimeException('This build of PHPDBG does not support code coverage');
}
Then i run and get this result:
prompt> ev function_exists('phpdbg_start_oplog');
1
As i undestand, problem is in namespace before phpdbg_start_oplog. So, why phpdbg_start_oplog is prefixed with PHPUnit namespace in PHAR?
PHPUnit 9.1.4 by Sebastian Bergmann and contributors.
PHP 7.4.1 (cli) (built: Dec 28 2019 11:16:02) ( NTS )
You found a bug in PHPUnit (or PHP-Scoper, one of the tools involved in building the PHAR distribution of PHPUnit). I opened a ticket for this issue on GitHub.

Drush command terminated abnormally due to an unrecoverable error

I have CentOS 6.6 with PHP 5.5.27 and Drupal 7.34
PHP 5.5.27 (cli) (built: Jul 10 2015 23:40:40)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
I've tried all latest 6,7,8 branches of Drush. When I type "drush -d -v status" I get an unrecoverable error (the error is the same on all branches of drush):
Drush bootstrap phase : bootstrap_drupal_full() [0.19 sec, 5.13 MB] [bootstrap]
Cannot modify header information - headers already sent by (output started at [warning]
/root/.composer/vendor/drush/drush/includes/output.inc:38) common.inc:698 [0.96 sec, 31.89 МБ]
Drush command terminated abnormally due to an unrecoverable error. [1.06 sec, 32.8 МБ]
I can't figure out what's wrong. Can anyone advise please?
Thanks in advance.
As mentioned in another comment, look for closing ?> tags at the end of custom modules, specifically any blank spaces after the >...but just remove the ?> to be in compliance.
A way to fix is to disable module by module until drush gives you a positive response. This will narrow down the code to review.
Also look at any hook_init() functions to see if anything is getting sent to the browser then check the weight of the module in the system table. If it is too low, it may cause an issue.

PHPUnit throws error on mountain lion

I've followed the instructions exactly described as here
http://phpunit.de/getting-started.html
Everything went fine but when i execute the following command
phpunit --bootstrap src/autoload.php tests/MoneyTest
It throws following error
PHPUnit 4.0.4 by Sebastian Bergmann.
PHP Fatal error: Class 'SebastianBergmann\Money\Money' not found in /Users/myname/Sites/lab/unittesting/tests/MoneyTest.php on line 54
PHP Stack trace:
PHP 1. {main}() /usr/local/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/local/bin/phpunit:581
PHP 3. PHPUnit_TextUI_Command->run() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:132
PHP 4. PHPUnit_TextUI_TestRunner->doRun() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:179
PHP 5. PHPUnit_Framework_TestSuite->run() phar:///usr/local/bin/phpunit/phpunit/TextUI/TestRunner.php:419
PHP 6. PHPUnit_Framework_TestCase->run() phar:///usr/local/bin/phpunit/phpunit/Framework/TestSuite.php:722
PHP 7. PHPUnit_Framework_TestResult->run() phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php:764
PHP 8. PHPUnit_Framework_TestCase->runBare() phar:///usr/local/bin/phpunit/phpunit/Framework/TestResult.php:692
PHP 9. PHPUnit_Framework_TestCase->runTest() phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php:824
PHP 10. ReflectionMethod->invokeArgs() phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php:956
PHP 11. SebastianBergmann\Money\MoneyTest->testExceptionIsRaisedForInvalidConstructorArguments() phar:///usr/local/bin/phpunit/phpunit/Framework/TestCase.php:956
Any idea what might be the cause?
Thanks
The following instructions worked for me:
$ git clone https://github.com/sebastianbergmann/money
$ cd money
$ phpunit --bootstrap src/autoload.php tests/MoneyTest
PHPUnit 3.7.32 by Sebastian Bergmann.
......................
Time: 882 ms, Memory: 3.25Mb
OK (22 tests, 41 assertions)
Be aware that I using 3.7.32 and you are using 4.0.4. If its still not working then it could be a bug.

How to set the classpath for Symfony Autoloader?

I renamed my working trunk to trunk-alldone, checked out a fresh copy of trunk, ran some symfony commands (like unit tests) on trunk, then deleted trunk and renamed trunk-alldone back to trunk.
Now when I try to run any symfony commands, I get:
sym cc
PHP Warning: require(/home/kiwi/checkouts/trunk-alldone/kiwi- web/plugins/kcEmailPlugin/l pleAutoload.class.php on line 123
PHP Stack trace:
PHP 1. {main}() /home/kiwi/checkouts/trunk/kiwi-web/symfony:0
PHP 2. include() /home/kiwi/checkouts/trunk/kiwi-web/symfony:37
PHP 3. sfCommandApplication->__construct() /home/kiwi/checkouts/trunk/kiwi-web/lib/vend
PHP 4. sfSymfonyCommandApplication->configure() /home/kiwi/checkouts/trunk/kiwi-web/lib
PHP 5. sfSymfonyCommandApplication->loadTasks() /home/kiwi/checkouts/trunk/kiwi-web/lib
PHP 6. class_exists() /home/kiwi/checkouts/trunk/kiwi-web/lib/vendor/symfony/lib/comman
PHP 7. sfSimpleAutoload->autoload() /home/kiwi/checkouts/trunk/kiwi-web/lib/vendor/symf
It's still looking for things in trunk-alldone!
How do I reset this to get it to look in the right place again?

Resources