Skip to content

Implemented #9 #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/DefaultPriorityTrait.php

This file was deleted.

13 changes: 3 additions & 10 deletions src/MiddlewareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,12 @@

/**
* Middleware, when a new request is made an instance specifically for that request is made for each request.
*
* Priority ranging from 0 to 1000. Where 1000 will be executed first on `pre`/`post`/`error`
* and 0 last on `pre`/`post`/`error`.
*/
interface MiddlewareInterface
{
/**
* Priority ranging from 0 to 1000. Where 1000 will be executed first on `pre`/`post`/`error`
* and 0 last on `pre`/`post`/`error`.
*
* @deprecated Use annotations for more fine grained control
*
* @return int
*/
public function priority(): int;

/**
* Return the processed $request via a fulfilled promise.
* When implementing cache or other feature that returns a response, do it with a rejected promise.
Expand Down
2 changes: 1 addition & 1 deletion src/MiddlewareRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ private function getPriority(string $method, MiddlewareInterface $middleware): i
return $annotation->priority();
}

return $middleware->priority();
return Priority::DEFAULT;
}
}
5 changes: 1 addition & 4 deletions tests/DummyMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<?php
declare(strict_types=1);
<?php declare(strict_types=1);

namespace ApiClients\Tests\Foundation\Middleware;

use ApiClients\Foundation\Middleware\DefaultPriorityTrait;
use ApiClients\Foundation\Middleware\ErrorTrait;
use ApiClients\Foundation\Middleware\MiddlewareInterface;
use ApiClients\Foundation\Middleware\PostTrait;
use ApiClients\Foundation\Middleware\PreTrait;

class DummyMiddleware implements MiddlewareInterface
{
use DefaultPriorityTrait;
use PreTrait;
use PostTrait;
use ErrorTrait;
Expand Down
9 changes: 0 additions & 9 deletions tests/DummyMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@

class DummyMiddlewareTest extends TestCase
{
public function testPriority()
{
$middleware = new DummyMiddleware();
$this->assertSame(
500,
$middleware->priority()
);
}

public function testPre()
{
$middleware = new DummyMiddleware();
Expand Down
11 changes: 4 additions & 7 deletions tests/MiddlewareRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ public function testAll()
$options = [];

$middlewareOne = Phake::mock(MiddlewareInterface::class);
Phake::when($middlewareOne)->priority()->thenReturn(1000);
$middlewareTwo = Phake::mock(MiddlewareInterface::class);
Phake::when($middlewareTwo)->priority()->thenReturn(500);
$middlewareThree = Phake::mock(MiddlewareInterface::class);
Phake::when($middlewareThree)->priority()->thenReturn(0);
$args = [
$options,
$middlewareThree,
Expand Down Expand Up @@ -68,15 +65,15 @@ public function testAll()
}

Phake::inOrder(
Phake::verify($middlewareThree)->pre($request, $options, $id),
Phake::verify($middlewareOne)->pre($request, $options, $id),
Phake::verify($middlewareTwo)->pre($request, $options, $id),
Phake::verify($middlewareThree)->pre($request, $options, $id),
Phake::verify($middlewareThree)->post($response, $options, $id),
Phake::verify($middlewareOne)->post($response, $options, $id),
Phake::verify($middlewareTwo)->post($response, $options, $id),
Phake::verify($middlewareThree)->post($response, $options, $id),
Phake::verify($middlewareThree)->error($exception, $options, $id),
Phake::verify($middlewareOne)->error($exception, $options, $id),
Phake::verify($middlewareTwo)->error($exception, $options, $id),
Phake::verify($middlewareThree)->error($exception, $options, $id)
Phake::verify($middlewareTwo)->error($exception, $options, $id)
);
}

Expand Down
3 changes: 0 additions & 3 deletions tests/TestMiddlewares/OneMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace ApiClients\Tests\Foundation\Middleware\TestMiddlewares;

use ApiClients\Foundation\Middleware\Annotation\Priority as PriorityAnnotation;
use ApiClients\Foundation\Middleware\DefaultPriorityTrait;
use ApiClients\Foundation\Middleware\MiddlewareInterface;
use ApiClients\Foundation\Middleware\Priority;
use Psr\Http\Message\RequestInterface;
Expand All @@ -15,8 +14,6 @@

class OneMiddleware implements MiddlewareInterface
{
use DefaultPriorityTrait;

private $calls = [];

/**
Expand Down
3 changes: 0 additions & 3 deletions tests/TestMiddlewares/ThreeMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use ApiClients\Foundation\Middleware\Annotation\Early;
use ApiClients\Foundation\Middleware\Annotation\First;
use ApiClients\Foundation\Middleware\Annotation\Late;
use ApiClients\Foundation\Middleware\DefaultPriorityTrait;
use ApiClients\Foundation\Middleware\MiddlewareInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -16,8 +15,6 @@

class ThreeMiddleware implements MiddlewareInterface
{
use DefaultPriorityTrait;

private $calls = [];

/**
Expand Down
3 changes: 0 additions & 3 deletions tests/TestMiddlewares/TwoMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace ApiClients\Tests\Foundation\Middleware\TestMiddlewares;

use ApiClients\Foundation\Middleware\DefaultPriorityTrait;
use ApiClients\Foundation\Middleware\MiddlewareInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -13,8 +12,6 @@

class TwoMiddleware implements MiddlewareInterface
{
use DefaultPriorityTrait;

private $calls = [];

/**
Expand Down