Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wierd behavior with PHP defined tests suites with filename == class name #173

Closed
tobyS opened this issue Feb 16, 2011 · 3 comments
Closed

Comments

@tobyS
Copy link
Contributor

tobyS commented Feb 16, 2011

Note the following code, which has been written after the example in http://www.phpunit.de/manual/current/en/organizing-tests.html#organizing-tests.testsuite:

If you name the file containing this class "TestSuite.php" and run $ phpunit TestSuite.php, you receive
PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Class does not extend PHPUnit_Framework_TestCase.' in /dev/PHP/phpunit/PHPUnit/Framework/TestSuite.php:186
Stack trace:
#0 /home/dotxp/Desktop/phpunit_bug/TestSuite.php(7): PHPUnit_Framework_TestSuite->__construct('TestSuite')
#1 [internal function]: TestSuite::suite('TestSuite')
#2 /home/dotxp/dev/PHP/phpunit/PHPUnit/Runner/BaseTestRunner.php(124): ReflectionMethod->invoke(NULL, 'TestSuite')
#3 /home/dotxp/dev/PHP/phpunit/PHPUnit/TextUI/Command.php(150): PHPUnit_Runner_BaseTestRunner->getTest('TestSuite', '/home/dotxp/Des...', false)
#4 /home/dotxp/dev/PHP/phpunit/PHPUnit/TextUI/Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#5 /usr/local/php/php-5.3.3/bin/phpunit(53): PHPUnit_TextUI_Command::main()
#6 {main}

thrown in /home/dotxp/dev/PHP/phpunit/PHPUnit/Framework/TestSuite.php on line 186

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Class does not extend PHPUnit_Framework_TestCase.' in /dev/PHP/phpunit/PHPUnit/Framework/TestSuite.php:186
Stack trace:
#0 /home/dotxp/Desktop/phpunit_bug/TestSuite.php(7): PHPUnit_Framework_TestSuite->__construct('TestSuite')
#1 [internal function]: TestSuite::suite('TestSuite')
#2 /home/dotxp/dev/PHP/phpunit/PHPUnit/Runner/BaseTestRunner.php(124): ReflectionMethod->invoke(NULL, 'TestSuite')
#3 /home/dotxp/dev/PHP/phpunit/PHPUnit/TextUI/Command.php(150): PHPUnit_Runner_BaseTestRunner->getTest('TestSuite', '/home/dotxp/Des...', false)
#4 /home/dotxp/dev/PHP/phpunit/PHPUnit/TextUI/Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#5 /usr/local/php/php-5.3.3/bin/phpunit(53): PHPUnit_TextUI_Command::main()
#6 {main}

thrown in /home/dotxp/dev/PHP/phpunit/PHPUnit/Framework/TestSuite.php on line 186

If you rename the file to something else, the suite runs fine.

@edorian
Copy link
Sponsor Contributor

edorian commented Nov 9, 2011

The issue was with the name passed to the TestSuite constructor. It expects the name of a TestCase to start off with or an empty string to start an empty test suite taking it's name as the second constructor.

I don't see that as a big issue as using test suites for organization is discouraged since at least PHPUnit 3.5 (afaik).

As this is an older one I'll just close it and should this be an issue for you you know where to find me :)

@nylen
Copy link

nylen commented Jul 26, 2018

I don't see that as a big issue as using test suites for organization is discouraged since at least PHPUnit 3.5 (afaik).

This is a pretty annoying issue, and difficult to track down.

Test suites are still mentioned in the manual as a valid way to organize tests: https://phpunit.de/manual/6.5/en/organizing-tests.html#organizing-tests.xml-configuration

@tobyS @edorian @sebastianbergmann please consider reopening and fixing this.

@keradus
Copy link
Contributor

keradus commented Jul 30, 2018

@nylen , pinging people in 7-years old PR may be missed by them :(

Please, consider raising the fix yourself at https://github.com/sebastianbergmann/phpunit-documentation-english ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants