From 31142fe0a91717631933144060088311d8da22cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20H=C3=A4rtl?= Date: Tue, 7 Jan 2020 09:15:06 +0100 Subject: [PATCH 1/2] Test against newer PHP versions and use require/autoload-dev --- .travis.yml | 4 ++++ composer.json | 44 ++++++++++++++++++++++--------------- tests/BootstrapTest.php | 5 ++++- tests/ConsoleConfigTest.php | 5 ++++- tests/EnvTest.php | 5 ++++- tests/WebConfigTest.php | 5 ++++- 6 files changed, 46 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index f3b5e35..4f44c9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ language: php +dist: trusty php: + - "7.4" + - "7.3" + - "7.2" - "7.1" - "7.0" - "5.6" diff --git a/composer.json b/composer.json index f2afa34..a8dc1ab 100644 --- a/composer.json +++ b/composer.json @@ -1,21 +1,29 @@ { - "name": "codemix/yii2-configloader", - "description": "Build configuration arrays from config files and env vars.", - "keywords": ["yii2", "config", "environment"], - "license": "MIT", - "authors": [ - { - "name": "Michael Härtl", - "email": "haertl.mike@gmail.com" - } - ], - "require": { - "yiisoft/yii2": "*", - "vlucas/phpdotenv": "2.5.*" - }, - "autoload": { - "psr-4": { - "codemix\\yii2confload\\": "src/" - } + "name": "codemix/yii2-configloader", + "description": "Build configuration arrays from config files and env vars.", + "keywords": ["yii2", "config", "environment"], + "license": "MIT", + "authors": [ + { + "name": "Michael Härtl", + "email": "haertl.mike@gmail.com" } + ], + "require": { + "yiisoft/yii2": "*", + "vlucas/phpdotenv": "2.5.*" + }, + "require-dev": { + "phpunit/phpunit": ">4.0 <8" + }, + "autoload": { + "psr-4": { + "codemix\\yii2confload\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "tests\\": "tests" + } + } } diff --git a/tests/BootstrapTest.php b/tests/BootstrapTest.php index 8b4ebec..42c21e6 100644 --- a/tests/BootstrapTest.php +++ b/tests/BootstrapTest.php @@ -1,7 +1,10 @@ Date: Wed, 5 Aug 2020 12:48:07 +0200 Subject: [PATCH 2/2] Upgrade to DotEnv 5.x --- .travis.yml | 4 ---- composer.json | 3 ++- phpunit.xml.dist | 1 - src/Config.php | 2 +- tests/EnvTest.php | 12 ++++++------ 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4f44c9a..34f3c2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,6 @@ php: - "7.3" - "7.2" - "7.1" - - "7.0" - - "5.6" - - "5.5" - - "5.4" install: - sudo apt-get update diff --git a/composer.json b/composer.json index a8dc1ab..2dd69e9 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,9 @@ } ], "require": { + "php": "^7.1.3 || ^8.0", "yiisoft/yii2": "*", - "vlucas/phpdotenv": "2.5.*" + "vlucas/phpdotenv": "^5.0" }, "require-dev": { "phpunit/phpunit": ">4.0 <8" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 79b8204..a814c26 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="false" - syntaxCheck="false" bootstrap="tests/bootstrap.php" > diff --git a/src/Config.php b/src/Config.php index c2b8ec4..99ea28b 100644 --- a/src/Config.php +++ b/src/Config.php @@ -231,7 +231,7 @@ public static function bootstrap($directory, $vendor = null, $initEnv = true) public static function initEnv($directory = null) { if ($directory !== null && file_exists($directory . DIRECTORY_SEPARATOR . '.env')) { - $dotenv = new \Dotenv\Dotenv($directory); + $dotenv = \Dotenv\Dotenv::createImmutable($directory); $dotenv->load(); } diff --git a/tests/EnvTest.php b/tests/EnvTest.php index e864485..60d28d4 100644 --- a/tests/EnvTest.php +++ b/tests/EnvTest.php @@ -61,11 +61,11 @@ public function testCanGetEnvVarsFromEnvFile() public function testEnvFileDoesNotClearEnvVars() { - putenv('TEST1=654'); - putenv('TEST2=xyz'); + $_ENV['TEST1'] = '654'; + $_ENV['TEST2'] = 'xyz'; Config::initEnv(__DIR__ . '/app'); - $this->assertEquals(654, Config::env('TEST1')); + $this->assertEquals('654', Config::env('TEST1')); $this->assertEquals('xyz', Config::env('TEST2')); $this->assertEquals('dotenv1', Config::env('VAR1')); $this->assertEquals(2, Config::env('VAR2')); @@ -74,13 +74,13 @@ public function testEnvFileDoesNotClearEnvVars() public function testEnvFileDoesNotOverrideEnvVars() { - putenv('VAR1=654'); - putenv('VAR2=xyz'); + $_ENV['VAR1'] = '654'; + $_ENV['VAR2'] = 'xyz'; Config::initEnv(__DIR__ . '/app'); $this->assertEquals(0, Config::env('YII_DEBUG')); $this->assertEquals('dev', Config::env('YII_ENV')); - $this->assertEquals(654, Config::env('VAR1')); + $this->assertEquals('654', Config::env('VAR1')); $this->assertEquals('xyz', Config::env('VAR2')); }