Skip to content

Commit 2c3baf8

Browse files
committed
updated tests
1 parent ef630cb commit 2c3baf8

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
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+
## NEXT
8+
9+
### Changed
10+
11+
* Updated tests
12+
713
## 0.2.0 - 2016-11-22
814

915
### Changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"require": {
2020
"php": "^5.6 || ^7.0",
2121
"http-interop/http-middleware": "^0.3",
22-
"middlewares/utils": "~0.5"
22+
"middlewares/utils": "~0.6"
2323
},
2424
"require-dev": {
2525
"phpunit/phpunit": "^5.5",

tests/TrailingSlashTest.php

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
use Middlewares\TrailingSlash;
66
use Middlewares\Utils\Dispatcher;
7-
use Middlewares\Utils\CallableMiddleware;
8-
use Zend\Diactoros\ServerRequest;
9-
use Zend\Diactoros\Response;
7+
use Middlewares\Utils\Factory;
108

119
class TrailingSlashTest extends \PHPUnit_Framework_TestCase
1210
{
@@ -23,20 +21,17 @@ public function removeProvider()
2321
/**
2422
* @dataProvider removeProvider
2523
*/
26-
public function testRemove($url, $result)
24+
public function testRemove($uri, $result)
2725
{
28-
$dispatcher = new Dispatcher([
29-
new TrailingSlash(),
30-
31-
new CallableMiddleware(function ($request, $next) {
32-
$response = new Response();
33-
$response->getBody()->write((string) $request->getUri());
26+
$request = Factory::createServerRequest([], 'GET', $uri);
3427

35-
return $response;
36-
}),
37-
]);
28+
$response = (new Dispatcher([
29+
new TrailingSlash(),
3830

39-
$response = $dispatcher->dispatch(new ServerRequest([], [], $url));
31+
function ($request, $next) {
32+
echo $request->getUri();
33+
},
34+
]))->dispatch($request);
4035

4136
$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
4237
$this->assertEquals($result, (string) $response->getBody());
@@ -57,32 +52,29 @@ public function addProvider()
5752
/**
5853
* @dataProvider addProvider
5954
*/
60-
public function testAdd($url, $result)
55+
public function testAdd($uri, $result)
6156
{
62-
$dispatcher = new Dispatcher([
63-
new TrailingSlash(true),
57+
$request = Factory::createServerRequest([], 'GET', $uri);
6458

65-
new CallableMiddleware(function ($request, $next) {
66-
$response = new Response();
67-
$response->getBody()->write((string) $request->getUri());
68-
69-
return $response;
70-
}),
71-
]);
59+
$response = (new Dispatcher([
60+
new TrailingSlash(true),
7261

73-
$response = $dispatcher->dispatch(new ServerRequest([], [], $url));
62+
function ($request, $next) {
63+
echo $request->getUri();
64+
},
65+
]))->dispatch($request);
7466

7567
$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
7668
$this->assertEquals($result, (string) $response->getBody());
7769
}
7870

7971
public function testRedirect()
8072
{
81-
$dispatcher = new Dispatcher([
82-
(new TrailingSlash())->redirect(),
83-
]);
73+
$request = Factory::createServerRequest([], 'GET', '/foo/bar/');
8474

85-
$response = $dispatcher->dispatch(new ServerRequest([], [], '/foo/bar/'));
75+
$response = (new Dispatcher([
76+
(new TrailingSlash())->redirect(),
77+
]))->dispatch($request);
8678

8779
$this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $response);
8880
$this->assertEquals(301, (string) $response->getStatusCode());

0 commit comments

Comments
 (0)