Exemple #1
0
 /**
  * Load the fixtures
  *
  * @param ObjectManager $manager
  * @return void
  */
 public function load(ObjectManager $manager)
 {
     $user = User::register(UserId::generate(), new Email('*****@*****.**'), new Username('username'), new HashedPassword('qwerty'));
     $group = new Group(GroupId::generate(), 'Cribbb');
     $thread = new Thread(ThreadId::generate(), $group, 'Hello World');
     $post = new Post(PostId::fromString('d16f9fe7-e947-460e-99f6-2d64d65f46bc'), $user, $thread, 'Hello world.');
     $manager->persist($post);
     $manager->flush();
 }
Exemple #2
0
 /** @test */
 public function should_create_post()
 {
     $post = new Post(PostId::generate(), $this->user, $this->thread, 'Once upon a time...');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Discussion\\Post', $post);
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Discussion\\PostId', $post->id());
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Identity\\User', $post->user());
     $this->assertInstanceOf('Carbon\\Carbon', $post->createdAt());
     $this->assertEquals('Once upon a time...', $post->body());
 }
 /** @test */
 public function should_add_new_post()
 {
     $user = User::register(UserId::generate(), new Email('*****@*****.**'), new Username('username'), new HashedPassword('qwerty'));
     $group = new Group(GroupId::generate(), 'Cribbb');
     $thread = new Thread(ThreadId::generate(), $group, 'Hello World');
     $id = PostId::generate();
     $post = new Post($id, $user, $thread, 'Hello world');
     $this->repository->add($post);
     $this->em->clear();
     $post = $this->repository->postOfId($id);
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Discussion\\PostId', $post->id());
     $this->assertEquals('hello-world', $post->slug());
 }
Exemple #4
0
 /**
  * Set the id
  *
  * @param PostId $id
  * @return void
  */
 private function setId(PostId $id)
 {
     $this->id = $id->toString();
 }
 /**
  * Find a Post by it's id
  *
  * @param PostId $id
  * @return Post
  */
 public function postOfId(PostId $id)
 {
     return $this->em->getRepository($this->class)->findOneBy(['id' => $id->toString()]);
 }
Exemple #6
0
 /** @test */
 public function should_return_id_as_string()
 {
     $id = PostId::fromString('d16f9fe7-e947-460e-99f6-2d64d65f46bc');
     $this->assertEquals('d16f9fe7-e947-460e-99f6-2d64d65f46bc', $id->toString());
     $this->assertEquals('d16f9fe7-e947-460e-99f6-2d64d65f46bc', (string) $id);
 }
Exemple #7
0
 /**
  * Create new Post
  *
  * @param User $user
  * @param string $body
  * @return Post
  */
 public function createNewPost(User $user, $body)
 {
     if ($this->group->isMember($user)) {
         $post = new Post(PostId::generate(), $user, $this, $body);
         $this->posts[] = $post;
         return $post;
     }
     throw new Exception('This user is not a member of the Group!');
 }