diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArray/ContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArray/ContainerTest.php index 8a61fde..6ce69d9 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArray/ContainerTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArray/ContainerTest.php @@ -2,18 +2,17 @@ /** * @file - * Contains \Drupal\Tests\service_container\DependencyInjection\ContainerTest + * Contains \Drupal\Tests\Core\DependencyInjection\PhpArray\ContainerTest. */ -namespace Drupal\Tests\service_container\DependencyInjection; +namespace Drupal\Tests\Core\DependencyInjection\PhpArray; -use Drupal\service_container\DependencyInjection\Container; -use Drupal\service_container\DependencyInjection\ContainerInterface; - -use Mockery; +use Drupal\Core\DependencyInjection\PhpArray\Container; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Exception\LogicException; /** - * @coversDefaultClass \Drupal\service_container\DependencyInjection\Container + * @coversDefaultClass \Drupal\Core\DependencyInjection\PhpArray\Container * @group dic */ class ContainerTest extends \PHPUnit_Framework_TestCase { @@ -21,7 +20,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase { /** * The tested container. * - * @var \Drupal\service_container\DependencyInjection\Container + * @var \Drupal\Core\DependencyInjection\PhpArray\Container */ protected $container; @@ -38,45 +37,8 @@ public function setUp() { } /** - * Tests that Container::hasDefinition() works properly. - * @covers ::hasDefinition() - */ - public function test_hasDefinition() { - $this->assertEquals($this->container->hasDefinition('service_container'), TRUE, 'Container has definition of itself.'); - $this->assertEquals($this->container->hasDefinition('service.does_not_exist'), FALSE, 'Container does not have non-existent service.'); - $this->assertEquals($this->container->hasDefinition('service.provider'), TRUE, 'Container has service.provider service.'); - } - - /** - * Tests that Container::getDefinition() works properly. - * @covers ::getDefinition() - */ - public function test_getDefinition() { - $this->assertEquals( $this->containerDefinition['services']['service_container'], $this->container->getDefinition('service_container'), 'Container definition matches for container service.'); - $this->assertEquals( $this->containerDefinition['services']['service.provider'], $this->container->getDefinition('service.provider'), 'Container definition matches for service.provider service.'); - } - - /** - * Tests that Container::getDefinition() works properly. - * @expectedException \RuntimeException - * @covers ::getDefinition() - */ - public function test_getDefinition_exception() { - $this->container->getDefinition('service_not_exist'); - } - - - /** - * Tests that Container::getDefinitions() works properly. - * @covers ::getDefinitions() - */ - public function test_getDefinitions() { - $this->assertEquals($this->containerDefinition['services'], $this->container->getDefinitions(), 'Container definition matches input.'); - } - - /** * Tests that Container::getParameter() works properly. - * @covers ::getParameter() + * @covers ::getParameter */ public function test_getParameter() { $this->assertEquals($this->containerDefinition['parameters']['some_config'], $this->container->getParameter('some_config'), 'Container parameter matches for %some_config%.'); @@ -85,7 +47,7 @@ public function test_getParameter() { /** * Tests that Container::hasParameter() works properly. - * @covers ::hasParameter() + * @covers ::hasParameter */ public function test_hasParameter() { $this->assertTrue($this->container->hasParameter('some_config'), 'Container parameters include %some_config%.'); @@ -95,7 +57,7 @@ public function test_hasParameter() { /** * Tests that Container::setParameter() in an unfrozen case works properly. * - * @covers ::setParameter() + * @covers ::setParameter */ public function test_setParameter_unfrozenContainer() { $this->container = new Container($this->containerDefinition, FALSE); @@ -106,9 +68,9 @@ public function test_setParameter_unfrozenContainer() { /** * Tests that Container::setParameter() in a frozen case works properly. * - * @covers ::setParameter() + * @covers ::setParameter * - * @expectedException \BadMethodCallException + * @expectedException LogicException */ public function test_setParameter_frozenContainer() { $this->container->setParameter('some_config', 'new_value'); @@ -116,7 +78,7 @@ public function test_setParameter_frozenContainer() { /** * Tests that Container::get() works properly. - * @covers ::get() + * @covers ::get */ public function test_get() { $container = $this->container->get('service_container'); @@ -142,7 +104,7 @@ public function test_get() { /** * Tests that Container::set() works properly. * - * @covers ::set() + * @covers ::set */ public function test_set() { $this->assertNull($this->container->get('new_id', ContainerInterface::NULL_ON_INVALID_REFERENCE)); @@ -155,7 +117,7 @@ public function test_set() { /** * Tests that Container::has() works properly. * - * @covers ::has() + * @covers ::has */ public function test_has() { $this->assertTrue($this->container->has('other.service')); @@ -170,7 +132,7 @@ public function test_has() { /** * Tests that Container::get() for circular dependencies works properly. * @expectedException \RuntimeException - * @covers ::get() + * @covers ::get */ public function test_get_circular() { $this->container->get('circular_dependency'); @@ -179,7 +141,7 @@ public function test_get_circular() { /** * Tests that Container::get() for non-existant dependencies works properly. * @expectedException \RuntimeException - * @covers ::get() + * @covers ::get */ public function test_get_exception() { $this->container->get('service_not_exists'); @@ -187,8 +149,8 @@ public function test_get_exception() { /** * Tests that Container::get() for non-existant parameters works properly. - * @covers ::get() - * @covers ::expandArguments() + * @covers ::get + * @covers ::expandArguments */ public function test_get_notFound_parameter() { $service = $this->container->get('service_parameter_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE); @@ -198,8 +160,8 @@ public function test_get_notFound_parameter() { /** * Tests Container::get() with an exception due to missing parameter on the second call. * - * @covers ::get() - * @covers ::expandArguments() + * @covers ::get + * @covers ::expandArguments * * @expectedException \RuntimeException */ @@ -215,8 +177,8 @@ public function test_get_notFound_parameterWithExceptionOnSecondCall() { /** * Tests that Container::get() for non-existant parameters works properly. * @expectedException \RuntimeException - * @covers ::get() - * @covers ::expandArguments() + * @covers ::get + * @covers ::expandArguments */ public function test_get_notFound_parameter_exception() { $this->container->get('service_parameter_not_exists'); @@ -224,8 +186,8 @@ public function test_get_notFound_parameter_exception() { /** * Tests that Container::get() for non-existent dependencies works properly. - * @covers ::get() - * @covers ::expandArguments() + * @covers ::get + * @covers ::expandArguments */ public function test_get_notFound_dependency() { $service = $this->container->get('service_dependency_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE); @@ -235,8 +197,8 @@ public function test_get_notFound_dependency() { /** * Tests that Container::get() for non-existant dependencies works properly. * @expectedException \RuntimeException - * @covers ::get() - * @covers ::expandArguments() + * @covers ::get + * @covers ::expandArguments */ public function test_get_notFound_dependency_exception() { $this->container->get('service_dependency_not_exists'); @@ -245,7 +207,7 @@ public function test_get_notFound_dependency_exception() { /** * Tests that Container::get() for non-existant dependencies works properly. - * @covers ::get() + * @covers ::get */ public function test_get_notFound() { $this->assertNull($this->container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE), 'Not found service does not throw exception.'); @@ -254,10 +216,13 @@ public function test_get_notFound() { /** * Tests multiple Container::get() calls for non-existing dependencies work. * - * @covers ::get() + * @covers ::get */ public function test_get_notFoundMultiple() { - $container = \Mockery::mock('Drupal\service_container\DependencyInjection\Container[getDefinition]', array($this->containerDefinition)); + $container = new Container([ + 'parameters' => [], + 'services' => [], + ]); $this->assertNull($container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE, 'Not found service does not throw exception.')); $this->assertNull($container->get('service_not_exists', ContainerInterface::NULL_ON_INVALID_REFERENCE, 'Not found service does not throw exception on second call.')); @@ -266,7 +231,7 @@ public function test_get_notFoundMultiple() { /** * Tests multiple Container::get() calls with exception on the second time. * - * @covers ::get() + * @covers ::get * * @expectedException \RuntimeException */ @@ -277,7 +242,7 @@ public function test_get_notFoundMulitpleWithExceptionOnSecondCall() { /** * Tests that Container::get() for aliased services works properly. - * @covers ::get() + * @covers ::get */ public function test_get_alias() { $service = $this->container->get('service.provider'); @@ -287,7 +252,7 @@ public function test_get_alias() { /** * Tests that Container::get() for factories via services works properly. - * @covers ::get() + * @covers ::get */ public function test_get_factoryService() { $factory_service = $this->container->get('factory_service'); @@ -297,7 +262,7 @@ public function test_get_factoryService() { /** * Tests that Container::get() for factories via factory_class works. - * @covers ::get() + * @covers ::get */ public function test_get_factoryClass() { $service = $this->container->get('service.provider'); @@ -311,7 +276,7 @@ public function test_get_factoryClass() { /** * Tests that Container::get() for wrong factories works correctly. * @expectedException \RuntimeException - * @covers ::get() + * @covers ::get */ public function test_get_factoryWrong() { $this->container->get('wrong_factory'); @@ -319,7 +284,7 @@ public function test_get_factoryWrong() { /** * Tests Container::get() for factories via services (Symfony 2.7.0). - * @covers ::get() + * @covers ::get */ public function test_get_factoryServiceNew() { $factory_service = $this->container->get('factory_service_new'); @@ -329,7 +294,7 @@ public function test_get_factoryServiceNew() { /** * Tests that Container::get() for factories via class works (Symfony 2.7.0). - * @covers ::get() + * @covers ::get */ public function test_get_factoryClassNew() { $service = $this->container->get('service.provider'); @@ -344,8 +309,8 @@ public function test_get_factoryClassNew() { /** * Tests that private services work correctly. - * @covers ::get() - * @covers ::expandArguments() + * @covers ::get + * @covers ::expandArguments */ public function test_expandArguments_privateService() { $service = $this->container->get('service_using_private'); @@ -355,8 +320,8 @@ public function test_expandArguments_privateService() { /** * Tests that services with an array of arguments work correctly. - * @covers ::get() - * @covers ::expandArguments() + * @covers ::get + * @covers ::expandArguments */ public function test_expandArguments_array() { $service = $this->container->get('service_using_array'); @@ -366,8 +331,8 @@ public function test_expandArguments_array() { /** * Tests that services that are optional work correctly. - * @covers ::get() - * @covers ::expandArguments() + * @covers ::get + * @covers ::expandArguments */ public function test_expandArguments_optional() { $service = $this->container->get('service_with_optional_dependency'); @@ -377,7 +342,7 @@ public function test_expandArguments_optional() { /** * Tests that Container::initialized works correctly. - * @covers ::initialized() + * @covers ::initialized */ public function test_initialized() { $this->assertFalse($this->container->initialized('late.service'), 'Late service is not initialized.'); @@ -386,49 +351,13 @@ public function test_initialized() { } /** - * Camelizes a string. - * - * @covers ::camelize - * @dataProvider underscoreCamelizeDataProvider - */ - public function test_camelize($string_underscore, $string_camelize) { - $result = $this->container->camelize($string_underscore); - $this->assertEquals($string_camelize, $result); - } - - /** - * Un-camelizes a string. - * - * @covers ::underscore - * @dataProvider underscoreCamelizeDataProvider - */ - public function test_underscore($string_underscore, $string_camelize) { - $result = $this->container->underscore($string_camelize); - $this->assertEquals($string_underscore, $result); - } - - /** - * Data Provider for ::underscore and ::camelize. - */ - public function underscoreCamelizeDataProvider() { - return array( - array('service_container', 'ServiceContainer'), - array('service_container_symfony', 'ServiceContainerSymfony'), - array('123service_container', '123serviceContainer'), - array('123service_container_symfony', '123serviceContainerSymfony'), - array('123service_container', '123serviceContainer'), - array('123service_container_symfony', '123serviceContainerSymfony'), - ); - } - - /** * Returns a mock container definition. * * @return array * Associated array with parameters and services. */ protected function getMockContainerDefinition() { - $fake_service = Mockery::mock('alias:Drupal\Tests\service_container\DependencyInjection\FakeService'); + $fake_service = new \stdClass(); $parameters = array(); $parameters['some_private_config'] = 'really_private_lama'; $parameters['some_config'] = 'foo'; @@ -447,7 +376,7 @@ protected function getMockContainerDefinition() { 'class' => get_class($fake_service), ); $services['service.provider'] = array( - 'class' => '\Drupal\Tests\service_container\DependencyInjection\MockService', + 'class' => '\Drupal\Tests\Core\DependencyInjection\PhpArray\MockService', 'arguments' => array('@other.service', '%some_config%'), 'properties' => array('_someProperty' => 'foo'), 'calls' => array( @@ -457,14 +386,14 @@ protected function getMockContainerDefinition() { 'priority' => 0, ); $private_service = array( - 'class' => '\Drupal\Tests\service_container\DependencyInjection\MockService', + 'class' => '\Drupal\Tests\Core\DependencyInjection\PhpArray\MockService', 'arguments' => array('@other.service', '%some_private_config%'), 'public' => FALSE, ); $private_hash = sha1(serialize($private_service)); $services['service_using_private'] = array( - 'class' => '\Drupal\Tests\service_container\DependencyInjection\MockService', + 'class' => '\Drupal\Tests\Core\DependencyInjection\PhpArray\\MockService', 'arguments' => array( (object) array( 'type' => 'service', @@ -479,11 +408,11 @@ protected function getMockContainerDefinition() { ); $services['service_using_array'] = array( - 'class' => '\Drupal\Tests\service_container\DependencyInjection\MockService', + 'class' => '\Drupal\Tests\Core\DependencyInjection\PhpArray\MockService', 'arguments' => array(array('@other.service'), '%some_private_config%') ); $services['service_with_optional_dependency'] = array( - 'class' => '\Drupal\Tests\service_container\DependencyInjection\MockService', + 'class' => '\Drupal\Tests\Core\DependencyInjection\PhpArray\MockService', 'arguments' => array('@?service.does_not_exist', '%some_private_config%') ); @@ -496,9 +425,9 @@ protected function getMockContainerDefinition() { $services['factory_class'] = array( 'class' => '\Drupal\service_container\ServiceContainer\ControllerInterface', 'factory_method' => 'getFactoryMethod', - 'factory_class' => '\Drupal\Tests\service_container\DependencyInjection\MockService', + 'factory_class' => '\Drupal\Tests\Core\DependencyInjection\PhpArray\MockService', 'arguments' => array( - '\Drupal\Tests\service_container\DependencyInjection\MockService', + '\Drupal\Tests\Core\DependencyInjection\PhpArray\MockService', array(NULL, 'bar'), ), 'calls' => array( @@ -515,9 +444,9 @@ protected function getMockContainerDefinition() { ); $services['factory_class_new'] = array( 'class' => '\Drupal\service_container\ServiceContainer\ControllerInterface', - 'factory' => '\Drupal\Tests\service_container\DependencyInjection\MockService::getFactoryMethod', + 'factory' => '\Drupal\Tests\Core\DependencyInjection\PhpArray\MockService::getFactoryMethod', 'arguments' => array( - '\Drupal\Tests\service_container\DependencyInjection\MockService', + '\Drupal\Tests\Core\DependencyInjection\PhpArray\MockService', array(NULL, 'bar'), ), 'calls' => array( @@ -530,15 +459,15 @@ protected function getMockContainerDefinition() { 'factory_method' => 'getFactoryMethod', ); $services['circular_dependency'] = array( - 'class' => '\Drupal\Tests\service_container\DependencyInjection\MockService', + 'class' => '\Drupal\Tests\Core\DependencyInjection\PhpArray\MockService', 'arguments' => array('@circular_dependency'), ); $services['service_parameter_not_exists'] = array( - 'class' => '\Drupal\Tests\service_container\DependencyInjection\MockService', + 'class' => '\Drupal\Tests\Core\DependencyInjection\PhpArray\MockService', 'arguments' => array('@service.provider', '%not_exists', -1), ); $services['service_dependency_not_exists'] = array( - 'class' => '\Drupal\Tests\service_container\DependencyInjection\MockService', + 'class' => '\Drupal\Tests\Core\DependencyInjection\PhpArray\MockService', 'arguments' => array('@service_not_exists', '%some_config'), ); @@ -547,4 +476,5 @@ protected function getMockContainerDefinition() { 'services' => $services, ); } + } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArray/MockService.php b/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArray/MockService.php index 7f41a42..35014a9 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArray/MockService.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/PhpArray/MockService.php @@ -2,14 +2,14 @@ /** * @file - * Contains \Drupal\Tests\service_container\DependencyInjection\MockService + * Contains \Drupal\Tests\Core\DependencyInjection\PhpArray\MockService. */ -namespace Drupal\Tests\service_container\DependencyInjection; +namespace Drupal\Tests\Core\DependencyInjection\PhpArray; use ReflectionClass; -use Drupal\service_container\DependencyInjection\Container; -use Drupal\service_container\DependencyInjection\ContainerInterface; +use Drupal\Core\DependencyInjection\PhpArray\Container; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Helper class to test Container::get() method.