cheeps = \Mockery::mock(CheepRepository::class); $this->authors = \Mockery::mock(AuthorRepository::class); $this->cheepService = new CheepService($this->authors, $this->cheeps); } /** @test */ public function itRaisesExceptionWhenAuthorNotFound(): void { $this->expectException(\RuntimeException::class); $this->authors->allows('ofUserName')->andReturns(null); $this->cheepService->postCheep('irrelevant', 'irrelevant'); } /** @test */ public function itShouldAddCheep(): void { $this->authors->allows('ofUsername')->andReturns(self::anAuthor()); $this->cheeps->expects('add'); $cheep = $this->cheepService->postCheep('irrelevant', 'message'); $this->assertNotNull($cheep); $this->assertEquals(1, $cheep->authorId()); $this->assertEquals('message', $cheep->message()); } private static function anAuthor(): Author { $author = Author::create('irrelevant'); $author->setId(1); return $author; } } //end-snippet