function it_does_not_create_an_organization_because_user_does_not_exist(CreateOrganizationCommand $command, UserRepository $userRepository)
 {
     $command->id()->shouldBeCalled()->willReturn(null);
     $command->creatorId()->shouldBeCalled()->willReturn('user-id');
     $userRepository->userOfId(Argument::type(UserId::class))->shouldBeCalled()->willReturn(null);
     $this->shouldThrow(UserDoesNotExistException::class)->during__invoke($command);
 }
示例#2
0
 public function __invoke(CreateOrganizationCommand $command)
 {
     if (null !== ($id = $command->id())) {
         $organization = $this->repository->organizationOfId(OrganizationId::generate($id));
         if ($organization instanceof Organization) {
             throw new OrganizationAlreadyExistsException();
         }
     }
     $user = $this->userRepository->userOfId(UserId::generate($command->creatorId()));
     if (!$user instanceof User) {
         throw new UserDoesNotExistException();
     }
     $organizationId = OrganizationId::generate($command->id());
     $organization = new Organization($organizationId, new OrganizationName($command->name()), new Slug(null === $command->slug() ? $command->name() : $command->slug()), $user->id());
     $this->repository->persist($organization);
 }