class AddCurrencyLocaleTest in Currency 8.3
@coversDefaultClass \Drupal\currency\Controller\AddCurrencyLocale
@group Currency
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\currency\Unit\Controller\AddCurrencyLocaleTest
Expanded class hierarchy of AddCurrencyLocaleTest
File
- tests/
src/ Unit/ Controller/ AddCurrencyLocaleTest.php, line 19
Namespace
Drupal\Tests\currency\Unit\ControllerView source
class AddCurrencyLocaleTest extends UnitTestCase {
/**
* The currency locale storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $currencyLocaleStorage;
/**
* The entity form builder.
*
* @var \Drupal\Core\Entity\EntityFormBuilderInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityFormBuilder;
/**
* The class under test.
*
* @var \Drupal\currency\Controller\AddCurrencyLocale
*/
protected $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->currencyLocaleStorage = $this
->createMock(EntityStorageInterface::class);
$this->entityFormBuilder = $this
->createMock(EntityFormBuilderInterface::class);
$this->sut = new AddCurrencyLocale($this->entityFormBuilder, $this->currencyLocaleStorage);
}
/**
* @covers ::create
* @covers ::__construct
*/
function testCreate() {
$entity_type_manager = $this
->createMock(EntityTypeManagerInterface::class);
$entity_type_manager
->expects($this
->atLeastOnce())
->method('getStorage')
->with('currency_locale')
->willReturn($this->currencyLocaleStorage);
$container = $this
->createMock(ContainerInterface::class);
$map = array(
array(
'entity.form_builder',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$this->entityFormBuilder,
),
array(
'entity_type.manager',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
$entity_type_manager,
),
);
$container
->expects($this
->any())
->method('get')
->willReturnMap($map);
$sut = AddCurrencyLocale::create($container);
$this
->assertInstanceOf(AddCurrencyLocale::class, $sut);
}
/**
* @covers ::execute
*/
public function testExecute() {
$currency_locale = $this
->createMock(CurrencyLocaleInterface::class);
$this->currencyLocaleStorage
->expects($this
->once())
->method('create')
->with(array())
->willReturn($currency_locale);
$form = $this
->createMock(EntityFormInterface::class);
$this->entityFormBuilder
->expects($this
->once())
->method('getForm')
->with($currency_locale)
->willReturn($form);
$this
->assertSame($form, $this->sut
->execute());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AddCurrencyLocaleTest:: |
protected | property | The currency locale storage. | |
AddCurrencyLocaleTest:: |
protected | property | The entity form builder. | |
AddCurrencyLocaleTest:: |
protected | property | The class under test. | |
AddCurrencyLocaleTest:: |
public | function |
Overrides UnitTestCase:: |
|
AddCurrencyLocaleTest:: |
function | @covers ::create @covers ::__construct | ||
AddCurrencyLocaleTest:: |
public | function | @covers ::execute | |
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. |