0

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.

2
  • Try laravel homestead, it works out of the box and if you will have the same problem - we will know your/default settings to help. thanks. Commented Mar 2, 2016 at 23:21
  • Post the code that the first error is referring to and backtrack from there. If phpunit returns an error by itself, post that as well. Commented Apr 28, 2016 at 4:56

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.