diff --git a/CHANGELOG.md b/CHANGELOG.md index a587fba..04a18c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +8.0 +--- + + * Remove `$defaultName` and `$defaultDescription` properties from `DebugCommand` command, configuration is done through the `#[AsCommand]` attribute + 7.1 --- diff --git a/Command/DebugCommand.php b/Command/DebugCommand.php index 5729b94..4f1f90c 100644 --- a/Command/DebugCommand.php +++ b/Command/DebugCommand.php @@ -30,16 +30,6 @@ #[AsCommand(name: 'debug:dotenv', description: 'List all dotenv files with variables and values')] final class DebugCommand extends Command { - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultName = 'debug:dotenv'; - - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultDescription = 'List all dotenv files with variables and values'; - public function __construct( private string $kernelEnvironment, private string $projectDirectory, @@ -54,15 +44,15 @@ protected function configure(): void new InputArgument('filter', InputArgument::OPTIONAL, 'The name of an environment variable or a filter.', null, $this->getAvailableVars(...)), ]) ->setHelp(<<<'EOT' -The %command.full_name% command displays all the environment variables configured by dotenv: + The %command.full_name% command displays all the environment variables configured by dotenv: - php %command.full_name% + php %command.full_name% -To get specific variables, specify its full or partial name: + To get specific variables, specify its full or partial name: - php %command.full_name% FOO_BAR + php %command.full_name% FOO_BAR -EOT + EOT ); } @@ -81,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $dotenvPath = $this->projectDirectory; if (is_file($composerFile = $this->projectDirectory.'/composer.json')) { - $runtimeConfig = (json_decode(file_get_contents($composerFile), true))['extra']['runtime'] ?? []; + $runtimeConfig = json_decode(file_get_contents($composerFile), true)['extra']['runtime'] ?? []; if (isset($runtimeConfig['dotenv_path'])) { $dotenvPath = $this->projectDirectory.'/'.$runtimeConfig['dotenv_path']; diff --git a/Command/DotenvDumpCommand.php b/Command/DotenvDumpCommand.php index 8a367a3..c94b76c 100644 --- a/Command/DotenvDumpCommand.php +++ b/Command/DotenvDumpCommand.php @@ -44,10 +44,10 @@ protected function configure(): void ]) ->addOption('empty', null, InputOption::VALUE_NONE, 'Ignore the content of .env files') ->setHelp(<<<'EOT' -The %command.name% command compiles .env files into a PHP-optimized file called .env.local.php. + The %command.name% command compiles .env files into a PHP-optimized file called .env.local.php. - %command.full_name% -EOT + %command.full_name% + EOT ) ; } @@ -75,13 +75,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $vars = var_export($vars, true); $vars = <<writeln(\sprintf('Successfully dumped .env files in .env.local.php for the %s environment.', $env)); diff --git a/README.md b/README.md index 2a1cc02..67ff66a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,15 @@ Getting Started composer require symfony/dotenv ``` +Usage +----- + +> For an .env file with this format: + +```env +YOUR_VARIABLE_NAME=my-string +``` + ```php use Symfony\Component\Dotenv\Dotenv; @@ -25,6 +34,12 @@ $dotenv->overload(__DIR__.'/.env'); // loads .env, .env.local, and .env.$APP_ENV.local or .env.$APP_ENV $dotenv->loadEnv(__DIR__.'/.env'); + +// Usage with $_ENV +$envVariable = $_ENV['YOUR_VARIABLE_NAME']; + +// Usage with $_SERVER +$envVariable = $_SERVER['YOUR_VARIABLE_NAME']; ``` Resources diff --git a/Tests/Command/DebugCommandTest.php b/Tests/Command/DebugCommandTest.php index 28c0b48..b3e6437 100644 --- a/Tests/Command/DebugCommandTest.php +++ b/Tests/Command/DebugCommandTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Dotenv\Tests\Command; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Helper\FormatterHelper; @@ -22,9 +23,7 @@ class DebugCommandTest extends TestCase { - /** - * @runInSeparateProcess - */ + #[RunInSeparateProcess] public function testErrorOnUninitializedDotenv() { unset($_SERVER['SYMFONY_DOTENV_VARS']); @@ -38,9 +37,7 @@ public function testErrorOnUninitializedDotenv() $this->assertStringContainsString('[ERROR] Dotenv component is not initialized', $output); } - /** - * @runInSeparateProcess - */ + #[RunInSeparateProcess] public function testEmptyDotEnvVarsList() { $_SERVER['SYMFONY_DOTENV_VARS'] = ''; @@ -50,17 +47,17 @@ public function testEmptyDotEnvVarsList() $tester = new CommandTester($command); $tester->execute([]); $expectedFormat = <<<'OUTPUT' -%a - ---------- ------- ------------ ------%S - Variable Value .env.local .env%S - ---------- ------- ------------ ------%S - FOO baz bar%S - TEST123 n/a true%S - ---------- ------- ------------ ------%S - - // Note that values might be different between web and CLI.%S -%a -OUTPUT; + %a + ---------- ------- ------------ ------%S + Variable Value .env.local .env%S + ---------- ------- ------------ ------%S + FOO baz bar%S + TEST123 n/a true%S + ---------- ------- ------------ ------%S + + // Note that values might be different between web and CLI.%S + %a + OUTPUT; $this->assertStringMatchesFormat($expectedFormat, $tester->getDisplay()); } @@ -275,9 +272,7 @@ public function testScenario2InProdEnvWithNameFilterPrefix() $this->assertStringContainsString('TEST 1234 1234 1234 0000', $output); } - /** - * @runInSeparateProcess - */ + #[RunInSeparateProcess] public function testCompletion() { $env = 'prod'; @@ -288,7 +283,7 @@ public function testCompletion() $command = new DebugCommand($env, $projectDirectory); $application = new Application(); - $application->add($command); + $application->addCommand($command); $tester = new CommandCompletionTester($application->get('debug:dotenv')); $this->assertSame(['FOO', 'TEST'], $tester->complete([''])); } diff --git a/Tests/Command/DotenvDumpCommandTest.php b/Tests/Command/DotenvDumpCommandTest.php index 44fc304..a80217a 100644 --- a/Tests/Command/DotenvDumpCommandTest.php +++ b/Tests/Command/DotenvDumpCommandTest.php @@ -21,14 +21,14 @@ class DotenvDumpCommandTest extends TestCase protected function setUp(): void { file_put_contents(__DIR__.'/.env', <<createCommand(); @@ -95,7 +95,7 @@ public function testExecuteTestEnvs() private function createCommand(): CommandTester { $application = new Application(); - $application->add(new DotenvDumpCommand(__DIR__)); + $application->addCommand(new DotenvDumpCommand(__DIR__)); return new CommandTester($application->find('dotenv:dump')); } diff --git a/Tests/DotenvTest.php b/Tests/DotenvTest.php index 7f8bd27..69a2e06 100644 --- a/Tests/DotenvTest.php +++ b/Tests/DotenvTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Dotenv\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\Dotenv\Exception\FormatException; @@ -18,9 +19,7 @@ class DotenvTest extends TestCase { - /** - * @dataProvider getEnvDataWithFormatErrors - */ + #[DataProvider('getEnvDataWithFormatErrors')] public function testParseWithFormatError($data, $error) { $dotenv = new Dotenv(); @@ -63,9 +62,7 @@ public static function getEnvDataWithFormatErrors() return $tests; } - /** - * @dataProvider getEnvData - */ + #[DataProvider('getEnvData')] public function testParse($data, $expected) { $dotenv = new Dotenv(); diff --git a/composer.json b/composer.json index 34c4718..0f2f8d4 100644 --- a/composer.json +++ b/composer.json @@ -16,15 +16,11 @@ } ], "require": { - "php": ">=8.2" + "php": ">=8.4" }, "require-dev": { - "symfony/console": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0" - }, - "conflict": { - "symfony/console": "<6.4", - "symfony/process": "<6.4" + "symfony/console": "^7.4|^8.0", + "symfony/process": "^7.4|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Dotenv\\": "" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 461dc69..0cbf618 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,11 @@ @@ -18,7 +19,7 @@ - + ./ @@ -26,5 +27,9 @@ ./Tests ./vendor - + + + + +