1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Spiral Framework. |
5
|
|
|
* |
6
|
|
|
* @license MIT |
7
|
|
|
* @author Anton Titov (Wolfy-J) |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Spiral\Tests\Http; |
13
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use Spiral\Core\Container; |
16
|
|
|
use Spiral\Http\CallableHandler; |
17
|
|
|
use Spiral\Http\Config\HttpConfig; |
18
|
|
|
use Spiral\Http\Exception\PipelineException; |
19
|
|
|
use Spiral\Http\Pipeline; |
20
|
|
|
use Spiral\Tests\Http\Diactoros\ResponseFactory; |
21
|
|
|
use Laminas\Diactoros\ServerRequest; |
22
|
|
|
|
23
|
|
|
class PipelineTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
public function testTarget(): void |
26
|
|
|
{ |
27
|
|
|
$pipeline = new Pipeline(new Container()); |
28
|
|
|
|
29
|
|
|
$handler = new CallableHandler(function () { |
30
|
|
|
return 'response'; |
31
|
|
|
}, new ResponseFactory(new HttpConfig(['headers' => []]))); |
32
|
|
|
|
33
|
|
|
$response = $pipeline->withHandler($handler)->handle(new ServerRequest()); |
34
|
|
|
|
35
|
|
|
$this->assertSame(200, $response->getStatusCode()); |
36
|
|
|
$this->assertSame('OK', $response->getReasonPhrase()); |
37
|
|
|
$this->assertSame('response', (string)$response->getBody()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testHandle(): void |
41
|
|
|
{ |
42
|
|
|
$pipeline = new Pipeline(new Container()); |
43
|
|
|
|
44
|
|
|
$handler = new CallableHandler(function () { |
45
|
|
|
return 'response'; |
46
|
|
|
}, new ResponseFactory(new HttpConfig(['headers' => []]))); |
47
|
|
|
|
48
|
|
|
$response = $pipeline->process(new ServerRequest(), $handler); |
49
|
|
|
|
50
|
|
|
$this->assertSame(200, $response->getStatusCode()); |
51
|
|
|
$this->assertSame('OK', $response->getReasonPhrase()); |
52
|
|
|
$this->assertSame('response', (string)$response->getBody()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testHandleException(): void |
56
|
|
|
{ |
57
|
|
|
$this->expectException(PipelineException::class); |
58
|
|
|
|
59
|
|
|
$pipeline = new Pipeline(new Container()); |
60
|
|
|
$pipeline->handle(new ServerRequest()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|