/** * Update BranchEmailConfiguration * * @param Command\BranchEmailConfigurationCommand $branchEmailConfigurationCommand * @return int */ public function updateBranchEmailConfiguration(Command\BranchEmailConfigurationCommand $branchEmailConfigurationCommand) { if ($this->getConfigurationByBranchId($branchEmailConfigurationCommand->branch)) { $branchEmailConfiguration = $this->getConfigurationByBranchId($branchEmailConfigurationCommand->branch); $branchEmailConfiguration->update($branchEmailConfigurationCommand->customerDomains, $branchEmailConfigurationCommand->supportAddress); } else { $branch = $this->branchRepository->get($branchEmailConfigurationCommand->branch); $branchEmailConfiguration = $this->branchEmailConfigurationFactory->create($branch, $branchEmailConfigurationCommand->customerDomains, $branchEmailConfigurationCommand->supportAddress); } $this->branchEmailConfigurationRepository->store($branchEmailConfiguration); return $branchEmailConfiguration->getId(); }
/** * @test */ public function updateBranchEmailConfigurationWhenNotExists() { $this->branchEmailConfigurationRepository->expects($this->exactly(1))->method('getByBranchId')->with($this->equalTo(self::DUMMY_BRANCH_ID))->will($this->returnValue(null)); $this->branchRepository->expects($this->once())->method('get')->with($this->equalTo(self::DUMMY_BRANCH_ID))->will($this->returnValue($this->branch)); $branchEmailConfigurationStub = new BranchEmailConfiguration($this->branch, self::DUMMY_CUSTOMER_DOMAINS, self::DUMMY_SUPPORT_ADDRESS); $this->branchEmailConfigurationFactory->expects($this->once())->method('create')->with($this->equalTo($this->branch), $this->equalTo(self::DUMMY_CUSTOMER_DOMAINS), $this->equalTo(self::DUMMY_SUPPORT_ADDRESS))->will($this->returnValue($branchEmailConfigurationStub)); $this->branchEmailConfigurationRepository->expects($this->once())->method('store')->with($this->equalTo($branchEmailConfigurationStub)); $command = new BranchEmailConfigurationCommand(); $command->branch = self::DUMMY_BRANCH_ID; $command->customerDomains = self::DUMMY_CUSTOMER_DOMAINS; $command->supportAddress = self::DUMMY_SUPPORT_ADDRESS; $this->branchEmailConfigurationServiceImpl->updateBranchEmailConfiguration($command); }