10
10
use GuzzleHttp \Psr7 \MessageTrait ;
11
11
use GuzzleHttp \Psr7 \Uri as GuzzleUri ;
12
12
use GuzzleHttp \Psr7 \Utils ;
13
- use InvalidArgumentException ;
14
- use PHPUnit \Framework \AssertionFailedError ;
13
+ use PHPUnit \Framework \Attributes \CoversClass ;
15
14
use Psr \Http \Message \RequestInterface ;
16
- use Psr \Http \Message \UriInterface ;
15
+ use Psr \Http \Message \StreamInterface ;
17
16
use RuntimeException ;
18
- use Throwable ;
19
- use TypeError ;
20
17
21
18
/**
22
- * @covers \Artemeon\HttpClient\Http\Request
23
- *
24
19
* @internal
25
20
*/
21
+ #[CoversClass(Request::class)]
26
22
class RequestTest extends TestCase
27
23
{
28
24
use MessageTrait;
29
25
30
- protected function buildUri ($ uri )
26
+ protected function buildUri ($ uri ): GuzzleUri
31
27
{
32
28
if (class_exists (GuzzleUri::class)) {
33
29
return new GuzzleUri ($ uri );
@@ -39,15 +35,12 @@ protected function buildUri($uri)
39
35
/**
40
36
* Overwrite, parent code doesn't work witz Guzzle > 7.2, remove when paren code is fixed.
41
37
*/
42
- protected function buildStream ($ data )
38
+ protected function buildStream ($ data ): StreamInterface
43
39
{
44
40
return Utils::streamFor ($ data );
45
41
}
46
42
47
- /**
48
- * {@inheritDoc}
49
- */
50
- public function createSubject ()
43
+ public function createSubject (): Request
51
44
{
52
45
$ this ->skippedTests ['testMethodIsExtendable ' ] = '' ;
53
46
@@ -124,58 +117,18 @@ public function testMethodIsExtendable(): void
124
117
$ this ->assertEquals ('CUSTOM ' , $ request ->getMethod ());
125
118
}
126
119
127
- /**
128
- * @dataProvider getInvalidMethods
129
- */
130
- public function testMethodWithInvalidArguments ($ method ): void
131
- {
132
- if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
133
- $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
134
- }
135
-
136
- try {
137
- $ this ->request ->withMethod ($ method );
138
- $ this ->fail ('withMethod() should have raised exception on invalid argument ' );
139
- } catch (AssertionFailedError $ e ) {
140
- // invalid argument not caught
141
- throw $ e ;
142
- } catch (InvalidArgumentException | TypeError $ e ) {
143
- // valid
144
- $ this ->assertInstanceOf (Throwable::class, $ e );
145
- } catch (Throwable $ e ) {
146
- // invalid
147
- $ this ->fail (sprintf (
148
- 'Unexpected exception (%s) thrown from withMethod(); expected TypeError or InvalidArgumentException ' ,
149
- gettype ($ e ),
150
- ));
151
- }
152
- }
153
-
154
- public static function getInvalidMethods ()
155
- {
156
- return [
157
- 'null ' => [null ],
158
- 'false ' => [false ],
159
- 'array ' => [['foo ' ]],
160
- 'object ' => [new \stdClass ()],
161
- ];
162
- }
163
-
164
120
public function testUri (): void
165
121
{
166
122
if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
167
123
$ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
168
124
}
169
125
$ original = clone $ this ->request ;
170
126
171
- $ this ->assertInstanceOf (UriInterface::class, $ this ->request ->getUri ());
172
-
173
127
$ uri = $ this ->buildUri ('http://www.foo.com/bar ' );
174
128
$ request = $ this ->request ->withUri ($ uri );
175
129
$ this ->assertNotSame ($ this ->request , $ request );
176
130
$ this ->assertEquals ($ this ->request , $ original , 'Request object MUST not be mutated ' );
177
131
$ this ->assertEquals ('www.foo.com ' , $ request ->getHeaderLine ('host ' ));
178
- $ this ->assertInstanceOf (UriInterface::class, $ request ->getUri ());
179
132
$ this ->assertEquals ('http://www.foo.com/bar ' , (string ) $ request ->getUri ());
180
133
181
134
$ request = $ request ->withUri ($ this ->buildUri ('/foobar ' ));
0 commit comments