class ServiceContainerAnnotationDiscoveryIntegrationTest in Service Container 7.2
Same name and namespace in other branches
- 7 modules/providers/service_container_annotation_discovery/lib/Drupal/service_container_annotation_discovery/Tests/ServiceContainerAnnotationDiscoveryIntegrationTest.php \Drupal\service_container_annotation_discovery\Tests\ServiceContainerAnnotationDiscoveryIntegrationTest
Hierarchy
- class \Drupal\service_container\Tests\ServiceContainerIntegrationTestBase extends \Drupal\service_container\Tests\DrupalWebTestCase
- class \Drupal\service_container_annotation_discovery\Tests\ServiceContainerAnnotationDiscoveryIntegrationTest
Expanded class hierarchy of ServiceContainerAnnotationDiscoveryIntegrationTest
File
- modules/
providers/ service_container_annotation_discovery/ lib/ Drupal/ service_container_annotation_discovery/ Tests/ ServiceContainerAnnotationDiscoveryIntegrationTest.php, line 16 - Contains \Drupal\service_container_annotation_discovery\Tests\ServiceContainerBlockIntegrationTest.
Namespace
Drupal\service_container_annotation_discovery\TestsView source
class ServiceContainerAnnotationDiscoveryIntegrationTest extends ServiceContainerIntegrationTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
$modules[] = 'service_container_annotation_discovery_test';
$modules[] = 'service_container_annotation_discovery_subtest';
parent::setUp($modules);
$this->container = \Drupal::getContainer();
}
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'ServiceContainerAnnotationDirectoryIntegrationTest',
'description' => 'Tests the \\ServiceContainer Annotation Discovery class',
'group' => 'service_container',
);
}
/**
* Tests if plugins with annotations are available as services.
*/
public function testDoctrinePlugin() {
$plugins = array(
array(
'owner' => 'sc_doctrine_test',
'type' => 'Plugin1',
'name' => 'Plugin1A',
),
array(
'owner' => 'sc_doctrine_test',
'type' => 'Plugin2',
'name' => 'Plugin2B',
),
);
foreach ($plugins as $plugin) {
$plugin_manager = $this->container
->get($plugin['owner'] . '.' . $plugin['type']);
$this
->assertTrue($plugin_manager
->hasDefinition($plugin['name']));
$object = $plugin_manager
->createInstance($plugin['name']);
$this
->assertTrue($object instanceof PluginBase);
}
$plugin = array(
'owner' => 'sc_doctrine_test',
'type' => 'Plugin3',
'name' => 'Plugin1C',
);
try {
$this->container
->get($plugin['owner'] . '.' . $plugin['type']);
} catch (\RuntimeException $e) {
$this
->pass('Bad input correctly threw an exception');
}
$plugin = array(
'owner' => 'sc_doctrine_test',
'type' => 'Plugin1',
'name' => 'Plugin3A',
);
$plugin_manager = $this->container
->get($plugin['owner'] . '.' . $plugin['type']);
$this
->assertFalse($plugin_manager
->hasDefinition($plugin['name']));
$plugin = array(
'owner' => 'sc_doctrine_test',
'type' => 'Plugin3',
'name' => 'Plugin3A',
);
$plugin_manager = $this->container
->get($plugin['owner'] . '.' . $plugin['type']);
$this
->assertTrue($plugin_manager
->hasDefinition($plugin['name']));
$object = $plugin_manager
->createInstance($plugin['name']);
$this
->assertEqual($object
->getData(), 'Hello world!');
$plugin = array(
'owner' => 'sc_doctrine_test',
'type' => 'Plugin4',
'name' => 'Plugin4A',
);
$plugin_manager = $this->container
->get($plugin['owner'] . '.' . $plugin['type']);
$this
->assertTrue($plugin_manager
->hasDefinition($plugin['name']));
$object = $plugin_manager
->createInstance($plugin['name']);
$this
->assertTrue($object
->getMessenger() instanceof MessengerInterface);
}
/**
* Tests if multiple module with plugins annotations are available as services.
*/
function testMultiple() {
$plugins = array(
array(
'owner' => 'sc_doctrine_test',
'type' => 'Plugin1',
'name' => 'Plugin1A',
),
array(
'owner' => 'sc_doctrine_test',
'type' => 'Plugin5',
'name' => 'Plugin5B',
),
);
foreach ($plugins as $plugin) {
$plugin_manager = $this->container
->get($plugin['owner'] . '.' . $plugin['type']);
$this
->assertTrue($plugin_manager
->hasDefinition($plugin['name']));
$object = $plugin_manager
->createInstance($plugin['name']);
$this
->assertTrue($object instanceof PluginBase);
}
}
/**
* Tests plugin_manager_name key in definition.
*/
function testPluginManagerKey() {
$plugins = array(
array(
'plugin_manager_name' => 'drupal8ftw',
'name' => 'Plugin5A',
),
);
foreach ($plugins as $plugin) {
$plugin_manager = $this->container
->get($plugin['plugin_manager_name']);
$this
->assertTrue($plugin_manager
->hasDefinition($plugin['name']));
$object = $plugin_manager
->createInstance($plugin['name']);
$this
->assertTrue($object instanceof PluginBase);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ServiceContainerAnnotationDiscoveryIntegrationTest:: |
public static | function | ||
ServiceContainerAnnotationDiscoveryIntegrationTest:: |
protected | function |
Overrides ServiceContainerIntegrationTestBase:: |
|
ServiceContainerAnnotationDiscoveryIntegrationTest:: |
public | function | Tests if plugins with annotations are available as services. | |
ServiceContainerAnnotationDiscoveryIntegrationTest:: |
function | Tests if multiple module with plugins annotations are available as services. | ||
ServiceContainerAnnotationDiscoveryIntegrationTest:: |
function | Tests plugin_manager_name key in definition. | ||
ServiceContainerIntegrationTestBase:: |
protected | property | The dependency injection container usable in the test. | |
ServiceContainerIntegrationTestBase:: |
protected | property | The profile to install as a basis for testing. | 1 |