You are here

class TargetTest in Drupal 7 to 8/9 Module Upgrader 8

@group DMU

Hierarchy

Expanded class hierarchy of TargetTest

File

tests/src/Unit/TargetTest.php, line 10

Namespace

Drupal\Tests\drupalmoduleupgrader\Unit
View source
class TargetTest extends TestBase {

  /**
   * @var \Drupal\drupalmoduleupgrader\IndexerInterface
   */
  protected $indexer;
  public function setUp() {
    parent::setUp();
    $this->indexer = $this
      ->getMockBuilder('\\Drupal\\drupalmoduleupgrader\\Plugin\\DMU\\Indexer\\Functions')
      ->disableOriginalConstructor()
      ->getMock();
    $this->container
      ->get('plugin.manager.drupalmoduleupgrader.indexer')
      ->method('createInstance')
      ->with('function')
      ->willReturn($this->indexer);
  }

  /**
   * @expectedException \RuntimeException
   */
  public function testInvalidBasePath() {

    // Trying to create a target with an invalid path should instantly
    // throw an exception.
    new Target('foobar', $this->container);
  }
  public function testID() {
    $this
      ->assertEquals('foo', $this->target
      ->id());
  }
  public function testGetBasePath() {
    $this
      ->assertEquals($this->dir
      ->url(), $this->target
      ->getBasePath());
  }
  public function testGetPath() {
    $this
      ->assertEquals($this->dir
      ->getChild('foo.module')
      ->url(), $this->target
      ->getPath('.module'));
    $this
      ->assertEquals($this->dir
      ->getChild('foo.install')
      ->url(), $this->target
      ->getPath('.install'));
  }
  public function testGetFinder() {
    $this
      ->assertInstanceOf('\\Symfony\\Component\\Finder\\Finder', $this->target
      ->getFinder());
  }

  /**
   * @depends testGetFinder
   */
  public function testFinder() {
    $expected = $this->target
      ->getFinder()
      ->exclude('menu_example')
      ->name('*.module')
      ->name('*.install')
      ->name('*.inc')
      ->name('*.test')
      ->name('*.php');
    $this
      ->assertEquals(array_keys(iterator_to_array($expected)), array_keys(iterator_to_array($this->target
      ->getFinder())));
  }
  public function testGetIndexer() {
    $this
      ->assertSame($this->indexer, $this->target
      ->getIndexer('function'));
  }
  public function testGetServices() {
    $this
      ->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $this->target
      ->getServices());
  }
  public function testImplementsHook() {
    $this->indexer
      ->method('has')
      ->willReturnMap([
      [
        'hook_permission',
        TRUE,
      ],
      [
        'hook_menu_alter',
        FALSE,
      ],
    ]);
    $this
      ->assertTrue($this->target
      ->implementsHook('permission'));
    $this
      ->assertFalse($this->target
      ->implementsHook('menu_alter'));
  }

  /**
   * @expectedException \InvalidArgumentException
   */
  public function testExecuteUnimplementedHook() {
    $this->indexer
      ->method('has')
      ->with('hook_menu')
      ->willReturn(FALSE);
    $this->target
      ->executeHook('menu');
  }
  public function testExecuteHook() {
    $expected = [
      'foo/baz' => [
        'title' => 'It worked!',
      ],
    ];
    $this->indexer
      ->method('has')
      ->with('hook_menu')
      ->willReturn(TRUE);
    $this->indexer
      ->method('hasExecutable')
      ->with('hook_menu')
      ->willReturn(TRUE);
    $this->indexer
      ->method('execute')
      ->with('hook_menu')
      ->willReturn($expected);
    $actual = $this->target
      ->executeHook('menu');
    $this
      ->assertInternalType('array', $actual);
    $this
      ->assertSame($expected, $actual);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContainerMockTrait::$container protected property
ContainerMockTrait::mockContainer protected function
ContainerMockTrait::mockLogger protected function
ContainerMockTrait::mockTranslator protected function
ModuleMockerTrait::mockModule protected function
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.
SQLiteDatabaseTrait::$db protected property
SQLiteDatabaseTrait::initDB protected function
TargetTest::$indexer protected property
TargetTest::setUp public function Mocks an entire module, called foo, in a virtual file system. Overrides TestBase::setUp
TargetTest::testExecuteHook public function
TargetTest::testExecuteUnimplementedHook public function @expectedException \InvalidArgumentException
TargetTest::testFinder public function @depends testGetFinder
TargetTest::testGetBasePath public function
TargetTest::testGetFinder public function
TargetTest::testGetIndexer public function
TargetTest::testGetPath public function
TargetTest::testGetServices public function
TargetTest::testID public function
TargetTest::testImplementsHook public function
TargetTest::testInvalidBasePath public function @expectedException \RuntimeException
TestBase::$dir protected property
TestBase::$info protected property The parsed annotations for the test class and method being executed.
TestBase::$target protected property
TestBase::getPlugin protected function Instantiates the plugin class covered by this test (as indicated by the @covers annotation). The plugin instance is given a randomly generated ID and description. Dependencies will be pulled from $this->container, so this should only be called once… 1
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.