You are here

class EnableCurrencyTest in Currency 8.3

@coversDefaultClass \Drupal\currency\Controller\EnableCurrency

@group Currency

Hierarchy

Expanded class hierarchy of EnableCurrencyTest

File

tests/src/Unit/Controller/EnableCurrencyTest.php, line 17

Namespace

Drupal\Tests\currency\Unit\Controller
View source
class EnableCurrencyTest extends UnitTestCase {

  /**
   * The url generator.
   *
   * @var \Drupal\Core\Routing\UrlGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $urlGenerator;

  /**
   * The class under test.
   *
   * @var \Drupal\currency\Controller\EnableCurrency
   */
  protected $sut;

  /**
   * {@inheritdoc}
   */
  public function setUp() : void {
    $this->urlGenerator = $this
      ->createMock(UrlGeneratorInterface::class);
    $this->sut = new EnableCurrency($this->urlGenerator);
  }

  /**
   * @covers ::create
   * @covers ::__construct
   */
  function testCreate() {
    $container = $this
      ->createMock(ContainerInterface::class);
    $map = array(
      array(
        'url_generator',
        ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
        $this->urlGenerator,
      ),
    );
    $container
      ->expects($this
      ->any())
      ->method('get')
      ->willReturnMap($map);
    $sut = EnableCurrency::create($container);
    $this
      ->assertInstanceOf(EnableCurrency::class, $sut);
  }

  /**
   * @covers ::execute
   */
  public function testExecute() {
    $url = $this
      ->randomMachineName();
    $currency = $this
      ->createMock(CurrencyInterface::class);
    $currency
      ->expects($this
      ->once())
      ->method('enable');
    $currency
      ->expects($this
      ->once())
      ->method('save');
    $this->urlGenerator
      ->expects($this
      ->once())
      ->method('generateFromRoute')
      ->with('entity.currency.collection')
      ->willReturn($url);
    $response = $this->sut
      ->execute($currency);
    $this
      ->assertInstanceOf(RedirectResponse::class, $response);
    $this
      ->assertSame($url, $response
      ->getTargetUrl());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EnableCurrencyTest::$sut protected property The class under test.
EnableCurrencyTest::$urlGenerator protected property The url generator.
EnableCurrencyTest::setUp public function Overrides UnitTestCase::setUp
EnableCurrencyTest::testCreate function @covers ::create @covers ::__construct
EnableCurrencyTest::testExecute public function @covers ::execute
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.