class DevelGenerateManagerTest
Same name in other branches
- 8.x-1.x devel_generate/tests/src/DevelGenerateManagerTest.php \Drupal\Tests\devel_generate\DevelGenerateManagerTest
- 4.x devel_generate/tests/src/Unit/DevelGenerateManagerTest.php \Drupal\Tests\devel_generate\Unit\DevelGenerateManagerTest
@coversDefaultClass \Drupal\devel_generate\DevelGeneratePluginManager @group devel_generate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\devel_generate\Unit\DevelGenerateManagerTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of DevelGenerateManagerTest
File
-
devel_generate/
tests/ src/ Unit/ DevelGenerateManagerTest.php, line 24
Namespace
Drupal\Tests\devel_generate\UnitView source
class DevelGenerateManagerTest extends UnitTestCase {
/**
* The plugin discovery.
*/
protected MockObject|DiscoveryInterface $discovery;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Mock the plugin discovery.
$this->discovery = $this->createMock(DiscoveryInterface::class);
$this->discovery
->expects($this->any())
->method('getDefinitions')
->willReturnCallback(function () : array {
return $this->getMockDefinitions();
});
}
/**
* Test creating an instance of the DevelGenerateManager.
*/
public function testCreateInstance() : void {
$namespaces = new \ArrayObject([
'Drupal\\devel_generate_example' => realpath(__DIR__ . '/../../../modules/devel_generate_example/lib'),
]);
$cache_backend = $this->createMock(CacheBackendInterface::class);
$module_handler = $this->createMock(ModuleHandlerInterface::class);
$entity_type_manager = $this->createMock(EntityTypeManager::class);
$messenger = $this->createMock(MessengerInterface::class);
$language_manager = $this->createMock(LanguageManagerInterface::class);
$string_translation = $this->createMock(TranslationInterface::class);
$entityFieldManager = $this->createMock(EntityFieldManagerInterface::class);
$manager = new DevelGeneratePluginManager($namespaces, $cache_backend, $module_handler, $entity_type_manager, $messenger, $language_manager, $string_translation, $entityFieldManager);
// Use reflection to set the protected discovery property.
$reflection = new \ReflectionClass($manager);
$property = $reflection->getProperty('discovery');
$property->setValue($manager, $this->discovery);
$container = new ContainerBuilder();
$time = $this->createMock(TimeInterface::class);
$container->set('entity_type.manager', $entity_type_manager);
$container->set('messenger', $messenger);
$container->set('language_manager', $language_manager);
$container->set('module_handler', $module_handler);
$container->set('string_translation', $string_translation);
$container->set('entity_field.manager', $entityFieldManager);
$container->set('datetime.time', $time);
\Drupal::setContainer($container);
$example_instance = $manager->createInstance('devel_generate_example');
$plugin_def = $example_instance->getPluginDefinition();
$this->assertInstanceOf(ExampleDevelGenerate::class, $example_instance);
$this->assertArrayHasKey('url', $plugin_def);
$this->assertTrue($plugin_def['url'] == 'devel_generate_example');
}
/**
* Callback function to return mock definitions.
*
* @return array
* The mock of devel generate plugin definitions.
*/
public function getMockDefinitions() : array {
return [
'devel_generate_example' => [
'id' => 'devel_generate_example',
'class' => ExampleDevelGenerate::class,
'url' => 'devel_generate_example',
'dependencies' => [],
],
];
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
DevelGenerateManagerTest::$discovery | protected | property | The plugin discovery. | |||
DevelGenerateManagerTest::getMockDefinitions | public | function | Callback function to return mock definitions. | |||
DevelGenerateManagerTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
DevelGenerateManagerTest::testCreateInstance | public | function | Test creating an instance of the DevelGenerateManager. | |||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |||
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |||
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
UnitTestCase::$root | protected | property | The app root. | 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::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::setUpBeforeClass | public static | function | ||||
UnitTestCase::__get | public | function |