Skip to content

Commit

Permalink
Replace API client mock even in behat tests (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Mar 28, 2022
1 parent 9eddcba commit 59b32e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions tests/Behat/Context/Setup/AkeneoContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,40 @@

namespace Tests\Webgriffe\SyliusAkeneoPlugin\Behat\Context\Setup;

use Akeneo\Pim\ApiClient\AkeneoPimClientInterface;
use Behat\Behat\Context\Context;
use Tests\Webgriffe\SyliusAkeneoPlugin\Integration\TestDouble\ApiClientMock;
use Webgriffe\SyliusAkeneoPlugin\ApiClientInterface;
use DateTime;
use Tests\Webgriffe\SyliusAkeneoPlugin\Integration\TestDouble\OfficialApiClientMock;
use Webmozart\Assert\Assert;

final class AkeneoContext implements Context
{
/** @var ApiClientInterface|ApiClientMock */
private $apiClient;

public function __construct(ApiClientInterface $apiClient)
{
$this->apiClient = $apiClient;
/**
* @param AkeneoPimClientInterface|OfficialApiClientMock $apiClient
*/
public function __construct(
private $apiClient
) {
}

/**
* @Given there is a product :identifier updated at :date on Akeneo
*/
public function thereIsAProductUpdatedAtOnAkeneo(string $identifier, \DateTime $date)
public function thereIsAProductUpdatedAtOnAkeneo(string $identifier, DateTime $date): void
{
Assert::isInstanceOf($this->apiClient, ApiClientMock::class);
Assert::isInstanceOf($this->apiClient, OfficialApiClientMock::class);
$this->apiClient->addProductUpdatedAt($identifier, $date);
}

/**
* @Given /^there are (\d+) products on Akeneo$/
* @Given /^there is (\d+) product on Akeneo$/
*/
public function thereAreProductsOnAkeneo(int $count)
public function thereAreProductsOnAkeneo(int $count): void
{
Assert::isInstanceOf($this->apiClient, OfficialApiClientMock::class);
for ($i = 1; $i <= $count; ++$i) {
$this->apiClient->addProductUpdatedAt('product-' . $i, new \DateTime());
$this->apiClient->addProductUpdatedAt('product-' . $i, new DateTime());
}
}
}
2 changes: 1 addition & 1 deletion tests/Behat/Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</service>

<service id="webgriffe_sylius_akeneo.behat.context.setup.akeneo" class="Tests\Webgriffe\SyliusAkeneoPlugin\Behat\Context\Setup\AkeneoContext">
<argument type="service" id="webgriffe_sylius_akeneo.api_client" />
<argument type="service" id="webgriffe_sylius_akeneo.api_client_official" />
</service>

<service id="webgriffe_sylius_akeneo.behat.context.cli.consume_command" class="Tests\Webgriffe\SyliusAkeneoPlugin\Behat\Context\Cli\ConsumeCommandContext">
Expand Down

0 comments on commit 59b32e8

Please sign in to comment.