草庐IT

mocking-comparison-part

全部标签

php - mock 重载类缺少方法

在使用Mockery时需要一些帮助-我想重载一个类,该类是在一个方法中使用newHelperUtil()创建的。使用Mockeryoverload我可以做到这一点,但它给我留下了一个空的shell类。然后我似乎必须创建所有被调用的方法。有没有办法创建一个重载的完整模拟,然后只更改一个方法?$mock=\Mockery::mock('overload:'.HelperUtil::class);$mock->shouldReceive('content')->andReturnUsing(function(){return'differentcontent';});谢谢编辑:我想我想做的是

php - mock & PHPUnit : method does not exist on this mock object

你能告诉我问题出在哪里吗?我有一个包含以下测试的GeneratorTest.php文件:shouldReceive('put')->with('foo.txt','foobar')->once();$generator=newGenerator($fileMock);$generator->fire();}publicfunctiontestGeneratorDoesNotOverwriteFile(){$fileMock=\Mockery::mock('\stats\jway\File');$fileMock->shouldReceive('exists')->once()->and

PHP XML Expat 解析器 : how to read only part of the XML document?

我有一个具有以下结构的XML文档:helloclienttimehelloclienthowcanIhelp?operatortimegoodmorningclienttimegoodmorninghowcanIhelp?operatortime我能够创建解析器并打印出整个文档,但问题是我只想打印(用户)节点和具有特定属性(id)的子节点。我的PHP代码是:if(!empty($_GET['id'])){$id=$_GET['id'];$parser=xml_parser_create();functionstart($parser,$element_name,$element_att

php - mock 对象参数验证问题

考虑示例类(很抱歉它太复杂了,但它尽可能简洁):classRecordLookup{private$records=[13=>'foo',42=>'bar',];function__construct($id){$this->record=$this->records[$id];}publicfunctiongetRecord(){return$this->record;}}classRecordPage{publicfunctionrun(RecordLookup$id){return"Recordis".$id->getRecord();}}classApp{function__c

php - Mock 应该恰好被调用 1 次但被调用 0 次

我在使用Laravel5和PHPUnit时遇到了奇怪的问题。当我尝试模拟Laravel的外观(例如Auth、View、Mail)时,我总是得到这个异常:Mockery\Exception\InvalidCountException:Methodsend("emails.register",array('user'=>'object(MCC\Models\Users\User)',),object(Closure))fromMockery_0_Illuminate_Mail_Mailershouldbecalledexactly1timesbutcalled0times.我对"shoul

php - WordPress 编辑 php get_template_part() 和 get_post_format() 函数

我只想加载没有标题、日期、评论等信息的帖子内容。有没有办法只抓帖子? 最佳答案 简单替换:与:前者正在寻找类似content-status.php或content-aside.php的东西,或者最有可能的是,在普通的旧“帖子”的情况下,content.php在您的主题根目录中。 关于php-WordPress编辑phpget_template_part()和get_post_format()函数,我们在StackOverflow上找到一个类似的问题: http

PHP "Warning: usort() [function.usort]: Invalid comparison function"排序

我有以下数据作为关联数组array'abc'=>array'label'=>string'abc'(length=3)'weight'=>float3'wsx'=>array'label'=>string'wsx'(length=3)'weight'=>float1'qay'=>array'label'=>string'qay'(length=3)'weight'=>float1'http://test.com'=>array'label'=>string'http://test.com'(length=15)'weight'=>float0'Nasi1'=>array'label'=

php - get_template_part 和 get_footer 的一页 wordpress 问题

我想做的是在wordpress中转换我的一页设计,我认为能够在单独的页面中编辑、添加和修改页面的不同部分会很好。单页网站将按菜单排序(ID为main)。按照我使用的wp-codexget_template_part,它应该可以正常工作,因为它应该:Loadatemplatepartintoatemplate(otherthanheader,sidebar,footer)get_header被跳过,但get_footer被执行并且网站呈现不正确。front-page.php$pages=wp_get_nav_menu_items('main');global$post;foreach($

php - paypal-php-sdk 中的 PayPal-Mock-Response

如何使用paypal-php-sdk进行负面测试。我尝试将header添加到api上下文,但总是收到此响应:{"name":"INVALID_NEGATIVE_TESTING_INPUT","message":"Invalidinputfound.Seethefollowingsupportedcases.","links":[{"href":"https://developer.paypal.com/docs/api/nt-rest/","rel":"information_link"}],"details":[{"issue":"YoumustuseavalidURLsupport

php - CakePHP/phpunit : how to mock a file upload

我正在尝试为端点编写测试,该端点需要带有附加CSV文件的发布请求。我知道像这样模拟发布请求:$this->post('/foo/bar');但我不知道如何添加文件数据。我尝试手动设置$_FILES数组,但没有成功...$_FILES=['csvfile'=>['tmp_name'=>'/home/path/to/tests/Fixture/csv/test.csv','name'=>'test.csv','type'=>'text/csv','size'=>335057,'error'=>0,],];$this->post('/foo/bar');正确的做法是什么?