diff --git a/core/lib/Drupal/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php b/core/lib/Drupal/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php index df9fccd..045a7e1 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php +++ b/core/lib/Drupal/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumper.php @@ -132,13 +132,13 @@ protected function getServiceDefinitions() { * * @param array $parameters * An array of parameters. - * * @param bool $escape * Whether keys with '%' should be escaped or not. * * @return array + * Returns an array of prepared parameters. */ - protected function prepareParameters($parameters, $escape = true) { + protected function prepareParameters(array $parameters, $escape = TRUE) { $filtered = array(); foreach ($parameters as $key => $value) { if (is_array($value)) { @@ -163,7 +163,7 @@ protected function prepareParameters($parameters, $escape = true) { * @return array * The escaped parameters. */ - protected function escape($parameters) { + protected function escape(array $parameters) { $args = array(); foreach ($parameters as $key => $value) { @@ -190,7 +190,7 @@ protected function escape($parameters) { * @return array * The service definition as PHP array. */ - protected function getServiceDefinition($definition) { + protected function getServiceDefinition(Definition $definition) { $service = array(); if ($definition->getClass()) { $service['class'] = $definition->getClass(); @@ -265,7 +265,7 @@ protected function getServiceDefinition($definition) { * @return array * The PHP array representation of the method calls. */ - protected function dumpMethodCalls($calls) { + protected function dumpMethodCalls(array $calls) { $code = array(); foreach ($calls as $key => $call) { @@ -329,7 +329,7 @@ protected function dumpCollection($collection, &$resolve = FALSE) { /** * Dumps callable to a PHP array. * - * @param callable $callable + * @param array|callable $callable * The callable to process. * * @return callable @@ -352,7 +352,8 @@ protected function dumpCallable($callable) { * @param \Symfony\Component\DependencyInjection\Definition $definition * The definition to process. * @param bool $shared - * (optional) Whether the service will be shared with others. Default: FALSE + * (optional) Whether the service will be shared with others. + * By default this parameter is FALSE. * * @return \stdClass * A very lightweight private service value object. @@ -380,7 +381,8 @@ protected function getPrivateServiceCall($id, Definition $definition, $shared = * @return mixed * The dumped value in a suitable format. * - * @throws RuntimeException When trying to dump object or resource + * @throws RuntimeException + * When trying to dump object or resource. */ protected function dumpValue($value) { if (is_array($value)) { @@ -489,7 +491,8 @@ protected function getParameterCall($name) { * @param string $expression * The expression to dump. * - * @throws RuntimeException When trying to dump an expression. + * @throws RuntimeException + * When trying to dump an expression. */ protected function getExpressionCall($expression) { throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.'); diff --git a/core/lib/Drupal/Core/DependencyInjection/Dumper/PhpArrayDumper.php b/core/lib/Drupal/Core/DependencyInjection/Dumper/PhpArrayDumper.php index d1da275..47349c1 100644 --- a/core/lib/Drupal/Core/DependencyInjection/Dumper/PhpArrayDumper.php +++ b/core/lib/Drupal/Core/DependencyInjection/Dumper/PhpArrayDumper.php @@ -10,10 +10,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** - * DebugPhpArrayDumper dumps a service container as a human readable serialized - * PHP array. + * PhpArrayDumper dumps a service container as a PHP array. * - * The format of this dumper is very similar to the YAML based format, but + * The format of this dumper is a human readable serialized + * PHP array, which is very similar to the YAML based format, but * based on PHP arrays instead of YAML strings. * * It is human readable, for a machine optimized version based on this one see diff --git a/core/lib/Drupal/Core/DependencyInjection/PhpArrayContainer.php b/core/lib/Drupal/Core/DependencyInjection/PhpArrayContainer.php index 694098b..7f6f3b9 100644 --- a/core/lib/Drupal/Core/DependencyInjection/PhpArrayContainer.php +++ b/core/lib/Drupal/Core/DependencyInjection/PhpArrayContainer.php @@ -92,36 +92,47 @@ protected function createService($definition, $id) { case 0: $service = new $class(); break; + case 1: $service = new $class($arguments[0]); break; + case 2: $service = new $class($arguments[0], $arguments[1]); break; + case 3: $service = new $class($arguments[0], $arguments[1], $arguments[2]); break; + case 4: $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3]); break; + case 5: $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]); break; + case 6: $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]); break; + case 7: $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6]); break; + case 8: $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7]); break; + case 9: $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8]); break; + case 10: $service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8], $arguments[9]); break; + default: $r = new \ReflectionClass($class); $service = $r->newInstanceArgs($arguments); @@ -176,12 +187,12 @@ protected function createService($definition, $id) { * {@inheritdoc} */ protected function resolveServicesAndParameters($arguments) { - // This method is different from the parent method only for the following cases: + // This method is different from the parent method only for the following + // cases: // - A service is denoted by '@service' and not by a \stdClass object. // - A parameter is denoted by '%parameter%' and not by a \stdClass object. // - Arguments are traversed recursively, there is no information how deep // to traverse. - foreach ($arguments as $key => $argument) { if ($argument instanceof \stdClass) { $type = $argument->type; @@ -193,6 +204,7 @@ protected function resolveServicesAndParameters($arguments) { // and to be able to create the service on the fly. // // Note: When constructing a private service by hand, 'id' must be set. + // // The PhpArrayDumper just uses the hash of the private service // definition to generate a unique id. // @@ -258,4 +270,5 @@ protected function resolveServicesAndParameters($arguments) { return $arguments; } + } diff --git a/core/modules/system/src/Tests/ServiceProvider/ServiceProviderWebTest.php b/core/modules/system/src/Tests/ServiceProvider/ServiceProviderWebTest.php index e743d7b..15120a5 100644 --- a/core/modules/system/src/Tests/ServiceProvider/ServiceProviderWebTest.php +++ b/core/modules/system/src/Tests/ServiceProvider/ServiceProviderWebTest.php @@ -24,13 +24,16 @@ class ServiceProviderWebTest extends WebTestBase { public static $modules = array('file', 'service_provider_test'); /** - * Tests that services provided by module service providers get registered to the DIC. + * Tests that module service providers get registered to the DIC. + * + * Also tests that services provided by module service providers get + * registered to the DIC. */ - function testServiceProviderRegistrationIntegration() { + public function testServiceProviderRegistrationIntegration() { $this->assertTrue(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service has been registered to the DIC'); - // The event subscriber method in the test class calls drupal_set_message with - // a message saying it has fired. This will fire on every page request so it - // should show up on the front page. + // The event subscriber method in the test class calls drupal_set_message + // with a message saying it has fired. This will fire on every page request + // so it should show up on the front page. $this->drupalGet(''); $this->assertText(t('The service_provider_test event subscriber fired!'), 'The service_provider_test event subscriber fired'); } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php index 8a7969b..82f5512 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php @@ -58,7 +58,7 @@ public function setUp() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ - public function test_construct() { + public function testConstruct() { $container_definition = $this->getMockContainerDefinition(); $container_definition['machine_format'] = !$this->machineFormat; $container = new $this->containerClass($container_definition, TRUE); @@ -69,7 +69,7 @@ public function test_construct() { * Tests that Container::getParameter() works properly. * @covers ::getParameter */ - public function test_getParameter() { + public function testGetParameter() { $this->assertEquals($this->containerDefinition['parameters']['some_config'], $this->container->getParameter('some_config'), 'Container parameter matches for %some_config%.'); $this->assertEquals($this->containerDefinition['parameters']['some_other_config'], $this->container->getParameter('some_other_config'), 'Container parameter matches for %some_other_config%.'); } @@ -84,7 +84,7 @@ public function test_getParameter() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException */ - public function test_getParameter_notFound() { + public function testGetParameterIfNotFound() { $this->container->getParameter('parameter_that_does_not_exist'); } @@ -95,7 +95,7 @@ public function test_getParameter_notFound() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException */ - public function test_getParameter_notFound_null() { + public function testGetParameterIfNotFoundBecauseNull() { $this->container->getParameter(NULL); } @@ -103,7 +103,7 @@ public function test_getParameter_notFound_null() { * Tests that Container::hasParameter() works properly. * @covers ::hasParameter */ - public function test_hasParameter() { + public function testHasParameter() { $this->assertTrue($this->container->hasParameter('some_config'), 'Container parameters include %some_config%.'); $this->assertFalse($this->container->hasParameter('some_config_not_exists'), 'Container parameters do not include %some_config_not_exists%.'); } @@ -113,7 +113,7 @@ public function test_hasParameter() { * * @covers ::setParameter */ - public function test_setParameter_unfrozenContainer() { + public function testSetParameterWithUnfrozenContainer() { $this->container = new $this->containerClass($this->containerDefinition, FALSE); $this->container->setParameter('some_config', 'new_value'); $this->assertEquals('new_value', $this->container->getParameter('some_config'), 'Container parameters can be set.'); @@ -126,7 +126,7 @@ public function test_setParameter_unfrozenContainer() { * * @expectedException LogicException */ - public function test_setParameter_frozenContainer() { + public function testSetParameterWithFrozenContainer() { $this->container = new $this->containerClass($this->containerDefinition, TRUE); $this->container->setParameter('some_config', 'new_value'); } @@ -137,7 +137,7 @@ public function test_setParameter_frozenContainer() { * @covers ::get * @covers ::createService */ - public function test_get() { + public function testGet() { $container = $this->container->get('service_container'); $this->assertSame($this->container, $container, 'Container can be retrieved from itself.'); @@ -164,7 +164,7 @@ public function test_get() { * @covers ::get * @covers ::createService */ - public function test_get_nonShared() { + public function testGetForNonSharedService() { $service = $this->container->get('non_shared_service'); $service2 = $this->container->get('non_shared_service'); @@ -176,7 +176,7 @@ public function test_get_nonShared() { * @covers ::get * @covers ::createService */ - public function test_get_classFromParameter() { + public function testGetForClassFromParameter() { $container = new $this->containerClass($this->containerDefinition, FALSE); $other_service_class = $this->containerDefinition['parameters']['some_parameter_class']; @@ -189,7 +189,7 @@ public function test_get_classFromParameter() { * * @covers ::set */ - public function test_set() { + public function testSet() { $this->assertNull($this->container->get('new_id', ContainerInterface::NULL_ON_INVALID_REFERENCE)); $mock_service = new MockService(); $this->container->set('new_id', $mock_service); @@ -202,7 +202,7 @@ public function test_set() { * * @covers ::set */ - public function test_set_serviceId() { + public function testSetHasServiceIdProperty() { $container = new $this->containerClass(); $class = new MockService(); $container->set('bar', $class); @@ -215,7 +215,7 @@ public function test_set_serviceId() { * * @covers ::has */ - public function test_has() { + public function testHas() { $this->assertTrue($this->container->has('other.service')); $this->assertFalse($this->container->has('another.service')); @@ -231,12 +231,12 @@ public function test_has() { * @covers ::get * @covers ::createService */ - public function test_get_circular() { + public function testGetForCircularServices() { $this->container->get('circular_dependency'); } /** - * Tests that Container::get() for non-existant dependencies works properly. + * Tests that Container::get() for non-existant services works properly. * * @covers ::get * @covers ::createService @@ -245,16 +245,17 @@ public function test_get_circular() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ - public function test_get_exception() { + public function testGetForNonExistantService() { $this->container->get('service_not_exists'); } /** - * Tests that Container::get() for serialized definition works properly. + * Tests that Container::get() for a serialized definition works properly. + * * @covers ::get * @covers ::createService */ - public function test_get_serializedDefinition() { + public function testGetForSerializedServiceDefinition() { $container_definition = $this->containerDefinition; $container_definition['services']['other.service'] = serialize($container_definition['services']['other.service']); $container = new $this->containerClass($container_definition); @@ -268,14 +269,14 @@ public function test_get_serializedDefinition() { $this->assertEquals($other_service, $service->getSomeOtherService(), '@other.service was injected via constructor.'); } - /** * Tests that Container::get() for non-existant parameters works properly. + * * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters */ - public function test_get_notFound_parameter() { + public function testGetForNonExistantParameterDependency() { $service = $this->container->get('service_parameter_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE); $this->assertNull($service, 'Service is NULL.'); } @@ -289,7 +290,7 @@ public function test_get_notFound_parameter() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ - public function test_get_notFound_parameterWithExceptionOnSecondCall() { + public function testGetForParameterDependencyWithExceptionOnSecondCall() { $service = $this->container->get('service_parameter_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE); $this->assertNull($service, 'Service is NULL.'); @@ -300,45 +301,50 @@ public function test_get_notFound_parameterWithExceptionOnSecondCall() { /** * Tests that Container::get() for non-existant parameters works properly. - * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ - public function test_get_notFound_parameter_exception() { + public function testGetForNonExistantParameterDependencyWithException() { $this->container->get('service_parameter_not_exists'); } /** * Tests that Container::get() for non-existent dependencies works properly. + * * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters */ - public function test_get_notFound_dependency() { + public function testGetForNonExistantServiceDependency() { $service = $this->container->get('service_dependency_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE); $this->assertNull($service, 'Service is NULL.'); } /** * Tests that Container::get() for non-existant dependencies works properly. - * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException + * * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters * @covers ::getAlternatives + * + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ - public function test_get_notFound_dependency_exception() { + public function testGetForNonExistantServiceDependencyWithException() { $this->container->get('service_dependency_not_exists'); } - /** - * Tests that Container::get() for non-existant dependencies works properly. + * Tests that Container::get() for non-existant services works properly. + * * @covers ::get * @covers ::createService */ - public function test_get_notFound() { + public function testGetForNonExistantServiceWhenUsingNull() { $this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does not throw exception.'); } @@ -349,18 +355,17 @@ public function test_get_notFound() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ - public function test_get_notFound_NULL() { + public function testGetForNonExistantNULLService() { $this->container->get(NULL); } - /** * Tests multiple Container::get() calls for non-existing dependencies work. * * @covers ::get * @covers ::createService */ - public function test_get_notFoundMultiple() { + public function testGetForNonExistantServiceMultipleTimes() { $container = new $this->containerClass(); $this->assertNull($container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE, 'Not found service does not throw exception.')); @@ -376,17 +381,18 @@ public function test_get_notFoundMultiple() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException */ - public function test_get_notFoundMulitpleWithExceptionOnSecondCall() { + public function testGetForNonExistantServiceWithExceptionOnSecondCall() { $this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE, 'Not found service does nto throw exception.')); $this->container->get('service_not_exists'); } /** * Tests that Container::get() for aliased services works properly. + * * @covers ::get * @covers ::createService */ - public function test_get_alias() { + public function testGetForAliasedService() { $service = $this->container->get('service.provider'); $aliased_service = $this->container->get('service.provider_alias'); $this->assertSame($service, $aliased_service); @@ -398,7 +404,7 @@ public function test_get_alias() { * @covers ::get * @covers ::createService */ - public function test_get_synthetic() { + public function testGetForSyntheticService() { $synthetic_service = new \stdClass(); $this->container->set('synthetic', $synthetic_service); $test_service = $this->container->get('synthetic'); @@ -413,7 +419,7 @@ public function test_get_synthetic() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ - public function test_get_synthetic_exception() { + public function testGetForSyntheticServiceWithException() { $this->container->get('synthetic'); } @@ -423,20 +429,20 @@ public function test_get_synthetic_exception() { * @covers ::get * @covers ::createService */ - public function test_get_file() { + public function testGetWithFileInclude() { $file_service = $this->container->get('container_test_file_service_test'); $this->assertTrue(function_exists('container_test_file_service_test_service_function')); $this->assertEquals('Hello Container', container_test_file_service_test_service_function()); } /** - * Tests that Container::get() for services with file includes works. + * Tests that Container::get() for various arguments lengths works. * * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters */ - public function test_get_instantiation() { + public function testGetForInstantiationWithVariousArgumentLengths() { $args = array(); for ($i=0; $i < 12; $i++) { $instantiation_service = $this->container->get('service_test_instantiation_'. $i); @@ -453,16 +459,17 @@ public function test_get_instantiation() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ - public function test_get_factoryWrong() { + public function testGetForWrongFactory() { $this->container->get('wrong_factory'); } /** * Tests Container::get() for factories via services (Symfony 2.7.0). + * * @covers ::get * @covers ::createService */ - public function test_get_factoryService() { + public function testGetForFactoryService() { $factory_service = $this->container->get('factory_service'); $factory_service_class = $this->container->getParameter('factory_service_class'); $this->assertInstanceOf($factory_service_class, $factory_service); @@ -473,7 +480,7 @@ public function test_get_factoryService() { * @covers ::get * @covers ::createService */ - public function test_get_factoryClass() { + public function testGetForFactoryClass() { $service = $this->container->get('service.provider'); $factory_service= $this->container->get('factory_class'); @@ -490,7 +497,7 @@ public function test_get_factoryClass() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ - public function test_get_configurator_exception() { + public function testGetForConfiguratorWithException() { $this->container->get('configurable_service_exception'); } @@ -499,7 +506,7 @@ public function test_get_configurator_exception() { * @covers ::get * @covers ::createService */ - public function test_get_configurator() { + public function testGetForConfigurator() { $container = $this->container; // Setup a configurator. @@ -522,7 +529,7 @@ public function test_get_configurator() { * @covers ::createService * @covers ::resolveServicesAndParameters */ - public function test_resolveServicesAndParameters_privateService() { + public function testResolveServicesAndParametersForPrivateService() { $service = $this->container->get('service_using_private'); $private_service = $service->getSomeOtherService(); $this->assertEquals($private_service->getSomeParameter(), 'really_private_lama', 'Private was found successfully.'); @@ -541,7 +548,7 @@ public function test_resolveServicesAndParameters_privateService() { * @covers ::createService * @covers ::resolveServicesAndParameters */ - public function test_resolveServicesAndParameters_privateServiceShared() { + public function testResolveServicesAndParametersForSharedPrivateService() { $service = $this->container->get('service_using_shared_private'); $private_service = $service->getSomeOtherService(); $this->assertEquals($private_service->getSomeParameter(), 'really_private_lama', 'Private was found successfully.'); @@ -555,11 +562,12 @@ public function test_resolveServicesAndParameters_privateServiceShared() { /** * Tests that services with an array of arguments work correctly. + * * @covers ::get * @covers ::createService * @covers ::resolveServicesAndParameters */ - public function test_resolveServicesAndParameters_array() { + public function testResolveServicesAndParametersForArgumentsUsingDeepArray() { $service = $this->container->get('service_using_array'); $other_service = $this->container->get('other.service'); $this->assertEquals($other_service, $service->getSomeOtherService(), '@other.service was injected via constructor.'); @@ -571,7 +579,7 @@ public function test_resolveServicesAndParameters_array() { * @covers ::createService * @covers ::resolveServicesAndParameters */ - public function test_resolveServicesAndParameters_optional() { + public function testResolveServicesAndParametersForOptionalServiceDependencies() { $service = $this->container->get('service_with_optional_dependency'); $this->assertNull($service->getSomeOtherService(), 'other service was NULL was expected.'); } @@ -585,7 +593,7 @@ public function test_resolveServicesAndParameters_optional() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ - public function test_resolveServicesAndParameters_invalidArgument() { + public function testResolveServicesAndParametersForInvalidArgument() { $this->container->get('invalid_argument_service'); } @@ -598,7 +606,7 @@ public function test_resolveServicesAndParameters_invalidArgument() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ - public function test_resolveServicesAndParameters_invalidArguments() { + public function testResolveServicesAndParametersForInvalidArguments() { // In case the machine format is not used, we need to simulate the test failure. if (!$this->machineFormat) { throw new \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException('Simulating the test failure.'); @@ -613,18 +621,17 @@ public function test_resolveServicesAndParameters_invalidArguments() { * @covers ::createService * @covers ::resolveServicesAndParameters */ - public function test_resolveServicesAndParameters_fromParameter() { + public function testResolveServicesAndParametersForServiceInstantiatedFromParameter() { $service = $this->container->get('service.provider'); $test_service = $this->container->get('service_with_parameter_service'); $this->assertSame($service, $test_service->getSomeOtherService(), 'Service was passed via parameter.'); } - /** * Tests that Container::initialized works correctly. * @covers ::initialized */ - public function test_initialized() { + public function testInitialized() { $this->assertFalse($this->container->initialized('late.service'), 'Late service is not initialized.'); $this->container->get('late.service'); $this->assertTrue($this->container->initialized('late.service'), 'Late service is initialized after it was retrieved once.'); @@ -634,7 +641,7 @@ public function test_initialized() { * Tests that Container::initialized works correctly for aliases. * @covers ::initialized */ - public function test_initialized_aliases() { + public function testInitializedForAliases() { $this->assertFalse($this->container->initialized('late.service_alias'), 'Late service is not initialized.'); $this->container->get('late.service'); $this->assertTrue($this->container->initialized('late.service_alias'), 'Late service is initialized after it was retrieved once.'); @@ -653,7 +660,7 @@ public function test_initialized_aliases() { * * @dataProvider scopeExceptionTestProvider */ - public function test_scope_exception($method, $argument) { + public function testScopeFunctionsWithException($method, $argument) { $callable = array( $this->container, $method, @@ -663,7 +670,7 @@ public function test_scope_exception($method, $argument) { } /** - * Data provider for test_scope_exception(). + * Data provider for scopeExceptionTestProvider(). * * @return array[] * Returns per data set an array with: @@ -688,7 +695,7 @@ public function scopeExceptionTestProvider() { * * @expectedException \PHPUnit_Framework_Error */ - public function test_sleep() { + public function testSleepWithException() { $serialized = serialize($this->container); } @@ -697,7 +704,7 @@ public function test_sleep() { * * @covers ::__sleep */ - public function test_sleep_working() { + public function testSleepWithIgnoredErrors() { $container = new $this->containerClass(); // Ignore any errors. @@ -717,7 +724,7 @@ public function ignoreErrorHandler() { * * @covers ::getServiceIds */ - public function test_getServiceIds() { + public function testGetServiceIds() { $service_definition_keys = array_keys($this->containerDefinition['services']); $this->assertEquals($service_definition_keys, $this->container->getServiceIds(), 'Retrieved service IDs match definition.'); diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php index 01b49d9..d441ea8 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -63,7 +63,7 @@ public function setUp() { * @covers ::getArray * @covers ::getMachineFormat */ - public function test_dump() { + public function testDumpForEmptyContainer() { $serialized_definition = $this->dumper->dump(); $this->assertEquals(serialize($this->containerDefinition), $serialized_definition); } @@ -75,7 +75,7 @@ public function test_dump() { * * @dataProvider getAliasesDataProvider */ - public function test_getAliases($aliases, $definition_aliases) { + public function testGetAliases($aliases, $definition_aliases) { $this->containerDefinition['aliases'] = $definition_aliases; $this->containerBuilder->getAliases()->willReturn($aliases); $this->assertEquals($this->containerDefinition, $this->dumper->getArray(), 'Expected definition matches dump.'); @@ -114,7 +114,7 @@ public function getAliasesDataProvider() { * * @dataProvider getParametersDataProvider */ - public function test_getParameters($parameters, $definition_parameters, $is_frozen) { + public function testGetParameters($parameters, $definition_parameters, $is_frozen) { $this->containerDefinition['parameters'] = $definition_parameters; $parameter_bag = new ParameterBag($parameters); @@ -185,7 +185,7 @@ public function getParametersDataProvider() { * * @dataProvider getDefinitionsDataProvider */ - public function test_getServiceDefinitions($services, $definition_services) { + public function testGetServiceDefinitions($services, $definition_services) { $this->containerDefinition['services'] = $definition_services; $this->containerBuilder->getDefinitions()->willReturn($services); @@ -228,8 +228,7 @@ public function getDefinitionsDataProvider() { ); // Test basic flags. - $service_definitions[] = array( - ) + $base_service_definition; + $service_definitions[] = array() + $base_service_definition; $service_definitions[] = array( 'public' => FALSE, @@ -262,7 +261,6 @@ public function getDefinitionsDataProvider() { 'arguments_expected' => $this->getCollection(array($this->getServiceCall('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE))), ) + $base_service_definition; - // Test a private shared servied, denoted by having a Reference. $private_definition = array( 'class' => '\stdClass', @@ -273,7 +271,10 @@ public function getDefinitionsDataProvider() { $service_definitions[] = array( 'arguments' => array('foo', new Reference('private_definition')), 'arguments_count' => 2, - 'arguments_expected' => $this->getCollection(array('foo', $this->getPrivateServiceCall('private_definition', $private_definition, TRUE ))), + 'arguments_expected' => $this->getCollection(array( + 'foo', + $this->getPrivateServiceCall('private_definition', $private_definition, TRUE), + )), ) + $base_service_definition; // Test a private non-shared service, denoted by having a Definition. @@ -283,7 +284,10 @@ public function getDefinitionsDataProvider() { $service_definitions[] = array( 'arguments' => array('foo', $private_definition_object), 'arguments_count' => 2, - 'arguments_expected' => $this->getCollection(array('foo', $this->getPrivateServiceCall(NULL, $private_definition))), + 'arguments_expected' => $this->getCollection(array( + 'foo', + $this->getPrivateServiceCall(NULL, $private_definition), + )), ) + $base_service_definition; // Test a deep collection without a reference. @@ -447,7 +451,7 @@ protected function getServiceCall($id, $invalid_behavior = ContainerInterface::E * * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ - public function test_getServiceDefinition_getScope() { + public function testGetServiceDefinitionWithInvalidScope() { $bar_definition = new Definition('\stdClass'); $bar_definition->setScope('foo_scope'); $services['bar'] = $bar_definition; @@ -457,13 +461,16 @@ public function test_getServiceDefinition_getScope() { } /** - * Tests that the correct InvalidArgumentException is thrown for getDecoratedService(). + * Tests that getDecoratedService() is unsupported. + * + * Tests that the correct InvalidArgumentException is thrown for + * getDecoratedService(). * * @covers ::getServiceDefinition * * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ - public function test_getServiceDefinition_getDecoratedService() { + public function testGetServiceDefinitionForDecoratedService() { $bar_definition = new Definition('\stdClass'); $bar_definition->setDecoratedService(new Reference('foo')); $services['bar'] = $bar_definition; @@ -480,7 +487,7 @@ public function test_getServiceDefinition_getDecoratedService() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ - public function test_getServiceDefinition_getExpressionCall() { + public function testGetServiceDefinitionForExpression() { $expression = new Expression(); $bar_definition = new Definition('\stdClass'); @@ -498,7 +505,7 @@ public function test_getServiceDefinition_getExpressionCall() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ - public function test_getServiceDefinition_dumpObject() { + public function testGetServiceDefinitionForObject() { $service = new \stdClass(); $bar_definition = new Definition('\stdClass'); @@ -516,7 +523,7 @@ public function test_getServiceDefinition_dumpObject() { * * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException */ - public function test_getServiceDefinition_dumpResource() { + public function testGetServiceDefinitionForResource() { $resource = fopen('php://memory', 'r'); $bar_definition = new Definition('\stdClass'); @@ -574,6 +581,9 @@ protected function getParameterCall($name) { */ namespace Symfony\Component\ExpressionLanguage { if (!class_exists('\Symfony\Component\ExpressionLanguage\Expression')) { + /** + * Dummy class to ensure non-existant Symfony component can be tested. + */ class Expression { /** @@ -582,6 +592,7 @@ class Expression { public function __toString() { return 'dummy_expression'; } + } } } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Fixture/container_test_file_service_test_service_function.data b/core/tests/Drupal/Tests/Core/DependencyInjection/Fixture/container_test_file_service_test_service_function.data index 164eaaf..09960fe 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Fixture/container_test_file_service_test_service_function.data +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Fixture/container_test_file_service_test_service_function.data @@ -1,6 +1,11 @@ machineFormat = FALSE; $this->containerClass = '\Drupal\Core\DependencyInjection\PhpArrayContainer';