public function testOverrideExpectation() { // 如果没有指定 expectation 调用次数, 那么每次调用 mock 的 expectation 方法都会返回第一个 expectation $mock = \Mockery::mock(); $mock->shouldReceive('foo')->andReturn('green'); $mock->shouldReceive('foo')->andReturn('blue'); $this->assertEquals('green', $mock->foo()); // 第一个 expectation 指定了只调用一次, 所以下面第二次调用的时候返回了 blue $mock = \Mockery::mock(); $mock->shouldReceive('foo')->once()->andReturn('green'); $mock->shouldReceive('foo')->andReturn('blue'); $this->assertEquals('green', $mock->foo()); $this->assertEquals('blue', $mock->foo()); }