public function addPost(Post $post) { if ($post->getAuthor() !== $this) { throw new DomainException('Author is not allowed'); } if ($this->hasPost($post)) { throw new DomainException('Post already added'); } $this->posts->add($post); }
public function testConstruct() { // arrange $author = $this->createAuthor(); // act $post = new Post($author, 'Title of post', 'Text of post'); // assert $this->assertEquals('Title of post', $post->getTitle()); $this->assertEquals('Text of post', $post->getText()); $this->assertSame($author, $post->getAuthor()); $this->assertTrue($author->getPosts()->contains($post)); }