class FixedRatesOverviewTest in Currency 8.3
@coversDefaultClass \Drupal\currency\Controller\FixedRatesOverview
@group Currency
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\currency\Unit\Controller\FixedRatesOverviewTest
Expanded class hierarchy of FixedRatesOverviewTest
File
- tests/
src/ Unit/ Controller/ FixedRatesOverviewTest.php, line 22
Namespace
Drupal\Tests\currency\Unit\ControllerView source
class FixedRatesOverviewTest extends UnitTestCase {
/**
* The currency amount formatter manager.
*
* @var \Drupal\currency\Plugin\Currency\AmountFormatter\AmountFormatterManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $currencyAmountFormatterManager;
/**
* The currency exchange rate provider manager.
*
* @var \Drupal\currency\Plugin\Currency\ExchangeRateProvider\ExchangeRateProviderManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $currencyExchangeRateProviderManager;
/**
* The currency storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $currencyStorage;
/**
* The string translator.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $stringTranslation;
/**
* The class under test.
*
* @var \Drupal\currency\Controller\FixedRatesOverview
*/
protected $sut;
/**
* The URL generator.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $urlGenerator;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->currencyStorage = $this
->createMock(EntityStorageInterface::class);
$this->currencyAmountFormatterManager = $this
->createMock(AmountFormatterManagerInterface::class);
$this->currencyExchangeRateProviderManager = $this
->createMock(ExchangeRateProviderManagerInterface::class);
$this->stringTranslation = $this
->getStringTranslationStub();
$this->urlGenerator = $this
->createMock(UrlGeneratorInterface::class);
$this->sut = new FixedRatesOverview($this->stringTranslation, $this->urlGenerator, $this->currencyStorage, $this->currencyAmountFormatterManager, $this->currencyExchangeRateProviderManager);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$entity_type_manager = $this
->createMock(EntityTypeManagerInterface::class);
$entity_type_manager
->expects($this
->atLeastOnce())
->method('getStorage')
->with('currency')
->willReturn($this->currencyStorage);
$container = $this
->createMock(ContainerInterface::class);
$map = array(
array(
'entity_type.manager',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$entity_type_manager,
),
array(
'plugin.manager.currency.amount_formatter',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->currencyAmountFormatterManager,
),
array(
'plugin.manager.currency.exchange_rate_provider',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->currencyExchangeRateProviderManager,
),
array(
'string_translation',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->stringTranslation,
),
array(
'url_generator',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->urlGenerator,
),
);
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$sut = FixedRatesOverview::create($container);
$this
->assertInstanceOf(FixedRatesOverview::class, $sut);
}
/**
* @covers ::overview
*/
public function testOverview() {
$currency_code_from = 'EUR';
$currency_code_to = 'NLG';
$rate = '2.20371';
$currency_from = $this
->createMock(CurrencyInterface::class);
$currency_from
->expects($this
->once())
->method('label');
$currency_to = $this
->createMock(CurrencyInterface::class);
$currency_to
->expects($this
->once())
->method('label');
$map = array(
array(
$currency_code_from,
$currency_from,
),
array(
$currency_code_to,
$currency_to,
),
);
$this->currencyStorage
->expects($this
->any())
->method('load')
->willReturnMap($map);
$rates_configuration = array(
$currency_code_from => array(
$currency_code_to => $rate,
),
);
$fixed_rates = $this
->getMockBuilder(FixedRates::class)
->disableOriginalConstructor()
->getMock();
$fixed_rates
->expects($this
->once())
->method('loadAll')
->willReturn($rates_configuration);
$this->currencyExchangeRateProviderManager
->expects($this
->once())
->method('createInstance')
->with('currency_fixed_rates')
->willReturn($fixed_rates);
$this->urlGenerator
->expects($this
->once())
->method('generateFromRoute')
->with('currency.exchange_rate_provider.fixed_rates.add');
$amount_formatter = $this
->createMock(AmountFormatterInterface::class);
$amount_formatter
->expects($this
->once())
->method('formatAmount')
->with($currency_to, $rate);
$this->currencyAmountFormatterManager
->expects($this
->once())
->method('getDefaultPlugin')
->willReturn($amount_formatter);
$build = $this->sut
->overview();
$this
->assertIsArray($build);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FixedRatesOverviewTest:: |
protected | property | The currency amount formatter manager. | |
FixedRatesOverviewTest:: |
protected | property | The currency exchange rate provider manager. | |
FixedRatesOverviewTest:: |
protected | property | The currency storage. | |
FixedRatesOverviewTest:: |
protected | property | The string translator. | |
FixedRatesOverviewTest:: |
protected | property | The class under test. | |
FixedRatesOverviewTest:: |
protected | property | The URL generator. | |
FixedRatesOverviewTest:: |
public | function |
Overrides UnitTestCase:: |
|
FixedRatesOverviewTest:: |
function | @covers ::create @covers ::__construct | ||
FixedRatesOverviewTest:: |
public | function | @covers ::overview | |
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. |