草庐IT

mock_func

全部标签

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 - 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 - 类上下文中的 call_user_func(定义了 $this)

有没有一种方法可以在对象的上下文中执行PHP5.3中的闭包?classTest{public$name='John';functiongreet(){eval('echo"Hello,".$this->name;');call_user_func(function(){echo"Goodbye,".$this->name;});}}$c=newTest;$c->greet();eval()可以正常工作,但是call_user_func将无法访问$this。(不在对象上下文中时使用$this)。我现在将“$this”作为参数传递给闭包,但这并不是我所需要的。

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 - call_user_func() 和 $var() 之间有区别吗?

call_user_func()和它的语法糖版本之间有什么区别吗...//Globalfunction$a='max';echocall_user_func($a,1,2);//2echo$a(1,2);//2//ClassmethodclassA{publicfunctionb(){return__CLASS__;}staticfunctionc(){return'Iamstatic!';}}$a=newA;$b='b';echocall_user_func(array($a,$b));//Aecho$a->$b();//A//Staticclassmethod$c='c';echo

php - 强制 func_get_args() 的结果是一个关联数组而不是 0-index

想知道是否有可能像func_get_args()(reference)那样调用,而不是生成一个0索引数组,而是生成一个关联数组,使用变量名作为key?例如:functionfoo($arg1,$arg2){var_dump(func_get_args());}foo('bar1','bar2');//Outputarray(2){[0]=>string(4)"bar1"[1]=>string(4)"bar2"}//Preferredarray(2){[arg1]=>string(4)"bar1"[arg2]=>string(4)"bar2"}我问的原因是,我需要验证这些作为数组传递给R

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');正确的做法是什么?

php - 从 call_user_func() 调用时,array_pop() 需要弃用的按引用调用

call_user_func('array_pop',$myarray);给出'参数1给array_pop()期望是一个引用,给定的值',而call_user_func('array_pop',&$myarray);给出“调用时间传递引用已被弃用”。那我该怎么办?我在Windows上使用的是“PHP5.3.5版”,无法关闭已弃用的警告。谢谢! 最佳答案 要么直接调用它:array_pop($myarray);或者使用call_user_func_array(),它接受一个引用数组作为参数,而不会对您大喊大叫调用时间传递引用:call

php - Laravel - call_user_func_array() 期望参数 1 是一个有效的回调

我收到这个错误:call_user_func_array()expectsparameter1tobeavalidcallback,class'Symfony\Component\HttpFoundation\LaravelRequest'doesnothaveamethod'url'我使用的代码是:路由.php:分数.php:classScores_ControllerextendsBase_Controller{public$restful=true;publicfunctionget_showscores(){//Imprimopantallacontabladeresultad