diff --git a/phpstan.neon b/phpstan.neon index 42eea45..ffc73d0 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,6 +9,7 @@ parameters: - '#Parameter .+ of method .+ has invalid typehint type .+Transfer#' - '#Return typehint of method .+ has invalid type .+Transfer#' - '#Instantiated class .+Transfer not found#' + - '#Instantiated class Orm\\Zed\\AmazonQuicksight\\Persistence\\.+ not found.+#' - '#Return typehint of method .+ has invalid type Orm\\.+#' - '#Call to method .+\(\) on an unknown class Orm\\.+#' - '#Call to static method create\(\) on an unknown class .+Query.#' diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightBusinessFactory.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightBusinessFactory.php index da6de49..0191606 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightBusinessFactory.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightBusinessFactory.php @@ -19,8 +19,8 @@ use SprykerEco\Zed\AmazonQuicksight\Business\Expander\UserExpanderInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Formatter\AmazonQuicksightRequestDataFormatter; use SprykerEco\Zed\AmazonQuicksight\Business\Formatter\AmazonQuicksightRequestDataFormatterInterface; -use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapper; -use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapperInterface; +use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\QuicksightUserMapper; +use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\QuicksightUserMapperInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\QuicksightEmbedUrlMapper; use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\QuicksightEmbedUrlMapperInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Provider\AnalyticsEmbedUrlProvider; @@ -60,7 +60,7 @@ public function createAmazonQuicksightApiClient(): AmazonQuicksightApiClientInte { return new AmazonQuicksightApiClient( $this->getConfig(), - $this->createAmazonQuicksightMapper(), + $this->createQuicksightUserMapper(), $this->createQuicksightEmbedUrlMapper(), $this->createAmazonQuicksightRequestDataFormatter(), $this->getAwsQuicksightClient(), @@ -68,11 +68,11 @@ public function createAmazonQuicksightApiClient(): AmazonQuicksightApiClientInte } /** - * @return \SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapperInterface + * @return \SprykerEco\Zed\AmazonQuicksight\Business\Mapper\QuicksightUserMapperInterface */ - public function createAmazonQuicksightMapper(): AmazonQuicksightMapperInterface + public function createQuicksightUserMapper(): QuicksightUserMapperInterface { - return new AmazonQuicksightMapper(); + return new QuicksightUserMapper(); } /** diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php index fd0d6d9..b3468a2 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php @@ -44,12 +44,12 @@ public function expandUserCollectionWithQuicksightUsers( * * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer */ - public function createQuicksightUsersForUserTransfers( + public function createQuicksightUsersForUserCollectionResponse( UserCollectionResponseTransfer $userCollectionResponseTransfer ): UserCollectionResponseTransfer { return $this->getFactory() ->createQuicksightUserCreator() - ->createQuicksightUsersForUserTransfers($userCollectionResponseTransfer); + ->createQuicksightUsersForUserCollectionResponse($userCollectionResponseTransfer); } /** diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php index c428249..ec6d4db 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php @@ -34,6 +34,7 @@ public function expandUserCollectionWithQuicksightUsers( /** * Specification: * - Expects `UserCollectionResponseTransfer.users.quicksightUser.role` to be set. + * - Does nothing if `UserTransfer.quicksightUser.role` is not set. * - Sends request to AWS API to register Quicksight users. For more information see {@link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RegisterUser.html}. * - Adds errors to `UserCollectionResponseTransfer.errors` if Quicksight user registration failed. * - Persists successfully registered Quicksight users in the database. @@ -45,7 +46,7 @@ public function expandUserCollectionWithQuicksightUsers( * * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer */ - public function createQuicksightUsersForUserTransfers( + public function createQuicksightUsersForUserCollectionResponse( UserCollectionResponseTransfer $userCollectionResponseTransfer ): UserCollectionResponseTransfer; diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/AmazonQuicksightApiClient.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/AmazonQuicksightApiClient.php index cca52e3..45b0704 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/AmazonQuicksightApiClient.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/AmazonQuicksightApiClient.php @@ -18,7 +18,7 @@ use Generated\Shared\Transfer\UserTransfer; use SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig; use SprykerEco\Zed\AmazonQuicksight\Business\Formatter\AmazonQuicksightRequestDataFormatterInterface; -use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapperInterface; +use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\QuicksightUserMapperInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\QuicksightEmbedUrlMapperInterface; use SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface; @@ -59,15 +59,18 @@ class AmazonQuicksightApiClient implements AmazonQuicksightApiClientInterface protected AmazonQuicksightConfig $amazonQuicksightConfig; /** - * @var \SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapperInterface + * @var \SprykerEco\Zed\AmazonQuicksight\Business\Mapper\QuicksightUserMapperInterface */ - protected AmazonQuicksightMapperInterface $amazonQuicksightMapper; + protected QuicksightUserMapperInterface $quicksightUserMapper; /** * @var \SprykerEco\Zed\AmazonQuicksight\Business\Mapper\QuicksightEmbedUrlMapperInterface */ protected QuicksightEmbedUrlMapperInterface $quicksightEmbedUrlMapper; + /** + * @var \SprykerEco\Zed\AmazonQuicksight\Business\Formatter\AmazonQuicksightRequestDataFormatterInterface + */ protected AmazonQuicksightRequestDataFormatterInterface $amazonQuicksightRequestDataFormatter; /** @@ -77,20 +80,20 @@ class AmazonQuicksightApiClient implements AmazonQuicksightApiClientInterface /** * @param \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig $amazonQuicksightConfig - * @param \SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapperInterface $amazonQuicksightMapper + * @param \SprykerEco\Zed\AmazonQuicksight\Business\Mapper\QuicksightUserMapperInterface $quicksightUserMapper * @param \SprykerEco\Zed\AmazonQuicksight\Business\Mapper\QuicksightEmbedUrlMapperInterface $quicksightEmbedUrlMapper * @param \SprykerEco\Zed\AmazonQuicksight\Business\Formatter\AmazonQuicksightRequestDataFormatterInterface $amazonQuicksightRequestDataFormatter * @param \SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface $amazonQuicksightToAwsQuicksightClient */ public function __construct( AmazonQuicksightConfig $amazonQuicksightConfig, - AmazonQuicksightMapperInterface $amazonQuicksightMapper, + QuicksightUserMapperInterface $quicksightUserMapper, QuicksightEmbedUrlMapperInterface $quicksightEmbedUrlMapper, AmazonQuicksightRequestDataFormatterInterface $amazonQuicksightRequestDataFormatter, AmazonQuicksightToAwsQuicksightClientInterface $amazonQuicksightToAwsQuicksightClient ) { $this->amazonQuicksightConfig = $amazonQuicksightConfig; - $this->amazonQuicksightMapper = $amazonQuicksightMapper; + $this->quicksightUserMapper = $quicksightUserMapper; $this->quicksightEmbedUrlMapper = $quicksightEmbedUrlMapper; $this->amazonQuicksightRequestDataFormatter = $amazonQuicksightRequestDataFormatter; $this->amazonQuicksightToAwsQuicksightClient = $amazonQuicksightToAwsQuicksightClient; @@ -104,7 +107,7 @@ public function __construct( public function registerUser(UserTransfer $userTransfer): QuicksightUserRegisterResponseTransfer { $quicksightUserRegisterRequestTransfer = $this->createQuicksightUserRegisterRequestTransfer(); - $quicksightUserRegisterRequestTransfer = $this->amazonQuicksightMapper->mapUserTransferToQuicksightUserRegisterRequestTransfer( + $quicksightUserRegisterRequestTransfer = $this->quicksightUserMapper->mapUserTransferToQuicksightUserRegisterRequestTransfer( $userTransfer, $quicksightUserRegisterRequestTransfer, ); @@ -128,7 +131,7 @@ public function registerUser(UserTransfer $userTransfer): QuicksightUserRegister ); } - $quicksightUserTransfer = $this->amazonQuicksightMapper->mapQuicksightUserDataToQuicksightUserTransfer( + $quicksightUserTransfer = $this->quicksightUserMapper->mapQuicksightUserDataToQuicksightUserTransfer( $response->get(static::RESPONSE_KEY_USER), $userTransfer->getQuicksightUserOrFail(), ); diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreator.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreator.php index 009147b..f4b6fc5 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreator.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreator.php @@ -44,7 +44,7 @@ public function __construct( * * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer */ - public function createQuicksightUsersForUserTransfers( + public function createQuicksightUsersForUserCollectionResponse( UserCollectionResponseTransfer $userCollectionResponseTransfer ): UserCollectionResponseTransfer { $userTransfersWithQuicksightUserRole = $this->extractUserTransfersWithQuicksightUserRole( diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreatorInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreatorInterface.php index d476f92..ffdc040 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreatorInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreatorInterface.php @@ -16,7 +16,7 @@ interface QuicksightUserCreatorInterface * * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer */ - public function createQuicksightUsersForUserTransfers( + public function createQuicksightUsersForUserCollectionResponse( UserCollectionResponseTransfer $userCollectionResponseTransfer ): UserCollectionResponseTransfer; } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/QuicksightUserMapper.php similarity index 95% rename from src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php rename to src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/QuicksightUserMapper.php index 06b22c2..8c01f6a 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/QuicksightUserMapper.php @@ -11,7 +11,7 @@ use Generated\Shared\Transfer\QuicksightUserTransfer; use Generated\Shared\Transfer\UserTransfer; -class AmazonQuicksightMapper implements AmazonQuicksightMapperInterface +class QuicksightUserMapper implements QuicksightUserMapperInterface { /** * @param \Generated\Shared\Transfer\UserTransfer $userTransfer diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/QuicksightUserMapperInterface.php similarity index 96% rename from src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php rename to src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/QuicksightUserMapperInterface.php index 8bcb1b8..09a9d70 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/QuicksightUserMapperInterface.php @@ -11,7 +11,7 @@ use Generated\Shared\Transfer\QuicksightUserTransfer; use Generated\Shared\Transfer\UserTransfer; -interface AmazonQuicksightMapperInterface +interface QuicksightUserMapperInterface { /** * @param \Generated\Shared\Transfer\UserTransfer $userTransfer diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserPostCreatePlugin.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserPostCreatePlugin.php index 0cf4fba..9c473f9 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserPostCreatePlugin.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserPostCreatePlugin.php @@ -21,6 +21,7 @@ class QuicksightUserPostCreatePlugin extends AbstractPlugin implements UserPostC /** * {@inheritDoc} * - Expects `UserCollectionResponseTransfer.users.quicksightUser.role` to be set. + * - Does nothing if `UserTransfer.quicksightUser.role` is not set. * - Sends request to AWS API to register Quicksight users. For more information see {@link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RegisterUser.html}. * - Adds errors to `UserCollectionResponseTransfer.errors` if Quicksight user registration failed. * - Persists successfully registered Quicksight users in the database. @@ -34,6 +35,6 @@ class QuicksightUserPostCreatePlugin extends AbstractPlugin implements UserPostC */ public function postCreate(UserCollectionResponseTransfer $userCollectionResponseTransfer): UserCollectionResponseTransfer { - return $this->getFacade()->createQuicksightUsersForUserTransfers($userCollectionResponseTransfer); + return $this->getFacade()->createQuicksightUsersForUserCollectionResponse($userCollectionResponseTransfer); } } diff --git a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/CreateQuicksightUsersForUserTransfersTest.php b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/CreateQuicksightUsersForUserCollectionResponseTest.php similarity index 73% rename from tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/CreateQuicksightUsersForUserTransfersTest.php rename to tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/CreateQuicksightUsersForUserCollectionResponseTest.php index 7e165be..3f37464 100644 --- a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/CreateQuicksightUsersForUserTransfersTest.php +++ b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/CreateQuicksightUsersForUserCollectionResponseTest.php @@ -17,7 +17,7 @@ use SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface; use SprykerEcoTest\Zed\AmazonQuicksight\AmazonQuicksightBusinessTester; -class CreateQuicksightUsersForUserTransfersTest extends Unit +class CreateQuicksightUsersForUserCollectionResponseTest extends Unit { /** * @uses \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig::QUICKSIGHT_USER_ROLE_READER @@ -51,24 +51,26 @@ public function testShouldPersistQuicksightUserWhenUserSuccessfullyRegisteredInQ // Arrange $userTransfer = $this->tester->haveUserWithNotPersistedQuicksightUserRole(static::QUICKSIGHT_USER_ROLE_READER); - $awsQuicksightClientMock = $this->getAwsQuicksightClientMock(); - $awsQuicksightClientMock->method('registerUser') - ->willReturn($this->createRegisterUserSuccessfulResponse($userTransfer)); $this->tester->setDependency( AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $awsQuicksightClientMock, + $this->getAwsQuicksightClientMockWithSuccessfulResponse( + $this->createRegisterUserSuccessfulResponse($userTransfer), + ), ); $userCollectionResponseTransfer = (new UserCollectionResponseTransfer())->addUser($userTransfer); // Act $userCollectionResponseTransfer = $this->tester->getFacade() - ->createQuicksightUsersForUserTransfers($userCollectionResponseTransfer); + ->createQuicksightUsersForUserCollectionResponse($userCollectionResponseTransfer); // Assert $this->assertCount(0, $userCollectionResponseTransfer->getErrors()); $this->assertCount(1, $userCollectionResponseTransfer->getUsers()); + $quicksightUserEntity = $this->tester->findQuicksightUserByIdUser($userTransfer->getIdUserOrFail()); + $this->assertNotNull($quicksightUserEntity); + /** @var \Generated\Shared\Transfer\UserTransfer $userTransfer */ $userTransfer = $userCollectionResponseTransfer->getUsers()->getIterator()->current(); $this->assertNotNull($userTransfer->getQuicksightUser()); @@ -85,19 +87,18 @@ public function testShouldReturnErrorWhenUserQuicksightClientThrowsException(): // Arrange $userTransfer = $this->tester->haveUserWithNotPersistedQuicksightUserRole(static::QUICKSIGHT_USER_ROLE_READER); - $awsQuicksightClientMock = $this->getAwsQuicksightClientMock(); - $awsQuicksightClientMock->method('registerUser') - ->willThrowException($this->getQuicksightExceptionMock(static::ERROR_MESSAGE_QUICKSIGHT_USER_REGISTER_FAILURE)); $this->tester->setDependency( AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $awsQuicksightClientMock, + $this->getAwsQuicksightClientMockWithErrorResponse( + $this->getQuicksightExceptionMock(static::ERROR_MESSAGE_QUICKSIGHT_USER_REGISTER_FAILURE), + ), ); $userCollectionResponseTransfer = (new UserCollectionResponseTransfer())->addUser($userTransfer); // Act $userCollectionResponseTransfer = $this->tester->getFacade() - ->createQuicksightUsersForUserTransfers($userCollectionResponseTransfer); + ->createQuicksightUsersForUserCollectionResponse($userCollectionResponseTransfer); // Assert $this->assertCount(1, $userCollectionResponseTransfer->getErrors()); @@ -124,19 +125,16 @@ public function testShouldReturnErrorWhenQuicksightUserRegisterResponseDoesNotCo // Arrange $userTransfer = $this->tester->haveUserWithNotPersistedQuicksightUserRole(static::QUICKSIGHT_USER_ROLE_READER); - $awsQuicksightClientMock = $this->getAwsQuicksightClientMock(); - $awsQuicksightClientMock->method('registerUser') - ->willReturn(new Result()); $this->tester->setDependency( AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $awsQuicksightClientMock, + $this->getAwsQuicksightClientMockWithSuccessfulResponse(new Result()), ); $userCollectionResponseTransfer = (new UserCollectionResponseTransfer())->addUser($userTransfer); // Act $userCollectionResponseTransfer = $this->tester->getFacade() - ->createQuicksightUsersForUserTransfers($userCollectionResponseTransfer); + ->createQuicksightUsersForUserCollectionResponse($userCollectionResponseTransfer); // Assert $this->assertCount(1, $userCollectionResponseTransfer->getErrors()); @@ -156,11 +154,31 @@ public function testShouldReturnErrorWhenQuicksightUserRegisterResponseDoesNotCo } /** - * @return \SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface|\PHPUnit\Framework\MockObject\MockObject + * @return void */ - protected function getAwsQuicksightClientMock(): AmazonQuicksightToAwsQuicksightClientInterface + public function testShouldDoNothingWhenQuicksightUserRoleIsNotProvidedForUser(): void { - return $this->getMockBuilder(AmazonQuicksightToAwsQuicksightClientInterface::class)->getMock(); + // Arrange + $userTransfer = $this->tester->haveUser(); + + $awsQuicksightClientMock = $this->getAwsQuicksightClientMock(); + $awsQuicksightClientMock->expects($this->never())->method('registerUser'); + $this->tester->setDependency( + AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, + $awsQuicksightClientMock, + ); + + // Act + $userCollectionResponseTransfer = (new UserCollectionResponseTransfer())->addUser($userTransfer); + + // Act + $userCollectionResponseTransfer = $this->tester->getFacade() + ->createQuicksightUsersForUserCollectionResponse($userCollectionResponseTransfer); + + // Assert + $this->assertCount(0, $userCollectionResponseTransfer->getErrors()); + $this->assertCount(1, $userCollectionResponseTransfer->getUsers()); + $this->assertNull($userCollectionResponseTransfer->getUsers()->getIterator()->current()->getQuicksightUser()); } /** @@ -182,6 +200,42 @@ protected function createRegisterUserSuccessfulResponse(UserTransfer $userTransf return new Result($responseData); } + /** + * @param \Aws\ResultInterface $result + * + * @return \SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface|\PHPUnit\Framework\MockObject\MockObject + */ + protected function getAwsQuicksightClientMockWithSuccessfulResponse(ResultInterface $result): AmazonQuicksightToAwsQuicksightClientInterface + { + $awsQuicksightClientMock = $this->getAwsQuicksightClientMock(); + $awsQuicksightClientMock->method('registerUser') + ->willReturn($result); + + return $awsQuicksightClientMock; + } + + /** + * @param \Aws\QuickSight\Exception\QuickSightException $quickSightException + * + * @return \SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface|\PHPUnit\Framework\MockObject\MockObject + */ + protected function getAwsQuicksightClientMockWithErrorResponse(QuickSightException $quickSightException): AmazonQuicksightToAwsQuicksightClientInterface + { + $awsQuicksightClientMock = $this->getAwsQuicksightClientMock(); + $awsQuicksightClientMock->method('registerUser') + ->willThrowException($quickSightException); + + return $awsQuicksightClientMock; + } + + /** + * @return \SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface|\PHPUnit\Framework\MockObject\MockObject + */ + protected function getAwsQuicksightClientMock(): AmazonQuicksightToAwsQuicksightClientInterface + { + return $this->getMockBuilder(AmazonQuicksightToAwsQuicksightClientInterface::class)->getMock(); + } + /** * @param string $message * diff --git a/tests/SprykerEcoTest/Zed/AmazonQuicksight/_support/AmazonQuicksightBusinessTester.php b/tests/SprykerEcoTest/Zed/AmazonQuicksight/_support/AmazonQuicksightBusinessTester.php index f0b34ad..204329d 100644 --- a/tests/SprykerEcoTest/Zed/AmazonQuicksight/_support/AmazonQuicksightBusinessTester.php +++ b/tests/SprykerEcoTest/Zed/AmazonQuicksight/_support/AmazonQuicksightBusinessTester.php @@ -12,6 +12,7 @@ use Generated\Shared\Transfer\QuicksightUserTransfer; use Generated\Shared\Transfer\UserTransfer; use Orm\Zed\AmazonQuicksight\Persistence\SpyQuicksightUser; +use Orm\Zed\AmazonQuicksight\Persistence\SpyQuicksightUserQuery; /** * Inherited Methods @@ -65,4 +66,24 @@ public function haveUserWithNotPersistedQuicksightUserRole(string $quicksightUse ]))->build(), ]); } + + /** + * @param int $idUser + * + * @return \Orm\Zed\AmazonQuicksight\Persistence\SpyQuicksightUser|null + */ + public function findQuicksightUserByIdUser(int $idUser): ?SpyQuicksightUser + { + return $this->getQuicksightUserQuery() + ->filterByFkUser($idUser) + ->findOne(); + } + + /** + * @return \Orm\Zed\AmazonQuicksight\Persistence\SpyQuicksightUserQuery + */ + protected function getQuicksightUserQuery(): SpyQuicksightUserQuery + { + return SpyQuicksightUserQuery::create(); + } }