@@ -9,28 +9,28 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class InstanceDefinition implements InstanceDefinitionInterface |
| 11 | 11 | { |
| 12 | - /** @var string */ |
|
| 13 | - private $serviceName; |
|
| 12 | + /** @var string */ |
|
| 13 | + private $serviceName; |
|
| 14 | 14 | |
| 15 | - /** @var mixed */ |
|
| 16 | - private $instance; |
|
| 15 | + /** @var mixed */ |
|
| 16 | + private $instance; |
|
| 17 | 17 | |
| 18 | - public function __construct(string $serviceName, $instance) |
|
| 19 | - { |
|
| 20 | - $this->serviceName = $serviceName; |
|
| 21 | - $this->instance = $instance; |
|
| 22 | - } |
|
| 18 | + public function __construct(string $serviceName, $instance) |
|
| 19 | + { |
|
| 20 | + $this->serviceName = $serviceName; |
|
| 21 | + $this->instance = $instance; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** @return string */ |
|
| 25 | - public function getServiceName() |
|
| 26 | - { |
|
| 27 | - return $this->serviceName; |
|
| 28 | - } |
|
| 24 | + /** @return string */ |
|
| 25 | + public function getServiceName() |
|
| 26 | + { |
|
| 27 | + return $this->serviceName; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** @return mixed */ |
|
| 31 | - public function getInstance() |
|
| 32 | - { |
|
| 33 | - return $this->instance; |
|
| 34 | - } |
|
| 30 | + /** @return mixed */ |
|
| 31 | + public function getInstance() |
|
| 32 | + { |
|
| 33 | + return $this->instance; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | } |
@@ -10,10 +10,10 @@ |
||
| 10 | 10 | interface InstanceDefinitionInterface |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** @return string */ |
|
| 14 | - public function getServiceName(); |
|
| 13 | + /** @return string */ |
|
| 14 | + public function getServiceName(); |
|
| 15 | 15 | |
| 16 | - /** @return mixed */ |
|
| 17 | - public function getInstance(); |
|
| 16 | + /** @return mixed */ |
|
| 17 | + public function getInstance(); |
|
| 18 | 18 | |
| 19 | 19 | } |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( !is_readable( __DIR__ . '/../../vendor/autoload.php' ) ) { |
| 4 | - die( 'You need to install this package with Composer before you can run the examples' ); |
|
| 4 | + die( 'You need to install this package with Composer before you can run the examples' ); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | require_once __DIR__ . '/../../vendor/autoload.php'; |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( !is_readable( __DIR__ . '/../../vendor/autoload.php' ) ) { |
|
| 4 | - die( 'You need to install this package with Composer before you can run the examples' ); |
|
| 3 | +if (!is_readable(__DIR__ . '/../../vendor/autoload.php')) { |
|
| 4 | + die('You need to install this package with Composer before you can run the examples'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | require_once __DIR__ . '/../../vendor/autoload.php'; |
@@ -9,18 +9,18 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class SampleClass |
| 11 | 11 | { |
| 12 | - private $first; |
|
| 13 | - private $second; |
|
| 12 | + private $first; |
|
| 13 | + private $second; |
|
| 14 | 14 | |
| 15 | - public function __construct($param1, $param2) |
|
| 16 | - { |
|
| 17 | - $this->first = $param1; |
|
| 18 | - $this->second = $param2; |
|
| 19 | - } |
|
| 15 | + public function __construct($param1, $param2) |
|
| 16 | + { |
|
| 17 | + $this->first = $param1; |
|
| 18 | + $this->second = $param2; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function callMethod($param1, $param2) |
|
| 22 | - { |
|
| 23 | - $this->first = $param1; |
|
| 24 | - $this->second = $param2; |
|
| 25 | - } |
|
| 21 | + public function callMethod($param1, $param2) |
|
| 22 | + { |
|
| 23 | + $this->first = $param1; |
|
| 24 | + $this->second = $param2; |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( !is_readable( __DIR__ . '/../../vendor/autoload.php' ) ) { |
| 4 | - die( 'You need to install this package with Composer before you can run the examples' ); |
|
| 4 | + die( 'You need to install this package with Composer before you can run the examples' ); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | require_once __DIR__ . '/../../vendor/autoload.php'; |
@@ -10,23 +10,23 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | // Create a new definition with another service as an argument |
| 12 | 12 | $definition = new \Wonderland\Container\Service\ServiceDefinition( |
| 13 | - 'service.name', |
|
| 14 | - \Wonderland\Container\Example\Object\SampleClass::class, |
|
| 15 | - ['param1', '@service.name2'] |
|
| 13 | + 'service.name', |
|
| 14 | + \Wonderland\Container\Example\Object\SampleClass::class, |
|
| 15 | + ['param1', '@service.name2'] |
|
| 16 | 16 | ); |
| 17 | 17 | |
| 18 | 18 | // Create a new definition with a method call taking two other services as arguments |
| 19 | 19 | $definition2 = new \Wonderland\Container\Service\ServiceDefinition( |
| 20 | - 'service.name2', |
|
| 21 | - \Wonderland\Container\Example\Object\SampleClass::class, |
|
| 22 | - ['param2', 'param3'], |
|
| 23 | - ['callMethod' => ['test', '@instance.name']] |
|
| 20 | + 'service.name2', |
|
| 21 | + \Wonderland\Container\Example\Object\SampleClass::class, |
|
| 22 | + ['param2', 'param3'], |
|
| 23 | + ['callMethod' => ['test', '@instance.name']] |
|
| 24 | 24 | ); |
| 25 | 25 | |
| 26 | 26 | // Create a new instance definition |
| 27 | 27 | $instance = new \Wonderland\Container\Service\InstanceDefinition( |
| 28 | - 'instance.name', |
|
| 29 | - new \DateTime() |
|
| 28 | + 'instance.name', |
|
| 29 | + new \DateTime() |
|
| 30 | 30 | ); |
| 31 | 31 | |
| 32 | 32 | // Registering them all |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( !is_readable( __DIR__ . '/../../vendor/autoload.php' ) ) { |
|
| 4 | - die( 'You need to install this package with Composer before you can run the examples' ); |
|
| 3 | +if (!is_readable(__DIR__ . '/../../vendor/autoload.php')) { |
|
| 4 | + die('You need to install this package with Composer before you can run the examples'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | require_once __DIR__ . '/../../vendor/autoload.php'; |
@@ -9,18 +9,18 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class SampleClass |
| 11 | 11 | { |
| 12 | - private $first; |
|
| 13 | - private $second; |
|
| 12 | + private $first; |
|
| 13 | + private $second; |
|
| 14 | 14 | |
| 15 | - public function __construct($param1, $param2) |
|
| 16 | - { |
|
| 17 | - $this->first = $param1; |
|
| 18 | - $this->second = $param2; |
|
| 19 | - } |
|
| 15 | + public function __construct($param1, $param2) |
|
| 16 | + { |
|
| 17 | + $this->first = $param1; |
|
| 18 | + $this->second = $param2; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function callMethod($param1, $param2) |
|
| 22 | - { |
|
| 23 | - $this->first = $param1; |
|
| 24 | - $this->second = $param2; |
|
| 25 | - } |
|
| 21 | + public function callMethod($param1, $param2) |
|
| 22 | + { |
|
| 23 | + $this->first = $param1; |
|
| 24 | + $this->second = $param2; |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -18,166 +18,166 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class ServiceContainerTest extends TestCase |
| 20 | 20 | { |
| 21 | - private const SERVICE_NAME = 'service.name'; |
|
| 22 | - private const DEFAULT_SERVICE_NANE = 'default.service.name'; |
|
| 23 | - |
|
| 24 | - /** @var ServiceContainer|MockObject */ |
|
| 25 | - private $container; |
|
| 26 | - |
|
| 27 | - /** @var ServiceContainer */ |
|
| 28 | - private $realContainer; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @throws DuplicatedServiceException |
|
| 32 | - */ |
|
| 33 | - protected function setUp() |
|
| 34 | - { |
|
| 35 | - $this->container = $this->getMockBuilder(ServiceContainer::class)->getMock(); |
|
| 36 | - $this->realContainer = new ServiceContainer(); |
|
| 37 | - $this->realContainer->addService(new ServiceDefinition(self::DEFAULT_SERVICE_NANE, \DateTime::class)); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function testConstructor() |
|
| 41 | - { |
|
| 42 | - $this->assertAttributeEquals([], 'serviceInstances', $this->container); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @covers \Wonderland\Container\ServiceContainer::addService |
|
| 47 | - * @throws DuplicatedServiceException |
|
| 48 | - */ |
|
| 49 | - public function test_AddService() |
|
| 50 | - { |
|
| 51 | - $definition = $this->getMockBuilder(ServiceDefinition::class) |
|
| 52 | - ->setConstructorArgs([self::SERVICE_NAME, \DateTime::class]) |
|
| 53 | - ->getMock(); |
|
| 54 | - ; |
|
| 55 | - |
|
| 56 | - $definition->expects($this->exactly(2)) |
|
| 57 | - ->method('getServiceName') |
|
| 58 | - ->willReturn(self::SERVICE_NAME); |
|
| 59 | - |
|
| 60 | - $this->assertSame($this->realContainer, $this->realContainer->addService($definition)); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @throws DuplicatedServiceException |
|
| 65 | - */ |
|
| 66 | - public function test_AddServiceException() |
|
| 67 | - { |
|
| 68 | - $this->expectException(DuplicatedServiceException::class); |
|
| 69 | - |
|
| 70 | - $definition = $this->getMockBuilder(ServiceDefinition::class) |
|
| 71 | - ->setConstructorArgs([self::SERVICE_NAME, \DateTime::class]) |
|
| 72 | - ->getMock(); |
|
| 73 | - ; |
|
| 74 | - |
|
| 75 | - $definition->expects($this->exactly(4)) |
|
| 76 | - ->method('getServiceName') |
|
| 77 | - ->willReturn(self::SERVICE_NAME); |
|
| 78 | - |
|
| 79 | - $this->realContainer->addService($definition); |
|
| 80 | - $this->realContainer->addService($definition); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function test_loadServices() |
|
| 84 | - { |
|
| 85 | - $definition = $this->getMockBuilder(ServiceDefinition::class) |
|
| 86 | - ->setConstructorArgs([self::SERVICE_NAME . '10', \DateTime::class]) |
|
| 87 | - ->getMock(); |
|
| 88 | - ; |
|
| 89 | - $definition2 = $this->getMockBuilder(ServiceDefinition::class) |
|
| 90 | - ->setConstructorArgs([self::SERVICE_NAME . '20', \DateTime::class]) |
|
| 91 | - ->getMock(); |
|
| 92 | - ; |
|
| 93 | - |
|
| 94 | - $list = [ |
|
| 95 | - $definition, |
|
| 96 | - $definition2 |
|
| 97 | - ]; |
|
| 98 | - |
|
| 99 | - $definition->expects($this->exactly(2)) |
|
| 100 | - ->method('getServiceName') |
|
| 101 | - ->willReturn(self::SERVICE_NAME . '10'); |
|
| 102 | - $definition2->expects($this->exactly(2)) |
|
| 103 | - ->method('getServiceName') |
|
| 104 | - ->willReturn(self::SERVICE_NAME . '20'); |
|
| 105 | - |
|
| 106 | - $this->realContainer->loadServices($list); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @throws DuplicatedServiceException |
|
| 111 | - */ |
|
| 112 | - public function test_AddServiceInstance() |
|
| 113 | - { |
|
| 114 | - $definition = $this->getMockBuilder(InstanceDefinition::class) |
|
| 115 | - ->setConstructorArgs([self::SERVICE_NAME, new \DateTime()]) |
|
| 116 | - ->getMock(); |
|
| 117 | - |
|
| 118 | - $definition->expects($this->atLeast(2)) |
|
| 119 | - ->method('getServiceName') |
|
| 120 | - ->willReturn(self::SERVICE_NAME); |
|
| 121 | - |
|
| 122 | - $this->container->expects($this->once()) |
|
| 123 | - ->method('addServiceInstance') |
|
| 124 | - ->willReturn($this->container); |
|
| 125 | - |
|
| 126 | - $this->assertSame($this->container, $this->container->addServiceInstance($definition)); |
|
| 127 | - $this->assertSame($this->realContainer, $this->realContainer->addServiceInstance($definition)); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @throws DuplicatedServiceException |
|
| 132 | - */ |
|
| 133 | - public function test_AddServiceInstanceException() |
|
| 134 | - { |
|
| 135 | - $this->expectException(DuplicatedServiceException::class); |
|
| 136 | - |
|
| 137 | - $definition = $this->getMockBuilder(InstanceDefinition::class) |
|
| 138 | - ->setConstructorArgs([self::SERVICE_NAME, new \DateTime()]) |
|
| 139 | - ->getMock(); |
|
| 140 | - |
|
| 141 | - $definition->expects($this->exactly(2)) |
|
| 142 | - ->method('getServiceName') |
|
| 143 | - ->willReturn(self::DEFAULT_SERVICE_NANE); |
|
| 144 | - |
|
| 145 | - $this->realContainer->addServiceInstance($definition); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @throws DuplicatedServiceException |
|
| 150 | - */ |
|
| 151 | - public function test_get() |
|
| 152 | - { |
|
| 153 | - $this->assertSame(null, $this->realContainer->get('test')); |
|
| 154 | - $this->assertSame(\DateTime::class, get_class($this->realContainer->get(self::DEFAULT_SERVICE_NANE))); |
|
| 155 | - $instance = $this->realContainer->get(self::DEFAULT_SERVICE_NANE); |
|
| 156 | - $this->assertSame(\DateTime::class, get_class($instance)); |
|
| 157 | - $this->assertSame($instance, $this->realContainer->get(self::DEFAULT_SERVICE_NANE)); |
|
| 158 | - |
|
| 159 | - $this->realContainer->addServiceInstance( |
|
| 160 | - new InstanceDefinition('call.format', 'd-m-Y') |
|
| 161 | - ); |
|
| 162 | - |
|
| 163 | - $this->realContainer->addService( |
|
| 164 | - new ServiceDefinition( |
|
| 165 | - 'service.call', |
|
| 166 | - \DateTime::class, |
|
| 167 | - ['1970-01-01'], |
|
| 168 | - ['format' => ['call.format']] |
|
| 169 | - ) |
|
| 170 | - ); |
|
| 171 | - |
|
| 172 | - $date = new \DateTime('1970-01-01'); |
|
| 173 | - $this->assertSame($date->format('m-d-Y'), $this->realContainer->get('service.call')->format('m-d-Y')); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - public function test_has() |
|
| 177 | - { |
|
| 178 | - $this->assertSame(false, $this->realContainer->has('fake')); |
|
| 179 | - $this->assertSame(true, $this->realContainer->has(self::DEFAULT_SERVICE_NANE)); |
|
| 180 | - $this->assertSame(true, $this->realContainer->has(self::DEFAULT_SERVICE_NANE)); |
|
| 181 | - } |
|
| 21 | + private const SERVICE_NAME = 'service.name'; |
|
| 22 | + private const DEFAULT_SERVICE_NANE = 'default.service.name'; |
|
| 23 | + |
|
| 24 | + /** @var ServiceContainer|MockObject */ |
|
| 25 | + private $container; |
|
| 26 | + |
|
| 27 | + /** @var ServiceContainer */ |
|
| 28 | + private $realContainer; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @throws DuplicatedServiceException |
|
| 32 | + */ |
|
| 33 | + protected function setUp() |
|
| 34 | + { |
|
| 35 | + $this->container = $this->getMockBuilder(ServiceContainer::class)->getMock(); |
|
| 36 | + $this->realContainer = new ServiceContainer(); |
|
| 37 | + $this->realContainer->addService(new ServiceDefinition(self::DEFAULT_SERVICE_NANE, \DateTime::class)); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function testConstructor() |
|
| 41 | + { |
|
| 42 | + $this->assertAttributeEquals([], 'serviceInstances', $this->container); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @covers \Wonderland\Container\ServiceContainer::addService |
|
| 47 | + * @throws DuplicatedServiceException |
|
| 48 | + */ |
|
| 49 | + public function test_AddService() |
|
| 50 | + { |
|
| 51 | + $definition = $this->getMockBuilder(ServiceDefinition::class) |
|
| 52 | + ->setConstructorArgs([self::SERVICE_NAME, \DateTime::class]) |
|
| 53 | + ->getMock(); |
|
| 54 | + ; |
|
| 55 | + |
|
| 56 | + $definition->expects($this->exactly(2)) |
|
| 57 | + ->method('getServiceName') |
|
| 58 | + ->willReturn(self::SERVICE_NAME); |
|
| 59 | + |
|
| 60 | + $this->assertSame($this->realContainer, $this->realContainer->addService($definition)); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @throws DuplicatedServiceException |
|
| 65 | + */ |
|
| 66 | + public function test_AddServiceException() |
|
| 67 | + { |
|
| 68 | + $this->expectException(DuplicatedServiceException::class); |
|
| 69 | + |
|
| 70 | + $definition = $this->getMockBuilder(ServiceDefinition::class) |
|
| 71 | + ->setConstructorArgs([self::SERVICE_NAME, \DateTime::class]) |
|
| 72 | + ->getMock(); |
|
| 73 | + ; |
|
| 74 | + |
|
| 75 | + $definition->expects($this->exactly(4)) |
|
| 76 | + ->method('getServiceName') |
|
| 77 | + ->willReturn(self::SERVICE_NAME); |
|
| 78 | + |
|
| 79 | + $this->realContainer->addService($definition); |
|
| 80 | + $this->realContainer->addService($definition); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function test_loadServices() |
|
| 84 | + { |
|
| 85 | + $definition = $this->getMockBuilder(ServiceDefinition::class) |
|
| 86 | + ->setConstructorArgs([self::SERVICE_NAME . '10', \DateTime::class]) |
|
| 87 | + ->getMock(); |
|
| 88 | + ; |
|
| 89 | + $definition2 = $this->getMockBuilder(ServiceDefinition::class) |
|
| 90 | + ->setConstructorArgs([self::SERVICE_NAME . '20', \DateTime::class]) |
|
| 91 | + ->getMock(); |
|
| 92 | + ; |
|
| 93 | + |
|
| 94 | + $list = [ |
|
| 95 | + $definition, |
|
| 96 | + $definition2 |
|
| 97 | + ]; |
|
| 98 | + |
|
| 99 | + $definition->expects($this->exactly(2)) |
|
| 100 | + ->method('getServiceName') |
|
| 101 | + ->willReturn(self::SERVICE_NAME . '10'); |
|
| 102 | + $definition2->expects($this->exactly(2)) |
|
| 103 | + ->method('getServiceName') |
|
| 104 | + ->willReturn(self::SERVICE_NAME . '20'); |
|
| 105 | + |
|
| 106 | + $this->realContainer->loadServices($list); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @throws DuplicatedServiceException |
|
| 111 | + */ |
|
| 112 | + public function test_AddServiceInstance() |
|
| 113 | + { |
|
| 114 | + $definition = $this->getMockBuilder(InstanceDefinition::class) |
|
| 115 | + ->setConstructorArgs([self::SERVICE_NAME, new \DateTime()]) |
|
| 116 | + ->getMock(); |
|
| 117 | + |
|
| 118 | + $definition->expects($this->atLeast(2)) |
|
| 119 | + ->method('getServiceName') |
|
| 120 | + ->willReturn(self::SERVICE_NAME); |
|
| 121 | + |
|
| 122 | + $this->container->expects($this->once()) |
|
| 123 | + ->method('addServiceInstance') |
|
| 124 | + ->willReturn($this->container); |
|
| 125 | + |
|
| 126 | + $this->assertSame($this->container, $this->container->addServiceInstance($definition)); |
|
| 127 | + $this->assertSame($this->realContainer, $this->realContainer->addServiceInstance($definition)); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @throws DuplicatedServiceException |
|
| 132 | + */ |
|
| 133 | + public function test_AddServiceInstanceException() |
|
| 134 | + { |
|
| 135 | + $this->expectException(DuplicatedServiceException::class); |
|
| 136 | + |
|
| 137 | + $definition = $this->getMockBuilder(InstanceDefinition::class) |
|
| 138 | + ->setConstructorArgs([self::SERVICE_NAME, new \DateTime()]) |
|
| 139 | + ->getMock(); |
|
| 140 | + |
|
| 141 | + $definition->expects($this->exactly(2)) |
|
| 142 | + ->method('getServiceName') |
|
| 143 | + ->willReturn(self::DEFAULT_SERVICE_NANE); |
|
| 144 | + |
|
| 145 | + $this->realContainer->addServiceInstance($definition); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @throws DuplicatedServiceException |
|
| 150 | + */ |
|
| 151 | + public function test_get() |
|
| 152 | + { |
|
| 153 | + $this->assertSame(null, $this->realContainer->get('test')); |
|
| 154 | + $this->assertSame(\DateTime::class, get_class($this->realContainer->get(self::DEFAULT_SERVICE_NANE))); |
|
| 155 | + $instance = $this->realContainer->get(self::DEFAULT_SERVICE_NANE); |
|
| 156 | + $this->assertSame(\DateTime::class, get_class($instance)); |
|
| 157 | + $this->assertSame($instance, $this->realContainer->get(self::DEFAULT_SERVICE_NANE)); |
|
| 158 | + |
|
| 159 | + $this->realContainer->addServiceInstance( |
|
| 160 | + new InstanceDefinition('call.format', 'd-m-Y') |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + $this->realContainer->addService( |
|
| 164 | + new ServiceDefinition( |
|
| 165 | + 'service.call', |
|
| 166 | + \DateTime::class, |
|
| 167 | + ['1970-01-01'], |
|
| 168 | + ['format' => ['call.format']] |
|
| 169 | + ) |
|
| 170 | + ); |
|
| 171 | + |
|
| 172 | + $date = new \DateTime('1970-01-01'); |
|
| 173 | + $this->assertSame($date->format('m-d-Y'), $this->realContainer->get('service.call')->format('m-d-Y')); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + public function test_has() |
|
| 177 | + { |
|
| 178 | + $this->assertSame(false, $this->realContainer->has('fake')); |
|
| 179 | + $this->assertSame(true, $this->realContainer->has(self::DEFAULT_SERVICE_NANE)); |
|
| 180 | + $this->assertSame(true, $this->realContainer->has(self::DEFAULT_SERVICE_NANE)); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | 183 | } |
@@ -14,76 +14,76 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class YamlParserTest extends TestCase |
| 16 | 16 | { |
| 17 | - /** @var YamlParser */ |
|
| 18 | - private $parser; |
|
| 17 | + /** @var YamlParser */ |
|
| 18 | + private $parser; |
|
| 19 | 19 | |
| 20 | - public function setUp() |
|
| 21 | - { |
|
| 22 | - $this->parser = new YamlParser(); |
|
| 23 | - } |
|
| 20 | + public function setUp() |
|
| 21 | + { |
|
| 22 | + $this->parser = new YamlParser(); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @throws \Wonderland\Container\Exception\InvalidResourceException |
|
| 27 | - * @throws \Wonderland\Container\Exception\ResourceNotFoundException |
|
| 28 | - */ |
|
| 29 | - public function test_load() |
|
| 30 | - { |
|
| 31 | - $this->assertInternalType('array', $this->parser->loadFile(__DIR__ . '/../data/yml/test-full.yml')); |
|
| 32 | - $this->assertInternalType('array', $this->parser->loadDirectory(__DIR__ . '/../data/yml/')); |
|
| 33 | - } |
|
| 25 | + /** |
|
| 26 | + * @throws \Wonderland\Container\Exception\InvalidResourceException |
|
| 27 | + * @throws \Wonderland\Container\Exception\ResourceNotFoundException |
|
| 28 | + */ |
|
| 29 | + public function test_load() |
|
| 30 | + { |
|
| 31 | + $this->assertInternalType('array', $this->parser->loadFile(__DIR__ . '/../data/yml/test-full.yml')); |
|
| 32 | + $this->assertInternalType('array', $this->parser->loadDirectory(__DIR__ . '/../data/yml/')); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @return array |
|
| 37 | - */ |
|
| 38 | - public function loadErrorNotFoundProvider() |
|
| 39 | - { |
|
| 40 | - return [ |
|
| 41 | - ['dontexists'] |
|
| 42 | - ]; |
|
| 43 | - } |
|
| 35 | + /** |
|
| 36 | + * @return array |
|
| 37 | + */ |
|
| 38 | + public function loadErrorNotFoundProvider() |
|
| 39 | + { |
|
| 40 | + return [ |
|
| 41 | + ['dontexists'] |
|
| 42 | + ]; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @dataProvider loadErrorNotFoundProvider |
|
| 47 | - * @param string $filePath |
|
| 48 | - * @throws \Wonderland\Container\Exception\InvalidResourceException |
|
| 49 | - * @throws \Wonderland\Container\Exception\ResourceNotFoundException |
|
| 50 | - */ |
|
| 51 | - public function test_loadFileErrorNotFound($filePath) |
|
| 52 | - { |
|
| 53 | - $this->expectException(ResourceNotFoundException::class); |
|
| 54 | - $this->parser->loadFile($filePath); |
|
| 55 | - } |
|
| 45 | + /** |
|
| 46 | + * @dataProvider loadErrorNotFoundProvider |
|
| 47 | + * @param string $filePath |
|
| 48 | + * @throws \Wonderland\Container\Exception\InvalidResourceException |
|
| 49 | + * @throws \Wonderland\Container\Exception\ResourceNotFoundException |
|
| 50 | + */ |
|
| 51 | + public function test_loadFileErrorNotFound($filePath) |
|
| 52 | + { |
|
| 53 | + $this->expectException(ResourceNotFoundException::class); |
|
| 54 | + $this->parser->loadFile($filePath); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @dataProvider loadErrorNotFoundProvider |
|
| 59 | - * @param string $filePath |
|
| 60 | - * @throws \Wonderland\Container\Exception\InvalidResourceException |
|
| 61 | - * @throws \Wonderland\Container\Exception\ResourceNotFoundException |
|
| 62 | - */ |
|
| 63 | - public function test_loadDirErrorNotFound($filePath) |
|
| 64 | - { |
|
| 65 | - $this->expectException(ResourceNotFoundException::class); |
|
| 66 | - $this->parser->loadDirectory($filePath); |
|
| 67 | - } |
|
| 57 | + /** |
|
| 58 | + * @dataProvider loadErrorNotFoundProvider |
|
| 59 | + * @param string $filePath |
|
| 60 | + * @throws \Wonderland\Container\Exception\InvalidResourceException |
|
| 61 | + * @throws \Wonderland\Container\Exception\ResourceNotFoundException |
|
| 62 | + */ |
|
| 63 | + public function test_loadDirErrorNotFound($filePath) |
|
| 64 | + { |
|
| 65 | + $this->expectException(ResourceNotFoundException::class); |
|
| 66 | + $this->parser->loadDirectory($filePath); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @throws \Wonderland\Container\Exception\InvalidResourceException |
|
| 71 | - * @throws \Wonderland\Container\Exception\ResourceNotFoundException |
|
| 72 | - */ |
|
| 73 | - public function test_loadFileErrorInvalid() |
|
| 74 | - { |
|
| 75 | - $this->expectException(InvalidResourceException::class); |
|
| 76 | - $this->parser->loadFile(__DIR__ . '/../data/yml'); |
|
| 77 | - } |
|
| 69 | + /** |
|
| 70 | + * @throws \Wonderland\Container\Exception\InvalidResourceException |
|
| 71 | + * @throws \Wonderland\Container\Exception\ResourceNotFoundException |
|
| 72 | + */ |
|
| 73 | + public function test_loadFileErrorInvalid() |
|
| 74 | + { |
|
| 75 | + $this->expectException(InvalidResourceException::class); |
|
| 76 | + $this->parser->loadFile(__DIR__ . '/../data/yml'); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @throws \Wonderland\Container\Exception\InvalidResourceException |
|
| 81 | - * @throws \Wonderland\Container\Exception\ResourceNotFoundException |
|
| 82 | - */ |
|
| 83 | - public function test_loadDirErrorInvalid() |
|
| 84 | - { |
|
| 85 | - $this->expectException(InvalidResourceException::class); |
|
| 86 | - $this->parser->loadDirectory(__DIR__ . '/../data/yml/test-full.yml'); |
|
| 87 | - } |
|
| 79 | + /** |
|
| 80 | + * @throws \Wonderland\Container\Exception\InvalidResourceException |
|
| 81 | + * @throws \Wonderland\Container\Exception\ResourceNotFoundException |
|
| 82 | + */ |
|
| 83 | + public function test_loadDirErrorInvalid() |
|
| 84 | + { |
|
| 85 | + $this->expectException(InvalidResourceException::class); |
|
| 86 | + $this->parser->loadDirectory(__DIR__ . '/../data/yml/test-full.yml'); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | } |
@@ -15,78 +15,78 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class ServiceLoaderTest extends TestCase |
| 17 | 17 | { |
| 18 | - /** @var ServiceLoader */ |
|
| 19 | - private $loaderYml; |
|
| 18 | + /** @var ServiceLoader */ |
|
| 19 | + private $loaderYml; |
|
| 20 | 20 | |
| 21 | - public function setUp() |
|
| 22 | - { |
|
| 23 | - $this->loaderYml = new ServiceLoader(new YamlParser()); |
|
| 24 | - } |
|
| 21 | + public function setUp() |
|
| 22 | + { |
|
| 23 | + $this->loaderYml = new ServiceLoader(new YamlParser()); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @return array |
|
| 28 | - */ |
|
| 29 | - public function ymlProvider() |
|
| 30 | - { |
|
| 31 | - return [ |
|
| 32 | - [__DIR__ . '/data/yml/test-empty.yml'], |
|
| 33 | - [__DIR__ . '/data/yml/test-full.yml'] |
|
| 34 | - ]; |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * @return array |
|
| 28 | + */ |
|
| 29 | + public function ymlProvider() |
|
| 30 | + { |
|
| 31 | + return [ |
|
| 32 | + [__DIR__ . '/data/yml/test-empty.yml'], |
|
| 33 | + [__DIR__ . '/data/yml/test-full.yml'] |
|
| 34 | + ]; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @dataProvider ymlProvider |
|
| 39 | - * @param string $testFile |
|
| 40 | - * @throws \Wonderland\Container\Exception\InvalidConfigFormatException |
|
| 41 | - */ |
|
| 42 | - public function test_loadFile($testFile) |
|
| 43 | - { |
|
| 44 | - $services = $this->loaderYml->loadFile($testFile); |
|
| 45 | - $this->assertInternalType('array', $services); |
|
| 46 | - foreach ($services as $service) { |
|
| 47 | - $this->assertInstanceOf(ServiceDefinition::class, $service); |
|
| 48 | - } |
|
| 49 | - } |
|
| 37 | + /** |
|
| 38 | + * @dataProvider ymlProvider |
|
| 39 | + * @param string $testFile |
|
| 40 | + * @throws \Wonderland\Container\Exception\InvalidConfigFormatException |
|
| 41 | + */ |
|
| 42 | + public function test_loadFile($testFile) |
|
| 43 | + { |
|
| 44 | + $services = $this->loaderYml->loadFile($testFile); |
|
| 45 | + $this->assertInternalType('array', $services); |
|
| 46 | + foreach ($services as $service) { |
|
| 47 | + $this->assertInstanceOf(ServiceDefinition::class, $service); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return array |
|
| 53 | - */ |
|
| 54 | - public function ymlErrorProvider() |
|
| 55 | - { |
|
| 56 | - return [ |
|
| 57 | - [__DIR__ . '/data/yml-error/empty.yml'], |
|
| 58 | - [__DIR__ . '/data/yml-error/err1.yml'], |
|
| 59 | - [__DIR__ . '/data/yml-error/err2.yml'], |
|
| 60 | - [__DIR__ . '/data/yml-error/err3.yml'], |
|
| 61 | - [__DIR__ . '/data/yml-error/err4.yml'], |
|
| 62 | - [__DIR__ . '/data/yml-error/err5.yml'], |
|
| 63 | - [__DIR__ . '/data/yml-error/err6.yml'], |
|
| 64 | - [__DIR__ . '/data/yml-error/err7.yml'], |
|
| 65 | - [__DIR__ . '/data/yml-error/err8.yml'] |
|
| 66 | - ]; |
|
| 67 | - } |
|
| 51 | + /** |
|
| 52 | + * @return array |
|
| 53 | + */ |
|
| 54 | + public function ymlErrorProvider() |
|
| 55 | + { |
|
| 56 | + return [ |
|
| 57 | + [__DIR__ . '/data/yml-error/empty.yml'], |
|
| 58 | + [__DIR__ . '/data/yml-error/err1.yml'], |
|
| 59 | + [__DIR__ . '/data/yml-error/err2.yml'], |
|
| 60 | + [__DIR__ . '/data/yml-error/err3.yml'], |
|
| 61 | + [__DIR__ . '/data/yml-error/err4.yml'], |
|
| 62 | + [__DIR__ . '/data/yml-error/err5.yml'], |
|
| 63 | + [__DIR__ . '/data/yml-error/err6.yml'], |
|
| 64 | + [__DIR__ . '/data/yml-error/err7.yml'], |
|
| 65 | + [__DIR__ . '/data/yml-error/err8.yml'] |
|
| 66 | + ]; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @dataProvider ymlErrorProvider |
|
| 71 | - * @param string $testFile |
|
| 72 | - * @throws \Wonderland\Container\Exception\InvalidConfigFormatException |
|
| 73 | - */ |
|
| 74 | - public function test_loadFileError($testFile) |
|
| 75 | - { |
|
| 76 | - $this->expectException(InvalidConfigFormatException::class); |
|
| 77 | - $this->loaderYml->loadFile($testFile); |
|
| 78 | - } |
|
| 69 | + /** |
|
| 70 | + * @dataProvider ymlErrorProvider |
|
| 71 | + * @param string $testFile |
|
| 72 | + * @throws \Wonderland\Container\Exception\InvalidConfigFormatException |
|
| 73 | + */ |
|
| 74 | + public function test_loadFileError($testFile) |
|
| 75 | + { |
|
| 76 | + $this->expectException(InvalidConfigFormatException::class); |
|
| 77 | + $this->loaderYml->loadFile($testFile); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @throws InvalidConfigFormatException |
|
| 82 | - */ |
|
| 83 | - public function test_loadDirectory() |
|
| 84 | - { |
|
| 85 | - $services = $this->loaderYml->loadDirectory(__DIR__ . '/data/yml'); |
|
| 86 | - $this->assertInternalType('array', $services); |
|
| 87 | - foreach ($services as $service) { |
|
| 88 | - $this->assertInstanceOf(ServiceDefinition::class, $service); |
|
| 89 | - } |
|
| 90 | - } |
|
| 80 | + /** |
|
| 81 | + * @throws InvalidConfigFormatException |
|
| 82 | + */ |
|
| 83 | + public function test_loadDirectory() |
|
| 84 | + { |
|
| 85 | + $services = $this->loaderYml->loadDirectory(__DIR__ . '/data/yml'); |
|
| 86 | + $this->assertInternalType('array', $services); |
|
| 87 | + foreach ($services as $service) { |
|
| 88 | + $this->assertInstanceOf(ServiceDefinition::class, $service); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | } |