final class FactoryMapperTest in Hook Event Dispatcher 8.2
Same name and namespace in other branches
- 3.x modules/preprocess_event_dispatcher/tests/src/Unit/FactoryMapperTest.php \Drupal\Tests\preprocess_event_dispatcher\Unit\FactoryMapperTest
Class FactoryMapperTest.
@group preprocess_event_dispatcher
Hierarchy
- class \Drupal\Tests\preprocess_event_dispatcher\Unit\FactoryMapperTest extends \PHPUnit\Framework\TestCase
Expanded class hierarchy of FactoryMapperTest
File
- modules/
preprocess_event_dispatcher/ tests/ src/ Unit/ FactoryMapperTest.php, line 19
Namespace
Drupal\Tests\preprocess_event_dispatcher\UnitView source
final class FactoryMapperTest extends TestCase {
/**
* Factory mapper.
*
* @var \Drupal\preprocess_event_dispatcher\Service\PreprocessEventFactoryMapper
*/
private $mapper;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->mapper = YamlDefinitionsLoader::getInstance()
->getMapper();
}
/**
* Test if all factories are in the YAML file.
*/
public function testYamlHasAllFactories() : void {
$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() : array {
$files = scandir(dirname(__DIR__, 3) . '/src/Factory', SCANDIR_SORT_NONE);
$invalidFactories = [
'.',
'..',
'PreprocessEventFactoryInterface.php',
];
$files = array_filter($files, static function ($file) use ($invalidFactories) {
return !in_array($file, $invalidFactories, TRUE);
});
$classNames = [];
foreach ($files as $file) {
$classNames[] = 'Drupal\\preprocess_event_dispatcher\\Factory\\' . substr($file, 0, -4);
}
return $classNames;
}
/**
* Test a none existing hook.
*/
public function testNoneExistingHook() : void {
$factory = $this->mapper
->getFactory('NoneExistingHook');
self::assertNull($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 | ||
FactoryMapperTest:: |
public | function | Test a none existing hook. | |
FactoryMapperTest:: |
public | function | Test if all factories are in the YAML file. |