You are here

class ExchangeRateTest in Currency 8.3

@coversDefaultClass \Drupal\currency\ExchangeRate

@group Currency

Hierarchy

Expanded class hierarchy of ExchangeRateTest

File

tests/src/Unit/ExchangeRateTest.php, line 14

Namespace

Drupal\Tests\currency\Unit
View 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

Namesort descending Modifiers Type Description Overrides
ExchangeRateTest::$sut protected property The subject under test.
ExchangeRateTest::setUp public function Overrides UnitTestCase::setUp
ExchangeRateTest::testCreateFromExchangeRate public function @covers ::createFromExchangeRate
ExchangeRateTest::testGetExchangeRateProviderId public function @covers ::getExchangeRateProviderId @covers ::setExchangeRateProviderId
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.