[英]PHPUnit displays Maximum function nesting level of '100' reached, aborting
i'm new to unit test and i'm trying to make work a first test ! 我是单元测试的新手,我正努力让工作成为第一次测试!
I get this long error twice: 我两次得到这个长错误:
Fatal Error :Maximum function nesting level of '100' reached, aborting in
C:\wamp\www\portailmg\dev\library\Zend\Test\PHPUnit\ControllerTestCase.php on line 27
9
My bootstrap.php: 我的bootstrap.php:
<?php
error_reporting( E_ALL | E_STRICT );
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/London');
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../applications/portail'));
define('APPLICATION_ENV', 'development');
define('LIBRARY_PATH', realpath(dirname(__FILE__) . '/../library'));
define('TESTS_PATH', realpath(dirname(__FILE__)));
$_SERVER['SERVER_NAME'] = 'http://localhost';
$includePaths = array(LIBRARY_PATH, get_include_path());
set_include_path(implode(PATH_SEPARATOR, $includePaths));
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
Zend_Session::$_unitTestEnabled = true;
Zend_Session::start();
my phpunit.xml: 我的phpunit.xml:
<phpunit bootstrap="./bootstrap.php" colors="false">
<testsuite name="MyApp">
<directory>./application/</directory>
<directory>./library/</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">../application</directory>
<directory suffix=".php">../library/Custom</directory>
<exclude>
<directory suffix=".phtml">../application/views</directory>
<file>../application/Bootstrap.php</file>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./log/coverage" charset="UTF-8"
yui="true" highlight="false" lowUpperBound="35" highLowerBound="70"/>
</logging>
</phpunit>
ControllerTestCase.php ControllerTestCase.php
<?php
class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
public $application;
public function setUp()
{
$this->application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '\configs\application.ini'
);
$this->bootstrap = array($this, 'bootstrap');
parent::setUp();
}
public function tearDown()
{
Zend_Controller_Front::getInstance()->resetInstance();
$this->resetRequest();
$this->resetResponse();
$this->request->setPost(array());
$this->request->setQuery(array());
}
}
?>
HomeControllerTest.php HomeControllerTest.php
<?php
require_once 'application/ControllerTestCase.php';
require_once 'application/controllers/HomeControllerTest.php';
class HomeControllerTest extends ControllerTestCase
{
public function testLoginAction()
{
$this->dispatch('/index/logincra'); //distribuer l'URL à tester en utilisant la méthode dispatch()
$this->assertController('index'); //spécifie le controller à tester
$this->assertAction('logincra'); //spécifie l'action à tester
/*
Assert against DOM selection; should contain exact number of nodes
param: string $path CSS selector path
param: string $count Number of nodes that should match
param: string $message
return: void
*/
$this->assertQueryCount('div.login', 1);
}
public function testlogincraAction()
{
$this->getRequest()
->setMethod('POST')
->setPost(array("username" => "example@example.com",
"password" => "password"));
$this->dispatch('/index/logincra');
$oLdap = new Mediagong_Ldap_Connect($_POST["username"], $_POST["password"]);
$this->assertEquals($oLdap->isLoggin(), true);
$this->assertRedirectTo('/index');
}
}
Arborescence: 树状:
dev
applications
portail
configs
controllers
layouts
models
services
views
Bootstrap.php
htdocs
..
..
tests
application
controllers
controllerTestCase.php
library
log
bootstrap.php
phpunit.xml
Thanks in advance for your help 在此先感谢您的帮助
In case you are using Xdebug you might want to increase the max_nesting_level
. 如果您使用Xdebug,可能需要增加
max_nesting_level
。 Have a look at the Xdebug manual 看看Xdebug手册
xdebug.max_nesting_level
xdebug.max_nesting_level
Type: integer, Default value: 100
类型:整数,默认值:100
Controls the protection mechanism for infinite recursion protection.
控制无限递归保护的保护机制。 The value of this setting is the maximum level of nested functions that are allowed before the script will be aborted.
此设置的值是在中止脚本之前允许的嵌套函数的最大级别。
Just add the value to your php.ini
. 只需将值添加到
php.ini
。 I have mine at around 250 depending on the amount of tests you run and their complexity. 根据您运行的测试数量及其复杂程度,我的情况大约为250。
A simple solution solved my problem. 一个简单的解决方案解决了我 I just commented the:
我刚才评论说:
"zend_extension = "d:/wamp/bin/php/php5.3.8/zend_ext/php_xdebug-2.1.2-5.3-vc9.dll" “zend_extension =”d:/wamp/bin/php/php5.3.8/zend_ext/php_xdebug-2.1.2-5.3-vc9.dll“
in php.ini file. 在php.ini文件中。 This extension was limiting the stack to 100 so I disabled it.
此扩展将堆栈限制为100,因此我禁用了它。 The recursive function is now working as anticipated.
递归函数现在正如预期的那样工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.