コード例 #1
0
ファイル: User.php プロジェクト: nebuchar/ddd-blog
 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);
 }
コード例 #2
0
ファイル: PostTest.php プロジェクト: nebuchar/ddd-blog
 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));
 }