Skip to content

Pre-release 4.2.127 → 4.2.126 — task 4.5 (environment): v13's environment detection, from APP_ENV by default - #100

Merged
agissept merged 1 commit into
masterfrom
pre-release/4.2.127
Oct 6, 2026
Merged

agissept merged 1 commit into
masterfrom
pre-release/4.2.127

Conversation

@oonid

@oonid oonid commented Oct 2, 2026 •

Copy link
Copy Markdown

Task 4.5, environment — v13's environment detection, from APP_ENV by default

Stacks on #99. The fork detected the environment with L4.2's rules: a map of hostnames, overridden by --env=X on the console. v13 takes it from APP_ENV, through config('app.env'), defaulting to production, and only --env overrides it. This release adopts v13's rules and API. The app can then move each machine onto APP_ENV before a later release drops its hostname list.

Changes

  • EnvironmentDetector is v13's:
    • it takes a callback instead of a hostname map;
    • on the console, --env=X and --env X both override the callback. The fork read only --env=X;
    • an argument such as --environment=X no longer counts as --env.
  • Application::detectEnvironment(Closure $callback) takes v13's closure. It reads the console arguments only when running in the console.
  • The start script names the environment right after .env loads, when the application has set none: APP_ENV, else production, the default v13's config gives. The .env.{env}.php file for that environment loads next. An environment the application detected itself still wins. Before, the default was production, or --env.
  • Tests:
    • FoundationEnvironmentDetectorTest is rewritten for v13's rules (4 tests);
    • FoundationApplicationTest: detectEnvironment() takes --env X over the callback, and asks the callback when there's no --env;
    • FoundationApplicationBuilderTest: APP_ENV from .env names the environment and picks its .env.{env}.php file, and an environment the application detected wins over APP_ENV.

What changes

  • detectEnvironment() no longer takes an array. A hostname map fails with a TypeError. The dicoding app passes a closure from its pair on.
  • --env X now works on the console. In the dicoding app, it left the environment empty before.

Verification

  • Fork: the suite is 291 green on PHPUnit 11.5.56, 5 more than 4.2.126. The ratchet is green, with every pattern at its baseline.
  • The tests catch real breaks. Each of these 6 mutations fails at least one test:
    • the start script detecting even when the application set an environment;
    • APP_ENV ignored;
    • detection before .env loads;
    • --env X not read;
    • every argument starting with --env taken as --env;
    • the console arguments ignored.
  • Downstream: the dicoding app pair is dicoding-dev/dicoding#6004 (feature/platform/framework-4.2.127-rc1). It passes a closure to detectEnvironment(): APP_ENV, else its local hostnames, else production. It ran with vendor installed from its lock, apart from the dev CLIs phpstan/phpstan and rector/rector, whose GitHub downloads are refused in this container:
    • With no APP_ENV, every probe gives the same environment as 4.2.126: artisan env and a php -S request, on this container's hostname and on dicoding-local and dicoding.com, each set in its own UTS namespace.
    • APP_ENV now names the environment on the console and the web, over the hostname. --env testing gives testing, where 4.2.126 left the environment empty.
    • config()->all() is byte-identical to 4.2.126 in production, local, testing and endtoend.
    • Psalm (full project, no cache): no errors.
    • Unit suite: 9077 green.
    • Integration suite: all 3039 tests. The only failures are the 4 long-standing ones. 191 are skipped and 5 incomplete, and no test is flagged risky.
    • The real entry points (php -S + server.php → index.php, and 7 artisan commands) and the 13 in-process request scenarios are identical to 4.2.126.
  • Checks ran in a cloud container without deck (PHP 8.4.26, MariaDB 10.11).

Tag

There's no 4.2.127 tag, as there are none for 4.2.119–4.2.126: tag pushes are refused for this session. The app pins the pre-release/4.2.127 branch (9415037b).

🤖 Generated with Claude Code

https://claude.ai/code/session_0169SsatCE8LhaTsQTPiGtVo

@agissept
agissept marked this pull request as ready for review October 6, 2026 06:16
@agissept
agissept force-pushed the pre-release/4.2.127 branch from 07dd324 to 541d7ee Compare October 6, 2026 06:16
Base automatically changed from pre-release/4.2.126 to master October 6, 2026 07:18
…NV by default (task 4.5)

EnvironmentDetector is v13's: it takes a callback only, and on the console
both --env=X and --env X override it. Application::detectEnvironment() takes
a Closure, as in v13, and reads the console arguments only when running in
the console.

When the application sets no environment, the start script now names it
right after .env loads: APP_ENV, else production, the default v13's config
gives. The .env.{env}.php file for that environment loads next. An
environment the application detected itself still wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169SsatCE8LhaTsQTPiGtVo
@agissept
agissept force-pushed the pre-release/4.2.127 branch from 541d7ee to 3723eae Compare October 6, 2026 07:18
@agissept
agissept merged commit 0ca2f84 into master Oct 6, 2026
2 checks passed
@agissept
agissept deleted the pre-release/4.2.127 branch October 6, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants