PHPUnit and ZF1 - get errors in CLI

时间:2015-12-14 17:54:16

标签: php zend-framework phpunit

I'm working on very first set of unit tests for Zend Framework 1.12 controller. In one of test cases I have the following lines:

  $this->assertController('student-professor');
  $this->assertResponseCode(200);

that produces error:

 Failed asserting last controller used <""> was "student-professor"

As I understand something went wrong and there was redirection to error(?) controller probably. Anyway I would like to get more information about errors or exceptions.

In the bootstrap I added lines to output all errors and redirect error messages to stdout, because I'm running tests from CLI

$cur_error_log = ini_get( 'error_log' );
ini_set( 'error_log', '/dev/stdout' );
error_log( 'This is a message from error_log()' );

ini_set('error_reporting', E_ALL); // or error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

However, I still don't receive any error messages. What can be the cause of this failed asserting and how to get more detailed info about it?

1 个答案:

答案 0 :(得分:1)

您可以在https://github.com/zendframework/zf1/blob/c57660e57755ec9920ac90d0e1cad5b6dc7fcfe1/library/Zend/Test/PHPUnit/ControllerTestCase.php#L937

中看到

有“$ this-&gt; request-&gt; getControllerName()”返回一个空字符串,你必须调用dispatch,就像在zf1文档中一样。

http://framework.zend.com/manual/1.12/de/zend.test.phpunit.html

希望这可以帮助你=)