PHPUNIT MOCK设置时间 expectation 覆盖
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());
}
public function test_items_can_expire()
{
Carbon::setTestNow(Carbon::now());
$store = new ArrayStore;
$store->put('foo', 'bar', 10);
Carbon::setTestNow(Carbon::now()->addSeconds(10)->addSecond());
$result = $store->get('foo');
$this->assertNull($result);
Carbon::setTestNow(null);
}
摘自原文www.cnblogs.com/eleven24/p/1064049...
本作品采用《CC 协议》,转载必须注明作者和本文链接