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

Commit

Permalink
Tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbundyra committed Dec 7, 2017
1 parent 669b76f commit 16bb652
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
6 changes: 5 additions & 1 deletion test/Application/ConfigInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ZendTest\Expressive\Application;

use Interop\Http\Server\MiddlewareInterface;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
Expand Down Expand Up @@ -60,7 +61,7 @@ public static function assertRoute($spec, array $routes)
return false;
}

if ($route->getMiddleware() !== $spec['middleware']) {
if (! $route->getMiddleware() instanceof MiddlewareInterface) {
return false;
}

Expand Down Expand Up @@ -117,6 +118,9 @@ function () {
*/
public function testInjectRoutesFromConfigSetsUpRoutesFromConfig($middleware)
{
$this->container->has('HelloWorld')->willReturn(true);
$this->container->has('Ping')->willReturn(true);

$config = [
'routes' => [
[
Expand Down
30 changes: 16 additions & 14 deletions test/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Interop\Http\Server\RequestHandlerInterface;
use InvalidArgumentException;
use Mockery;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
Expand Down Expand Up @@ -138,15 +139,6 @@ public function testCanCallRouteWithMultipleHttpMethods()
$this->assertSame($methods, $route->getAllowedMethods());
}

public function testCanCallRouteWithARoute()
{
$route = new Route('/foo', $this->noopMiddleware);
$this->router->addRoute($route)->shouldBeCalled();
$app = $this->getApp();
$test = $app->route($route);
$this->assertSame($route, $test);
}

public function testCallingRouteWithExistingPathAndOmittingMethodsArgumentRaisesException()
{
$this->router->addRoute(Argument::type(Route::class))->shouldBeCalledTimes(2);
Expand Down Expand Up @@ -543,14 +535,24 @@ public function testRunReturnsResponseWithBadRequestStatusWhenServerRequestFacto

public function testRetrieveRegisteredRoutes()
{
$route = new Route('/foo', $this->noopMiddleware);
$this->router->addRoute($route)->shouldBeCalled();
// $route = new Route('/foo', $this->noopMiddleware);
$this->router->addRoute(Argument::that(function ($arg) {
Assert::assertInstanceOf(Route::class, $arg);
Assert::assertSame('/foo', $arg->getPath());
Assert::assertSame($this->noopMiddleware, $arg->getMiddleware());
return true;
}))->shouldBeCalled();

$app = $this->getApp();
$test = $app->route($route);
$this->assertSame($route, $test);
$test = $app->route('/foo', $this->noopMiddleware);

$this->assertInstanceOf(Route::class, $test);
$this->assertSame('/foo', $test->getPath());
$this->assertSame($this->noopMiddleware, $test->getMiddleware());

$routes = $app->getRoutes();
$this->assertCount(1, $routes);
$this->assertInstanceOf(Route::class, $routes[0]);
$this->assertContainsOnlyInstancesOf(Route::class, $routes);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions test/Container/ApplicationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace ZendTest\Expressive\Container;

use ArrayObject;
use Interop\Http\Server\MiddlewareInterface;
use Interop\Http\Server\RequestHandlerInterface;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -82,7 +83,7 @@ public static function assertRoute($spec, array $routes)
return false;
}

if ($route->getMiddleware() !== $spec['middleware']) {
if (! $route->getMiddleware() instanceof MiddlewareInterface) {
return false;
}

Expand Down Expand Up @@ -129,7 +130,6 @@ public function callableMiddlewares()
'service-name' => 'HelloWorld',
'closure' => function () {
},
'callable' => [InvokableMiddleware::class, 'staticallyCallableMiddleware'],
];

$configTypes = [
Expand All @@ -153,6 +153,9 @@ public function callableMiddlewares()
*/
public function testFactorySetsUpRoutesFromConfig($middleware, $configType)
{
$this->container->has('HelloWorld')->willReturn(true);
$this->container->has('Ping')->willReturn(true);

$config = [
'routes' => [
[
Expand Down Expand Up @@ -233,9 +236,12 @@ public function testMiddlewareIsNotAddedIfSpecIsInvalid($configType)
* @dataProvider configTypes
*
* @param null|string $configType
* @group xya
*/
public function testCanSpecifyRouteViaConfigurationWithNoMethods($configType)
{
$this->container->has('HelloWorld')->willReturn(true);

$config = [
'routes' => [
[
Expand Down Expand Up @@ -265,6 +271,8 @@ public function testCanSpecifyRouteViaConfigurationWithNoMethods($configType)
*/
public function testCanSpecifyRouteOptionsViaConfiguration($configType)
{
$this->container->has('HelloWorld')->willReturn(true);

$expected = [
'values' => [
'foo' => 'bar',
Expand Down Expand Up @@ -331,6 +339,8 @@ public function testExceptionIsRaisedInCaseOfInvalidRouteMethodsConfiguration($c
*/
public function testExceptionIsRaisedInCaseOfInvalidRouteOptionsConfiguration($configType)
{
$this->container->has('HelloWorld')->willReturn(true);

$config = [
'routes' => [
[
Expand Down
2 changes: 1 addition & 1 deletion test/Middleware/RouteMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testRoutingFailureDueToHttpMethodCallsNextWithNotAllowedResponse

public function testGeneralRoutingFailureInvokesDelegateWithSameRequest()
{
$result = RouteResult::fromRouteFailure([]);
$result = RouteResult::fromRouteFailure(Route::HTTP_METHOD_ANY);

$this->router->match($this->request->reveal())->willReturn($result);
$this->response->withStatus()->shouldNotBeCalled();
Expand Down

0 comments on commit 16bb652

Please sign in to comment.