Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Mar 3, 2025
1 parent 4c86874 commit d07046c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/CronBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,12 @@ public function build(): string
public static function merge(string $existingCron, self $cronBuilder): string
{
$existingCron = trim($existingCron);

Check warning on line 123 in src/CronBuilder.php

View workflow job for this annotation

GitHub Actions / Mutation tests (8.3, highest)

Escaped Mutant for Mutator "UnwrapTrim": --- Original +++ New @@ @@ } public static function merge(string $existingCron, self $cronBuilder) : string { - $existingCron = trim($existingCron); + $existingCron = $existingCron; $cron = $cronBuilder->build(); if ('' === $existingCron) { return $cron;
$cron = $cronBuilder->build();

if ('' === $existingCron) {
return $cronBuilder->build();
return $cron;
}

$cron = $cronBuilder->build();

$replacedCron = preg_replace(
sprintf(
'/%s.*%s/ms',
Expand Down
28 changes: 28 additions & 0 deletions tests/CronBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,34 @@ public function it_merges(): void
self::assertSame($expected, CronBuilder::merge($existingCrontab, self::getCronBuilder()));
}

/**
* @test
*/
public function it_does_not_add_the_same_file_twice(): void
{
$cronBuilder = self::getCronBuilder();
$cronBuilder->addFile(__DIR__ . '/cronjobs/jobs.php');

$expected = <<<CRON
###> Generated by PHPUnit ###
0 0 * * * /usr/bin/php /home/johndoe/public_html/12/send-report.php --verbose # Run every day at midnight
###< Generated by PHPUnit ###
CRON;

self::assertSame($expected, $cronBuilder->build());
}

/**
* @test
*/
public function it_throws_exception_when_jobs_file_does_not_exist(): void
{
$this->expectException(\InvalidArgumentException::class);

(new CronBuilder())->addFile(__DIR__ . '/cronjobs/does_not_exist.php');
}

/**
* @test
*
Expand Down

0 comments on commit d07046c

Please sign in to comment.