class ExchangeRateTest in Currency 8.3
@coversDefaultClass \Drupal\currency\ExchangeRate
@group Currency
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\currency\Unit\ExchangeRateTest
Expanded class hierarchy of ExchangeRateTest
File
- tests/
src/ Unit/ ExchangeRateTest.php, line 14
Namespace
Drupal\Tests\currency\UnitView source
class ExchangeRateTest extends UnitTestCase {
/**
* The subject under test.
*
* @var \Drupal\currency\ExchangeRate
*/
protected $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$exchange_rate_provider_id = $this
->randomMachineName();
$timestamp = mt_rand();
$source_currency_code = $this
->randomMachineName(3);
$destination_currency_code = $this
->randomMachineName(3);
$rate = mt_rand();
$this->sut = new ExchangeRate($exchange_rate_provider_id, $timestamp, $source_currency_code, $destination_currency_code, $rate);
}
/**
* @covers ::createFromExchangeRate
*/
public function testCreateFromExchangeRate() {
$exchange_rate_provider_id = $this
->randomMachineName();
$timestamp = mt_rand();
$source_currency_code = $this
->randomMachineName(3);
$destination_currency_code = $this
->randomMachineName(3);
$rate = mt_rand();
$other_exchange_rate = new GenericExchangeRate($source_currency_code, $destination_currency_code, $rate);
$other_exchange_rate
->setTimestamp($timestamp);
$created_exchange_rate = ExchangeRate::createFromExchangeRate($other_exchange_rate, $exchange_rate_provider_id);
$this
->assertSame($other_exchange_rate
->getSourceCurrencyCode(), $created_exchange_rate
->getSourceCurrencyCode());
$this
->assertSame($other_exchange_rate
->getDestinationCurrencyCode(), $created_exchange_rate
->getDestinationCurrencyCode());
$this
->assertSame($other_exchange_rate
->getRate(), $created_exchange_rate
->getRate());
$this
->assertSame($other_exchange_rate
->getTimestamp(), $created_exchange_rate
->getTimestamp());
$this
->assertSame($exchange_rate_provider_id, $created_exchange_rate
->getExchangeRateProviderId());
}
/**
* @covers ::getExchangeRateProviderId
* @covers ::setExchangeRateProviderId
*/
public function testGetExchangeRateProviderId() {
$id = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setExchangeRateProviderId($id));
$this
->assertSame($id, $this->sut
->getExchangeRateProviderId());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExchangeRateTest:: |
protected | property | The subject under test. | |
ExchangeRateTest:: |
public | function |
Overrides UnitTestCase:: |
|
ExchangeRateTest:: |
public | function | @covers ::createFromExchangeRate | |
ExchangeRateTest:: |
public | function | @covers ::getExchangeRateProviderId @covers ::setExchangeRateProviderId | |
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. |