我试图嘲笑Carbon::parse($date)->format("Y")
,但我不知道该怎么做。
这是我到目前为止所拥有的:
public function testGetYear2014FromPost()
{
$mock = Mockery::mock("DateFormatter");
$mock->shouldReceive("parse")
->with("2014-02-08 16:23:33")
->once()
->andReturn($mock);
$mock->shouldReceive("format")
->with("Y")
->once()
->andReturn("2014");
$this->article->setDateFormatter($mock);
$this->assertEquals("2014", $this->article->getYear());
}