Skip to content

Commit 68d2f52

Browse files
authored
Raise code coverage to 100% (#39)
* Implemented an in memory job execution storage * Covered event dispatching & not executable job executions * Added tests to cover events * Added tests that covers configurable elements helper traits * Added tests for AbstractJob * Add more tests to cover items expand * Add more test to cover edge cases on job execution serialization * Add more tests to cover edge cases of filesystem job execution storage * Add tests to cover NullJobExecutionStorage * Add tests to cover QueryBuilder & Query * Removed unused exception parts * Add more tests to cover DoctrineDBALJobExecutionStorage * Add way more test to cover JobExecutionRowNormalizer via DoctrineDBALJobExecutionStorage * Cover all edge cases of symfony/console bridge * Cover all edge cases of symfony/framework-bundle bridge * Cover all edge cases of symfony/validator bridge * Fixed compatibility of symfony/validator bridge tests with Symfony 4.x * Create readonly filesystem storage dir at runtime * Fixed static analysis & checkstyle issues
1 parent 484b3f3 commit 68d2f52

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

src/DependencyInjection/YokaiBatchExtension.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,8 @@ public function load(array $configs, ContainerBuilder $container): void
6060

6161
private function installed(string $package): bool
6262
{
63-
if (InstalledVersions::isInstalled('yokai/batch-src')) {
64-
return true;
65-
}
66-
67-
return InstalledVersions::isInstalled('yokai/batch-' . $package);
63+
return InstalledVersions::isInstalled('yokai/batch-src')
64+
|| InstalledVersions::isInstalled('yokai/batch-' . $package);
6865
}
6966

7067
private function getLoader(ContainerBuilder $container): ConfigLoader\LoaderInterface
@@ -126,17 +123,18 @@ private function configureStorage(ContainerBuilder $container, array $config): v
126123
);
127124
}
128125

129-
$interfaces = [
130-
JobExecutionStorageInterface::class => true,
131-
ListableJobExecutionStorageInterface::class => false,
132-
QueryableJobExecutionStorageInterface::class => false,
133-
];
134126
$defaultStorageClass = $defaultStorageDefinition->getClass();
135127
if ($defaultStorageClass === null) {
136128
throw new LogicException(
137129
\sprintf('Job execution storage service "%s", has no class.', $defaultStorage)
138130
);
139131
}
132+
133+
$interfaces = [
134+
JobExecutionStorageInterface::class => true,
135+
ListableJobExecutionStorageInterface::class => false,
136+
QueryableJobExecutionStorageInterface::class => false,
137+
];
140138
foreach ($interfaces as $interface => $required) {
141139
if (!is_a($defaultStorageClass, $interface, true)) {
142140
if ($required) {

tests/DependencyInjection/YokaiBatchExtensionTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
namespace Yokai\Batch\Tests\Bridge\Symfony\Framework\DependencyInjection;
66

7+
use Exception;
78
use PHPUnit\Framework\TestCase;
89
use Symfony\Component\DependencyInjection\ContainerBuilder;
10+
use Symfony\Component\DependencyInjection\Exception\LogicException;
911
use Yokai\Batch\Bridge\Symfony\Framework\DependencyInjection\YokaiBatchExtension;
1012
use Yokai\Batch\Launcher\JobLauncherInterface;
1113
use Yokai\Batch\Storage\JobExecutionStorageInterface;
@@ -40,4 +42,43 @@ public function configs(): \Generator
4042
yield [['storage' => ['dbal' => null]], 'yokai_batch.storage.dbal'];
4143
yield [['storage' => ['service' => 'app.yokai_batch.storage']], 'app.yokai_batch.storage'];
4244
}
45+
46+
/**
47+
* @dataProvider errors
48+
*/
49+
public function testErrors(array $config, ?callable $configure, Exception $error): void
50+
{
51+
$this->expectExceptionObject($error);
52+
53+
$container = new ContainerBuilder();
54+
if ($configure !== null) {
55+
$configure($container);
56+
}
57+
58+
(new YokaiBatchExtension())->load([$config], $container);
59+
}
60+
61+
public function errors(): \Generator
62+
{
63+
yield 'Storage : Unknown service' => [
64+
['storage' => ['service' => 'unknown.service']],
65+
null,
66+
new LogicException('Configured default job execution storage service "unknown.service" does not exists.'),
67+
];
68+
yield 'Storage : Service with no class' => [
69+
['storage' => ['service' => 'service.with.no.class']],
70+
fn(ContainerBuilder $container) => $container->register('service.with.no.class'),
71+
new LogicException('Job execution storage service "service.with.no.class", has no class.'),
72+
];
73+
yield 'Storage : Service without required interface' => [
74+
['storage' => ['service' => 'service.without.required.interface']],
75+
fn(ContainerBuilder $container) => $container->register('service.without.required.interface', __CLASS__),
76+
new LogicException(
77+
'Job execution storage service "service.without.required.interface",' .
78+
' is of class' .
79+
' "Yokai\Batch\Tests\Bridge\Symfony\Framework\DependencyInjection\YokaiBatchExtensionTest",' .
80+
' and must implements interface "Yokai\Batch\Storage\JobExecutionStorageInterface".'
81+
),
82+
];
83+
}
4384
}

0 commit comments

Comments
 (0)