예제 #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
 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));
 }