Skip to content

Commit dee30fb

Browse files
committed
updated http-middleware interface to 0.3
1 parent 03c7a4f commit dee30fb

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 0.3.0 - 2016-11-22
8+
9+
### Changed
10+
11+
* Updated to `http-interop/http-middleware#0.3`
12+
713
## 0.2.0 - 2016-11-19
814

915
### Changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# middlewares/error-handler
22

33
[![Latest Version on Packagist][ico-version]][link-packagist]
4-
[![Software License][ico-license]](LICENSE.md)
4+
[![Software License][ico-license]](LICENSE)
55
[![Build Status][ico-travis]][link-travis]
66
[![Quality Score][ico-scrutinizer]][link-scrutinizer]
77
[![Total Downloads][ico-downloads]][link-downloads]
88
[![SensioLabs Insight][ico-sensiolabs]][link-sensiolabs]
99

1010
Middleware to execute a handler if the response returned by the next middlewares has any error (status code 400-599). It can also catch the exceptions.
1111

12-
**Note:** This middleware is intended for server side only
13-
1412
## Requirements
1513

1614
* PHP >= 5.6

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
},
1717
"require": {
1818
"php": "^5.6 || ^7.0",
19-
"http-interop/http-middleware": "^0.2",
20-
"middlewares/utils": "~0.3"
19+
"http-interop/http-middleware": "^0.3",
20+
"middlewares/utils": "~0.5"
2121
},
2222
"require-dev": {
2323
"phpunit/phpunit": "^5.5",
2424
"zendframework/zend-diactoros": "^1.3",
2525
"friendsofphp/php-cs-fixer": "^1.12",
26-
"squizlabs/php_codesniffer": "^2.7",
27-
"mindplay/middleman": "^2.0"
26+
"squizlabs/php_codesniffer": "^2.7"
2827
},
2928
"autoload": {
3029
"psr-4": {

tests/ErrorHandlerTest.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
namespace Middlewares\Tests;
44

55
use Middlewares\ErrorHandler;
6+
use Middlewares\Utils\Dispatcher;
7+
use Middlewares\Utils\CallableMiddleware;
68
use Zend\Diactoros\ServerRequest;
79
use Zend\Diactoros\Response;
8-
use mindplay\middleman\Dispatcher;
910
use Exception;
1011

1112
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
@@ -18,9 +19,9 @@ public function testError()
1819

1920
return (new Response())->withStatus($request->getAttribute('error')['status_code']);
2021
}),
21-
function () {
22+
new CallableMiddleware(function () {
2223
return (new Response())->withStatus(404);
23-
},
24+
}),
2425
]))->dispatch(new ServerRequest());
2526

2627
$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
@@ -36,9 +37,9 @@ public function testAttribute()
3637

3738
return (new Response())->withStatus($request->getAttribute('foo')['status_code']);
3839
}))->attribute('foo'),
39-
function () {
40+
new CallableMiddleware(function () {
4041
return (new Response())->withStatus(404);
41-
},
42+
}),
4243
]))->dispatch(new ServerRequest());
4344

4445
$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
@@ -56,10 +57,10 @@ public function testException()
5657

5758
return (new Response())->withStatus($request->getAttribute('error')['status_code']);
5859
}))->catchExceptions(),
59-
function ($request) use ($exception) {
60+
new CallableMiddleware(function ($request) use ($exception) {
6061
echo 'not showed text';
6162
throw $exception;
62-
},
63+
}),
6364
]))->dispatch(new ServerRequest());
6465

6566
$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
@@ -90,9 +91,9 @@ public function testFormats($type)
9091
$request = (new ServerRequest())->withHeader('Accept', $type);
9192
$response = (new Dispatcher([
9293
new ErrorHandler(),
93-
function () {
94+
new CallableMiddleware(function () {
9495
return (new Response())->withStatus(500);
95-
},
96+
}),
9697
]))->dispatch($request);
9798

9899
$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
@@ -104,9 +105,9 @@ public function testDefaultFormat()
104105
{
105106
$response = (new Dispatcher([
106107
new ErrorHandler(),
107-
function () {
108+
new CallableMiddleware(function () {
108109
return (new Response())->withStatus(500);
109-
},
110+
}),
110111
]))->dispatch(new ServerRequest());
111112

112113
$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
@@ -123,9 +124,9 @@ public function testArguments()
123124

124125
return $response;
125126
}))->arguments('Hello world'),
126-
function () {
127+
new CallableMiddleware(function () {
127128
return (new Response())->withStatus(500);
128-
},
129+
}),
129130
]))->dispatch(new ServerRequest());
130131

131132
$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
@@ -141,25 +142,25 @@ public function testValidators()
141142

142143
$response = (new Dispatcher([
143144
(new ErrorHandler())->statusCode($validator),
144-
function () {
145+
new CallableMiddleware(function () {
145146
$response = (new Response())->withStatus(500);
146147
$response->getBody()->write('Content');
147148

148149
return $response;
149-
},
150+
}),
150151
]))->dispatch(new ServerRequest());
151152

152153
$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
153154
$this->assertEquals('Content', (string) $response->getBody());
154155

155156
$response = (new Dispatcher([
156157
(new ErrorHandler())->statusCode($validator),
157-
function () {
158+
new CallableMiddleware(function () {
158159
$response = (new Response())->withStatus(404);
159160
$response->getBody()->write('Content');
160161

161162
return $response;
162-
},
163+
}),
163164
]))->dispatch(new ServerRequest());
164165

165166
$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);

0 commit comments

Comments
 (0)