/** * @test */ public function itShouldConstructTheCommand() { $command = CreateUserCommand::create($this->userId, $this->user, $this->language, $this->context); $this->assertEquals($this->userId, $command->getId()); $this->assertEquals($this->user, $command->getOriginalUser()); $this->assertEquals(CreateUserCommand::NAME, $command->getCommandName()); $this->assertEquals($this->context, $command->getContext()); $this->assertEquals($this->language, $command->getPreferredLanguage()); }
public function setUp() { $faker = Factory::create(); $this->userId = new ApplicationUserId($faker->uuid); $this->userName = $faker->userName; $this->language = $faker->countryISOAlpha3; $this->account = \Mockery::mock(Account::class); $this->user = \Mockery::mock(SourcedUser::class); $this->command = CreateUserCommand::create($this->userId, $this->user, $this->language); $this->userFactory = \Mockery::mock(UserFactory::class); $this->accountFactory = \Mockery::mock(AccountFactory::class); $this->userRepository = \Mockery::spy(UserEventSourcedRepository::class); $this->errorHandler = \Mockery::spy(ErrorEventHandler::class); $this->serviceUnderTest = new MessageAppCommandHandler($this->userFactory, $this->userRepository, $this->accountFactory, $this->errorHandler); }
/** * Handles a CreateUserCommand * * @param CreateUserCommand $command */ public function handleCreateUserCommand(CreateUserCommand $command) { $user = null; $originalUser = $command->getOriginalUser(); ContextContainer::setContext($command->getContext()); try { $user = $this->createUser($command->getId(), $originalUser, $command->getPreferredLanguage()); $this->userManager->save($user); $this->logger->info('User Created'); } catch (\Exception $e) { $this->logger->error('Error creating the user'); $this->errorHandler->handle(new UnableToCreateUserEvent($command->getId(), new UndefinedApplicationUser($this->accountFactory->build($originalUser))), $command->getContext()); } ContextContainer::reset(); }