Error when running a PHPUnit test - phpunit

I get an error when I try to run a test in PHPUnit. Even if I type phpunit by itself, I still get an error. It works fine when I call it outside the Bootstrap folder.
Configuration read from /home/milen/Documents/codific/icho/module/Application/tests/phpunit.xml
PHP Fatal error: Call to a member function getId() on a non-object in /home/milen/Documents/codific/icho/module/Application/tests/ApplicationTest/Controller/PoCourseTest.php on line 268
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_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:176
PHP 5. PHPUnit_Framework_TestSuite->run() /home/milen/Documents/codific/icho/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:426
PHP 6. PHPUnit_Extensions_SeleniumTestCase->run() /home/milen/Documents/codific/icho/vendor/phpunit/phpunit/src/Framework/TestSuite.php:699
PHP 7. PHPUnit_Framework_TestCase->run() /home/milen/Documents/codific/icho/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumTestCase.php:648
PHP 8. PHPUnit_Framework_TestResult->run() /home/milen/Documents/codific/icho/vendor/phpunit/phpunit/src/Framework/TestCase.php:760
PHP 9. PHPUnit_Framework_TestCase->runBare() /home/milen/Documents/codific/icho/vendor/phpunit/phpunit/src/Framework/TestResult.php:686
PHP 10. PoCourseTest->tearDown() /home/milen/Documents/codific/icho/vendor/phpunit/phpunit/src/Framework/TestCase.php:852
I tried reinstalling it, no luck.

I usually see an error along these lines when I have defined a bootstap.php file to run for PHPUnit which gets specified in the phpunit.xml file. With this setup, you need to be careful from where you run your tests so that the bootstrap file is run properly. This isn't a problem of PHPUnit per se, but a side effect from the phpunit.xml file.
This would appear to be the case because you stated that when you are not in the folder called "Bootstrap" (what / where ever that is), PHPUnit works fine. But without more information aside from the error dump this would be difficult to ascertain.

I think this question could be fixed with this answer.
I don't think its a problem with configuration, but rather a code execution in the setUp and tearDown method.

Related

Unable to run phpunit since upgrade to Symfony 2.8/3.0

Since upgrading to Symfony 2.8, I get the following error when I run phpunit in the Symfony root:
PHP Fatal error: Class 'PHPUnit_Util_ErrorHandler' not found in /var/www/foo/symfony/vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php on line 40
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_TextUI_Command->handleArguments() /usr/share/php/PHPUnit/TextUI/Command.php:138
PHP 5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() /usr/share/php/PHPUnit/TextUI/Command.php:657
PHP 6. PHPUnit_Util_Configuration->getTestSuite() /usr/share/php/PHPUnit/Util/Configuration.php:789
PHP 7. PHPUnit_Framework_TestSuite->addTestFiles() /usr/share/php/PHPUnit/Util/Configuration.php:873
PHP 8. PHPUnit_Framework_TestSuite->addTestFile() /usr/share/php/PHPUnit/Framework/TestSuite.php:416
PHP 9. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/php/PHPUnit/Framework/TestSuite.php:355
PHP 10. PHPUnit_Util_Fileloader::load() /usr/share/php/PHPUnit/Util/Fileloader.php:76
PHP 11. Symfony\Bridge\PhpUnit\DeprecationErrorHandler::Symfony\Bridge\PhpUnit\{closure}() /usr/share/php/PHPUnit/Util/Fileloader.php:92
THE ERROR HANDLER HAS CHANGED!
This also occurs under Symfony 3.0. Should I now be running phpunit in a different manner?
I just ran into this problem using Symfony 2.8.
Just update your local install of phpunit.
Run this.
phpunit --self-update
That should do it.
I was running phpunit version 4.7.*, but Symfony wanted to see phpunit 5.1.3.
You should clear the app/cache/test directory.
You could also make your global phpunit symlink to the one provided by Symfony located in vendor/phpunit/phpunit/phpunit
Update: I'm not sure what this error is referring to, I still get it, but seems to occur when I have a problem with a test. At the least, it's a confusing message.

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

Nginx PHP (5.5.1) FPM strange errors

At the moment I'm experimenting with Nginx.
I got it working using the newest version installed via repo.
Everything works fine with Nginx standalone.
Then I installed PHP 5.5.1 via sources that I can run different versions and not affection the production webserver and php version. (Nginx was running on another port then 80 for testing purposes.)
Everything went fine. Compiled PHP 5.5.1 without errors, installed it, started PHP-FPM and changed the Nginx config to call PHP FPM when needed. My first test website worked perfectly with this version. Then I tried to get running another website I created. I've changed only the document root for that.
Then I got very strange errors:
PHP Fatal error: Call to undefined function apache_request_headers() in [...]
Yes, not real an error... So I removed the function to test if the website works then smoothly when removing a function, which isn't available in PHP-FPM/FastCGI Mode.
Then another error showed in the logs when trying again:
PHP Parse error: syntax error, unexpected ''INSERT ' (T_ENCAPSED_AND_WHITESPACE) in [...]
After commenting out this variable (only for testing) another error occured:
PHP Parse error: syntax error, unexpected end of file, expecting ')' in [...]
So I don't know why those 2 errors occured. The first one is of course of the changed system; function not available.
So my main question is: Why is my code causing these errors with PHP 5.5.1 in FPM mode?
The website works perfectly on my local dev server (PHP 5.4 and Apache) and production Server (Apache 2.2 and PHP 5.4)... I have NO code changed (except config files for db etc). So is someone knowing what can cause this issue?
If you need more information, just ask!
Edit:
Error 1:
$sql = 'INSERT INTO ' . TABLE . '
(name)
VALUES
("' . $name . '")
ON DUPLICATE KEY UPDATE name=VALUES(name)';
Error 2:
'TEXT' => text::parse($row['text']),
Problem solved.
PHP rebuilt via source and used newest version (5.5.2).

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?

set phpstorm working

I'm trying to configure correctly phpstorm but I receive this error:
/Applications/MAMP/bin/php/php5.3.6/bin/php/private/var/folders/k9/kwf7lc153rngm1ky4_3948sc0000gn/T/ide-phpunit.php --no-configuration /Applications/MAMP/htdocs/FirstAid_jquerymobile
Testing started at 21:17 ...
Process finished with exit code 255
I installed phpunit but I don't even know which could be the error?
Usually PhpStorm produces this error when PHPUnit fails with fatal - check the PHP error log or run PHPUnit directly from CLI - it will help to localize the problem.

Resources