Skip to content

Commit c59ae3c

Browse files
committed
Made all classes final, updated tests to phpunit 8 and removed some tests that were useless under the new php version
1 parent d02d72b commit c59ae3c

File tree

8 files changed

+18
-29
lines changed

8 files changed

+18
-29
lines changed

CHANGELOG.md

Whitespace-only changes.

src/CacheMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace leinonen\DataLoader;
44

5-
class CacheMap implements CacheMapInterface, \Countable
5+
final class CacheMap implements CacheMapInterface, \Countable
66
{
77
/**
88
* @var array

src/DataLoader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace leinonen\DataLoader;
44

5+
use React\Promise\ExtendedPromiseInterface;
56
use React\Promise\Promise;
67
use React\EventLoop\LoopInterface;
7-
use React\Promise\PromiseInterface;
88

9-
class DataLoader implements DataLoaderInterface
9+
final class DataLoader implements DataLoaderInterface
1010
{
1111
/**
1212
* @var callable
@@ -57,7 +57,7 @@ public function __construct(
5757
/**
5858
* {@inheritdoc}
5959
*/
60-
public function load($key): PromiseInterface
60+
public function load($key): ExtendedPromiseInterface
6161
{
6262
if ($key === null) {
6363
throw new \InvalidArgumentException(self::class . '::load must be called with a value, but got null');
@@ -91,7 +91,7 @@ function (callable $resolve, callable $reject) use ($key) {
9191
/**
9292
* {@inheritdoc}
9393
*/
94-
public function loadMany(array $keys): PromiseInterface
94+
public function loadMany(array $keys): ExtendedPromiseInterface
9595
{
9696
return \React\Promise\all(
9797
\array_map(

src/DataLoaderException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
namespace leinonen\DataLoader;
44

5-
class DataLoaderException extends \RuntimeException
5+
final class DataLoaderException extends \RuntimeException
66
{
77
}

src/DataLoaderInterface.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
namespace leinonen\DataLoader;
44

5+
use React\Promise\ExtendedPromiseInterface;
56
use React\Promise\Promise;
6-
use React\Promise\PromiseInterface;
7+
78

89
interface DataLoaderInterface
910
{
@@ -15,7 +16,7 @@ interface DataLoaderInterface
1516
* @return Promise
1617
* @throws \InvalidArgumentException
1718
*/
18-
public function load($key): PromiseInterface;
19+
public function load($key): ExtendedPromiseInterface;
1920

2021
/**
2122
* Loads multiple keys, promising an array of values.
@@ -32,7 +33,7 @@ public function load($key): PromiseInterface;
3233
* @return Promise
3334
* @throws \InvalidArgumentException
3435
*/
35-
public function loadMany(array $keys): PromiseInterface;
36+
public function loadMany(array $keys): ExtendedPromiseInterface;
3637

3738
/**
3839
* Clears the value for the given key from the cache if it exists. Returns itself for method chaining.

src/DataLoaderOptions.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace leinonen\DataLoader;
44

5-
class DataLoaderOptions
5+
final class DataLoaderOptions
66
{
77
/**
88
* @var bool
@@ -31,7 +31,7 @@ public function __construct(
3131
bool $shouldBatch = true,
3232
bool $shouldCache = true
3333
) {
34-
$this->validateOptions($maxBatchSize, $shouldBatch, $shouldCache);
34+
$this->validateMaxBatchSizeOption($maxBatchSize);
3535
$this->shouldBatch = $shouldBatch;
3636
$this->maxBatchSize = $maxBatchSize;
3737
$this->shouldCache = $shouldCache;
@@ -61,18 +61,6 @@ public function shouldCache(): bool
6161
return $this->shouldCache;
6262
}
6363

64-
/**
65-
* Validates the options.
66-
*
67-
* @param null|int $maxBatchSize
68-
* @param bool $shouldBatch
69-
* @param bool $shouldCache
70-
*/
71-
private function validateOptions($maxBatchSize, $shouldBatch, $shouldCache): void
72-
{
73-
$this->validateMaxBatchSizeOption($maxBatchSize);
74-
}
75-
7664
/**
7765
* @param null|int $maxBatchSize
7866
*/

tests/Unit/DataLoaderAbuseTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ public function setUp(): void
2424

2525
/**
2626
* @test
27-
* @expectedException \InvalidArgumentException
28-
* @expectedExceptionMessage leinonen\DataLoader\DataLoader::load must be called with a value, but got null
2927
*/
3028
public function load_method_requires_an_actual_key()
3129
{
30+
$this->expectException(\InvalidArgumentException::class);
31+
$this->expectExceptionMessage('leinonen\DataLoader\DataLoader::load must be called with a value, but got null');
32+
3233
$loader = $this->createDataLoader(function ($keys) {
3334
return \React\Promise\resolve($keys);
3435
});
@@ -46,11 +47,12 @@ public function falsey_values_are_however_permitted()
4647

4748
/**
4849
* @test
49-
* @expectedException \InvalidArgumentException
50-
* @expectedExceptionMessage leinonen\DataLoader\DataLoader::load must be called with a value, but got null
5150
*/
5251
public function load_many_requires_actual_keys()
5352
{
53+
$this->expectException(\InvalidArgumentException::class);
54+
$this->expectExceptionMessage('leinonen\DataLoader\DataLoader::load must be called with a value, but got null');
55+
5456
$loader = $this->createDataLoader(function ($keys) {
5557
return \React\Promise\resolve($keys);
5658
});

tests/Unit/DataLoaderOptionsTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public function it_can_be_initiated()
2828

2929
/**
3030
* @test
31-
* @expectedException \InvalidArgumentException
32-
* @expectedExceptionMessage Expected argument $maxBatchSize to be null or a positive integer
3331
*/
3432
public function it_should_throw_an_exception_if_maxBatchSize_is_not_a_positive_integer()
3533
{

0 commit comments

Comments
 (0)