Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit d4199e7

Browse files
committed
Merge pull request #50 from Maks3w/hotfix/test-improvements
test improvements
2 parents d3e7fe3 + fefde14 commit d4199e7

File tree

8 files changed

+43
-38
lines changed

8 files changed

+43
-38
lines changed

test/MessageTraitTest.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
namespace ZendTest\Diactoros;
1111

1212
use PHPUnit_Framework_TestCase as TestCase;
13+
use Psr\Http\Message\MessageInterface;
1314
use Zend\Diactoros\Request;
14-
use Zend\Diactoros\Stream;
1515

1616
class MessageTraitTest extends TestCase
1717
{
18+
/** @var MessageInterface */
19+
protected $message;
20+
1821
public function setUp()
1922
{
20-
$this->stream = new Stream('php://memory', 'wb+');
21-
$this->message = new Request(null, null, $this->stream);
23+
$this->message = new Request(null, null, $this->getMock('Psr\Http\Message\StreamInterface'));
2224
}
2325

2426
public function testProtocolHasAcceptableDefault()
@@ -33,14 +35,9 @@ public function testProtocolMutatorReturnsCloneWithChanges()
3335
$this->assertEquals('1.0', $message->getProtocolVersion());
3436
}
3537

36-
public function testUsesStreamProvidedInConstructorAsBody()
37-
{
38-
$this->assertSame($this->stream, $this->message->getBody());
39-
}
40-
4138
public function testBodyMutatorReturnsCloneWithChanges()
4239
{
43-
$stream = new Stream('php://memory', 'wb+');
40+
$stream = $this->getMock('Psr\Http\Message\StreamInterface');
4441
$message = $this->message->withBody($stream);
4542
$this->assertNotSame($this->message, $message);
4643
$this->assertSame($stream, $message->getBody());
@@ -186,13 +183,6 @@ public function testWithoutHeaderDoesNothingIfHeaderDoesNotExist()
186183
$this->assertFalse($message->hasHeader('X-Foo'));
187184
}
188185

189-
public function testHeadersInitialization()
190-
{
191-
$headers = ['X-Foo' => ['bar']];
192-
$this->message = new Request(null, null, $this->stream, $headers);
193-
$this->assertSame($headers, $this->message->getHeaders());
194-
}
195-
196186
public function testGetHeaderReturnsAnEmptyArrayWhenHeaderDoesNotExist()
197187
{
198188
$this->assertSame([], $this->message->getHeader('X-Foo-Bar'));

test/PhpInputStreamTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
class PhpInputStreamTest extends TestCase
1616
{
17+
/** @var string */
18+
protected $file;
19+
20+
/** @var PhpInputStream */
21+
protected $stream;
22+
1723
public function setUp()
1824
{
1925
$this->file = __DIR__ . '/TestAsset/php-input-stream.txt';

test/RequestTest.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
class RequestTest extends TestCase
1818
{
19+
/** @var Request */
20+
protected $request;
21+
1922
public function setUp()
2023
{
2124
$this->request = new Request();
@@ -44,19 +47,6 @@ public function testConstructorRaisesExceptionForInvalidStream()
4447
new Request(['TOTALLY INVALID']);
4548
}
4649

47-
public function invalidUrls()
48-
{
49-
return [
50-
'null' => [null],
51-
'true' => [true],
52-
'false' => [false],
53-
'int' => [1],
54-
'float' => [1.1],
55-
'array' => [['foo']],
56-
'object' => [(object) ['foo']],
57-
];
58-
}
59-
6050
public function testWithUriReturnsNewInstanceWithNewUri()
6151
{
6252
$request = $this->request->withUri(new Uri('https://example.com:10082/foo/bar?baz=bat'));

test/Response/SapiEmitterTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
class SapiEmitterTest extends TestCase
1919
{
20+
/** @var SapiEmitter */
21+
protected $emitter;
22+
2023
public function setUp()
2124
{
2225
HeaderStack::reset();

test/ResponseTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
class ResponseTest extends TestCase
1717
{
18+
/** @var Response */
19+
protected $response;
20+
1821
public function setUp()
1922
{
2023
$this->response = new Response();

test/ServerRequestTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
class ServerRequestTest extends TestCase
1919
{
20+
/** @var ServerRequest */
21+
protected $request;
22+
2023
public function setUp()
2124
{
2225
$this->request = new ServerRequest();

test/ServerTest.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,31 @@
1010
namespace ZendTest\Diactoros;
1111

1212
use PHPUnit_Framework_TestCase as TestCase;
13+
use Psr\Http\Message\ResponseInterface;
14+
use Psr\Http\Message\ServerRequestInterface;
1315
use Zend\Diactoros\Server;
1416
use ZendTest\Diactoros\TestAsset\HeaderStack;
1517

1618
class ServerTest extends TestCase
1719
{
20+
/** @var Callable */
21+
protected $callback;
22+
23+
/** @var ServerRequestInterface|\PHPUnit_Framework_MockObject_MockObject */
24+
protected $request;
25+
26+
/** @var ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */
27+
protected $response;
28+
1829
public function setUp()
1930
{
2031
HeaderStack::reset();
2132

2233
$this->callback = function ($req, $res, $done) {
2334
// Intentionally empty
2435
};
25-
$this->request = $this
26-
->getMockBuilder('Psr\Http\Message\ServerRequestInterface')
27-
->getMock();
28-
$this->response = $this
29-
->getMockBuilder('Psr\Http\Message\ResponseInterface')
30-
->getMock();
36+
$this->request = $this->getMock('Psr\Http\Message\ServerRequestInterface');
37+
$this->response = $this->getMock('Psr\Http\Message\ResponseInterface');
3138
}
3239

3340
public function tearDown()
@@ -129,7 +136,7 @@ public function testListenEmitsStatusHeaderWithoutReasonPhraseIfNoReasonPhrase()
129136
'QUERY_STRING' => 'bar=baz',
130137
];
131138

132-
$callback = function ($req, $res) {
139+
$callback = function (ServerRequestInterface $req, ResponseInterface $res) {
133140
$res = $res->withStatus(299);
134141
$res = $res->withAddedHeader('Content-Type', 'text/plain');
135142
$res->getBody()->write('FOOBAR');
@@ -155,7 +162,7 @@ public function testEnsurePercentCharactersDoNotResultInOutputError()
155162
'QUERY_STRING' => 'bar=baz',
156163
];
157164

158-
$callback = function ($req, $res) {
165+
$callback = function (ServerRequestInterface $req, ResponseInterface $res) {
159166
$res = $res->withAddedHeader('Content-Type', 'text/plain');
160167
$res->getBody()->write('100%');
161168
return $res;
@@ -178,7 +185,7 @@ public function testEmitsHeadersWithMultipleValuesMultipleTimes()
178185
'REQUEST_URI' => '/foo/bar',
179186
];
180187

181-
$callback = function ($req, $res) {
188+
$callback = function (ServerRequestInterface $req, ResponseInterface $res) {
182189
$res = $res->withAddedHeader('Content-Type', 'text/plain');
183190
$res = $res->withAddedHeader(
184191
'Set-Cookie',

test/StreamTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class StreamTest extends TestCase
1717
{
1818
public $tmpnam;
1919

20+
/** @var Stream */
21+
protected $stream;
22+
2023
public function setUp()
2124
{
2225
$this->tmpnam = null;

0 commit comments

Comments
 (0)