Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Formatter/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class Cron

public function header(): Header
{
$this->header = new Header($this);
if ($this->header === null) {
$this->header = new Header($this);
}

return $this->header;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Formatter/CronTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,25 @@ public function shouldBuildConfiguration(): void

$this->assertEquals($expected, $this->cron->format());
}

/** @test */
public function headerShouldReturnSameInstance(): void
{
$h1 = $this->cron->header();
$h2 = $this->cron->header();

$this->assertSame($h1, $h2);
}

/** @test */
public function headerShouldNotLoseStateWhenCalledMultipleTimes(): void
{
$this->cron->header()->setPath('path')->end();
$this->cron->header()->setMailto('test@example.com')->end();

$output = $this->cron->format();

$this->assertStringContainsString("PATH=path", $output);
$this->assertStringContainsString("MAILTO=test@example.com", $output);
}
}