Skip to content

Commit a55a9e3

Browse files
committed
Refactored test so coverage of constructor is evaluated
1 parent 8937739 commit a55a9e3

File tree

1 file changed

+47
-46
lines changed

1 file changed

+47
-46
lines changed

src/batch/tests/Job/Item/Reader/IndexWithReaderTest.php

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,60 @@
55
namespace Yokai\Batch\Tests\Job\Item\Reader;
66

77
use ArrayIterator;
8-
use Generator;
98
use PHPUnit\Framework\TestCase;
109
use Yokai\Batch\Job\Item\Reader\IndexWithReader;
1110
use Yokai\Batch\Job\Item\Reader\StaticIterableReader;
1211
use Yokai\Batch\JobExecution;
1312

1413
class IndexWithReaderTest extends TestCase
1514
{
16-
/**
17-
* @dataProvider provider
18-
*/
19-
public function test(IndexWithReader $reader, array $expected): void
15+
public function testArrayKey(): void
16+
{
17+
$john = ['name' => 'John', 'location' => 'Washington'];
18+
$marie = ['name' => 'Marie', 'location' => 'London'];
19+
$reader = IndexWithReader::withArrayKey(
20+
new StaticIterableReader([$john, $marie]),
21+
'name'
22+
);
23+
24+
$this->doTest($reader, ['John' => $john, 'Marie' => $marie]);
25+
}
26+
27+
public function testObjectProperty(): void
28+
{
29+
$john = (object)['name' => 'John', 'location' => 'Washington'];
30+
$marie = (object)['name' => 'Marie', 'location' => 'London'];
31+
$reader = IndexWithReader::withProperty(
32+
new StaticIterableReader([$john, $marie]),
33+
'name'
34+
);
35+
36+
$this->doTest($reader, ['John' => $john, 'Marie' => $marie]);
37+
}
38+
39+
public function testObjectGetter(): void
40+
{
41+
$three = new ArrayIterator([1, 2, 3]);
42+
$six = new ArrayIterator([1, 2, 3, 4, 5, 6]);
43+
$reader = IndexWithReader::withGetter(
44+
new StaticIterableReader([$three, $six]),
45+
'count'
46+
);
47+
48+
$this->doTest($reader, [3 => $three, 6 => $six]);
49+
}
50+
51+
public function testArbitraryClosure(): void
52+
{
53+
$reader = new IndexWithReader(
54+
new StaticIterableReader([1, 2, 3]),
55+
fn(int $value) => $value * $value
56+
);
57+
58+
$this->doTest($reader, [1 => 1, 4 => 2, 9 => 3]);
59+
}
60+
61+
private function doTest(IndexWithReader $reader, array $expected): void
2062
{
2163
$reader->setJobExecution(JobExecution::createRoot('123456', 'testing'));
2264
$reader->initialize();
@@ -30,45 +72,4 @@ public function test(IndexWithReader $reader, array $expected): void
3072

3173
self::assertSame($expected, $actual);
3274
}
33-
34-
public function provider(): Generator
35-
{
36-
$john = ['name' => 'John', 'location' => 'Washington'];
37-
$marie = ['name' => 'Marie', 'location' => 'London'];
38-
yield 'Index with array key' => [
39-
IndexWithReader::withArrayKey(
40-
new StaticIterableReader([$john, $marie]),
41-
'name'
42-
),
43-
['John' => $john, 'Marie' => $marie],
44-
];
45-
46-
$john = (object)$john;
47-
$marie = (object)$marie;
48-
yield 'Index with object property' => [
49-
IndexWithReader::withProperty(
50-
new StaticIterableReader([$john, $marie]),
51-
'name'
52-
),
53-
['John' => $john, 'Marie' => $marie],
54-
];
55-
56-
$three = new ArrayIterator([1, 2, 3]);
57-
$six = new ArrayIterator([1, 2, 3, 4, 5, 6]);
58-
yield 'Index with object method' => [
59-
IndexWithReader::withGetter(
60-
new StaticIterableReader([$three, $six]),
61-
'count'
62-
),
63-
[3 => $three, 6 => $six],
64-
];
65-
66-
yield 'Index with arbitrary closure' => [
67-
new IndexWithReader(
68-
new StaticIterableReader([1, 2, 3]),
69-
fn(int $value) => $value * $value
70-
),
71-
[1 => 1, 4 => 2, 9 => 3],
72-
];
73-
}
7475
}

0 commit comments

Comments
 (0)