phpunit 9 does not print error stack trace - phpunit

I recently updated my unit test environment from phpunit v8.5.13 to v9.5.1. Same config file, same php version, all the same except the php unit phar file in command line.
All works fine but when there araises a not expected exception then the stack trace is no longer printed (as it was until v8):
PHPUnit 9.5.1 by Sebastian Bergmann and contributors.
E
Time: 00:00.973, Memory: 42.00 MB
There was 1 error:
1) moduleTmEmployeeTest::testAdd with data set "default" (array(), array())
mobEx: this is my exception
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
phpunit 8
PHPUnit 8.5.13 by Sebastian Bergmann and contributors.
E
Time: 1.36 seconds, Memory: 36.00 MB
There was 1 error:
1) moduleTmEmployeeTest::testAdd with data set "default" (array(), array())
mobEx: this is my exception
[path]\unittests\phpunit\tm\moduleTmEmployeeTest.php:54
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
I checked out docs and migration guide but got no clue which new flag to set or what else I could do. Does anyone know?

As referenced by #sebastian in his comment, it's a bug fixed in current release v9.5.2.

Related

What are the purpose of Targets in the .Net Core xUnit Test-Runner Output, and how do I use them?

I'm building a Web API using .Net Core. I'm building and running my unit tests as I go. When I run my tests, I get something like this:
The-Monarch:MyAwesomeService.Tests homr$ dotnet test
Project MyAwesomeService (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
Project MyAwesomeService.Tests (.NETCoreApp,Version=v1.0) will be compiled because inputs were modified
Compiling MyAwesomeService.Tests for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:01.2618204
xUnit.net .NET CLI test runner (64-bit osx.10.11-x64)
Discovering: MyAwesomeService.Tests
Discovered: MyAwesomeService.Tests
Starting: MyAwesomeService.Tests
Finished: MyAwesomeService.Tests
=== TEST EXECUTION SUMMARY ===
MyAwesomeService.Tests Total: 20, Errors: 0, Failed: 0, Skipped: 0, Time: 3.522s
SUMMARY: Total: 1 targets, Passed: 1, Failed: 0.
The-Monarch:MyAwesomeService.Tests homr$
I'm curious about the line that says SUMMARY: Total: 1 targets, Passed: 1, Failed: 0.. So far, I've never seen a total higher than "1" here. How do you get more than one "Test Target" in a single output, and what's the purpose?

PhpStorm 7.1.3, XDebug 2.2.3, Symfony 2.4 - WebTestCase not found

I'm getting the following error when attempting to run my own Symfony unit tests in PhpStorm:
/usr/bin/php /home/kevin/www/src/Blah/MyBundle/Tests/Controller/HomeControllerTest.php
PHP Fatal error: Class 'Symfony\Bundle\FrameworkBundle\Test\WebTestCase' not found in /home/kevin/www/src/Blah/MyBundle/Tests/Controller/HomeControllerTest.php on line 8
PHP Stack trace:
PHP 1. {main}() /home/kevin/www/src/Blah/MyBundle/Tests/Controller/HomeControllerTest.php:0
Fatal error: Class 'Symfony\Bundle\FrameworkBundle\Test\WebTestCase' not found in /home/kevin/www/src/Blah/MyBundle/Tests/Controller/HomeControllerTest.php on line 8
Call Stack:
0.0002 234112 1. {main}() /home/kevin/www/src/Blah/MyBundle/Tests/Controller/HomeControllerTest.php:0
Process finished with exit code 255
Some research has informed me that I may have to point PhpStorm/Xdebug to Symfony's bootstrap and/or test suite XML file, but I'm not sure how to do that in PhpStorm. Nothing is jumping out at me in the various config screens. Please help.
Although I'm using IntelliJ IDEA, the configuration is the same, so:
Settings -> PHP -> PHPUnit - there are inputs for bootstrap and config

Phpunit.xml.dist Symfony2

I am trying to follow this link http://welcometothebundle.com/symfony2-rest-api-the-best-2013-way/. When I run this command :
bin/phpunit -c app
I have this error :
Configuration read from /home/ismail/NetBeansProjects/tuto/blog-rest-
symfony2/app/phpunit.xml.dist
E.
Time: 1.87 seconds, Memory: 15.75Mb
FAILURES!
enter code hereTests: 2, Assertions: 3, Errors: 1.
ideas please ?!!
The error message states that one of your Tests returned an error. Usually PHPUnit adds a . for every passed test, an F for assertion failure and an E for an error (e.g. an exception). Check your test code and correct it.

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.

PhpUnit 3.6.10 + NetBeans 7.1: Good test throws exception

In cmdline everything is OK:
d:\xampp\htdocs\PhpProject1\Tests>phpunit TestStub.php
PHPUnit 3.6.10 by Sebastian Bergmann.
.
Time: 0 seconds, Memory: 2.75Mb
OK (1 test, 1 assertion)
Called in NetBeans7.1:
Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class "" in "D:\Program Files (x86)\NetBeans 7.1\php\phpunit\NetBeansSuite.php".' in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php:123
Stack trace:
0 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('', 'D:\Program File...')
1 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(130): PHPUnit_TextUI_Command->run(Array, true)
2 D:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
3 {main}
thrown in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php on line 123
I think this is a NetBeans issue.
If I run:
d:\Program Files (x86)\NetBeans 7.1\php\phpunit>phpunit NetBeansSuite.php run=d:\xampp\htdocs\PhpProject1\Tests\TestStub.php
PHPUnit 3.6.10 by Sebastian Bergmann.
.
Time: 0 seconds, Memory: 2.75Mb
OK (1 test, 1 assertion)
It's OK. But if I give the test directory, it fails.
d:\Program Files (x86)\NetBeans 7.1\php\phpunit>phpunit NetBeansSuite.php run=d:\xampp\htdocs\PhpProject1\Tests\
Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class "" in "D:\Program Files (x86)\NetBeans 7.1\php\phpunit\NetBea
nsSuite.php".' in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php:123
Stack trace:
0 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('', 'D:\Program File...')
1 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(130): PHPUnit_TextUI_Command->run(Array, true)
2 D:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
3 {main}
thrown in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php on line 123
Any temporary solution?
When running PHPUnit against a single file it will always open the file and look for a test case inside of it.
When running it against a directory (what netbeans does) it will only look into files that end in *Test.php (unless something else is specified in the phpunit.xml).
If it can't find any Tests it will try to look into the $TestSuiteName folder and {$TestSuiteName}.php files hence the error message:
Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class ""
as it is looking for a "not named" test suite in the netbeans phpunit harness. The error message is really not helping you out there :)
The general suggestion would be to create a phpunit.xml and point Netbeans to it.
On a more personal note: From the phpunit support in the major IDEs Netbeans does quite a lot of things right and works well for a lot of people so don't let this bump discourage you from using it from the IDE if thats what you want.

Resources