草庐IT

PHPUnit_Invoker

全部标签

php - 为什么模拟的 returnValue 在 phpunit 的拆卸中不起作用?

在我的测试类的设置中,我为用户创建了一个模拟对象。创建模拟时,它会执行如下操作:$other=$this->getMock('Other');$user->expects($this->any())->method('_getOtherInstance')->will($this->returnValue($other));现在在删除用户时调用_getOtherInstance删除三级信息。当我在测试类的tearDown中运行删除时,在parent::tearDown之前,_getOtherInstance返回null.我知道模拟已正确设置,因为在setUp中运行delete可以正常工

php - 在安装了 Twig 的 PHPUnit 中进行单元测试

当我运行PHPUnit时,它会尝试在意想不到的位置(即Twig安装目录)运行测试文件,并多次尝试加载Twig类文件。有谁知道如何解决这些问题?背景我正在使用Twig(只是Twig,不是Symfony)在网络应用程序中,通过Composer安装Twig。Composer和Twig安装在自定义位置,我的测试在/test/中,所以我有以下简化的项目结构:/src/includes/vendor/autoload.phpcomposer/twig/twig/lib/test//test/bootstrap.php(variousfilesnamed,e.g.,someClassTest.php

Phpunit 在 Laravel 中测试具有部分 View 的表单时抛出错误

我最近开始编写单元测试,所以这个概念本身对我来说仍然不是很清楚,我正在尝试通过为我目前正在从事的项目编写单元测试来学习它。我已经测试了认证,一切正常;但是,当我想测试表单提交时,它会抛出以下错误:'ErrorException',消息为'Undefinedvariable:errors'当我调试时,我发现View变量$errors没有为Phpunit定义。我正在测试的表单被抽象为局部View,以便从中引用以进行CREATE/UPDATE,但事实证明Phpunit无法处理局部View。当我评论@include('view.name')形成我正在测试的View时,我已经测试过它。我的问题是

PHPUnit 测试写入文件的函数并将内容检查到创建的文件中

我正在为sonata/exporter做贡献,一个用于以多种格式(CSV、JSON、XML、XLS等)导出数据的库。我致力于通过封装另一个Writer(如CsvWriter或XlsWriter)将bool值转换为字符串(例如yes/no)的Writer。这是我第一次使用phpunit。对现有Writer进行的所有单元测试都使用此逻辑:-创建一个文件。-使用相应的格式将数据写入文件。-在file_get_contents(filename)上创建一个assertEquals。所以,我写了这个测试:publicfunctionsetUp(){$this->filename='formate

PHPUnit 在应该为 200 时返回 404

我以前从未编写过测试用例,现在正尝试为我编写的API编写测试用例。我正在尝试使用post请求调用路由,因此我使用了以下内容:publicfunctiontestRequestCorrectApiKey(){//RequestwithX-AuthorizationsendingcorrectAPIKey$response=$this->call('POST','/authenticate',['email'=>'testingphpunit@phpunittest.com','password'=>'phpunittest',[],[],['X-Authorization'=>'123w

PHPUnit 静默失败

当我单独运行$phpunit时,它默默地失败了,这就是我试图知道问题所在但没有​​运气:$phpunit$echo$?=>255$php-i|grep错误display_errors=>STDOUT=>STDOUTdisplay_startup_errors=>On=>Onerror_append_string=>novalue=>novalueerror_log=>/usr/local/var/log/php_error.log=>/usr/local/var/log/php_error.logerror_prepend_string=>novalue=>novalueerror_r

php - 当我从 phpunit 登录时,当前用户的对象在 Symfony Controller 中为 NULL

我有PHPUnit的登录功能,并使用它作为测试用户进行授权。privatefunctionlogIn(Client$client){$session=$client->getContainer()->get('session');/**@varUser$user*/$user=$client->getContainer()->get('doctrine')->getRepository('DWDAdminBundle:User')->find(1);//HereIhaveuserobject$firewall='main';$token=newUsernamePasswordToken

PHPUnit 数据提供程序参数计数错误

我刚刚开始使用PHPUnit。到目前为止,除了DataProvider问题外,一切都很完美。问题是当我运行测试时,它通过了。但是,如果我再次运行它,它会失败并出现以下错误:ArgumentCountError:ToofewargumentstofunctionValidationTest::testValidateType(),0passedandatleast3expected如果我对数据提供程序函数进行任何更改(即更改要返回的数据、提供程序函数名称等)并重新运行,它会通过一次并失败,并在所有连续测试运行中出现上述错误。我使用的是最新版本的PHPUnit(一小时前更新)。不幸的是,我

php - 无法在 codeigniter 上运行 phpunit 测试,找不到 CI 错误

我在codeigniter上运行phpunittest,我有一个包含这段代码的admin_test.php文件。classAdmin_testextendsPHPUnit_Framework_TestCase{private$CI;publicfunction__construct(){//createinstancevariable$this->CI=&get_instance();}publicfunctiontestRenderReturnsHelloWorld(){$this->CI->load->controller('admin');$data=$this->admin->

php - 使用 PHPUnit 对 Doctrine 对象进行单元测试

我开始尝试使用PHPUnit测试我的Doctrine对象,并且希望每次都从我的模型对象重新加载数据库。我的第一次尝试看起来像这样:classTests_UserextendsPHPUnit_Framework_TestCase{publicfunctionsetUp(){Doctrine_Manager::connection('mysql://user:pass@localhost/testdb');Doctrine::createDatabases();Doctrine::createTablesFromModels('../../application/models');}pub