diff --git a/src/Customer/Infrastructure/Repository.php b/src/Customer/Infrastructure/Repository.php index ed162161..b902935e 100644 --- a/src/Customer/Infrastructure/Repository.php +++ b/src/Customer/Infrastructure/Repository.php @@ -91,7 +91,7 @@ public function getCustomerByPasswordUpdateId(string $passwordUpdateId): EshopUs { $user = $this->oxNewFactory->getModel(EshopUserModel::class); $user = $user->loadUserByUpdateId($passwordUpdateId); - if (!$user->isLoaded()) { + if (!$user instanceof EshopUserModel || !$user->isLoaded()) { throw new CustomerNotFoundByUpdateId($passwordUpdateId); } diff --git a/tests/Unit/Customer/Infrastructure/RepositoryTest.php b/tests/Unit/Customer/Infrastructure/RepositoryTest.php index 45917c2b..9489e377 100644 --- a/tests/Unit/Customer/Infrastructure/RepositoryTest.php +++ b/tests/Unit/Customer/Infrastructure/RepositoryTest.php @@ -58,7 +58,7 @@ public function testGetCustomerByPasswordUpdateId(): void $repository->getCustomerByPasswordUpdateId($passwordUpdateId); } - public function testCustomerByPasswordUpdateIdNotFound(): void + public function testCustomerByPasswordUpdateIdNotLoaded(): void { $passwordUpdateId = 'wrongId'; @@ -76,4 +76,22 @@ public function testCustomerByPasswordUpdateIdNotFound(): void $repository = new Repository($sharedRepository, $oxNewFactory); $repository->getCustomerByPasswordUpdateId($passwordUpdateId); } + + public function testCustomerByPasswordUpdateIdNotFound(): void + { + $passwordUpdateId = 'wrongId'; + + $userMock = $this->createMock(User::class); + $userMock->expects($this->once())->method('loadUserByUpdateId')->with($passwordUpdateId)->willReturn(null); + + $sharedRepository = $this->createMock(RepositoryInterface::class); + $oxNewFactory = $this->createMock(OxNewFactoryInterface::class); + $oxNewFactory->expects($this->once())->method('getModel')->with(User::class)->willReturn($userMock); + + $this->expectException(CustomerNotFoundByUpdateId::class); + $this->expectExceptionMessage('No customer was found by update id: "wrongId".'); + + $repository = new Repository($sharedRepository, $oxNewFactory); + $repository->getCustomerByPasswordUpdateId($passwordUpdateId); + } }