Skip to content

Commit

Permalink
FRW-1817 Adjusted Dynamic Multistore Test Coverage (#10800)
Browse files Browse the repository at this point in the history
FRW-1817 Adjusted Dynamic Multistore Test Coverage
  • Loading branch information
vol4onok authored Mar 20, 2024
1 parent b17fa19 commit 1f0f42a
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerTest\Zed\Customer\Communication\Console;

use Codeception\Test\Unit;
use Generated\Shared\Transfer\CustomerCollectionTransfer;
use Generated\Shared\Transfer\CustomerTransfer;
use Spryker\Zed\Customer\Communication\Console\CustomerPasswordResetConsole;
use Spryker\Zed\Customer\Communication\Console\CustomerPasswordSetConsole;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Auto-generated group annotations
*
* @group SprykerTest
* @group Zed
* @group Customer
* @group Communication
* @group Console
* @group CustomerPasswordActionConsoleTest
* Add your own group annotations below this line
*/
class CustomerPasswordActionConsoleTest extends Unit
{
/**
* @var string
*/
protected const OPTION_NO_TOKEN = '--no-token';

/**
* @var string
*/
protected const OPTION_STORE = '--store';

/**
* @var string
*/
protected const NAME_STORE = 'DE';

/**
* @var string
*/
protected const FLAG_FORCE = '--force';

/**
* @var \SprykerTest\Zed\Customer\CustomerCommunicationTester
*/
protected $tester;

/**
* @return void
*/
public function setUp(): void
{
parent::setUp();
}

/**
* @dataProvider getCustomerPasswordConsoleCommands
*
* @param string $consoleCommand
*
* @return void
*/
public function testExecuteSetUserStoreForDynamicMultiStore(string $consoleCommand): void
{
if ($this->tester->isDynamicStoreEnabled() === false) {
$this->markTestSkipped('This test requires DynamicStore to be enabled.');
}
// Arrange
$inputMock = new ArgvInput([static::OPTION_NO_TOKEN . '=' . true, static::OPTION_STORE . '=' . static::NAME_STORE, static::FLAG_FORCE]);
$output = $this->createMock(OutputInterface::class);

$facadeMock = $this->tester->createCustomerFacadeMock();
$facadeMock->method('getCustomerCollectionByCriteria')->willReturn(
(new CustomerCollectionTransfer())->addCustomer(new CustomerTransfer()),
);
$facadeMock->method('sendPasswordRestoreMailForCustomerCollection')->with(
(new CustomerCollectionTransfer())
->addCustomer(
(new CustomerTransfer())->setStoreName(static::NAME_STORE),
),
$output,
);
$factoryMock = $this->tester->createCustomerCommunicationFactoryMock();
$storeFacadeMock = $this->tester->createStoreFacadeMock();

$storeFacadeMock->method('isDynamicStoreEnabled')->willReturn(true);
$factoryMock->method('getStoreFacade')->willReturn($storeFacadeMock);

$consoleComand = new $consoleCommand();
$consoleComand->setFactory($factoryMock);
$consoleComand->setFacade($facadeMock);

// Act
$result = $consoleComand->run($inputMock, $output);

// Assert
$this->assertEquals($consoleCommand::CODE_SUCCESS, $result);
}

/**
* @dataProvider getCustomerPasswordConsoleCommands
*
* @param string $consoleCommand
*
* @return void
*/
public function testExecuteReturnsErrorCodeIfStoreOptionIsEmpty(string $consoleCommand): void
{
if ($this->tester->isDynamicStoreEnabled() === false) {
$this->markTestSkipped('This test requires DynamicStore to be enabled.');
}

// Arrange
$inputMock = new ArgvInput([static::OPTION_NO_TOKEN, static::FLAG_FORCE]);
$output = $this->createMock(OutputInterface::class);

$facadeMock = $this->tester->createCustomerFacadeMock();
$facadeMock->method('getCustomerCollectionByCriteria')->willReturn(
(new CustomerCollectionTransfer())->addCustomer(new CustomerTransfer()),
);
$factoryMock = $this->tester->createCustomerCommunicationFactoryMock();
$storeFacadeMock = $this->tester->createStoreFacadeMock();

$storeFacadeMock->method('isDynamicStoreEnabled')->willReturn(true);
$factoryMock->method('getStoreFacade')->willReturn($storeFacadeMock);

$consoleComand = new $consoleCommand();
$consoleComand->setFactory($factoryMock);
$consoleComand->setFacade($facadeMock);

// Act
$result = $consoleComand->run($inputMock, $output);

// Assert
$this->assertEquals(defined('APPLICATION_STORE') ? $consoleCommand::CODE_SUCCESS : $consoleCommand::CODE_ERROR, $result);
}

/**
* @return array<string>
*/
public function getCustomerPasswordConsoleCommands(): array
{
return [
'CustomerPasswordResetConsole' => [CustomerPasswordResetConsole::class],
'CustomerPasswordSetConsole' => [CustomerPasswordSetConsole::class],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
namespace SprykerTest\Zed\Customer\Communication\Form\DataProvider;

use Codeception\Test\Unit;
use Generated\Shared\Transfer\CountryCollectionTransfer;
use Generated\Shared\Transfer\CountryTransfer;
use Spryker\Zed\Customer\Communication\Form\AddressForm;
use Spryker\Zed\Customer\Communication\Form\DataProvider\AddressFormDataProvider;

/**
* Auto-generated group annotations
Expand All @@ -29,6 +32,16 @@ class AddressFormDataProviderTest extends Unit
*/
protected $tester;

/**
* @var string
*/
protected const NAME_COUNTRY = 'US';

/**
* @var int
*/
protected const ID_COUNTRY = 1;

/**
* @return void
*/
Expand All @@ -51,4 +64,40 @@ public function testGetOptionReturnRequiredKeys(): void
array_keys($options),
);
}

/**
* @return void
*/
public function testGetOptionContriesReturnsCountriesForDynamicStore(): void
{
if ($this->tester->isDynamicStoreEnabled() === false) {
$this->markTestSkipped('This test requires DynamicStore to be enabled.');
}

// Arrange
$countryTransfer = new CountryTransfer();
$countryTransfer->setIdCountry(static::ID_COUNTRY);
$countryTransfer->setName(static::NAME_COUNTRY);

/** @var \Spryker\Zed\Customer\Communication\CustomerCommunicationFactory $customerCommunicationFactory */
$customerCommunicationFactory = $this->tester->getFactory();
$countryFacadeMock = $this->tester->createCountryFacadeMock();
$countryFacadeMock->method('getAvailableCountries')->willReturn(
(new CountryCollectionTransfer())
->addCountries($countryTransfer),
);
$storeFacadeMock = $this->tester->createStoreFacadeMock();
$storeFacadeMock->method('isDynamicStoreEnabled')->willReturn(true);
$dataProvider = new AddressFormDataProvider(
$countryFacadeMock,
$this->tester->createCustomerQueryContainerMock(),
$storeFacadeMock,
);

// Action
$options = $dataProvider->getOptions();

// Assert
$this->assertEquals([$countryTransfer->getIdCountry() => $countryTransfer->getName()], $options[AddressForm::OPTION_COUNTRY_CHOICES]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
namespace SprykerTest\Zed\Customer;

use Codeception\Actor;
use Codeception\Stub;
use Spryker\Zed\Customer\Business\CustomerFacade;
use Spryker\Zed\Customer\Communication\CustomerCommunicationFactory;
use Spryker\Zed\Customer\Dependency\Facade\CustomerToCountryInterface;
use Spryker\Zed\Customer\Dependency\Facade\CustomerToStoreFacadeInterface;
use Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface;

/**
* @method void wantToTest($text)
Expand All @@ -26,4 +32,44 @@
class CustomerCommunicationTester extends Actor
{
use _generated\CustomerCommunicationTesterActions;

/**
* @return (\object&\PHPUnit\Framework\MockObject\MockObject)|(\object&\PHPUnit\Framework\MockObject\MockObject&\Spryker\Zed\Customer\Business\CustomerFacade)|(\object&\PHPUnit\Framework\MockObject\MockObject&\Spryker\Zed\Customer\Business\CustomerFacade&\object&\PHPUnit\Framework\MockObject\MockObject)
*/
public function createCustomerFacadeMock(): CustomerFacade
{
return Stub::makeEmpty(CustomerFacade::class);
}

/**
* @return (\object&\PHPUnit\Framework\MockObject\MockObject)|(\Spryker\Zed\Customer\Communication\CustomerCommunicationFactory&\object&\PHPUnit\Framework\MockObject\MockObject)|(\Spryker\Zed\Customer\Communication\CustomerCommunicationFactory&\object&\PHPUnit\Framework\MockObject\MockObject&\object&\PHPUnit\Framework\MockObject\MockObject)
*/
public function createCustomerCommunicationFactoryMock(): CustomerCommunicationFactory
{
return Stub::makeEmpty(CustomerCommunicationFactory::class);
}

/**
* @return (\object&\PHPUnit\Framework\MockObject\MockObject)|(\Spryker\Zed\Customer\Dependency\Facade\CustomerToStoreFacadeInterface&\object&\PHPUnit\Framework\MockObject\MockObject)|(\Spryker\Zed\Customer\Dependency\Facade\CustomerToStoreFacadeInterface&\object&\PHPUnit\Framework\MockObject\MockObject&\object&\PHPUnit\Framework\MockObject\MockObject)
*/
public function createStoreFacadeMock(): CustomerToStoreFacadeInterface
{
return Stub::makeEmpty(CustomerToStoreFacadeInterface::class);
}

/**
* @return (\object&\PHPUnit\Framework\MockObject\MockObject)|(\Spryker\Zed\Customer\Dependency\Facade\CustomerToCountryInterface&\object&\PHPUnit\Framework\MockObject\MockObject)|(\Spryker\Zed\Customer\Dependency\Facade\CustomerToCountryInterface&\object&\PHPUnit\Framework\MockObject\MockObject&\object&\PHPUnit\Framework\MockObject\MockObject)
*/
public function createCountryFacadeMock(): CustomerToCountryInterface
{
return Stub::makeEmpty(CustomerToCountryInterface::class);
}

/**
* @return (\object&\PHPUnit\Framework\MockObject\MockObject)|(\Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface&\object&\PHPUnit\Framework\MockObject\MockObject)|(\Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface&\object&\PHPUnit\Framework\MockObject\MockObject&\object&\PHPUnit\Framework\MockObject\MockObject)
*/
public function createCustomerQueryContainerMock(): CustomerQueryContainerInterface
{
return Stub::makeEmpty(CustomerQueryContainerInterface::class);
}
}
2 changes: 2 additions & 0 deletions tests/SprykerTest/Zed/Customer/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ suites:
- \SprykerTest\Shared\Customer\Helper\CustomerDataHelper
- \SprykerTest\Service\Container\Helper\ContainerHelper
- \SprykerTest\Shared\Store\Helper\StoreDependencyHelper
- \SprykerTest\Shared\Store\Helper\StoreDataHelper

Communication:
path: Communication
Expand Down Expand Up @@ -64,3 +65,4 @@ suites:
- \SprykerTest\Zed\Application\Helper\ApplicationHelper
- \SprykerTest\Shared\Customer\Helper\CustomerDataHelper
- \SprykerTest\Shared\Testify\Helper\DataCleanupHelper
- \SprykerTest\Shared\Store\Helper\StoreDataHelper

0 comments on commit 1f0f42a

Please sign in to comment.