Skip to content

Commit 868fa10

Browse files
committed
Add tests to cover changes
1 parent 789e7a7 commit 868fa10

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

src/batch-doctrine-dbal/src/DoctrineDBALInsertWriter.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ public function __construct(ConnectionRegistry $doctrine, string $table, string
3333
*/
3434
public function write(iterable $items): void
3535
{
36-
if (!\is_iterable($items)) {
37-
throw UnexpectedValueException::type('iterable', $items);
38-
}
39-
4036
foreach ($items as $item) {
4137
if (!\is_array($item)) {
4238
throw UnexpectedValueException::type('array', $item);

src/batch-doctrine-dbal/tests/DoctrineDBALInsertWriterTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
namespace Yokai\Batch\Tests\Bridge\Doctrine\DBAL;
66

77
use Doctrine\DBAL\Types\Types;
8+
use Generator;
89
use Yokai\Batch\Bridge\Doctrine\DBAL\DoctrineDBALInsertWriter;
10+
use Yokai\Batch\Exception\UnexpectedValueException;
911

1012
class DoctrineDBALInsertWriterTest extends DoctrineDBALTestCase
1113
{
@@ -36,4 +38,11 @@ public function test(): void
3638
['firstName' => 'Jack', 'lastName' => 'Doe'],
3739
], $this->findAll('persons'));
3840
}
41+
42+
public function testItemNotAnArray(): void
43+
{
44+
$this->expectException(UnexpectedValueException::class);
45+
$writer = new DoctrineDBALInsertWriter($this->doctrine, 'persons');
46+
$writer->write(['string']);
47+
}
3948
}

src/batch-symfony-console/tests/RunJobCommandTest.php

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

55
namespace Yokai\Batch\Tests\Bridge\Symfony\Console;
66

7+
use JsonException;
78
use PHPUnit\Framework\TestCase;
89
use Prophecy\Argument;
910
use Prophecy\PhpUnit\ProphecyTrait;
1011
use Prophecy\Prophecy\ObjectProphecy;
11-
use Symfony\Component\Console\Exception\InvalidArgumentException;
1212
use Symfony\Component\Console\Output\OutputInterface;
1313
use Symfony\Component\Console\Tester\CommandTester;
1414
use Yokai\Batch\BatchStatus;
1515
use Yokai\Batch\Bridge\Symfony\Console\RunJobCommand;
16+
use Yokai\Batch\Exception\UnexpectedValueException;
1617
use Yokai\Batch\Failure;
1718
use Yokai\Batch\JobExecution;
1819
use Yokai\Batch\Launcher\JobLauncherInterface;
@@ -50,12 +51,20 @@ private function execute(string $configuration = null, int $verbosity = OutputIn
5051

5152
public function testRunWithMalformedConfiguration(): void
5253
{
53-
$this->expectException(InvalidArgumentException::class);
54+
$this->expectException(JsonException::class);
5455

5556
$this->jobLauncher->launch(Argument::cetera())->shouldNotBeCalled();
5657
$this->execute('{]');
5758
}
5859

60+
public function testRunWithInvalidConfiguration(): void
61+
{
62+
$this->expectException(UnexpectedValueException::class);
63+
64+
$this->jobLauncher->launch(Argument::cetera())->shouldNotBeCalled();
65+
$this->execute('"string"');
66+
}
67+
5968
/**
6069
* @dataProvider verbosity
6170
*/

src/batch/tests/SummaryTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Yokai\Batch\Tests;
66

77
use PHPUnit\Framework\TestCase;
8+
use Yokai\Batch\Exception\UnexpectedValueException;
89
use Yokai\Batch\Summary;
910

1011
class SummaryTest extends TestCase
@@ -97,4 +98,26 @@ public function testCount(): void
9798

9899
self::assertCount(0, $summary);
99100
}
101+
102+
public function testAppend(): void
103+
{
104+
$summary = new Summary(['empty' => [], 'init' => [1, 2]]);
105+
$summary->append('empty', 1);
106+
$summary->append('empty', 2);
107+
$summary->append('empty', 3);
108+
$summary->append('init', 3);
109+
$summary->append('undefined', 1);
110+
$summary->append('undefined', 2);
111+
$summary->append('undefined', 3);
112+
self::assertSame([1, 2, 3], $summary->get('empty'));
113+
self::assertSame([1, 2, 3], $summary->get('init'));
114+
self::assertSame([1, 2, 3], $summary->get('undefined'));
115+
}
116+
117+
public function testAppendNotAnArray(): void
118+
{
119+
$this->expectException(UnexpectedValueException::class);
120+
$summary = new Summary(['init' => 'string']);
121+
$summary->append('init', 3);
122+
}
100123
}

0 commit comments

Comments
 (0)