Skip to content

Commit aa9d4ff

Browse files
committedAug 3, 2019
🚿 test cleanup
1 parent b35a27a commit aa9d4ff

8 files changed

+18
-59
lines changed
 

‎tests/Psr15/PriorityQueueRequestHandlerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
namespace chillerlan\HTTPTest\Psr15;
1414

15-
use chillerlan\HTTP\{Psr15\QueueRunner, Psr17, Psr7};
16-
use chillerlan\HTTP\Psr15\PriorityQueueRequestHandler;
15+
use chillerlan\HTTP\Psr17;
1716
use chillerlan\HTTP\Psr15\Middleware\{MiddlewareException, PriorityMiddleware};
17+
use chillerlan\HTTP\Psr15\PriorityQueueRequestHandler;
1818
use PHPUnit\Framework\TestCase;
1919
use Psr\Http\Message\{ResponseInterface, ServerRequestInterface};
2020
use Psr\Http\Server\{MiddlewareInterface, RequestHandlerInterface};

‎tests/Psr17/FactoryHelpersTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace chillerlan\HTTPTest\Psr17;
1414

1515
use chillerlan\HTTP\Psr17;
16-
use chillerlan\HTTP\Psr7\{UploadedFile, Uri, UriExtended};
16+
use chillerlan\HTTP\Psr7\{UploadedFile, UriExtended};
1717
use InvalidArgumentException;
1818
use PHPUnit\Framework\TestCase;
1919
use Psr\Http\Message\StreamInterface;

‎tests/Psr7/MessageHelpersTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
namespace chillerlan\HTTPTest\Psr7;
1414

15-
use chillerlan\HTTP\{Psr7, Psr7\Request, Psr7\Response, Psr17};
15+
use chillerlan\HTTP\{Psr17, Psr7, Psr7\Request, Psr7\Response};
1616
use PHPUnit\Framework\TestCase;
17-
use Psr\Http\Message\{MessageInterface, ResponseInterface};
17+
use Psr\Http\Message\{MessageInterface};
1818

1919
class MessageHelpersTest extends TestCase{
2020

‎tests/Psr7/RequestTest.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,14 @@
1515
namespace chillerlan\HTTPTest\Psr7;
1616

1717
use chillerlan\HTTP\Psr7\{Request, Uri};
18-
use chillerlan\HTTP\Psr17\RequestFactory;
1918
use InvalidArgumentException;
2019
use Psr\Http\Message\StreamInterface;
2120
use PHPUnit\Framework\TestCase;
2221

2322
class RequestTest extends TestCase{
2423

25-
/**
26-
* @var \chillerlan\HTTP\Psr17\RequestFactory
27-
*/
28-
protected $requestFactory;
29-
30-
protected function setUp():void{
31-
$this->requestFactory = new RequestFactory;
32-
}
33-
3424
public function testRequestUriMayBeString(){
35-
$this->assertEquals('/', $this->requestFactory->createRequest($this->requestFactory::METHOD_GET, '/')->getUri()); // RequestFactory coverage
25+
$this->assertEquals('/', (new Request(Request::METHOD_GET, '/'))->getUri());
3626
}
3727

3828
public function testRequestUriMayBeUri(){

‎tests/Psr7/ResponseTest.php

+4-20
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,14 @@
1515
namespace chillerlan\HTTPTest\Psr7;
1616

1717
use chillerlan\HTTP\Psr7\Response;
18-
use chillerlan\HTTP\Psr17\{StreamFactory, ResponseFactory};
18+
use chillerlan\HTTP\Psr17;
1919
use Psr\Http\Message\StreamInterface;
2020
use PHPUnit\Framework\TestCase;
2121

2222
class ResponseTest extends TestCase{
2323

24-
/**
25-
* @var \chillerlan\HTTP\Psr17\ResponseFactory
26-
*/
27-
protected $responseFactory;
28-
29-
/**
30-
* @var \chillerlan\HTTP\Psr17\StreamFactory
31-
*/
32-
protected $streamFactory;
33-
34-
protected function setUp():void{
35-
$this->responseFactory = new ResponseFactory;
36-
$this->streamFactory = new StreamFactory;
37-
}
38-
3924
public function testDefaultConstructor(){
40-
$r = $this->responseFactory->createResponse();
25+
$r = new Response;
4126

4227
$this->assertSame(200, $r->getStatusCode());
4328
$this->assertSame('1.1', $r->getProtocolVersion());
@@ -48,7 +33,7 @@ public function testDefaultConstructor(){
4833
}
4934

5035
public function testCanConstructWithStatusCode(){
51-
$r = $this->responseFactory->createResponse(404);
36+
$r = new Response(404);
5237

5338
$this->assertSame(404, $r->getStatusCode());
5439
$this->assertSame('Not Found', $r->getReasonPhrase());
@@ -148,8 +133,7 @@ public function testSameInstanceWhenSameProtocol(){
148133
}
149134

150135
public function testWithBody(){
151-
$b = $this->streamFactory->createStream('0');
152-
$r = (new Response)->withBody($b);
136+
$r = (new Response)->withBody(Psr17\create_stream('0'));
153137
$this->assertInstanceOf(StreamInterface::class, $r->getBody());
154138
$this->assertSame('0', (string) $r->getBody());
155139
}

‎tests/Psr7/ServerRequestTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
namespace chillerlan\HTTPTest\Psr7;
1616

17-
use chillerlan\HTTP\Psr7\{ServerRequest, UploadedFile, Uri};
18-
use chillerlan\HTTP\Psr17;
17+
use chillerlan\HTTP\Psr7\{ServerRequest, UploadedFile};
1918
use chillerlan\HTTP\Psr17\ServerRequestFactory;
2019
use InvalidArgumentException;
2120
use PHPUnit\Framework\TestCase;

‎tests/Psr7/StreamTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
use chillerlan\HTTP\Psr7\Stream;
1818
use chillerlan\HTTP\Psr17\StreamFactory;
19-
use Exception;
20-
use InvalidArgumentException;
2119
use Psr\Http\Message\StreamInterface;
2220
use PHPUnit\Framework\TestCase;
23-
use RuntimeException;
21+
use Exception, InvalidArgumentException, RuntimeException;
2422

2523
class StreamTest extends TestCase{
2624

‎tests/Psr7/UploadedFileTest.php

+6-18
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
namespace chillerlan\HTTPTest\Psr7;
1616

17+
use chillerlan\HTTP\Psr17;
1718
use chillerlan\HTTP\Psr7;
1819
use chillerlan\HTTP\Psr7\UploadedFile;
19-
use chillerlan\HTTP\Psr17\{StreamFactory, UploadedFileFactory};
2020
use InvalidArgumentException;
2121
use PHPUnit\Framework\TestCase;
2222

@@ -27,20 +27,8 @@ class UploadedFileTest extends TestCase{
2727
*/
2828
protected $cleanup;
2929

30-
/**
31-
* @var \chillerlan\HTTP\Psr17\UploadedFileFactory
32-
*/
33-
protected $uploadedFileFactory;
34-
35-
/**
36-
* @var \chillerlan\HTTP\Psr17\StreamFactory
37-
*/
38-
protected $streamFactory;
39-
4030
protected function setUp():void{
4131
$this->cleanup = [];
42-
$this->uploadedFileFactory = new UploadedFileFactory;
43-
$this->streamFactory = new StreamFactory;
4432
}
4533

4634
protected function tearDown():void{
@@ -93,8 +81,8 @@ public function testRaisesExceptionOnInvalidErrorStatus(int $status){
9381
}
9482

9583
public function testGetStreamReturnsOriginalStreamObject(){
96-
$stream = $this->streamFactory->createStream('');
97-
$upload = $this->uploadedFileFactory->createUploadedFile($stream, 0, UPLOAD_ERR_OK); // coverage
84+
$stream = Psr17\create_stream('');
85+
$upload = new UploadedFile($stream, 0, UPLOAD_ERR_OK);
9886

9987
$this->assertSame($stream, $upload->getStream());
10088
}
@@ -108,7 +96,7 @@ public function testGetStreamReturnsWrappedPhpStream(){
10896
}
10997

11098
public function testSuccessful(){
111-
$stream = $this->streamFactory->createStream('Foo bar!');
99+
$stream = Psr17\create_stream('Foo bar!');
112100
$upload = new UploadedFile($stream, $stream->getSize(), UPLOAD_ERR_OK, 'filename.txt', 'text/plain');
113101

114102
$this->assertEquals($stream->getSize(), $upload->getSize());
@@ -123,7 +111,7 @@ public function testSuccessful(){
123111
}
124112

125113
public function testMoveCannotBeCalledMoreThanOnce(){
126-
$stream = $this->streamFactory->createStream('Foo bar!');
114+
$stream = Psr17\create_stream('Foo bar!');
127115
$upload = new UploadedFile($stream, 0, UPLOAD_ERR_OK);
128116

129117
$this->cleanup[] = $to = tempnam(sys_get_temp_dir(), 'diac');
@@ -136,7 +124,7 @@ public function testMoveCannotBeCalledMoreThanOnce(){
136124
}
137125

138126
public function testCannotRetrieveStreamAfterMove(){
139-
$stream = $this->streamFactory->createStream('Foo bar!');
127+
$stream = Psr17\create_stream('Foo bar!');
140128
$upload = new UploadedFile($stream, 0, UPLOAD_ERR_OK);
141129

142130
$this->cleanup[] = $to = tempnam(sys_get_temp_dir(), 'diac');

0 commit comments

Comments
 (0)
Please sign in to comment.