Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Mar 3, 2025
1 parent d07046c commit c5142b6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/CronBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static function merge(string $existingCron, self $cronBuilder): string
);

if (0 === $replacements) {
return $existingCron . "\n" . $cron;
return $existingCron . "\n\n" . $cron;
}

if (1 === $replacements) {
Expand Down
40 changes: 39 additions & 1 deletion tests/CronBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function it_builds_with_prod_env_set(): void
/**
* @test
*/
public function it_merges(): void
public function it_merges1(): void
{
$existingCrontab = <<<CRON
Expand All @@ -60,6 +60,44 @@ public function it_merges(): void
CRON;

$expected = <<<CRON
0 0 * * * /usr/bin/php /home/johndoe/public_html/other-job.php
###> 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::merge($existingCrontab, self::getCronBuilder()));
}

/**
* @test
*/
public function it_merges2(): void
{
$existingCrontab = '';

$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::merge($existingCrontab, self::getCronBuilder()));
}

/**
* @test
*/
public function it_merges3(): void
{
$existingCrontab = <<<CRON
0 0 * * * /usr/bin/php /home/johndoe/public_html/other-job.php
CRON;

$expected = <<<CRON
Expand Down

0 comments on commit c5142b6

Please sign in to comment.