4
votes

Hi I am currently running through the ZF2 User Guide trying to run a PHPUnit Test on the skeleton application as outlined here http://zf2.readthedocs.org/en/latest/user-guide/unit-testing.html.

But even though I have not edited the Module and have copied all the files from the tutorial every time I run the PHPUnit Test in Zend Studio I get this error

Error:

Fatal error: Class 'ApplicationTest\Bootstrap' not found in C:\Program Files (x86)\Zend\Apache2\htdocs\exerciseDB\module\Application\test\ApplicationTest\Controller\IndexControllerTest.php on line 24

But when I click on the Bootstrap::getServiceManager(); on line 24 Zend Studio takes me to the correct method.

File Stucture:

module
|_Application
    |_config
    |_language
    |_src
    |_test
       |_ApplicationTest
       |    |_Controller
       |        |_IndexControllerTest.php
       |_Bootstrap.php
       |_phpunit.xml.dist
       |_TestConfig.php.dist

Can anyine tell me where I am going wrong?

3

3 Answers

0
votes

This was a really annoying bug that is somewhat of an irritation. Your phpunit config seems to be changed slightly from the one on the skeleton application. To give you direct answer that fixed my issue I did the following...

module
|_Application
    |_config
    |_language
    |_src
    |_tests
       |_ZendApplicationModule
       |    |_Framework
       |        |TestCase.php
       |    |_IndexControllerTest.php
       |    |_SampleTest.php
       |_Bootstrap.php
       |_phpunit.xml.dist
       |_TestConfig.php.dist

With the base setup as outlined above from the skeleton APP I had to add

require_once 'Framework/TestCase.php';

To SampleTest.php

For your actual fix you will need to require_once the file that is generating the issue. That should fix it.

Also make sure to update your autoload_classmap.php

0
votes

I ran into the same issue where phpunit was not seeing my "module/Application/test/phpunit.xml.dist" file (I had it miss-spelled)

Try adding the file directly to the command line: phpunit --bootstrap Bootstrap.php .

0
votes

I had the issue as well.

I solved it by running phpunit from the root of my ZF2 project with the following arguments:

 ./vendor/bin/phpunit
  --bootstrap ./module/Rest/test/Bootstrap.php

One can also specify the Test suite to use:

 ./vendor/bin/phpunit
  --bootstrap ./module/Rest/test/Bootstrap.php
  ./module/Rest/test/RestTest/Controller/RestControllerTest.php

more details here