Skip to content

Commit 126023b

Browse files
committed
chore: Clean up
1 parent 71386cf commit 126023b

File tree

7 files changed

+19
-118
lines changed

7 files changed

+19
-118
lines changed

src/Client/Options/ClientOptions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ClientOptions
2626
private bool $addReferer;
2727

2828
/** @var resource|null */
29-
private mixed $sink;
29+
private mixed $sink = null;
3030

3131
private bool $httpErrors;
3232

src/Http/Uri.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private function filterUserInfoComponent(string $component): string
262262

263263
private function rawurlencodeMatchZero(array $match): string
264264
{
265-
return rawurlencode($match[0]);
265+
return rawurlencode((string) $match[0]);
266266
}
267267

268268
/**

tests/Integration/RequestTest.php

+6-53
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,20 @@
1010
use GuzzleHttp\Psr7\MessageTrait;
1111
use GuzzleHttp\Psr7\Uri as GuzzleUri;
1212
use GuzzleHttp\Psr7\Utils;
13-
use InvalidArgumentException;
14-
use PHPUnit\Framework\AssertionFailedError;
13+
use PHPUnit\Framework\Attributes\CoversClass;
1514
use Psr\Http\Message\RequestInterface;
16-
use Psr\Http\Message\UriInterface;
15+
use Psr\Http\Message\StreamInterface;
1716
use RuntimeException;
18-
use Throwable;
19-
use TypeError;
2017

2118
/**
22-
* @covers \Artemeon\HttpClient\Http\Request
23-
*
2419
* @internal
2520
*/
21+
#[CoversClass(Request::class)]
2622
class RequestTest extends TestCase
2723
{
2824
use MessageTrait;
2925

30-
protected function buildUri($uri)
26+
protected function buildUri($uri): GuzzleUri
3127
{
3228
if (class_exists(GuzzleUri::class)) {
3329
return new GuzzleUri($uri);
@@ -39,15 +35,12 @@ protected function buildUri($uri)
3935
/**
4036
* Overwrite, parent code doesn't work witz Guzzle > 7.2, remove when paren code is fixed.
4137
*/
42-
protected function buildStream($data)
38+
protected function buildStream($data): StreamInterface
4339
{
4440
return Utils::streamFor($data);
4541
}
4642

47-
/**
48-
* {@inheritDoc}
49-
*/
50-
public function createSubject()
43+
public function createSubject(): Request
5144
{
5245
$this->skippedTests['testMethodIsExtendable'] = '';
5346

@@ -124,58 +117,18 @@ public function testMethodIsExtendable(): void
124117
$this->assertEquals('CUSTOM', $request->getMethod());
125118
}
126119

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-
164120
public function testUri(): void
165121
{
166122
if (isset($this->skippedTests[__FUNCTION__])) {
167123
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
168124
}
169125
$original = clone $this->request;
170126

171-
$this->assertInstanceOf(UriInterface::class, $this->request->getUri());
172-
173127
$uri = $this->buildUri('http://www.foo.com/bar');
174128
$request = $this->request->withUri($uri);
175129
$this->assertNotSame($this->request, $request);
176130
$this->assertEquals($this->request, $original, 'Request object MUST not be mutated');
177131
$this->assertEquals('www.foo.com', $request->getHeaderLine('host'));
178-
$this->assertInstanceOf(UriInterface::class, $request->getUri());
179132
$this->assertEquals('http://www.foo.com/bar', (string) $request->getUri());
180133

181134
$request = $request->withUri($this->buildUri('/foobar'));

tests/Integration/ResponseTest.php

+2-45
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@
77
use Artemeon\HttpClient\Http\Response;
88
use Artemeon\HttpClient\Tests\TestCase;
99
use GuzzleHttp\Psr7\Utils;
10-
use InvalidArgumentException;
11-
use PHPUnit\Framework\AssertionFailedError;
12-
use Throwable;
13-
use TypeError;
1410

1511
/**
16-
* @covers \Artemeon\HttpClient\Http\Response
17-
*
1812
* @internal
1913
*/
14+
#[\PHPUnit\Framework\Attributes\CoversClass(Response::class)]
2015
class ResponseTest extends TestCase
2116
{
2217
private Response $response;
@@ -32,7 +27,7 @@ protected function buildStream($data)
3227
/**
3328
* {@inheritDoc}
3429
*/
35-
public function createSubject()
30+
public function createSubject(): Response
3631
{
3732
return new Response(200, '1.1');
3833
}
@@ -60,44 +55,6 @@ public function testStatusCode(): void
6055
$this->assertSame(204, $response->getStatusCode());
6156
}
6257

63-
/**
64-
* @dataProvider getInvalidStatusCodeArguments
65-
*/
66-
public function testStatusCodeInvalidArgument($statusCode): void
67-
{
68-
if (isset($this->skippedTests[__FUNCTION__])) {
69-
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
70-
}
71-
72-
try {
73-
$this->response->withStatus($statusCode);
74-
$this->fail('withStatus() should have raised exception on invalid argument');
75-
} catch (AssertionFailedError $e) {
76-
// invalid argument not caught
77-
throw $e;
78-
} catch (InvalidArgumentException | TypeError $e) {
79-
// valid
80-
$this->assertInstanceOf(Throwable::class, $e);
81-
} catch (Throwable $e) {
82-
// invalid
83-
$this->fail(sprintf(
84-
'Unexpected exception (%s) thrown from withStatus(); expected TypeError or InvalidArgumentException',
85-
gettype($e),
86-
));
87-
}
88-
}
89-
90-
public static function getInvalidStatusCodeArguments()
91-
{
92-
return [
93-
'true' => [true],
94-
'string' => ['foobar'],
95-
'too-low' => [99],
96-
'too-high' => [600],
97-
'object' => [new \stdClass()],
98-
];
99-
}
100-
10158
public function testReasonPhrase(): void
10259
{
10360
if (isset($this->skippedTests[__FUNCTION__])) {

tests/Integration/UriTest.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
use Psr\Http\Message\UriInterface;
1010

1111
/**
12-
* @covers \Artemeon\HttpClient\Http\Uri
13-
*
1412
* @internal
1513
*/
14+
#[\PHPUnit\Framework\Attributes\CoversClass(Uri::class)]
1615
class UriTest extends TestCase
1716
{
1817
/**
1918
* {@inheritDoc}
2019
*/
21-
public function createUri($uri)
20+
public function createUri(string $uri)
2221
{
2322
return Uri::fromString($uri);
2423
}
@@ -55,10 +54,9 @@ public function testGetPathNormalizesMultipleLeadingSlashesToSingleSlashToPreven
5554
* leading slashes in the path is presented verbatim (in contrast to what is
5655
* provided when calling getPath()).
5756
*
58-
* @depends testGetPathNormalizesMultipleLeadingSlashesToSingleSlashToPreventXSS
59-
*
6057
* @psalm-param array{expected: non-empty-string, uri: UriInterface} $test
6158
*/
59+
#[\PHPUnit\Framework\Attributes\Depends('testGetPathNormalizesMultipleLeadingSlashesToSingleSlashToPreventXSS')]
6260
public function testStringRepresentationWithMultipleSlashes(array $test): void
6361
{
6462
$this->assertSame($test['expected'], (string) $test['uri']);

tests/Unit/Client/ArtemeonHttpClientTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use Mockery;
4242
use Mockery\MockInterface;
4343
use Override;
44+
use PHPUnit\Framework\Attributes\DataProvider;
4445
use PHPUnit\Framework\TestCase;
4546

4647
/**
@@ -114,9 +115,7 @@ public function testSendConvertsGuzzleResponseToValidResponse(): void
114115
self::assertSame($expectedHeaders, $response->getHeaders());
115116
}
116117

117-
/**
118-
* @dataProvider provideExceptionMappings
119-
*/
118+
#[DataProvider('provideExceptionMappings')]
120119
public function testSendGuzzleThrowsExceptionMappedToHttpClientException(
121120
\RuntimeException $guzzleException,
122121
string $httpClientException,

tests/Unit/Stream/StreamTest.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use org\bovigo\vfs\vfsStream;
2020
use org\bovigo\vfs\vfsStreamDirectory;
2121
use Override;
22+
use PHPUnit\Framework\Attributes\DataProvider;
2223
use PHPUnit\Framework\TestCase;
2324

2425
/**
@@ -195,9 +196,7 @@ public function testCloseIsDetachedShouldNotCallClose(): void
195196
$fcloseMock = Mockery::mock('overload:fclose');
196197
$fcloseMock->shouldReceive('__invoke')
197198
->with(Mockery::type('resource'))
198-
->andReturnUsing(function ($resource) {
199-
return fclose($resource);
200-
});
199+
->andReturnUsing(static fn ($resource) => fclose($resource));
201200

202201
$this->stream = Stream::fromString('content');
203202
$this->stream->detach();
@@ -390,9 +389,7 @@ public function testIsWritableIsDetachedReturnsFalse(): void
390389
self::assertFalse($this->stream->isWritable());
391390
}
392391

393-
/**
394-
* @dataProvider provideIsModeWriteable
395-
*/
392+
#[DataProvider('provideIsModeWriteable')]
396393
public function testIsWritableReturnsExpectedValue(string $mode, bool $isWritable, string $file): void
397394
{
398395
$file = $this->filesystem->url() . '/' . $file;
@@ -409,10 +406,7 @@ public function testIsReadableIsDetachedReturnsFalse(): void
409406
self::assertFalse($this->stream->isReadable());
410407
}
411408

412-
/**
413-
* @dataProvider provideIsReadable
414-
*/
415-
409+
#[DataProvider('provideIsReadable')]
416410
public function testIsReadableReturnsExpectedValue(string $mode, bool $isReadable, string $file): void
417411
{
418412
$file = $this->filesystem->url() . '/' . $file;

0 commit comments

Comments
 (0)