Skip to content

Commit edf65fd

Browse files
committed
Update test suite
1 parent fb8ac56 commit edf65fd

10 files changed

+357
-315
lines changed

tests/CacheTest.php

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespace Pdp\Tests;
1717

1818
use DateInterval;
19+
use Generator;
1920
use Iterator;
2021
use org\bovigo\vfs\vfsStream;
2122
use Pdp\Cache;
@@ -34,46 +35,53 @@
3435
*/
3536
class CacheTest extends TestCase
3637
{
38+
/**
39+
* @var Cache
40+
*/
3741
protected $cache;
3842

43+
/**
44+
* @var \org\bovigo\vfs\vfsStreamDirectory
45+
*/
3946
protected $root;
4047

48+
/**
49+
* @var string
50+
*/
4151
protected $cacheDir;
4252

43-
public function setUp()
53+
public function setUp(): void
4454
{
4555
$this->root = vfsStream::setup('pdp');
4656
vfsStream::create(['cache' => []], $this->root);
4757
$this->cacheDir = vfsStream::url('pdp/cache');
4858
$this->cache = new Cache($this->cacheDir);
4959
}
5060

51-
public function tearDown()
61+
public function tearDown(): void
5262
{
53-
$this->cache = null;
54-
$this->cacheDir = null;
55-
$this->root = null;
63+
unset($this->cache, $this->cacheDir, $this->root);
5664
}
5765

58-
public function testConstructorOnEmptyCachePath()
66+
public function testConstructorOnEmptyCachePath(): void
5967
{
6068
$cache = new Cache('');
6169
self::assertNull($cache->get('invalid_key'));
6270
}
6371

64-
public function testConstructorOnParentCachePathIsNotExisted()
72+
public function testConstructorOnParentCachePathIsNotExisted(): void
6573
{
6674
$cache = new Cache(vfsStream::url('pdp/cache_not_exist'));
6775
self::assertNull($cache->get('invalid_key'));
6876
}
6977

70-
public function testSetOnNotWritableCachePath()
78+
public function testSetOnNotWritableCachePath(): void
7179
{
7280
self::expectException(\InvalidArgumentException::class);
7381
$cache = new Cache('/bin');
7482
}
7583

76-
public function testSetOnNotExistingCachePath()
84+
public function testSetOnNotExistingCachePath(): void
7785
{
7886
self::expectException(\InvalidArgumentException::class);
7987
$cache = new Cache('/foo/bar');
@@ -84,13 +92,13 @@ public function testSetOnNotExistingCachePath()
8492
*
8593
* @param mixed $expected
8694
*/
87-
public function testSetGet($expected)
95+
public function testSetGet($expected): void
8896
{
8997
$this->cache->set('foo', $expected);
9098
self::assertEquals($expected, $this->cache->get('foo'));
9199
}
92100

93-
public function storableValuesProvider()
101+
public function storableValuesProvider(): iterable
94102
{
95103
return [
96104
'string' => ['bar'],
@@ -105,27 +113,27 @@ public function storableValuesProvider()
105113
/**
106114
* @depends testSetGet
107115
*/
108-
public function testDelete()
116+
public function testDelete(): void
109117
{
110118
$this->cache->set('foo', 'bar');
111119
self::assertEquals('bar', $this->cache->get('foo'));
112120
$this->cache->delete('foo');
113121
self::assertNull($this->cache->get('foo'));
114122
}
115123

116-
public function testGetInvalidArg()
124+
public function testGetInvalidArg(): void
117125
{
118126
self::expectException(InvalidArgumentException::class);
119127
$this->cache->get(null);
120128
}
121129

122-
public function testInvalidKey()
130+
public function testInvalidKey(): void
123131
{
124132
self::expectException(InvalidArgumentException::class);
125133
$this->cache->get('foo:bar', 'bar');
126134
}
127135

128-
public function testSetInvalidTTL()
136+
public function testSetInvalidTTL(): void
129137
{
130138
self::expectException(InvalidArgumentException::class);
131139
$this->cache->set('foo', 'bar', date_create());
@@ -134,15 +142,15 @@ public function testSetInvalidTTL()
134142
/**
135143
* @depends testDelete
136144
*/
137-
public function testGetNotFound()
145+
public function testGetNotFound(): void
138146
{
139147
self::assertNull($this->cache->get('notfound'));
140148
}
141149

142150
/**
143151
* @depends testDelete
144152
*/
145-
public function testGetNotFoundDefault()
153+
public function testGetNotFoundDefault(): void
146154
{
147155
$expected = 'chickpeas';
148156
self::assertEquals($expected, $this->cache->get('notfound', $expected));
@@ -152,7 +160,7 @@ public function testGetNotFoundDefault()
152160
* @depends testSetGet
153161
* @slow
154162
*/
155-
public function testSetExpire()
163+
public function testSetExpire(): void
156164
{
157165
$this->cache->set('foo', 'bar', 1);
158166
self::assertEquals('bar', $this->cache->get('foo'));
@@ -166,7 +174,7 @@ public function testSetExpire()
166174
* @depends testSetGet
167175
* @slow
168176
*/
169-
public function testSetExpireDateInterval()
177+
public function testSetExpireDateInterval(): void
170178
{
171179
$this->cache->set('foo', 'bar', new DateInterval('PT1S'));
172180
self::assertEquals('bar', $this->cache->get('foo'));
@@ -176,13 +184,13 @@ public function testSetExpireDateInterval()
176184
self::assertNull($this->cache->get('foo'));
177185
}
178186

179-
public function testSetInvalidArg()
187+
public function testSetInvalidArg(): void
180188
{
181189
self::expectException(InvalidArgumentException::class);
182190
$this->cache->set(null, 'bar');
183191
}
184192

185-
public function testDeleteInvalidArg()
193+
public function testDeleteInvalidArg(): void
186194
{
187195
self::expectException(InvalidArgumentException::class);
188196
$this->cache->delete(null);
@@ -191,7 +199,7 @@ public function testDeleteInvalidArg()
191199
/**
192200
* @depends testSetGet
193201
*/
194-
public function testClearCache()
202+
public function testClearCache(): void
195203
{
196204
$this->cache->set('foo', 'bar');
197205
$this->cache->clear();
@@ -201,7 +209,7 @@ public function testClearCache()
201209
/**
202210
* @depends testSetGet
203211
*/
204-
public function testHas()
212+
public function testHas(): void
205213
{
206214
$this->cache->set('foo', 'bar');
207215
self::assertTrue($this->cache->has('foo'));
@@ -210,12 +218,12 @@ public function testHas()
210218
/**
211219
* @depends testHas
212220
*/
213-
public function testHasNot()
221+
public function testHasNot(): void
214222
{
215223
self::assertFalse($this->cache->has('not-found'));
216224
}
217225

218-
public function testHasInvalidArg()
226+
public function testHasInvalidArg(): void
219227
{
220228
self::expectException(InvalidArgumentException::class);
221229
$this->cache->has(null);
@@ -224,7 +232,7 @@ public function testHasInvalidArg()
224232
/**
225233
* @depends testSetGet
226234
*/
227-
public function testSetGetMultiple()
235+
public function testSetGetMultiple(): void
228236
{
229237
$values = [
230238
'key1' => 'value1',
@@ -247,15 +255,15 @@ public function testSetGetMultiple()
247255
/**
248256
* @depends testSetGet
249257
*/
250-
public function testSetGetMultipleGenerator()
258+
public function testSetGetMultipleGenerator(): void
251259
{
252260
$values = [
253261
'key1' => 'value1',
254262
'key2' => 'value2',
255263
'key3' => 'value3',
256264
];
257265

258-
$gen = function () use ($values) {
266+
$gen = function () use ($values): Generator {
259267
foreach ($values as $key => $value) {
260268
yield $key => $value;
261269
}
@@ -277,15 +285,15 @@ public function testSetGetMultipleGenerator()
277285
/**
278286
* @depends testSetGet
279287
*/
280-
public function testSetGetMultipleGenerator2()
288+
public function testSetGetMultipleGenerator2(): void
281289
{
282290
$values = [
283291
'key1' => 'value1',
284292
'key2' => 'value2',
285293
'key3' => 'value3',
286294
];
287295

288-
$gen = function () use ($values) {
296+
$gen = function () use ($values): Generator {
289297
foreach ($values as $key => $value) {
290298
yield $key;
291299
}
@@ -308,7 +316,7 @@ public function testSetGetMultipleGenerator2()
308316
* @depends testSetExpire
309317
* @slow
310318
*/
311-
public function testSetMultipleExpireDateIntervalNotExpired()
319+
public function testSetMultipleExpireDateIntervalNotExpired(): void
312320
{
313321
$values = [
314322
'key1' => 'value1',
@@ -333,7 +341,7 @@ public function testSetMultipleExpireDateIntervalNotExpired()
333341
/**
334342
* @slow
335343
*/
336-
public function testSetMultipleExpireDateIntervalExpired()
344+
public function testSetMultipleExpireDateIntervalExpired(): void
337345
{
338346
$values = [
339347
'key1' => 'value1',
@@ -370,7 +378,7 @@ public function testSetMultipleExpireDateIntervalExpired()
370378
/**
371379
* @slow
372380
*/
373-
public function testSetMultipleExpireDateIntervalInt()
381+
public function testSetMultipleExpireDateIntervalInt(): void
374382
{
375383
$values = [
376384
'key1' => 'value1',
@@ -404,13 +412,13 @@ public function testSetMultipleExpireDateIntervalInt()
404412
self::assertEquals([], $expected);
405413
}
406414

407-
public function testSetMultipleInvalidArg()
415+
public function testSetMultipleInvalidArg(): void
408416
{
409417
self::expectException(InvalidArgumentException::class);
410418
$this->cache->setMultiple(null);
411419
}
412420

413-
public function testGetMultipleInvalidArg()
421+
public function testGetMultipleInvalidArg(): void
414422
{
415423
self::expectException(InvalidArgumentException::class);
416424
$result = $this->cache->getMultiple(null);
@@ -426,7 +434,7 @@ public function testGetMultipleInvalidArg()
426434
/**
427435
* @depends testSetGetMultiple
428436
*/
429-
public function testDeleteMultipleDefaultGet()
437+
public function testDeleteMultipleDefaultGet(): void
430438
{
431439
$values = [
432440
'key1' => 'value1',
@@ -459,7 +467,7 @@ public function testDeleteMultipleDefaultGet()
459467
/**
460468
* @depends testSetGetMultiple
461469
*/
462-
public function testDeleteMultipleGenerator()
470+
public function testDeleteMultipleGenerator(): void
463471
{
464472
$values = [
465473
'key1' => 'value1',
@@ -469,7 +477,7 @@ public function testDeleteMultipleGenerator()
469477

470478
$this->cache->setMultiple($values);
471479

472-
$gen = function () {
480+
$gen = function (): Generator {
473481
yield 'key1';
474482
yield 'key3';
475483
};
@@ -494,7 +502,7 @@ public function testDeleteMultipleGenerator()
494502
self::assertEquals([], $expected);
495503
}
496504

497-
public function testDeleteMultipleInvalidArg()
505+
public function testDeleteMultipleInvalidArg(): void
498506
{
499507
self::expectException(InvalidArgumentException::class);
500508
$this->cache->deleteMultiple(null);

tests/ConverterTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,30 @@
2424
*/
2525
class ConverterTest extends TestCase
2626
{
27-
public function testConverter()
27+
public function testConverter(): void
2828
{
29+
/** @var string $string */
2930
$string = file_get_contents(__DIR__.'/data/public_suffix_list.dat');
3031
$retval = (new Converter())->convert($string);
3132
self::assertNotEmpty($retval[Converter::ICANN_DOMAINS]);
3233
self::assertNotEmpty($retval[Converter::PRIVATE_DOMAINS]);
3334
}
3435

35-
public function testConvertThrowsExceptionWithInvalidContent()
36+
public function testConvertThrowsExceptionWithInvalidContent(): void
3637
{
3738
self::expectException(CouldNotLoadRules::class);
39+
/** @var string $content */
3840
$content = file_get_contents(__DIR__.'/data/invalid_suffix_list_content.dat');
3941
(new Converter())->convert($content);
4042
}
4143

42-
public function testConvertWithEmptyString()
44+
public function testConvertWithEmptyString(): void
4345
{
4446
$retval = (new Converter())->convert('');
4547
self::assertEquals([Converter::ICANN_DOMAINS => [], Converter::PRIVATE_DOMAINS => []], $retval);
4648
}
4749

48-
public function testConvertWithInvalidString()
50+
public function testConvertWithInvalidString(): void
4951
{
5052
$retval = (new Converter())->convert('foobar');
5153
self::assertEquals([Converter::ICANN_DOMAINS => [], Converter::PRIVATE_DOMAINS => []], $retval);

tests/CurlHttpClientTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ class CurlHttpClientTest extends TestCase
2929
* @covers ::__construct
3030
* @covers ::getContent
3131
*/
32-
public function testGetContent()
32+
public function testGetContent(): void
3333
{
3434
$content = (new CurlHttpClient())->getContent('https://www.google.com');
35-
self::assertNotNull($content);
36-
self::assertContains('google', $content);
35+
36+
self::assertStringContainsString('google', $content);
3737
}
3838

3939
/**
4040
* @covers ::__construct
4141
* @covers ::getContent
4242
*/
43-
public function testThrowsException()
43+
public function testThrowsException(): void
4444
{
4545
self::expectException(HttpClientException::class);
4646
(new CurlHttpClient())->getContent('https://qsfsdfqdf.dfsf');
@@ -49,7 +49,7 @@ public function testThrowsException()
4949
/**
5050
* @covers ::__construct
5151
*/
52-
public function testConstructorThrowsException()
52+
public function testConstructorThrowsException(): void
5353
{
5454
self::expectException(Exception::class);
5555
new CurlHttpClient(['foo' => 'bar']);

0 commit comments

Comments
 (0)