Skip to content

Conversation

@zigzagdev
Copy link

Description

This PR ensures Cron::header() returns the same Header instance instead of creating a new one on every call. It also adds regression tests to prevent state loss when header() is called multiple times before formatting.

Motivation

header() previously reinitialised the Header each time, which could silently drop previously configured header state (e.g. PATH, MAILTO) when chaining multiple header calls. Returning a single instance makes the behaviour predictable and preserves configuration until format() is called.

What changed

  • Updated Cron::header() to lazily initialise the Header once and reuse it for subsequent calls.
  • Added tests to confirm:
    • header() returns the same instance (assertSame)
      Header state is preserved across multiple calls and appears in the formatted output.

Test plan & results

composer install

./vendor/bin/phpunit

スクリーンショット 2026-01-14 21 00 16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant