1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cerbero\OctaneTestbench\Stubs; |
4
|
|
|
|
5
|
|
|
use Cerbero\OctaneTestbench\ResponseTestCase; |
6
|
|
|
use Illuminate\Foundation\Application; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Laravel\Octane\Contracts\Client; |
9
|
|
|
use Laravel\Octane\OctaneResponse; |
10
|
|
|
use Laravel\Octane\RequestContext; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Throwable; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The client stub. |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
class ClientStub implements Client |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* The response test case. |
22
|
|
|
* |
23
|
|
|
* @var ResponseTestCase |
24
|
|
|
*/ |
25
|
|
|
public $response; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Instantiate the class. |
29
|
|
|
* |
30
|
|
|
* @param TestCase $testCase |
31
|
|
|
*/ |
32
|
13 |
|
public function __construct(protected TestCase $testCase) |
33
|
|
|
{ |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Marshal the given request context. |
38
|
|
|
* |
39
|
|
|
* @param RequestContext $context |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
13 |
|
public function marshalRequest(RequestContext $context): array |
43
|
|
|
{ |
44
|
13 |
|
return compact('context'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Record the response. |
49
|
|
|
* |
50
|
|
|
* @param RequestContext $context |
51
|
|
|
* @param OctaneResponse $response |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
11 |
|
public function respond(RequestContext $context, OctaneResponse $response): void |
55
|
|
|
{ |
56
|
11 |
|
$this->response = new ResponseTestCase($this->testCase, $response->response); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Record the error. |
61
|
|
|
* |
62
|
|
|
* @param Throwable $e |
63
|
|
|
* @param Application $app |
64
|
|
|
* @param Request $request |
65
|
|
|
* @param RequestContext $context |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
2 |
|
public function error(Throwable $e, Application $app, Request $request, RequestContext $context): void |
69
|
|
|
{ |
70
|
2 |
|
while (ob_get_level() > 1) { |
71
|
2 |
|
ob_end_clean(); |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
$this->response = new ResponseTestCase($this->testCase, $e); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|