Laravel 4 即使使用$this->;任何事

Laravel 4 即使使用$this->;任何事,laravel-4,mockery,Laravel 4,Mockery,我正在为一个Laravel控制器方法编写一个单元测试,但无论我如何使用(…)->使用(…)执行->操作,我都会得到NomatchingExpectationException异常。正在测试的代码: public function destroy($id) { $foo = FooService::foo($id); //returns a Foo object (an Eloquent model) $fooCollection = new Collection(array($foo))

我正在为一个Laravel控制器方法编写一个单元测试,但无论我如何使用(…)->使用(…)执行
->操作,我都会得到NomatchingExpectationException异常。正在测试的代码:

public function destroy($id) {
  $foo = FooService::foo($id); //returns a Foo object (an Eloquent model)
  $fooCollection = new Collection(array($foo));
  $response = FooService::archive($fooCollection);

  return Response::json($response);
}
单元测试:

public function testArchiveSingle() {
  $foo = Mockery::mock('Foo', array('id' => 1));
  $fooCollection = new \Illuminate\Database\Eloquent\Collection();
  $fooCollection->add($foo);

  FooService::shouldReceive('foo')->once()
      ->with(1)
      ->andReturn($foo);

  //here's the shouldReceive that's throwing the error:
  FooService::shouldReceive('archive')->once()
      ->with($this->anything())
      ->andReturn(array('result'=>'here'));

  $response = $this->action('DELETE', 'FoosController@destroy',
      array('site' => 12345, 'foos' => 1),
      array());
  $this->assertResponseOk();
  $this->assertTrue($response->headers->contains('Content-Type', 'application/json'));
  //other tests that are proprietary in nature go here
}
->with()
中,我尝试了传入
$fooCollection
$this->instanceOf('Collection')
$this->instanceOf('\illumb\Database\elount\Collection')
和其他一些东西。我还尝试将
$fooCollection
定义更改为仅
新集合

当我运行测试时,我得到:

Mockry\Exception\NoMatchingExpectationException:找不到Mockry\u 1\u FooService::archive(Illumb\Database\Eloquent\Collection)的匹配处理程序。该方法是意外的,或者其参数与此方法的预期参数列表不匹配


当我删除带有(…)的
->
时,Troublemy shouldReceive测试运行正常,但失去了价值,因为它不会捕获一个(理论上的)错误,而这个错误会意外地归档太多。

您应该使用
mockry::any()
来匹配任何参数。PHPUnit自己的模拟库使用
$this->anythis()
。看


不确定
$this->anythis()
应该做什么?尝试使用
mockry::any()
@BramGerritsen-Aha。我又溜进了直起的PHPUnit,这就造成了问题。这是有效的,
mockry::mustBe($fooCollection)
。如果你想把它作为答复,我会接受的。
FooService::shouldReceive('archive')->once()
  ->with(Mockery::any())
  ->andReturn(array('result'=>'here'));