Skip to content

Commit 85897a2

Browse files
committed
Abstract test for middleware runners
1 parent 5cc7545 commit 85897a2

File tree

3 files changed

+55
-47
lines changed

3 files changed

+55
-47
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"require-dev": {
1818
"phpunit/phpunit": "^4.8.6",
1919
"mikey179/vfsStream": "^1.6",
20-
"slim/slim": "^3.1"
20+
"slim/slim": "^3.0"
2121
},
2222
"autoload": {
2323
"psr-4": {

test/AbstractMiddlewareRunnerTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace PhpMiddlewareTest\PhpDebugBar;
4+
5+
use PHPUnit_Framework_TestCase;
6+
use Psr\Http\Message\ResponseInterface;
7+
8+
abstract class AbstractMiddlewareRunnerTest extends PHPUnit_Framework_TestCase
9+
{
10+
final public function testAppendJsIntoHtmlContent()
11+
{
12+
$response = $this->dispatchApplication([
13+
'REQUEST_URI' => '/hello',
14+
'REQUEST_METHOD' => 'GET',
15+
'HTTP_ACCEPT' => 'text/html',
16+
]);
17+
18+
$responseBody = (string) $response->getBody();
19+
20+
$this->assertContains('var phpdebugbar = new PhpDebugBar.DebugBar();', $responseBody);
21+
$this->assertContains('Hello!', $responseBody);
22+
$this->assertContains('"/phpdebugbar/debugbar.js"', $responseBody);
23+
}
24+
25+
final public function testGetStatics()
26+
{
27+
$response = $this->dispatchApplication([
28+
'DOCUMENT_ROOT' => __DIR__,
29+
'REMOTE_ADDR' => '127.0.0.1',
30+
'REMOTE_PORT' => '40226',
31+
'SERVER_SOFTWARE' => 'PHP 7.0.8-3ubuntu3 Development Server',
32+
'SERVER_PROTOCOL' => 'HTTP/1.1',
33+
'SERVER_NAME' => '0.0.0.0',
34+
'SERVER_PORT' => '8080',
35+
'REQUEST_URI' => '/phpdebugbar/debugbar.js',
36+
'REQUEST_METHOD' => 'GET',
37+
'SCRIPT_NAME' => '/phpdebugbar/debugbar.js',
38+
'SCRIPT_FILENAME' => __FILE__,
39+
'PHP_SELF' => '/phpdebugbar/debugbar.js',
40+
'HTTP_HOST' => '0.0.0.0:8080',
41+
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
42+
]);
43+
44+
$contentType = $response->getHeaderLine('Content-type');
45+
46+
$this->assertContains('text/javascript', $contentType);
47+
}
48+
49+
/**
50+
* @return ResponseInterface
51+
*/
52+
abstract protected function dispatchApplication(array $server);
53+
}

test/Slim3Test.php

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,11 @@
44

55
use DebugBar\StandardDebugBar;
66
use PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware;
7-
use PHPUnit_Framework_TestCase;
8-
use Psr\Http\Message\ResponseInterface;
97
use Slim\App;
108
use Slim\Http\Environment;
119

12-
class Slim3Test extends PHPUnit_Framework_TestCase
10+
final class Slim3Test extends AbstractMiddlewareRunnerTest
1311
{
14-
public function testAppendJsIntoHtmlContent()
15-
{
16-
$response = $this->dispatchApplication([
17-
'REQUEST_URI' => '/hello',
18-
'REQUEST_METHOD' => 'GET',
19-
'HTTP_ACCEPT' => 'text/html',
20-
]);
21-
22-
$responseBody = (string) $response->getBody();
23-
24-
$this->assertContains('var phpdebugbar = new PhpDebugBar.DebugBar();', $responseBody);
25-
$this->assertContains('Hello!', $responseBody);
26-
}
27-
28-
public function testGetStatics()
29-
{
30-
$response = $this->dispatchApplication([
31-
'DOCUMENT_ROOT' => __DIR__,
32-
'REMOTE_ADDR' => '127.0.0.1',
33-
'REMOTE_PORT' => '40226',
34-
'SERVER_SOFTWARE' => 'PHP 7.0.8-3ubuntu3 Development Server',
35-
'SERVER_PROTOCOL' => 'HTTP/1.1',
36-
'SERVER_NAME' => '0.0.0.0',
37-
'SERVER_PORT' => '8080',
38-
'REQUEST_URI' => '/phpdebugbar/debugbar.js',
39-
'REQUEST_METHOD' => 'GET',
40-
'SCRIPT_NAME' => '/phpdebugbar/debugbar.js',
41-
'SCRIPT_FILENAME' => __FILE__,
42-
'PHP_SELF' => '/phpdebugbar/debugbar.js',
43-
'HTTP_HOST' => '0.0.0.0:8080',
44-
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
45-
]);
46-
47-
$contentType = $response->getHeaderLine('Content-type');
48-
49-
$this->assertContains('text/javascript', $contentType);
50-
}
51-
52-
/**
53-
* @param array $server
54-
* @return ResponseInterface
55-
*/
5612
protected function dispatchApplication(array $server)
5713
{
5814
$app = new App();
@@ -73,5 +29,4 @@ protected function dispatchApplication(array $server)
7329

7430
return $app->run(true);
7531
}
76-
7732
}

0 commit comments

Comments
 (0)