-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXDEV-7728: Refactoring and tests for Password
- Loading branch information
1 parent
27c97e1
commit bb28ab8
Showing
6 changed files
with
146 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace OxidEsales\GraphQL\Storefront\Customer\Infrastructure; | ||
|
||
use OxidEsales\Eshop\Application\Model\User; | ||
|
||
interface PasswordInterface | ||
{ | ||
public function sendPasswordForgotEmail(string $email): bool|int; | ||
|
||
public function validatePassword(User $customer, string $newPassword, string $repeatPassword): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace OxidEsales\GraphQL\Storefront\Customer\Infrastructure; | ||
|
||
use OxidEsales\Eshop\Application\Model\User as EshopUserModel; | ||
use OxidEsales\GraphQL\Storefront\Address\DataType\DeliveryAddress; | ||
use OxidEsales\GraphQL\Storefront\Customer\DataType\Customer as CustomerDataType; | ||
use OxidEsales\GraphQL\Storefront\Customer\Exception\CustomerNotFoundByUpdateId; | ||
|
||
interface RepositoryInterface | ||
{ | ||
/** | ||
* @throws CustomerNotFoundByUpdateId | ||
*/ | ||
public function createUser(EshopUserModel $user): CustomerDataType; | ||
|
||
/** | ||
* @return DeliveryAddress[] | ||
*/ | ||
public function addresses(CustomerDataType $customer): array; | ||
|
||
public function checkEmailExists(string $email): bool; | ||
|
||
public function saveNewPasswordForCustomer(EshopUserModel $customer, string $newPassword): bool; | ||
|
||
public function getCustomerByPasswordUpdateId(string $passwordUpdateId): EshopUserModel; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace OxidEsales\GraphQL\Storefront\Customer\Service; | ||
|
||
use DateTimeInterface; | ||
use OxidEsales\GraphQL\Base\Exception\InvalidLogin; | ||
use OxidEsales\GraphQL\Storefront\Customer\DataType\Customer as CustomerDataType; | ||
use OxidEsales\GraphQL\Storefront\Customer\Exception\CustomerNotDeletable; | ||
use OxidEsales\GraphQL\Storefront\Customer\Exception\CustomerNotFoundByUpdateId; | ||
|
||
interface CustomerInterface | ||
{ | ||
/** | ||
* @throws InvalidLogin | ||
* @throws CustomerNotFoundByUpdateId | ||
*/ | ||
public function customer(string $id): CustomerDataType; | ||
|
||
public function create(CustomerDataType $customer): CustomerDataType; | ||
|
||
public function changeEmail(string $email): CustomerDataType; | ||
|
||
public function changeBirthdate(DateTimeInterface $birthdate): CustomerDataType; | ||
|
||
/** | ||
* @throws CustomerNotDeletable | ||
*/ | ||
public function deleteCustomer(): bool; | ||
|
||
public function fetchCustomer(string $id): CustomerDataType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GraphQL\Storefront\Tests\Unit\Customer\Service; | ||
|
||
use OxidEsales\Eshop\Application\Model\User; | ||
use OxidEsales\GraphQL\Storefront\Customer\Infrastructure\PasswordInterface as PasswordInfrastructureInterface; | ||
use OxidEsales\GraphQL\Storefront\Customer\Infrastructure\RepositoryInterface as CustomerRepositoryInterface; | ||
use OxidEsales\GraphQL\Storefront\Customer\Service\CustomerInterface; | ||
use OxidEsales\GraphQL\Storefront\Customer\Service\Password as PasswordService; | ||
use PHPUnit\Framework\TestCase; | ||
use TheCodingMachine\GraphQLite\Security\AuthenticationServiceInterface; | ||
|
||
/** | ||
* @covers \OxidEsales\GraphQL\Storefront\Customer\Service\Password | ||
*/ | ||
class PasswordServiceTest extends TestCase | ||
{ | ||
|
||
public function testResetPasswordByUpdateId(): void | ||
{ | ||
$customer = $this->createStub(User::class); | ||
$password = 'password'; | ||
$passwordRepeated = 'password'; | ||
|
||
$customerRepository = $this->createMock(CustomerRepositoryInterface::class); | ||
$customerRepository->expects($this->once()) | ||
->method('getCustomerByPasswordUpdateId') | ||
->with('1234') | ||
->willReturn($customer); | ||
$customerRepository->expects($this->once()) | ||
->method('saveNewPasswordForCustomer') | ||
->with($customer, $password); | ||
$passwordInfrastructure = $this->createMock(PasswordInfrastructureInterface::class); | ||
$passwordInfrastructure->expects($this->once()) | ||
->method('validatePassword') | ||
->with( | ||
$customer, | ||
$password, | ||
$passwordRepeated | ||
); | ||
$customerService = $this->createMock(CustomerInterface::class); | ||
$authenticationService = $this->createMock(AuthenticationServiceInterface::class); | ||
$passwordService = new PasswordService( | ||
$customerRepository, | ||
$customerService, | ||
$authenticationService, | ||
$passwordInfrastructure | ||
); | ||
|
||
$passwordService->resetPasswordByUpdateId('1234', $password, $passwordRepeated); | ||
} | ||
} |