Exemple #1
0
 public function testAuthor()
 {
     $p = new Post();
     static::assertNull($p->getAuthor());
     $u = new User();
     static::assertCount(0, $u->getAuthoredPosts());
     $p->setAuthor($u);
     static::assertNotNull($p->getAuthor());
     static::assertSame($u, $p->getAuthor());
     static::assertCount(1, $u->getAuthoredPosts());
     static::assertContains($p, $u->getAuthoredPosts());
 }
Exemple #2
0
 /**
  * Sets the Post's author.
  *
  * Will add this Post to the Author's authored post list.
  *
  * @param User $author
  * @return Post
  *
  * @throws InvalidArgumentException
  */
 public function setAuthor($author)
 {
     if (!$author instanceof User) {
         throw new InvalidArgumentException('Author must be Instance of ' . User::class);
     }
     $this->author = $author;
     $author->addPost($this);
     return $this;
 }