使用Zend Framework 1.10和Doctrine 2(Beta1)启动项目.我在自己的库代码中使用命名空间.
生成代码覆盖率报告时,我收到有关重新声明类的致命错误.为了提供更多信息,我在我的phpunit可执行文件中注释掉了xdebug_disable()调用,这样你就可以看到函数trace(由于输出太多而禁用了局部变量输出).
这是我的终端输出:
$ phpunit
PHPUnit 3.4.12 by Sebastian Bergmann.
........
Time: 4 seconds, Memory: 16.50Mb
OK (8 tests, 14 assertions)
Generating code coverage report, this may take a moment.PHP Fatal error: Cannot redeclare class Cob\Application\Resource\HelperBroker in /Users/Cobby/Sites/project/trunk/code/library/Cob/Application/Resource/HelperBroker.php on line 93
PHP Stack trace:
PHP 1. {main}() /usr/local/zend/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/local/zend/bin/phpunit:54
PHP 3. PHPUnit_TextUI_Command->run() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:146
PHP 4. PHPUnit_TextUI_TestRunner->doRun() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:213
PHP 5. PHPUnit_Util_Report::render() /usr/local/zend/share/pear/PHPUnit/TextUI/TestRunner.php:478
PHP 6. PHPUnit_Framework_TestResult->getCodeCoverageInformation() /usr/local/zend/share/pear/PHPUnit/Util/Report.php:97
PHP 7. PHPUnit_Util_Filter::getFilteredCodeCoverage() /usr/local/zend/share/pear/PHPUnit/Framework/TestResult.php:623
Fatal error: … PHPUnit自己的手册有一些尚未写的部分,名为"操作"和"数据库测试最佳实践".
用于测试数据库的最佳实践是什么PHPUnit,特别是在MySQL?
当我跑:
peardev install phpunit/PHPUnit
Run Code Online (Sandbox Code Playgroud)
我得到以下内容:
No releases available for package "pear.phpunit.de/PHPUnit"
install failed
Run Code Online (Sandbox Code Playgroud)
我运行了以下内容:
pear channel-discover pear.phpunit.de
Channel "pear.phpunit.de" is already initialized
Run Code Online (Sandbox Code Playgroud)
和
pear install --alldeps phpunit/PHPUnit
No releases available for package "pear.phpunit.de/PHPUnit"
install failed
Run Code Online (Sandbox Code Playgroud)
和
pear remote-list -c phpunit
CHANNEL PHPUNIT AVAILABLE PACKAGES:
===================================
PACKAGE VERSION
DbUnit 1.0.2
File_Iterator 1.2.6
Object_Freezer 1.0.0
PHPUnit 3.5.14
PHPUnit_MockObject 1.0.9
PHPUnit_Selenium 1.0.3
PHP_CodeBrowser 1.0.0
PHP_CodeCoverage 1.0.4
PHP_Timer 1.0.0
PHP_TokenStream 1.0.1
Text_Template 1.1.0
bytekit 1.1.1
phpUnderControl 0.5.0
phpcpd 1.3.2
phpdcd 0.9.2
phploc 1.6.1
ppw …Run Code Online (Sandbox Code Playgroud) 我想测试一个调用具有相同名称的父方法的类方法.有没有办法做到这一点?
class Parent {
function foo() {
echo 'bar';
}
}
class Child {
function foo() {
$foo = parent::foo();
return $foo;
}
}
class ChildTest extend PHPUnit_TestCase {
function testFoo() {
$mock = $this->getMock('Child', array('foo'));
//how do i mock parent methods and simulate responses?
}
}
Run Code Online (Sandbox Code Playgroud) 我现在正在努力设置PhpStorm以进行单元测试.无论我做什么,我都会得到这个
Process finished with exit code 1
Cannot find PHPUnit in include path ...
Run Code Online (Sandbox Code Playgroud)
PHPUnit(通过命令行)可以从任何地方访问; 我已经设置了正确的包含路径,并将PHPUnit添加到外部库中.没有机会.
它是否可能或仅通过PEAR安装?我已经解决了所有相关问题,我在Mac上,PHPUnit通过CLI顺利运行.
我在使用phpunit时遇到了一些问题.当我执行测试时,phpunit给我这些警告:
1)警告在"Illuminate\Foundation\Testing\TestCase"类中没有找到测试.
2)警告在"TestCase"类中没有找到测试.
但是我想忽略这些文件,因此phpunit不会尝试从它们运行测试.
怎么做?
要求:
如何:
我一直在使用PHPUnit一段时间了,它开始看起来像我可能需要将我的测试分解为将作为单独执行的组运行phpunit.主要原因是我的大多数测试都需要在不同的进程中运行,而有些实际上不能在单独的进程中运行,因为这里记录了一个问题.我想做的是编写一个bash脚本,触发几个执行phpunit,每个执行配置为使用不同的设置运行不同的测试.
所以我的问题是:有没有办法聚合多次phpunit执行的代码覆盖率结果?我可以直接通过PHPUnit本身或使用其他工具吗?在phpunit使用PHPUnit的测试套件概念的一次运行中,是否有可能获得我正在寻找的东西?
我正在学习单元测试,我试图解决以下问题:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for zfcUserAuthentication
Run Code Online (Sandbox Code Playgroud)
...使用给出的唯一答案:
所以我的setUp函数看起来一样.不幸的是,我收到错误消息:
Zend\Mvc\Exception\InvalidPluginException: Plugin of type Mock_ZfcUserAuthentication_868bf824 is invalid; must implement Zend\Mvc\Controller\Plugin\PluginInterface
Run Code Online (Sandbox Code Playgroud)
它是由代码的这一部分引起的(在我的代码中以相同的方式分开):
$this -> controller->getPluginManager()
->setService('zfcUserAuthentication', $authMock); // Error refers to this line.
Run Code Online (Sandbox Code Playgroud)
$ authMock对象显然没有实现plugininterface,我需要实现它来传递到setService.
$ authMock是不是要通过那里,因为它用于单元测试?我应该使用不同的(面向单元测试的)setService方法吗?
我需要一种方法来处理登录到我的应用程序,或者我的单元测试毫无意义.
谢谢你的建议.
===编辑(11/02/2013)===
我想专注于这一部分以澄清,因为我认为这是问题领域:
// Getting mock of authentication object, which is used as a plugin.
$authMock = $this->getMock('ZfcUser\Controller\Plugin\ZfcUserAuthentication');
// Some expectations of the authentication service.
$authMock -> expects($this->any())
-> method('hasIdentity')
-> will($this->returnValue(true));
$authMock -> expects($this->any())
-> method('getIdentity')
-> …Run Code Online (Sandbox Code Playgroud)