1 | <?php |
||
10 | final class TaggedResponse implements ResponseInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var Tag |
||
14 | */ |
||
15 | private $tag; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $line; |
||
21 | |||
22 | /** |
||
23 | * @param Tag $tag |
||
24 | * @param string $line |
||
25 | */ |
||
26 | 29 | public function __construct(Tag $tag, string $line) |
|
31 | |||
32 | /** |
||
33 | * @return string |
||
34 | */ |
||
35 | 1 | public function __toString(): string |
|
39 | |||
40 | /** |
||
41 | * @param CompletionResult $expectedResult |
||
42 | * @return ResponseInterface |
||
43 | * @throws AssertionFailedException |
||
44 | */ |
||
45 | 14 | public function assertCompletion(CompletionResult $expectedResult): ResponseInterface |
|
46 | { |
||
47 | try { |
||
48 | 14 | $completionResult = CompletionResult::fromLine($this->line); |
|
49 | 13 | if (!$completionResult->equals($expectedResult)) { |
|
50 | 1 | throw new AssertionFailedException( |
|
51 | 1 | \sprintf( |
|
52 | 1 | 'Returned completion, but %s is not equals to expected %s', |
|
53 | 1 | (string)$completionResult, |
|
54 | 13 | (string)$expectedResult |
|
55 | ) |
||
56 | ); |
||
57 | } |
||
58 | 2 | } catch (\InvalidArgumentException $e) { |
|
59 | 1 | throw new AssertionFailedException( |
|
60 | 1 | \sprintf( |
|
61 | 1 | 'Response %s does not include a completion result', |
|
62 | 1 | $this->line |
|
63 | ) |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | 12 | return $this; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return ResponseInterface |
||
72 | * @throws AssertionFailedException |
||
73 | */ |
||
74 | 1 | public function assertContinuation(): ResponseInterface |
|
75 | { |
||
76 | 1 | throw new AssertionFailedException(); |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * @return ResponseInterface |
||
81 | */ |
||
82 | 24 | public function assertTagged(): ResponseInterface |
|
83 | { |
||
84 | 24 | return $this; |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * @param string $className |
||
89 | * @return ResponseInterface |
||
90 | * @throws AssertionFailedException |
||
91 | */ |
||
92 | public function assertParsed(string $className): ResponseInterface |
||
93 | { |
||
94 | throw new AssertionFailedException('A tagged response is never parsed'); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @return string |
||
99 | */ |
||
100 | 1 | public function getBody(): string |
|
104 | } |
||
105 |