Loading src/DotenvServiceProvider.php +15 −7 Original line number Diff line number Diff line Loading @@ -5,11 +5,19 @@ namespace Drupal\dotenv; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderInterface; class DotenvServiceProvider implements ServiceProviderInterface { public function register(ContainerBuilder $container) { /** * The dotenv service provider. * * Sets container parameters for configuring the Symfony Console commands. */ class DotenvServiceProvider implements ServiceProviderInterface { /** * {@inheritdoc} */ public function register(ContainerBuilder $container) { $container->setParameter('dotenv.project_dir', DRUPAL_ROOT . '/..'); $container->setParameter('dotenv.environment', $_ENV['APP_ENV'] ?? 'prod'); } } tests/src/Unit/DotenvServiceProviderTest.php +34 −28 Original line number Diff line number Diff line Loading @@ -7,17 +7,20 @@ use Drupal\dotenv\DotenvServiceProvider; use Drupal\Tests\UnitTestCase; /** * Tests the dotenv service provider * Tests the dotenv service provider. * * @coversDefaultClass \Drupal\dotenv\DotenvServiceProvider * * @group Dotenv */ class DotenvServiceProviderTest extends UnitTestCase { /** @dataProvider dataProvider */ public function testRegister(?string $appEnv, string $expectedEnv): void { class DotenvServiceProviderTest extends UnitTestCase { /** * Tests the dotenv service provider. * * @dataProvider dataProvider */ public function testRegister(?string $appEnv, string $expectedEnv): void { $container = new ContainerBuilder(); $dotenvServiceProvider = new DotenvServiceProvider(); $originalEnv = $_ENV['APP_ENV']; Loading @@ -29,17 +32,20 @@ class DotenvServiceProviderTest extends UnitTestCase static::assertEquals($expectedEnv, $container->getParameter('dotenv.environment')); } public function dataProvider(): array { /** * Provides some test cases. */ public function dataProvider(): array { return [ 'When no APP_ENV is set, it fallback to "prod"' => [ null, NULL, 'prod', ], 'It uses the APP_ENV to populate "dotenv.environment"' => [ 'foobar', 'foobar', ] ], ]; } } drush.services.yml +14 −14 File changed.Contains only whitespace changes. Show changes Loading
src/DotenvServiceProvider.php +15 −7 Original line number Diff line number Diff line Loading @@ -5,11 +5,19 @@ namespace Drupal\dotenv; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderInterface; class DotenvServiceProvider implements ServiceProviderInterface { public function register(ContainerBuilder $container) { /** * The dotenv service provider. * * Sets container parameters for configuring the Symfony Console commands. */ class DotenvServiceProvider implements ServiceProviderInterface { /** * {@inheritdoc} */ public function register(ContainerBuilder $container) { $container->setParameter('dotenv.project_dir', DRUPAL_ROOT . '/..'); $container->setParameter('dotenv.environment', $_ENV['APP_ENV'] ?? 'prod'); } }
tests/src/Unit/DotenvServiceProviderTest.php +34 −28 Original line number Diff line number Diff line Loading @@ -7,17 +7,20 @@ use Drupal\dotenv\DotenvServiceProvider; use Drupal\Tests\UnitTestCase; /** * Tests the dotenv service provider * Tests the dotenv service provider. * * @coversDefaultClass \Drupal\dotenv\DotenvServiceProvider * * @group Dotenv */ class DotenvServiceProviderTest extends UnitTestCase { /** @dataProvider dataProvider */ public function testRegister(?string $appEnv, string $expectedEnv): void { class DotenvServiceProviderTest extends UnitTestCase { /** * Tests the dotenv service provider. * * @dataProvider dataProvider */ public function testRegister(?string $appEnv, string $expectedEnv): void { $container = new ContainerBuilder(); $dotenvServiceProvider = new DotenvServiceProvider(); $originalEnv = $_ENV['APP_ENV']; Loading @@ -29,17 +32,20 @@ class DotenvServiceProviderTest extends UnitTestCase static::assertEquals($expectedEnv, $container->getParameter('dotenv.environment')); } public function dataProvider(): array { /** * Provides some test cases. */ public function dataProvider(): array { return [ 'When no APP_ENV is set, it fallback to "prod"' => [ null, NULL, 'prod', ], 'It uses the APP_ENV to populate "dotenv.environment"' => [ 'foobar', 'foobar', ] ], ]; } }