简体   繁体   中英

Zend Framework 2 PHPUnit Test Error

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?

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

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM