mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
Add fixes and ExchangeRate transform
This commit is contained in:
parent
a247cb7aad
commit
d305957233
6 changed files with 82 additions and 24 deletions
|
|
@ -31,7 +31,7 @@ interface ApiClientInterface
|
|||
|
||||
public function buildFilter(array $filters): void;
|
||||
|
||||
/** @param string|int */
|
||||
/** @param string|int $value */
|
||||
public function addRequestData(string $key, $value): void;
|
||||
|
||||
public function addCompoundRequestData(array $data): void;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ use Sylius\Behat\Client\ApiClientInterface;
|
|||
use Sylius\Behat\Service\SharedStorageInterface;
|
||||
use Sylius\Component\Currency\Model\CurrencyInterface;
|
||||
use Sylius\Component\Currency\Model\ExchangeRateInterface;
|
||||
use Sylius\Component\Currency\Repository\ExchangeRateRepositoryInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class ManagingExchangeRatesContext implements Context
|
||||
|
|
@ -24,19 +23,14 @@ final class ManagingExchangeRatesContext implements Context
|
|||
/** @var ApiClientInterface */
|
||||
private $client;
|
||||
|
||||
/** @var ExchangeRateRepositoryInterface */
|
||||
private $exchangeRateRepository;
|
||||
|
||||
/** @var SharedStorageInterface */
|
||||
private $sharedStorage;
|
||||
|
||||
public function __construct(
|
||||
ApiClientInterface $client,
|
||||
ExchangeRateRepositoryInterface $exchangeRateRepository,
|
||||
SharedStorageInterface $sharedStorage
|
||||
) {
|
||||
$this->client = $client;
|
||||
$this->exchangeRateRepository = $exchangeRateRepository;
|
||||
$this->sharedStorage = $sharedStorage;
|
||||
}
|
||||
|
||||
|
|
@ -121,13 +115,10 @@ final class ManagingExchangeRatesContext implements Context
|
|||
}
|
||||
|
||||
/**
|
||||
* @When I delete the exchange rate between :sourceCurrency and :targetCurrency
|
||||
* @When /^I delete the (exchange rate between "[^"]+" and "[^"]+")$/
|
||||
*/
|
||||
public function iDeleteTheExchangeRateBetweenAnd(CurrencyInterface $sourceCurrency, CurrencyInterface $targetCurrency) : void
|
||||
public function iDeleteTheExchangeRateBetweenAnd(ExchangeRateInterface $exchangeRate) : void
|
||||
{
|
||||
/** @var ExchangeRateInterface */
|
||||
$exchangeRate = $this->getExchangeRateBetweenCurrencies($sourceCurrency->getCode(), $targetCurrency->getCode());
|
||||
|
||||
$this->client->delete('exchange_rates', $exchangeRate->getId());
|
||||
}
|
||||
|
||||
|
|
@ -223,7 +214,7 @@ final class ManagingExchangeRatesContext implements Context
|
|||
$exchangeRate->getTargetCurrency()
|
||||
),
|
||||
sprintf(
|
||||
'Exchange rate with ratio %s between %s and %s still exists',
|
||||
'Exchange rate with ratio %s between %s and %s still exists, but it should not.',
|
||||
$exchangeRate->getRatio(),
|
||||
$exchangeRate->getSourceCurrency()->getName(),
|
||||
$exchangeRate->getTargetCurrency()->getName()
|
||||
|
|
@ -318,16 +309,6 @@ final class ManagingExchangeRatesContext implements Context
|
|||
);
|
||||
}
|
||||
|
||||
private function getExchangeRateBetweenCurrencies(string $sourceCode, string $targetCode): ExchangeRateInterface
|
||||
{
|
||||
/** @var ExchangeRateInterface|null */
|
||||
$exchangeRate = $this->exchangeRateRepository->findOneWithCurrencyPair($sourceCode, $targetCode);
|
||||
|
||||
Assert::notNull($exchangeRate);
|
||||
|
||||
return $exchangeRate;
|
||||
}
|
||||
|
||||
private function getExchangeRateFromResponse(
|
||||
CurrencyInterface $sourceCurrency,
|
||||
CurrencyInterface $targetCurrency
|
||||
|
|
|
|||
71
src/Sylius/Behat/Context/Transform/ExchangeRateContext.php
Normal file
71
src/Sylius/Behat/Context/Transform/ExchangeRateContext.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Behat\Context\Transform;
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Sylius\Component\Currency\Converter\CurrencyNameConverterInterface;
|
||||
use Sylius\Component\Currency\Model\ExchangeRateInterface;
|
||||
use Sylius\Component\Currency\Repository\ExchangeRateRepositoryInterface;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class ExchangeRateContext implements Context
|
||||
{
|
||||
/** @var CurrencyNameConverterInterface */
|
||||
private $currencyNameConverter;
|
||||
|
||||
/** @var RepositoryInterface */
|
||||
private $currencyRepository;
|
||||
|
||||
/** @var ExchangeRateRepositoryInterface */
|
||||
private $exchangeRateRepository;
|
||||
|
||||
public function __construct(
|
||||
CurrencyNameConverterInterface $currencyNameConverter,
|
||||
RepositoryInterface $currencyRepository,
|
||||
ExchangeRateRepositoryInterface $exchangeRateRepository
|
||||
) {
|
||||
$this->currencyNameConverter = $currencyNameConverter;
|
||||
$this->currencyRepository = $currencyRepository;
|
||||
$this->exchangeRateRepository = $exchangeRateRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Transform /^exchange rate between "([^"]+)" and "([^"]+)"$/
|
||||
*/
|
||||
public function getExchangeRateByCurrencies(
|
||||
string $sourceCurrencyName,
|
||||
string $targetCurrencyName
|
||||
): ExchangeRateInterface {
|
||||
$sourceCurrencyCode = $this->currencyNameConverter->convertToCode($sourceCurrencyName);
|
||||
$targetCurrencyCode = $this->currencyNameConverter->convertToCode($targetCurrencyName);
|
||||
|
||||
/** @var ExchangeRateInterface|null */
|
||||
$exchangeRate = $this
|
||||
->exchangeRateRepository
|
||||
->findOneWithCurrencyPair($sourceCurrencyCode, $targetCurrencyCode)
|
||||
;
|
||||
|
||||
Assert::notNull(
|
||||
$exchangeRate,
|
||||
sprintf(
|
||||
'ExchangeRate for %s and %s currencies does not exist.',
|
||||
$sourceCurrencyName,
|
||||
$targetCurrencyName
|
||||
)
|
||||
);
|
||||
|
||||
return $exchangeRate;
|
||||
}
|
||||
}
|
||||
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
<service id="sylius.behat.context.api.admin.managing_exchange_rates" class="Sylius\Behat\Context\Api\Admin\ManagingExchangeRatesContext">
|
||||
<argument type="service" id="Sylius\Behat\Client\ApiClientInterface" />
|
||||
<argument type="service" id="sylius.repository.exchange_rate" />
|
||||
<argument type="service" id="sylius.behat.shared_storage" />
|
||||
</service>
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@
|
|||
<service id="sylius.behat.context.transform.date_time" class="Sylius\Behat\Context\Transform\DateTimeContext">
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.transform.exchange_rate" class="Sylius\Behat\Context\Transform\ExchangeRateContext">
|
||||
<argument type="service" id="sylius.currency_name_converter" />
|
||||
<argument type="service" id="sylius.repository.currency" />
|
||||
<argument type="service" id="sylius.repository.exchange_rate" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.transform.lexical" class="Sylius\Behat\Context\Transform\LexicalContext">
|
||||
</service>
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ default:
|
|||
- sylius.behat.context.hook.doctrine_orm
|
||||
|
||||
- sylius.behat.context.transform.currency
|
||||
- sylius.behat.context.transform.exchange_rate
|
||||
- sylius.behat.context.transform.lexical
|
||||
- sylius.behat.context.transform.shared_storage
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue