class ExchangeRateProviderDecoratorTest in Currency 8.3
@coversDefaultClass \Drupal\currency\Plugin\Currency\ExchangeRateProvider\ExchangeRateProviderDecorator
@group Currency
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\currency\Unit\Plugin\Currency\ExchangeRateProvider\ExchangeRateProviderDecoratorTest
Expanded class hierarchy of ExchangeRateProviderDecoratorTest
File
- tests/
src/ Unit/ Plugin/ Currency/ ExchangeRateProvider/ ExchangeRateProviderDecoratorTest.php, line 16
Namespace
Drupal\Tests\currency\Unit\Plugin\Currency\ExchangeRateProviderView source
class ExchangeRateProviderDecoratorTest extends UnitTestCase {
/**
* The decorated exchange rate provider
*
* @var \Commercie\CurrencyExchange\ExchangeRateProviderInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $exchangeRateProvider;
/**
* The plugin ID.
*
* @var string
*/
protected $pluginId;
/**
* The class under test.
*
* @var \Drupal\currency\Plugin\Currency\ExchangeRateProvider\HistoricalRates
*/
protected $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->exchangeRateProvider = $this
->createMock(ExchangeRateProviderInterface::class);
$configuration = array();
$this->pluginId = $this
->randomMachineName();
$plugin_definition = array();
$this->sut = new ExchangeRateProviderDecorator($configuration, $this->pluginId, $plugin_definition, $this->exchangeRateProvider);
}
/**
* @covers ::load
*/
public function testLoad() {
$source_currency_code = $this
->randomMachineName();
$destination_currency_code = $this
->randomMachineName();
$rate = mt_rand();
$exchange_rate = new ExchangeRate($source_currency_code, $destination_currency_code, $rate, $this->pluginId);
$this->exchangeRateProvider
->expects($this
->once())
->method('load')
->with($source_currency_code, $destination_currency_code)
->willReturn($exchange_rate);
$this
->assertExchangeRateEquals($exchange_rate, $this->sut
->load($source_currency_code, $destination_currency_code));
}
/**
* @covers ::loadMultiple
*/
public function testLoadMultiple() {
$source_currency_code = $this
->randomMachineName();
$destination_currency_code_a = $this
->randomMachineName();
$destination_currency_code_b = $this
->randomMachineName();
$exchange_rate_a = new ExchangeRate($source_currency_code, $destination_currency_code_a, mt_rand(), $this->pluginId);
$exchange_rate_b = new ExchangeRate($source_currency_code, $destination_currency_code_b, mt_rand(), $this->pluginId);
$exchange_rates = [
$source_currency_code => [
$destination_currency_code_a => $exchange_rate_a,
$destination_currency_code_b => $exchange_rate_b,
],
];
$this->exchangeRateProvider
->expects($this
->once())
->method('loadMultiple')
->with([
$source_currency_code => [
$destination_currency_code_a,
$destination_currency_code_b,
],
])
->willReturn($exchange_rates);
$loaded_exchange_rates = $this->sut
->loadMultiple([
$source_currency_code => [
$destination_currency_code_a,
$destination_currency_code_b,
],
]);
$this
->assertExchangeRateEquals($exchange_rate_a, $loaded_exchange_rates[$source_currency_code][$destination_currency_code_a]);
$this
->assertExchangeRateEquals($exchange_rate_b, $loaded_exchange_rates[$source_currency_code][$destination_currency_code_b]);
}
/**
* Asserts that two exchange rates are equal.
*
* @param \Drupal\currency\ExchangeRateInterface $expected
* @param \Drupal\currency\ExchangeRateInterface $real
*/
protected function assertExchangeRateEquals(ExchangeRateInterface $expected, ExchangeRateInterface $real) {
$this
->assertSame($expected
->getSourceCurrencyCode(), $real
->getSourceCurrencyCode());
$this
->assertSame($expected
->getDestinationCurrencyCode(), $real
->getDestinationCurrencyCode());
$this
->assertSame($expected
->getRate(), $real
->getRate());
$this
->assertSame($expected
->getTimestamp(), $real
->getTimestamp());
$this
->assertSame($expected
->getExchangeRateProviderId(), $real
->getExchangeRateProviderId());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExchangeRateProviderDecoratorTest:: |
protected | property | The decorated exchange rate provider | |
ExchangeRateProviderDecoratorTest:: |
protected | property | The plugin ID. | |
ExchangeRateProviderDecoratorTest:: |
protected | property | The class under test. | |
ExchangeRateProviderDecoratorTest:: |
protected | function | Asserts that two exchange rates are equal. | |
ExchangeRateProviderDecoratorTest:: |
public | function |
Overrides UnitTestCase:: |
|
ExchangeRateProviderDecoratorTest:: |
public | function | @covers ::load | |
ExchangeRateProviderDecoratorTest:: |
public | function | @covers ::loadMultiple | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |