final class FactoryMapperTest in Hook Event Dispatcher 8
Class FactoryMapperTest.
@group hook_event_dispatcher
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\hook_event_dispatcher\Unit\Preprocess\FactoryMapperTest
Expanded class hierarchy of FactoryMapperTest
File
- tests/
src/ Unit/ Preprocess/ FactoryMapperTest.php, line 13
Namespace
Drupal\Tests\hook_event_dispatcher\Unit\PreprocessView source
final class FactoryMapperTest extends UnitTestCase {
/**
* Factory mapper.
*
* @var \Drupal\hook_event_dispatcher\Service\PreprocessEventFactoryMapper
*/
private $mapper;
/**
* {@inheritdoc}
*/
public function setUp() {
$this->mapper = YamlDefinitionsLoader::getInstance()
->getMapper();
}
/**
* Test if all factories are in the YAML file.
*/
public function testYamlHasAllFactories() {
$factoriesYaml = YamlDefinitionsLoader::getInstance()
->getFactories();
$classNames = $this
->getFactoryClassNamesFromFilesystem();
self::assertCount(\count($factoriesYaml), $classNames);
foreach ($factoriesYaml as $entry) {
self::assertContains($entry['class'], $classNames);
}
}
/**
* Get the Factory class names from the filesystems directory.
*
* @return array
* Class names array.
*/
private function getFactoryClassNamesFromFilesystem() {
$files = \scandir(\dirname(\dirname(\dirname(\dirname(__DIR__)))) . '/src/Event/Preprocess/Factory', SCANDIR_SORT_NONE);
$invalidFactories = [
'.',
'..',
'PreprocessEventFactoryInterface.php',
];
$files = \array_filter($files, function ($file) use ($invalidFactories) {
return !\in_array($file, $invalidFactories, TRUE);
});
$classNames = [];
foreach ($files as $file) {
$classNames[] = 'Drupal\\hook_event_dispatcher\\Event\\Preprocess\\Factory\\' . \substr($file, 0, -4);
}
return $classNames;
}
/**
* Test a none existing hook.
*/
public function testNoneExistingHook() {
$factory = $this->mapper
->getFactory('NoneExistingHook');
self::assertEquals(NULL, $factory);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FactoryMapperTest:: |
private | property | Factory mapper. | |
FactoryMapperTest:: |
private | function | Get the Factory class names from the filesystems directory. | |
FactoryMapperTest:: |
public | function |
Overrides UnitTestCase:: |
|
FactoryMapperTest:: |
public | function | Test a none existing hook. | |
FactoryMapperTest:: |
public | function | Test if all factories are in the YAML file. | |
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. |