Exemplo n.º 1
0
 /**
  * Find a Group by its id
  *
  * @param string $id
  * @return Group
  */
 private function findGroupById($id)
 {
     $group = $this->groups->groupById(GroupId::fromString($id));
     if ($group) {
         return $group;
     }
     throw new ValueNotFoundException("{$id} is not a valid group id");
 }
Exemplo n.º 2
0
 /**
  * Create a new Group
  *
  * @param User $user
  * @param string $name
  * @return Group
  */
 public function create(User $user, $name)
 {
     $this->checkNameIsUnique($name);
     $group = new Group(GroupId::generate(), $name);
     $group->addAdmin($user);
     $this->groups->add($group);
     return $group;
 }
Exemplo n.º 3
0
 /**
  * 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();
 }
Exemplo n.º 4
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();
 }
 /** @test */
 public function should_add_new_group()
 {
     $this->repository->add(new Group(GroupId::generate(), 'Cribbb'));
     $this->em->clear();
     $group = $this->repository->groupOfName('Cribbb');
     $this->assertInstanceOf('Cribbb\\Domain\\Model\\Groups\\GroupId', $group->id());
     $this->assertEquals('Cribbb', $group->name());
     $this->assertEquals('cribbb', $group->slug());
 }
 /** @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());
 }
Exemplo n.º 7
0
 /** @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());
 }
Exemplo n.º 8
0
 /** @test */
 public function should_return_group_id_as_string()
 {
     $id = GroupId::fromString('d16f9fe7-e947-460e-99f6-2d64d65f46bc');
     $this->assertEquals('d16f9fe7-e947-460e-99f6-2d64d65f46bc', $id->toString());
     $this->assertEquals('d16f9fe7-e947-460e-99f6-2d64d65f46bc', (string) $id);
 }
Exemplo n.º 9
0
 /** @test */
 public function should_throw_exception_when_non_member_attempts_to_create_thread()
 {
     $this->setExpectedException('Exception');
     $group = new Group(GroupId::generate(), 'Cribbb');
     $thread = $group->startNewThread($this->user, 'Hello World');
 }
Exemplo n.º 10
0
 public function setUp()
 {
     $this->group = new Group(GroupId::generate(), 'Cribbb');
     $this->user = User::register(UserId::generate(), new Email('*****@*****.**'), new Username('username'), new HashedPassword('password'));
 }
Exemplo n.º 11
0
 /**
  * Set the Group's id
  *
  * @param GroupId $id
  * @return void
  */
 private function setId(GroupId $id)
 {
     $this->id = $id->toString();
 }
Exemplo n.º 12
0
 /**
  * Find a Group by it's id
  *
  * @param GroupId $id
  * @return Group
  */
 public function groupOfId(GroupId $id)
 {
     return $this->em->getRepository($this->class)->findOneBy(['id' => $id->toString()]);
 }
Exemplo n.º 13
0
 /** @test */
 public function should_become_an_admin_of_a_group()
 {
     $user = User::register(UserId::generate(), new Email('*****@*****.**'), new Username('zuck'), new HashedPassword('facemash'));
     $group = new Group(GroupId::generate(), 'Porcellian');
     $this->assertEquals(0, $group->admins()->count());
     $this->assertEquals(0, $user->adminOf()->count());
     $user->addAsAdminOf($group);
     $this->assertEquals(1, $group->admins()->count());
     $this->assertEquals(1, $user->adminOf()->count());
 }
Exemplo n.º 14
0
 /**
  * Load the Group fixtures
  *
  * @param ObjectManager $manager
  * @return void
  */
 public function load(ObjectManager $manager)
 {
     $group = new Group(GroupId::fromString('d16f9fe7-e947-460e-99f6-2d64d65f46bc'), 'Cribbb');
     $manager->persist($group);
     $manager->flush();
 }