class AmountFormatterManagerTest in Currency 8.3
@coversDefaultClass \Drupal\currency\Plugin\Currency\AmountFormatter\AmountFormatterManager
@group Currency
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\currency\Unit\Plugin\Currency\AmountFormatter\AmountFormatterManagerTest
Expanded class hierarchy of AmountFormatterManagerTest
File
- tests/
src/ Unit/ Plugin/ Currency/ AmountFormatter/ AmountFormatterManagerTest.php, line 21
Namespace
Drupal\Tests\currency\Unit\Plugin\Currency\AmountFormatterView source
class AmountFormatterManagerTest extends UnitTestCase {
/**
* The cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $cache;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configFactory;
/**
* The plugin discovery.
*
* @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $discovery;
/**
* The plugin factory.
*
* @var \Drupal\Component\Plugin\Factory\DefaultFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $factory;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $moduleHandler;
/**
* The class under test.
*
* @var \Drupal\currency\Plugin\Currency\AmountFormatter\AmountFormatterManager
*/
public $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->discovery = $this
->createMock(DiscoveryInterface::class);
$this->factory = $this
->getMockBuilder(DefaultFactory::class)
->disableOriginalConstructor()
->getMock();
$this->moduleHandler = $this
->createMock(ModuleHandlerInterface::class);
$this->cache = $this
->createMock(CacheBackendInterface::class);
$this->configFactory = $this
->createMock(ConfigFactoryInterface::class);
$namespaces = new ArrayObject();
$this->sut = new AmountFormatterManager($namespaces, $this->cache, $this->moduleHandler, $this->configFactory);
$discovery_property = new \ReflectionProperty($this->sut, 'discovery');
$discovery_property
->setAccessible(TRUE);
$discovery_property
->setValue($this->sut, $this->discovery);
$factory_property = new \ReflectionProperty($this->sut, 'factory');
$factory_property
->setAccessible(TRUE);
$factory_property
->setValue($this->sut, $this->factory);
}
/**
* @covers ::getFallbackPluginId
*/
public function testGetFallbackPluginId() {
$plugin_id = $this
->randomMachineName();
$plugin_configuration = array(
$this
->randomMachineName(),
);
$this
->assertIsString($this->sut
->getFallbackPluginId($plugin_id, $plugin_configuration));
}
/**
* @covers ::getDefaultPluginId
*/
public function testGetDefaultPluginId() {
$plugin_id = $this
->randomMachineName();
$config = $this
->getMockBuilder(Config::class)
->disableOriginalConstructor()
->getMock();
$config
->expects($this
->once())
->method('get')
->with('plugin_id')
->willReturn($plugin_id);
$this->configFactory
->expects($this
->once())
->method('get')
->with('currency.amount_formatting')
->willReturn($config);
$this
->assertSame($plugin_id, $this->sut
->getDefaultPluginId());
}
/**
* @covers ::setDefaultPluginId
*/
public function testSetDefaultPluginId() {
$plugin_id = $this
->randomMachineName();
$config = $this
->getMockBuilder(Config::class)
->disableOriginalConstructor()
->getMock();
$config
->expects($this
->once())
->method('set')
->with('plugin_id', $plugin_id)
->will($this
->returnSelf());
$config
->expects($this
->once())
->method('save');
$this->configFactory
->expects($this
->once())
->method('get')
->with('currency.amount_formatting')
->willReturn($config);
$this
->assertSame(spl_object_hash($this->sut), spl_object_hash($this->sut
->setDefaultPluginId($plugin_id)));
}
/**
* @covers ::getDefaultPlugin
*/
public function testGetDefaultPlugin() {
$namespaces = new ArrayObject();
$default_plugin_id = $this
->randomMachineName();
$formatter = $this
->createMock(AmountFormatterInterface::class);
/** @var \Drupal\currency\Plugin\Currency\AmountFormatter\AmountFormatterManager|\PHPUnit_Framework_MockObject_MockObject $currency_amount_formatter_manager */
$currency_amount_formatter_manager = $this
->getMockBuilder(AmountFormatterManager::class)
->setConstructorArgs(array(
$namespaces,
$this->cache,
$this->moduleHandler,
$this->configFactory,
))
->setMethods(array(
'getDefaultPluginId',
'createInstance',
))
->getMock();
$currency_amount_formatter_manager
->expects($this
->once())
->method('getDefaultPluginId')
->willReturn($default_plugin_id);
$currency_amount_formatter_manager
->expects($this
->once())
->method('createInstance')
->with($default_plugin_id)
->willReturn($formatter);
$this
->assertSame(spl_object_hash($formatter), spl_object_hash($currency_amount_formatter_manager
->getDefaultPlugin()));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AmountFormatterManagerTest:: |
protected | property | The cache backend. | |
AmountFormatterManagerTest:: |
protected | property | The config factory. | |
AmountFormatterManagerTest:: |
protected | property | The plugin discovery. | |
AmountFormatterManagerTest:: |
protected | property | The plugin factory. | |
AmountFormatterManagerTest:: |
protected | property | The module handler. | |
AmountFormatterManagerTest:: |
public | property | The class under test. | |
AmountFormatterManagerTest:: |
public | function |
Overrides UnitTestCase:: |
|
AmountFormatterManagerTest:: |
public | function | @covers ::getDefaultPlugin | |
AmountFormatterManagerTest:: |
public | function | @covers ::getDefaultPluginId | |
AmountFormatterManagerTest:: |
public | function | @covers ::getFallbackPluginId | |
AmountFormatterManagerTest:: |
public | function | @covers ::setDefaultPluginId | |
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. |