class TargetTest in Drupal 7 to 8/9 Module Upgrader 8
@group DMU
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\drupalmoduleupgrader\Unit\TestBase uses ContainerMockTrait, ModuleMockerTrait, SQLiteDatabaseTrait, PhpunitCompatibilityTrait
- class \Drupal\Tests\drupalmoduleupgrader\Unit\TargetTest
- class \Drupal\Tests\drupalmoduleupgrader\Unit\TestBase uses ContainerMockTrait, ModuleMockerTrait, SQLiteDatabaseTrait, PhpunitCompatibilityTrait
Expanded class hierarchy of TargetTest
File
- tests/
src/ Unit/ TargetTest.php, line 10
Namespace
Drupal\Tests\drupalmoduleupgrader\UnitView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContainerMockTrait:: |
protected | property | ||
ContainerMockTrait:: |
protected | function | ||
ContainerMockTrait:: |
protected | function | ||
ContainerMockTrait:: |
protected | function | ||
ModuleMockerTrait:: |
protected | function | ||
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. | |
SQLiteDatabaseTrait:: |
protected | property | ||
SQLiteDatabaseTrait:: |
protected | function | ||
TargetTest:: |
protected | property | ||
TargetTest:: |
public | function |
Mocks an entire module, called foo, in a virtual file system. Overrides TestBase:: |
|
TargetTest:: |
public | function | ||
TargetTest:: |
public | function | @expectedException \InvalidArgumentException | |
TargetTest:: |
public | function | @depends testGetFinder | |
TargetTest:: |
public | function | ||
TargetTest:: |
public | function | ||
TargetTest:: |
public | function | ||
TargetTest:: |
public | function | ||
TargetTest:: |
public | function | ||
TargetTest:: |
public | function | ||
TargetTest:: |
public | function | ||
TargetTest:: |
public | function | @expectedException \RuntimeException | |
TestBase:: |
protected | property | ||
TestBase:: |
protected | property | The parsed annotations for the test class and method being executed. | |
TestBase:: |
protected | property | ||
TestBase:: |
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:: |
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. |