Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppEnvironment: add aliases for production and test environments #1170

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions src/Boot/src/Environment/AppEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public static function detect(EnvironmentInterface $environment): self
{
$value = $environment->get('APP_ENV');

// Aliases
$value = match ($value) {
'production' => self::Production->value,
'test' => self::Testing->value,
default => $value,
};

return \is_string($value)
? (self::tryFrom($value) ?? self::Local)
: self::Local;
Expand Down
4 changes: 4 additions & 0 deletions src/Boot/tests/Environment/AppEnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ public static function envVariablesDataProvider(): \Traversable
{
yield ['wrong', AppEnvironment::Local];
yield ['prod', AppEnvironment::Production];
yield ['production', AppEnvironment::Production];
yield ['stage', AppEnvironment::Stage];
yield ['local', AppEnvironment::Local];
yield ['dev', AppEnvironment::Local];
yield ['development', AppEnvironment::Local];
yield ['testing', AppEnvironment::Testing];
yield ['test', AppEnvironment::Testing];
}

public function testClassMethods(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Spiral\Framework\Spiral;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[Scope(Spiral::ConsoleCommand)]
final class ApplicationInProduction
Expand All @@ -22,7 +23,7 @@ public function __construct(
OutputInterface $output,
) {
$this->input = $input;
$this->output = $output;
$this->output = new SymfonyStyle($input, $output);
}

public function confirmToProceed(string $message = 'Application in production.'): bool
Expand Down
1 change: 1 addition & 0 deletions tests/app/src/Command/ApplicationInProductionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function __invoke(ApplicationInProduction $confirmation, OutputInterface
{
if ($confirmation->confirmToProceed('Application in production.')) {
$this->writeln('Application is in production.');
return self::SUCCESS;
}

$this->writeln('Application is in testing.');
Expand Down
Loading