You are here

class CurrencyTest in Currency 8.3

Same name in this branch
  1. 8.3 tests/src/Kernel/CurrencyTest.php \Drupal\Tests\currency\Kernel\CurrencyTest
  2. 8.3 tests/src/Unit/Entity/CurrencyTest.php \Drupal\Tests\currency\Unit\Entity\CurrencyTest
  3. 8.3 tests/src/Unit/Plugin/views/filter/CurrencyTest.php \Drupal\Tests\currency\Unit\Plugin\views\filter\CurrencyTest
  4. 8.3 tests/src/Unit/Plugin/views/field/CurrencyTest.php \Drupal\Tests\currency\Unit\Plugin\views\field\CurrencyTest

@coversDefaultClass \Drupal\currency\Plugin\views\filter\Currency

@group Currency

Hierarchy

Expanded class hierarchy of CurrencyTest

File

tests/src/Unit/Plugin/views/filter/CurrencyTest.php, line 15

Namespace

Drupal\Tests\currency\Unit\Plugin\views\filter
View source
class CurrencyTest extends UnitTestCase {

  /**
   * The form helper
   *
   * @var \Drupal\currency\FormHelperInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $formHelper;

  /**
   * The class under test.
   *
   * @var \Drupal\currency\Plugin\views\field\Currency
   */
  protected $sut;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    $configuration = [];
    $plugin_id = $this
      ->randomMachineName();
    $plugin_definition = [];
    $this->formHelper = $this
      ->createMock(FormHelperInterface::class);
    $this->sut = new Currency($configuration, $plugin_id, $plugin_definition, $this->formHelper);
  }

  /**
   * @covers ::create
   * @covers ::__construct
   */
  function testCreate() {
    $container = $this
      ->createMock(ContainerInterface::class);
    $map = [
      [
        'currency.form_helper',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $this->formHelper,
      ],
    ];
    $container
      ->expects($this
      ->any())
      ->method('get')
      ->willReturnMap($map);
    $configuration = [];
    $plugin_id = $this
      ->randomMachineName();
    $plugin_definition = [];
    $sut = Currency::create($container, $configuration, $plugin_id, $plugin_definition);
    $this
      ->assertInstanceOf(Currency::class, $sut);
  }

  /**
   * @covers ::getValueOptions
   */
  public function testGetValueOptions() {
    $options = array(
      $this
        ->randomMachineName() => $this
        ->randomMachineName(),
    );
    $this->formHelper
      ->expects($this
      ->atLeastOnce())
      ->method('getCurrencyOptions')
      ->willReturn($options);
    $method = new \ReflectionMethod($this->sut, 'getValueOptions');
    $method
      ->setAccessible(TRUE);
    $this
      ->assertSame($options, $method
      ->invoke($this->sut));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CurrencyTest::$formHelper protected property The form helper
CurrencyTest::$sut protected property The class under test.
CurrencyTest::setUp public function Overrides UnitTestCase::setUp
CurrencyTest::testCreate function @covers ::create @covers ::__construct
CurrencyTest::testGetValueOptions public function @covers ::getValueOptions
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.