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

Commit

Permalink
�Fixed coding standard violations
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaposa committed Nov 23, 2015
1 parent 910bbaa commit 8aea829
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
19 changes: 8 additions & 11 deletions src/Container/ApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Zend\Diactoros\Response\EmitterInterface;
use Zend\Expressive\Application;
use Zend\Expressive\Exception;
use Zend\Expressive\Container\Exception\InvalidArgumentException as CntInvalidArgumentException;
use Zend\Expressive\Container\Exception\InvalidArgumentException as ContainerInvalidArgumentException;
use Zend\Expressive\Router\FastRouteRouter;
use Zend\Expressive\Router\Route;
use Zend\Expressive\Router\RouterInterface;
Expand Down Expand Up @@ -152,11 +152,7 @@ public function __invoke(ContainerInterface $container)
*/
private function injectRoutes(Application $app, ContainerInterface $container)
{
if (!$container->has('config')) {
return;
}

$config = $container->get('config');
$config = $container->has('config') ? $container->get('config') : [];

if (! isset($config['routes'])) {
$app->pipeRoutingMiddleware();
Expand All @@ -168,23 +164,24 @@ private function injectRoutes(Application $app, ContainerInterface $container)
continue;
}

$methods = Route::HTTP_METHOD_ANY;
if (isset($spec['allowed_methods'])) {
$methods = $spec['allowed_methods'];
if (! is_array($methods)) {
throw new CntInvalidArgumentException(sprintf(
throw new ContainerInvalidArgumentException(sprintf(
'Allowed HTTP methods for a route must be in form of an array; received "%s"',
gettype($methods)
));
}
} else {
$methods = Route::HTTP_METHOD_ANY;
}
$name = isset($spec['name']) ? $spec['name'] : null;
$route = new Route($spec['path'], $spec['middleware'], $methods, $name);

if (isset($spec['options'])) {
$options = $spec['options'];
if (! is_array($options)) {
throw new CntInvalidArgumentException(sprintf(
throw new ContainerInvalidArgumentException(sprintf(
'Route options must be an array; received "%s"',
gettype($options)
));
Expand Down Expand Up @@ -245,7 +242,7 @@ private function injectPreMiddleware(Application $app, ContainerInterface $conta
$middlewareCollection = $config['middleware_pipeline']['pre_routing'];

if (! is_array($middlewareCollection)) {
throw new CntInvalidArgumentException(sprintf(
throw new ContainerInvalidArgumentException(sprintf(
'Pre-routing middleware collection must be an array; received "%s"',
gettype($middlewareCollection)
));
Expand Down Expand Up @@ -278,7 +275,7 @@ private function injectPostMiddleware(Application $app, ContainerInterface $cont
$middlewareCollection = $config['middleware_pipeline']['post_routing'];

if (! is_array($middlewareCollection)) {
throw new CntInvalidArgumentException(sprintf(
throw new ContainerInvalidArgumentException(sprintf(
'Post-routing middleware collection must be an array; received "%s"',
gettype($middlewareCollection)
));
Expand Down
20 changes: 8 additions & 12 deletions test/Container/ApplicationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,6 @@ public function testCanSpecifyRouteOptionsViaConfiguration()
$this->assertEquals($expected, $route->getOptions());
}

/**
* @expectedException \Zend\Expressive\Container\Exception\InvalidArgumentException
*/
public function testExceptionIsRaisedInCaseOfInvalidRouteMethodsConfiguration()
{
$router = $this->prophesize('Zend\Expressive\Router\RouterInterface');
Expand Down Expand Up @@ -1125,12 +1122,11 @@ public function testExceptionIsRaisedInCaseOfInvalidRouteMethodsConfiguration()
->get('config')
->willReturn($config);

$this->setExpectedException('Zend\Expressive\Container\Exception\InvalidArgumentException');

$this->factory->__invoke($this->container->reveal());
}

/**
* @expectedException \Zend\Expressive\Container\Exception\InvalidArgumentException
*/
public function testExceptionIsRaisedInCaseOfInvalidRouteOptionsConfiguration()
{
$router = $this->prophesize('Zend\Expressive\Router\RouterInterface');
Expand Down Expand Up @@ -1181,12 +1177,11 @@ public function testExceptionIsRaisedInCaseOfInvalidRouteOptionsConfiguration()
->get('config')
->willReturn($config);

$this->setExpectedException('Zend\Expressive\Container\Exception\InvalidArgumentException');

$this->factory->__invoke($this->container->reveal());
}

/**
* @expectedException \Zend\Expressive\Container\Exception\InvalidArgumentException
*/
public function testExceptionIsRaisedInCaseOfInvalidPreRoutingMiddlewarePipeline()
{
$router = $this->prophesize('Zend\Expressive\Router\RouterInterface');
Expand Down Expand Up @@ -1236,12 +1231,11 @@ public function testExceptionIsRaisedInCaseOfInvalidPreRoutingMiddlewarePipeline
->get('config')
->willReturn($config);

$this->setExpectedException('Zend\Expressive\Container\Exception\InvalidArgumentException');

$this->factory->__invoke($this->container->reveal());
}

/**
* @expectedException \Zend\Expressive\Container\Exception\InvalidArgumentException
*/
public function testExceptionIsRaisedInCaseOfInvalidPostRoutingMiddlewarePipeline()
{
$router = $this->prophesize('Zend\Expressive\Router\RouterInterface');
Expand Down Expand Up @@ -1291,6 +1285,8 @@ public function testExceptionIsRaisedInCaseOfInvalidPostRoutingMiddlewarePipelin
->get('config')
->willReturn($config);

$this->setExpectedException('Zend\Expressive\Container\Exception\InvalidArgumentException');

$this->factory->__invoke($this->container->reveal());
}
}

0 comments on commit 8aea829

Please sign in to comment.