我有一个曾经运行良好的测试套件。它基于 FWOpenCartTest,它是 PHPUnit_Framework_TestCase 的一个大后代,实现了一个 MVC 框架(基于 OpenCart)。
今天我不得不向这样的后代添加一个实例化另一个类的调用,该类在内部分配一个 var 流,如下所示:
// register a variable stream wrapper
require_once( DIR_SYSTEM . 'library/variable_stream.php' );
$ok = stream_wrapper_register("var", "VariableStream");
if (!$ok) {
trigger_error("Failed to register protocol for a variable stream");
exit;
}
从那以后,我无法运行任何测试,因为我不断收到 PHPUnit 转储,例如:
phpunit ControllerAccountWishListTest.php
PHP Warning: stream_wrapper_register(): Protocol var:// is already defined. in /var/www/domain.tld/public_html/system/engine/factory.php on line 73
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP 4. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/php/PHPUnit/TextUI/Command.php:150
PHP 5. PHPUnit_Framework_TestSuite->__construct() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:142
PHP 6. PHPUnit_Framework_TestSuite->addTestMethod() /usr/share/php/PHPUnit/Framework/TestSuite.php:212
PHP 7. PHPUnit_Framework_TestSuite::createTest() /usr/share/php/PHPUnit/Framework/TestSuite.php:834
PHP 8. FWOpenCartTest->__construct() /usr/share/php/PHPUnit/Framework/TestSuite.php:473
PHP 9. Factory->__construct() /var/www/domain.tld/public_html/unittests/VisualPHPUnit/app/test/opencart/FW_OpenCartTest.php:41
PHP 10. stream_wrapper_register() /var/www/domain.tld/public_html/system/engine/factory.php:73
PHP Notice: Failed to register protocol for a variable stream in /var/www/domain.tld/public_html/system/engine/factory.php on line 75
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP 4. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/php/PHPUnit/TextUI/Command.php:150
PHP 5. PHPUnit_Framework_TestSuite->__construct() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:142
PHP 6. PHPUnit_Framework_TestSuite->addTestMethod() /usr/share/php/PHPUnit/Framework/TestSuite.php:212
PHP 7. PHPUnit_Framework_TestSuite::createTest() /usr/share/php/PHPUnit/Framework/TestSuite.php:834
PHP 8. FWOpenCartTest->__construct() /usr/share/php/PHPUnit/Framework/TestSuite.php:473
PHP 9. Factory->__construct() /var/www/domain.tld/public_html/unittests/VisualPHPUnit/app/test/opencart/FW_OpenCartTest.php:41
PHP 10. trigger_error() /var/www/domain.tld/public_html/system/engine/factory.php:75
这是导致错误的小测试:
<?php
require_once('FW_OpenCartTest.php');
class ControllerAccountWishListTest extends FWOpenCartTest {
public function testTheContentsOfALoggedInCustomersWishList() {
$controller = $this->loadControllerByRoute("account/wishlist");
$this->customerLogin('username@domain.tld','9a24b01674');
$controller->index();
$this->assertEquals(1, preg_match('/Your wish list is empty./', $this->getOutput()));
}
}
?>
我要问的是:这是 PHPUnit 和测试用例类 FWOpenCartTest 之间的交互吗?
完成的应用程序可以工作,如果我不使用 PHPUnit 而只是创建一个包装器来实例化测试它也可以工作。
如果有交互,有没有办法隐藏 stream_wrapper_register() 以便 FWOpenCartTest 的构造函数不会发现它已经分配?