Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 5a14304

Browse files
committed
Make config injection methods static
This patch marks the two public injection methods in the delegator factory as static, allowing them to be used without instantiating the factory. It also correctly places the tests for the delegator factory, and moves required test assests in a tree beneath it.
1 parent b99b5be commit 5a14304

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

src/Container/ApplicationConfigInjectionDelegator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal
3838
return $application;
3939
}
4040

41-
$this->injectPipelineFromConfig($application, $config);
42-
$this->injectRoutesFromConfig($application, $config);
41+
self::injectPipelineFromConfig($application, $config);
42+
self::injectRoutesFromConfig($application, $config);
4343

4444
return $application;
4545
}
@@ -95,7 +95,7 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal
9595
* a `Zend\Stratigility\MiddlewarePipe` instance, with the middleware
9696
* specified piped in the order provided.
9797
*/
98-
public function injectPipelineFromConfig(Application $application, array $config) : void
98+
public static function injectPipelineFromConfig(Application $application, array $config) : void
9999
{
100100
if (empty($config['middleware_pipeline'])) {
101101
if (! isset($config['routes']) || ! is_array($config['routes'])) {
@@ -158,7 +158,7 @@ public function injectPipelineFromConfig(Application $application, array $config
158158
*
159159
* @throws InvalidArgumentException
160160
*/
161-
public function injectRoutesFromConfig(Application $application, array $config) : void
161+
public static function injectRoutesFromConfig(Application $application, array $config) : void
162162
{
163163
if (! isset($config['routes']) || ! is_array($config['routes'])) {
164164
return;

src/Container/ApplicationConfigInjectionDelegatorTest.php renamed to test/Container/ApplicationConfigInjectionDelegatorTest.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ public function setUp()
5555
new Response()
5656
);
5757
$this->dispatchMiddleware = $this->prophesize(Middleware\DispatchMiddleware::class)->reveal();
58-
59-
$this->injector = new ApplicationConfigInjectionDelegator();
6058
}
6159

6260
public function createApplication()
@@ -211,7 +209,7 @@ public function testInjectRoutesFromConfigSetsUpRoutesFromConfig($middleware)
211209

212210
$app = $this->createApplication();
213211

214-
$this->injector->injectRoutesFromConfig($app, $config);
212+
ApplicationConfigInjectionDelegator::injectRoutesFromConfig($app, $config);
215213

216214
$routes = $app->getRoutes();
217215

@@ -235,7 +233,7 @@ public function testNoRoutesAreAddedIfSpecDoesNotProvidePathOrMiddleware()
235233

236234
$app = $this->createApplication();
237235

238-
$this->injector->injectRoutesFromConfig($app, $config);
236+
ApplicationConfigInjectionDelegator::injectRoutesFromConfig($app, $config);
239237

240238
$routes = $app->getRoutes();
241239
$this->assertCount(0, $routes);
@@ -280,7 +278,7 @@ public function testProvidingRoutesAndNoPipelineImplicitlyRegistersRoutingAndDis
280278
);
281279
$app = $this->createApplication();
282280

283-
$this->injector->injectPipelineFromConfig($app, $config);
281+
ApplicationConfigInjectionDelegator::injectPipelineFromConfig($app, $config);
284282

285283
$queue = $this->getQueueFromApplicationPipeline($app);
286284

@@ -306,7 +304,7 @@ public function testInjectPipelineFromConfigHonorsPriorityOrderWhenAttachingMidd
306304

307305
$app = $this->createApplication();
308306

309-
$this->injector->injectPipelineFromConfig($app, $config);
307+
ApplicationConfigInjectionDelegator::injectPipelineFromConfig($app, $config);
310308

311309
$pipeline = $this->getQueueFromApplicationPipeline($app);
312310

@@ -328,7 +326,7 @@ public function testMiddlewareWithoutPriorityIsGivenDefaultPriorityAndRegistered
328326

329327
$app = $this->createApplication();
330328

331-
$this->injector->injectPipelineFromConfig($app, $config);
329+
ApplicationConfigInjectionDelegator::injectPipelineFromConfig($app, $config);
332330

333331
$pipeline = $this->getQueueFromApplicationPipeline($app);
334332

@@ -340,15 +338,15 @@ public function testMiddlewareWithoutPriorityIsGivenDefaultPriorityAndRegistered
340338
public function testInjectPipelineFromConfigWithEmptyConfigDoesNothing()
341339
{
342340
$app = $this->createApplication();
343-
$this->injector->injectPipelineFromConfig($app, []);
341+
ApplicationConfigInjectionDelegator::injectPipelineFromConfig($app, []);
344342
$pipeline = $this->getQueueFromApplicationPipeline($app);
345343
$this->assertEquals(0, $pipeline->count());
346344
}
347345

348346
public function testInjectRoutesFromConfigWithEmptyConfigDoesNothing()
349347
{
350348
$app = $this->createApplication();
351-
$this->injector->injectRoutesFromConfig($app, []);
349+
ApplicationConfigInjectionDelegator::injectRoutesFromConfig($app, []);
352350
$this->assertEquals([], $app->getRoutes());
353351
$pipeline = $this->getQueueFromApplicationPipeline($app);
354352
$this->assertEquals(0, $pipeline->count());
@@ -370,7 +368,7 @@ public function testInjectRoutesFromConfigRaisesExceptionIfAllowedMethodsIsInval
370368

371369
$this->expectException(InvalidArgumentException::class);
372370
$this->expectExceptionMessage('Allowed HTTP methods');
373-
$this->injector->injectRoutesFromConfig($app, $config);
371+
ApplicationConfigInjectionDelegator::injectRoutesFromConfig($app, $config);
374372
}
375373

376374
public function testInjectRoutesFromConfigRaisesExceptionIfOptionsIsNotAnArray()
@@ -390,7 +388,7 @@ public function testInjectRoutesFromConfigRaisesExceptionIfOptionsIsNotAnArray()
390388

391389
$this->expectException(InvalidArgumentException::class);
392390
$this->expectExceptionMessage('Route options must be an array');
393-
$this->injector->injectRoutesFromConfig($app, $config);
391+
ApplicationConfigInjectionDelegator::injectRoutesFromConfig($app, $config);
394392
}
395393

396394
public function testInjectRoutesFromConfigCanProvideRouteOptions()
@@ -410,7 +408,7 @@ public function testInjectRoutesFromConfigCanProvideRouteOptions()
410408
$this->container->has('config')->willReturn(false);
411409
$app = $this->createApplication();
412410

413-
$this->injector->injectRoutesFromConfig($app, $config);
411+
ApplicationConfigInjectionDelegator::injectRoutesFromConfig($app, $config);
414412

415413
$routes = $app->getRoutes();
416414

@@ -445,7 +443,7 @@ public function testInjectRoutesFromConfigWillSkipSpecsThatOmitPath()
445443

446444
$app = $this->createApplication();
447445

448-
$this->injector->injectPipelineFromConfig($app, $config);
446+
ApplicationConfigInjectionDelegator::injectPipelineFromConfig($app, $config);
449447
$this->assertEquals([], $app->getRoutes());
450448
}
451449

@@ -476,7 +474,7 @@ public function testInjectRoutesFromConfigWillSkipSpecsThatOmitMiddleware()
476474

477475
$app = $this->createApplication();
478476

479-
$this->injector->injectPipelineFromConfig($app, $config);
477+
ApplicationConfigInjectionDelegator::injectPipelineFromConfig($app, $config);
480478
$this->assertEquals([], $app->getRoutes());
481479
}
482480

@@ -493,6 +491,6 @@ public function testInjectPipelineFromConfigRaisesExceptionForSpecsOmittingMiddl
493491

494492
$this->expectException(InvalidArgumentException::class);
495493
$this->expectExceptionMessage('Invalid pipeline specification received');
496-
$this->injector->injectPipelineFromConfig($app, $config);
494+
ApplicationConfigInjectionDelegator::injectPipelineFromConfig($app, $config);
497495
}
498496
}

test/Application/TestAsset/CallableInteropMiddleware.php renamed to test/Container/TestAsset/CallableInteropMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
declare(strict_types=1);
99

10-
namespace ZendTest\Expressive\Application\TestAsset;
10+
namespace ZendTest\Expressive\Container\TestAsset;
1111

1212
use Psr\Http\Server\RequestHandlerInterface;
1313

test/Application/TestAsset/CallableMiddleware.php renamed to test/Container/TestAsset/CallableMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
declare(strict_types=1);
99

10-
namespace ZendTest\Expressive\Application\TestAsset;
10+
namespace ZendTest\Expressive\Container\TestAsset;
1111

1212
class CallableMiddleware
1313
{

test/Application/TestAsset/InteropMiddleware.php renamed to test/Container/TestAsset/InteropMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
declare(strict_types=1);
99

10-
namespace ZendTest\Expressive\Application\TestAsset;
10+
namespace ZendTest\Expressive\Container\TestAsset;
1111

1212
use Psr\Http\Message\ResponseInterface;
1313
use Psr\Http\Message\ServerRequestInterface;

0 commit comments

Comments
 (0)