/** @test */ public function should_fail_to_create_post_when_user_is_not_a_member() { $this->setExpectedException('Exception'); $thread = new Thread(ThreadId::generate(), $this->group, 'Hello World'); $post = $thread->createNewPost($this->user, 'Once upon a time...'); $this->assertInstanceOf('Cribbb\\Domain\\Model\\Discussion\\Post', $post); }
/** * Find a Thread by its id * * @param string $id * @return Thread */ private function findThreadById($id) { $thread = $this->threads->threadById(ThreadId::fromString($id)); if ($thread) { return $thread; } throw new ValueNotFoundException("{$id} is not a valid thread id"); }
/** * Load the fixtures * * @param ObjectManager $manager * @return void */ public function load(ObjectManager $manager) { $group = new Group(GroupId::generate(), 'Cribbb'); $id = ThreadId::fromString('d16f9fe7-e947-460e-99f6-2d64d65f46bc'); $thread = new Thread($id, $group, 'Hello World'); $manager->persist($thread); $manager->flush(); }
/** * 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(); }
/** @test */ public function should_add_new_thread() { $group = new Group(GroupId::generate(), 'Cribbb'); $id = ThreadId::generate(); $thread = new Thread($id, $group, 'Hello World'); $this->repository->add($thread); $this->em->clear(); $thread = $this->repository->threadOfId($id); $this->assertInstanceOf('Cribbb\\Domain\\Model\\Discussion\\ThreadId', $thread->id()); $this->assertEquals('hello-world', $thread->slug()); }
/** @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()); }
/** * Find a Thread by it's id * * @param ThreadId $id * @return Thread */ public function threadOfId(ThreadId $id) { return $this->em->getRepository($this->class)->findOneBy(['id' => $id->toString()]); }
/** * Start a new Thread * * @param User $user * @param string $subject * @return Thread */ public function startNewThread(User $user, $subject) { if ($this->members->contains($user)) { $thread = new Thread(ThreadId::generate(), $this, $subject); $this->threads[] = $thread; return $thread; } throw new Exception('This user is not a member of the Group!'); }
public function setUp() { $this->user = User::register(UserId::generate(), new Email('*****@*****.**'), new Username('username'), new HashedPassword('password')); $this->thread = new Thread(ThreadId::generate(), new Group(GroupId::generate(), 'Cribbb'), 'Hello World'); }
/** @test */ public function should_return_thread_id_as_string() { $id = ThreadId::fromString('d16f9fe7-e947-460e-99f6-2d64d65f46bc'); $this->assertEquals('d16f9fe7-e947-460e-99f6-2d64d65f46bc', $id->toString()); $this->assertEquals('d16f9fe7-e947-460e-99f6-2d64d65f46bc', (string) $id); }
/** * Set the id * * @param GroupId $id * @return void */ private function setId(ThreadId $id) { $this->id = $id->toString(); }