|
4 | 4 |
|
5 | 5 | use GuzzleHttp\ClientInterface; |
6 | 6 | use GuzzleHttp\Exception\ClientException; |
| 7 | +use GuzzleHttp\Psr7\NoSeekStream; |
| 8 | +use GuzzleHttp\Psr7\PumpStream; |
7 | 9 | use GuzzleHttp\Psr7\Request; |
8 | 10 | use GuzzleHttp\Psr7\Response; |
9 | 11 | use GuzzleHttp\Psr7\Utils; |
@@ -75,6 +77,85 @@ public function verbosityProvider(): array |
75 | 77 | ]; |
76 | 78 | } |
77 | 79 |
|
| 80 | + public function test_it_outputs_body_for_json() |
| 81 | + { |
| 82 | + $value = 'foobar'; |
| 83 | + |
| 84 | + $request = new Request( |
| 85 | + 'POST', |
| 86 | + '/servers', |
| 87 | + ['Content-Type' => 'application/json'], |
| 88 | + json_encode(['foo' => $value]) |
| 89 | + ); |
| 90 | + |
| 91 | + $str = $this->builder->str($request, 2); |
| 92 | + $this->assertStringContainsString($value, $str); |
| 93 | + } |
| 94 | + |
| 95 | + public function test_it_skips_body_for_low_verbosity() |
| 96 | + { |
| 97 | + $value = 'foobar'; |
| 98 | + |
| 99 | + $request = new Request( |
| 100 | + 'POST', |
| 101 | + '/servers', |
| 102 | + ['Content-Type' => 'application/json'], |
| 103 | + json_encode(['foo' => $value]) |
| 104 | + ); |
| 105 | + |
| 106 | + $str = $this->builder->str($request, 1); |
| 107 | + $this->assertStringNotContainsString($value, $str); |
| 108 | + } |
| 109 | + |
| 110 | + public function test_it_cuts_big_body_for_json() |
| 111 | + { |
| 112 | + $value = str_repeat('A', Builder::MAX_BODY_LENGTH); |
| 113 | + |
| 114 | + $request = new Request( |
| 115 | + 'POST', |
| 116 | + '/servers', |
| 117 | + ['Content-Type' => 'application/json'], |
| 118 | + json_encode(['foo' => $value]) |
| 119 | + ); |
| 120 | + |
| 121 | + $str = $this->builder->str($request, 2); |
| 122 | + $this->assertStringNotContainsString($value, $str); |
| 123 | + $this->assertStringContainsString('AAAAAA...', $str); |
| 124 | + } |
| 125 | + |
| 126 | + public function test_it_did_not_read_full_body_for_json() |
| 127 | + { |
| 128 | + $value = str_repeat('A', Builder::MAX_BODY_LENGTH + 1); |
| 129 | + |
| 130 | + $request = new Request( |
| 131 | + 'POST', |
| 132 | + '/servers', |
| 133 | + ['Content-Type' => 'application/json'], |
| 134 | + new PumpStream(function ($size) { |
| 135 | + return str_repeat('A', $size); |
| 136 | + }) |
| 137 | + ); |
| 138 | + |
| 139 | + $str = $this->builder->str($request, 2); |
| 140 | + $this->assertStringNotContainsString($value, $str); |
| 141 | + $this->assertStringContainsString('AAAAAA...', $str); |
| 142 | + } |
| 143 | + |
| 144 | + public function test_it_skips_body_for_binary() |
| 145 | + { |
| 146 | + $value = 'foobar'; |
| 147 | + |
| 148 | + $request = new Request( |
| 149 | + 'POST', |
| 150 | + '/servers', |
| 151 | + ['Content-Type' => 'binary/octet-stream'], |
| 152 | + $value |
| 153 | + ); |
| 154 | + |
| 155 | + $str = $this->builder->str($request, 2); |
| 156 | + $this->assertStringNotContainsString($value, $str); |
| 157 | + } |
| 158 | + |
78 | 159 | public function test_it_builds_user_input_errors() |
79 | 160 | { |
80 | 161 | $expected = 'A well-formed string'; |
|
0 commit comments