Skip to content

Commit 82fd719

Browse files
committed
Add support for psr-15
1 parent b588404 commit 82fd719

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

.travis.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
language: php
22

3-
matrix:
4-
fast_finish: true
5-
include:
6-
- php: 5.5
7-
- php: 5.6
8-
- php: 7
9-
- php: hhvm
10-
allow_failures:
11-
- php: 7
12-
- php: hhvm
3+
php:
4+
- 5.5
5+
- 5.6
6+
- 7.0
7+
- 7.1
8+
- hhvm
139

14-
install:
15-
- travis_retry composer install --no-interaction --ignore-platform-reqs --prefer-source
16-
- composer info -i
10+
env:
11+
- COMPOSER_FLAGS=--prefer-lowest
12+
- COMPOSER_FLAGS=
13+
14+
before_script:
15+
- composer update --no-interaction --no-suggest --prefer-dist $COMPOSER_FLAGS
1716

1817
script:
19-
- ./vendor/bin/phpunit
18+
- vendor/bin/phpunit

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
"php": ">=5.5",
1616
"psr/log": "^1.0.0",
1717
"psr/http-message": "^1.0",
18-
"zendframework/zend-diactoros": "^1.1.3"
19-
},
20-
"require-dev": {
21-
"phpunit/phpunit": "^4.8.6"
18+
"zendframework/zend-diactoros": "^1.1.3",
19+
"http-interop/http-middleware": "^0.4.1"
2220
},
2321
"autoload": {
2422
"psr-4": {
@@ -29,5 +27,8 @@
2927
"psr-4": {
3028
"PhpMiddlewareTest\\LogHttpMessages\\": "test/"
3129
}
30+
},
31+
"require-dev": {
32+
"phpunit/phpunit": "^5.0"
3233
}
3334
}

src/LogMiddleware.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
namespace PhpMiddleware\LogHttpMessages;
44

5+
use Interop\Http\ServerMiddleware\DelegateInterface;
6+
use Interop\Http\ServerMiddleware\MiddlewareInterface;
57
use PhpMiddleware\LogHttpMessages\Formatter\HttpMessagesFormatter;
8+
use Psr\Http\Message\ResponseInterface;
69
use Psr\Http\Message\ResponseInterface as Response;
10+
use Psr\Http\Message\ServerRequestInterface;
711
use Psr\Http\Message\ServerRequestInterface as ServerRequest;
12+
use Psr\Log\LoggerInterface;
813
use Psr\Log\LoggerInterface as Logger;
914
use Psr\Log\LogLevel;
15+
use UnexpectedValueException;
1016

11-
class LogMiddleware
17+
class LogMiddleware implements MiddlewareInterface
1218
{
1319
/**
1420
* @var Logger
@@ -50,11 +56,17 @@ public function __invoke(ServerRequest $request, Response $response, callable $n
5056
$messages = $this->formatter->format($request, $outResponse);
5157

5258
if (!is_string($messages)) {
53-
throw new \UnexpectedValueException(sprintf('%s must return string', HttpMessagesFormatter::class));
59+
throw new UnexpectedValueException(sprintf('%s must return string', HttpMessagesFormatter::class));
5460
}
5561

5662
$this->logger->log($this->level, $messages);
5763

5864
return $outResponse;
5965
}
66+
67+
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
68+
{
69+
70+
}
71+
6072
}

test/LogMiddlewareTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testLogMessage()
4141
$this->formatter->expects($this->once())->method('format')->with($this->request, $this->nextResponse)->willReturn('boo');
4242
$this->logger->expects($this->once())->method('log')->with($this->level, 'boo');
4343

44-
$response = $this->executeMiddleware();
44+
$response = $this->executeDoublePassMiddleware();
4545

4646
$this->assertSame($this->nextResponse, $response);
4747
}
@@ -53,10 +53,10 @@ public function testTryToLogNullMessage()
5353
{
5454
$this->formatter->expects($this->once())->method('format')->willReturn(null);
5555

56-
$this->executeMiddleware();
56+
$this->executeDoublePassMiddleware();
5757
}
5858

59-
public function executeMiddleware()
59+
public function executeDoublePassMiddleware()
6060
{
6161
return call_user_func($this->middleware, $this->request, $this->response, $this->next);
6262
}

0 commit comments

Comments
 (0)