Phpunit throws Optional PHPUnit_Framework_Exception

I have a Zend Framework project and want to use unit testing to test it.

In the test folder, I have phpunit.xml as shown below:

 <phpunit bootstrap="./application/bootstrap.php" colors="true"> <testsuite name="Application Test Suite"> <directory>./</directory> </testsuite> <filter> <whitelist> <directory suffix=".php">../application/</directory> <exclude> <directory suffix=".phtml">../application/</directory> <file>../application/Bootstrap.php</file> <file>../application/controllers/ErrorController.php</file> </exclude> </whitelist> </filter> <logging> <log type="coverage-html" target="./log/reprot" charset="UTP-8" yui="true" highlight = "true" lowUpoerBound="50" highLowerBound="80"/> <log type="textdox" target="./log/testdox.html" /> </logging> 

And I have bootstrap.php in the / tests / application folder, as shown below:

  <?php error_reporting(E_ALL | E_STRICT); // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), ))); require_once 'Zend/Loader/Autoloader.php'; require_once 'controllers/ControllerTestCase.php'; Zend_Loader_Autoloader::getInstance(); 

when i go to command prompt run the following command

 phpunit --configuration phpunit.xml 

it throws an exception:

  PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message
 'Neither "Application Test Suite.php" nor "Application Test Suite.php" could be
 opened. '  in D: \ PHP \ php5 \ PEAR \ PHPUnit \ Util \ Skeleton \ Test.php: 102
 Stack trace:
 # 0 D: \ PHP \ php5 \ PEAR \ PHPUnit \ TextUI \ Command.php (157): PHPUnit_Util_Skeleton_Test-
 > __ construct ('Application Tes ...', '')
 # 1 D: \ PHP \ php5 \ PEAR \ PHPUnit \ TextUI \ Command.php (129): PHPUnit_TextUI_Command-> run
 (Array, true)
 # 2 D: \ PHP \ php5 \ phpunit (53): PHPUnit_TextUI_Command :: main ()
 # 3 {main}
   thrown in D: \ PHP \ php5 \ PEAR \ PHPUnit \ Util \ Skeleton \ Test.php on line 102 

How can i fix this?

+6
source share
3 answers

You will notice that he threw an exception because he is looking for a file with a name just like the name you provided for his test suite. You need to write a test suite, and then specify the name of this test suite in your config: http://www.phpunit.de/manual/3.2/en/organizing-test-suites.html

+5
source

I had the same problem with the same setup. From what I understand, more recent versions of PHPUnit require at least one actual test to work correctly. After creating a simple test, it worked.

MyProject / tests / applications / DemoTest.php

 <?php class DemoTest extends ControllerTestCase { public function setUp() { parent::setUp(); } public function testCanDoUnitTest() { $this->assertTrue(true); } } 
+7
source

I noticed that you are not using <testsuites> , which contains several occurrences of <testsuite> .

Here is my phpunit.xml, which is great for Zend Framework projects:

 <testsuites> <testsuite name="UnitTests"> <directory>./library</directory> </testsuite> <testsuite name="ApplicationTests"> <directory>./application</directory> </testsuite> </testsuites> 
0
source

Source: https://habr.com/ru/post/886616/


All Articles