Skip to content

Commit

Permalink
Add more code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Sep 17, 2024
1 parent 1ea950f commit c873772
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/CronBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ public function it_merges(): void
self::assertSame($expected, CronBuilder::merge($existingCrontab, self::getCronBuilder()));
}

/**
* @test
*
* @dataProvider invalidJobsFileProvider
*/
public function it_throws_exception_when_jobs_file_is_invalid(string $jobsFile): void
{
$this->expectException(\InvalidArgumentException::class);

(new CronBuilder())
->addFile(__DIR__ . '/cronjobs_invalid/' . $jobsFile)
->build()
;
}

/**
* @return \Generator<array-key, array{string}>
*/
public function invalidJobsFileProvider(): \Generator
{
yield ['jobs1.php'];
yield ['jobs2.php'];
yield ['jobs3.php'];
yield ['jobs4.php'];
}

private static function getCronBuilder(): CronBuilder
{
$cronBuilder = new CronBuilder();
Expand Down
9 changes: 9 additions & 0 deletions tests/cronjobs_invalid/jobs1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

use Setono\CronBuilder\CronJob;

return [
new CronJob('0 0 * * *', '/usr/bin/php {{ release_path }}/{{ release_number }}/send-report.php {{ args|join(" ") }}', 'Run every day at midnight'),
];
10 changes: 10 additions & 0 deletions tests/cronjobs_invalid/jobs2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Setono\CronBuilder\Context;
use Setono\CronBuilder\CronJob;

return static function (Context $context): string {
return 'not an iterable';
};
10 changes: 10 additions & 0 deletions tests/cronjobs_invalid/jobs3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Setono\CronBuilder\Context;
use Setono\CronBuilder\CronJob;

return static function (Context $context): iterable {
yield 'not an object';
};
10 changes: 10 additions & 0 deletions tests/cronjobs_invalid/jobs4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Setono\CronBuilder\Context;
use Setono\CronBuilder\CronJob;

return static function (Context $context): iterable {
yield new \stdClass();
};

0 comments on commit c873772

Please sign in to comment.