From 3d4139421dd34a887a1fbc4719d18abaa5f48f85 Mon Sep 17 00:00:00 2001 From: Brian French Date: Wed, 15 Feb 2023 16:37:18 -0500 Subject: [PATCH 01/42] Updating this to support php8.x --- .phpunit.result.cache | 1 + .travis.yml | 10 +- composer.json | 13 +- phpunit.xml | 14 -- src/josegonzalez/Dotenv/Expect.php | 2 + src/josegonzalez/Dotenv/Loader.php | 2 +- tests/josegonzalez/Dotenv/ExpectTest.php | 20 ++- tests/josegonzalez/Dotenv/LoaderTest.php | 198 ++++++++++++++--------- 8 files changed, 154 insertions(+), 106 deletions(-) create mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..f52d24c --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"josegonzalez\\Dotenv\\ExpectTest::testExpectLogicException":4,"josegonzalez\\Dotenv\\ExpectTest::testExpectRuntimeException":4,"josegonzalez\\Dotenv\\LoaderTest::testParse":4,"josegonzalez\\Dotenv\\LoaderTest::testParseException":4,"josegonzalez\\Dotenv\\LoaderTest::testParseFileNotFound":4,"josegonzalez\\Dotenv\\LoaderTest::testParseFileIsDirectory":4,"josegonzalez\\Dotenv\\LoaderTest::testParseFileIsUnreadable":4,"josegonzalez\\Dotenv\\LoaderTest::testSetFilterNonexistentFilter":4,"josegonzalez\\Dotenv\\LoaderTest::testSetFilterInvalidCallable":4,"josegonzalez\\Dotenv\\LoaderTest::testExpectRequireParse":4,"josegonzalez\\Dotenv\\LoaderTest::testExpectLogicException":4,"josegonzalez\\Dotenv\\LoaderTest::testExpectRuntimeException":4,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenvException":3,"josegonzalez\\Dotenv\\LoaderTest::testDefineException":4,"josegonzalez\\Dotenv\\LoaderTest::testToPutenvException":4,"josegonzalez\\Dotenv\\LoaderTest::testToEnvException":4,"josegonzalez\\Dotenv\\LoaderTest::testToServerException":4,"josegonzalez\\Dotenv\\LoaderTest::testToArrayRequireParse":4,"josegonzalez\\Dotenv\\LoaderTest::testRequireParse":5,"josegonzalez\\Dotenv\\LoaderTest::testRequireParseException":4,"josegonzalez\\Dotenv\\LoaderTest::testRequireParseNoException":5,"josegonzalez\\Dotenv\\LoaderTest::testRaise":4,"josegonzalez\\Dotenv\\LoaderTest::testRaiseNoException":5},"times":{"josegonzalez\\Dotenv\\ExpectTest::testExpect":0.013,"josegonzalez\\Dotenv\\ExpectTest::testExpectLogicException":0.003,"josegonzalez\\Dotenv\\ExpectTest::testExpectRuntimeException":0,"josegonzalez\\Dotenv\\LoaderTest::testFilepath":0.003,"josegonzalez\\Dotenv\\LoaderTest::testFilepaths":0,"josegonzalez\\Dotenv\\LoaderTest::testSetFilepath":0.001,"josegonzalez\\Dotenv\\LoaderTest::testParse":0.01,"josegonzalez\\Dotenv\\LoaderTest::testParseException":0.002,"josegonzalez\\Dotenv\\LoaderTest::testParseFileNotFound":0,"josegonzalez\\Dotenv\\LoaderTest::testParseFileIsDirectory":0,"josegonzalez\\Dotenv\\LoaderTest::testParseFileIsUnreadable":0,"josegonzalez\\Dotenv\\LoaderTest::testFilters":0,"josegonzalez\\Dotenv\\LoaderTest::testSetFilters":0.001,"josegonzalez\\Dotenv\\LoaderTest::testSetFilterNonexistentFilter":0,"josegonzalez\\Dotenv\\LoaderTest::testSetFilterInvalidCallable":0,"josegonzalez\\Dotenv\\LoaderTest::testFilter":0.009,"josegonzalez\\Dotenv\\LoaderTest::testFilterCallable":0.002,"josegonzalez\\Dotenv\\LoaderTest::testLowercaseKeyFilter":0.002,"josegonzalez\\Dotenv\\LoaderTest::testNullFilter":0.001,"josegonzalez\\Dotenv\\LoaderTest::testRemapKeysFilter":0.002,"josegonzalez\\Dotenv\\LoaderTest::testUppercaseFirstKeyFilter":0.002,"josegonzalez\\Dotenv\\LoaderTest::testUrlParseFilter":0.002,"josegonzalez\\Dotenv\\LoaderTest::testUnderscoreArrayFilter":0.003,"josegonzalez\\Dotenv\\LoaderTest::testMultipleFilters":0.001,"josegonzalez\\Dotenv\\LoaderTest::testExpect":0.001,"josegonzalez\\Dotenv\\LoaderTest::testExpectRequireParse":0,"josegonzalez\\Dotenv\\LoaderTest::testExpectLogicException":0.001,"josegonzalez\\Dotenv\\LoaderTest::testExpectRuntimeException":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenvExceptionUnavailable":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenv":0.028,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenvSkip":0.003,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenvException":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenvPreserveZeros":0.003,"josegonzalez\\Dotenv\\LoaderTest::testDefine":0.001,"josegonzalez\\Dotenv\\LoaderTest::testDefineSkip":0.001,"josegonzalez\\Dotenv\\LoaderTest::testDefineException":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToPutenv":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToPutenvSkip":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToPutenvException":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToPutenvPreserveZeros":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToEnv":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToEnvSkip":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToEnvException":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToEnvPreserveZeros":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToServer":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToServerSkip":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToServerException":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToServerPreserveZeros":0.002,"josegonzalez\\Dotenv\\LoaderTest::testSkipExisting":0,"josegonzalez\\Dotenv\\LoaderTest::testPrefix":0,"josegonzalez\\Dotenv\\LoaderTest::testToArray":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToArrayRequireParse":0,"josegonzalez\\Dotenv\\LoaderTest::testToString":0.003,"josegonzalez\\Dotenv\\LoaderTest::testRequireParse":0.002,"josegonzalez\\Dotenv\\LoaderTest::testRequireParseException":0,"josegonzalez\\Dotenv\\LoaderTest::testRequireParseNoException":0,"josegonzalez\\Dotenv\\LoaderTest::testRaise":0,"josegonzalez\\Dotenv\\LoaderTest::testRaiseNoException":0,"josegonzalez\\Dotenv\\LoaderTest::testStatic":0.006}} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 231644f..130a69a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,10 @@ php: - 5.6 - 7.0 - 7.1 + - 7.4 + - 8.0 + - 8.1 + - 8.2 - hhvm matrix: @@ -16,8 +20,8 @@ before_script: - composer install script: - - vendor/bin/phpcs --standard=psr2 src/ - - phpunit --coverage-text --coverage-clover build/logs/clover.xml + - composer cs-check + - composet test after_success: - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then php vendor/bin/coveralls -v; fi + - if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then composer coveralls -v; fi diff --git a/composer.json b/composer.json index 347e6d4..aa9be49 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,20 @@ "m1/env": "2.*" }, "require-dev": { - "squizlabs/php_codesniffer": "2.*", - "satooshi/php-coveralls": "1.*", - "php-mock/php-mock-phpunit": "^1.1" + "php": ">=7", + "squizlabs/php_codesniffer": "2.*|3.*", + "php-coveralls/php-coveralls": "~2.5", + "php-mock/php-mock-phpunit": "~2.6" }, "autoload": { "psr-0": { "josegonzalez\\Dotenv": ["src", "tests"] } + }, + "scripts": { + "cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 ./src ./tests", + "cs-fix": "php -d memory_limit=-1 ./vendor/bin/phpcbf --standard=psr2 ./src ./tests", + "test": "php -d memory_limit=-1 ./vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml", + "coveralls": "php -d memory_limit=-1 ./vendor/bin/vendor/bin/coveralls -v" } } diff --git a/phpunit.xml b/phpunit.xml index b055268..63336b0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="./tests/bootstrap.php" > @@ -15,17 +14,4 @@ tests/josegonzalez/Dotenv - - - ./docs - ./vendor - ./tests/bootstrap.php - - - - src - - diff --git a/src/josegonzalez/Dotenv/Expect.php b/src/josegonzalez/Dotenv/Expect.php index 7389f1a..4d6a6cd 100644 --- a/src/josegonzalez/Dotenv/Expect.php +++ b/src/josegonzalez/Dotenv/Expect.php @@ -7,6 +7,8 @@ class Expect { + protected $environment = []; + protected $raise = true; public function __construct($environment, $raise = true) diff --git a/src/josegonzalez/Dotenv/Loader.php b/src/josegonzalez/Dotenv/Loader.php index a9519e3..fb0209f 100644 --- a/src/josegonzalez/Dotenv/Loader.php +++ b/src/josegonzalez/Dotenv/Loader.php @@ -10,6 +10,7 @@ class Loader { + protected $exceptions = []; protected $environment = null; @@ -32,7 +33,6 @@ class Loader public function __construct($filepaths = null) { $this->setFilepaths($filepaths); - return $this; } public static function load($options = null) diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index 0cd5c7c..53f0b3d 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -3,18 +3,21 @@ namespace josegonzalez\Dotenv; use josegonzalez\Dotenv\Expect; -use \PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; -class ExpectTest extends PHPUnit_Framework_TestCase +class ExpectTest extends TestCase { + protected $env = []; + + protected $server = []; - public function setUp() + public function setUp(): void { $this->env = $_ENV; $this->server = $_SERVER; } - public function tearDown() + public function tearDown(): void { $_ENV = $this->env; $_SERVER = $this->server; @@ -27,7 +30,7 @@ public function tearDown() * @covers \josegonzalez\Dotenv\Expect::__invoke * @covers \josegonzalez\Dotenv\Expect::raise */ - public function testExpect() + public function testExpect(): void { $expect = new Expect($this->server); $this->assertTrue($expect('USER')); @@ -44,8 +47,9 @@ public function testExpect() * @expectedException LogicException * @expectedExceptionMessage No arguments were passed to expect() */ - public function testExpectLogicException() + public function testExpectLogicException(): void { + $this->expectException(\LogicException::class); $expect = new Expect($this->server); $expect(); } @@ -56,10 +60,10 @@ public function testExpectLogicException() * @expectedException RuntimeException * @expectedExceptionMessage Required ENV vars missing: ['INVALID'] */ - public function testExpectRuntimeException() + public function testExpectRuntimeException(): void { + $this->expectException(\RuntimeException::class); $expect = new Expect($this->server); $expect('INVALID'); } - } diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index b3894c5..fc13a33 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -4,28 +4,35 @@ use josegonzalez\Dotenv\Loader; use phpmock\phpunit\PHPMock; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; function doNothing($data) { return $data; } -class LoaderTest extends PHPUnit_Framework_TestCase +class LoaderTest extends TestCase { use PHPMock; - public function setUp() + protected $env = []; + + protected $server = []; + + protected $fixturePath = ''; + + protected $Loader; + + public function setUp(): void { $this->env = $_ENV; $this->server = $_SERVER; $this->fixturePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR; $this->Loader = new Loader($this->fixturePath . '.env'); $GLOBALS['apache_test_data'] = array(); - } - public function tearDown() + public function tearDown(): void { $_ENV = $this->env; $_SERVER = $this->server; @@ -38,7 +45,7 @@ public function tearDown() /** * @covers \josegonzalez\Dotenv\Loader::filepath */ - public function testFilepath() + public function testFilepath(): void { $this->assertEquals($this->fixturePath . '.env', $this->Loader->filepath()); } @@ -46,7 +53,7 @@ public function testFilepath() /** * @covers \josegonzalez\Dotenv\Loader::filepaths */ - public function testFilepaths() + public function testFilepaths(): void { $this->assertEquals(array($this->fixturePath . '.env'), $this->Loader->filepaths()); } @@ -55,7 +62,7 @@ public function testFilepaths() * @covers \josegonzalez\Dotenv\Loader::setFilepath * @covers \josegonzalez\Dotenv\Loader::setFilepaths */ - public function testSetFilepath() + public function testSetFilepath(): void { $this->Loader->setFilepath('/tmp/.env'); $this->assertEquals('/tmp/.env', $this->Loader->filepath()); @@ -72,7 +79,7 @@ public function testSetFilepath() /** * @covers \josegonzalez\Dotenv\Loader::parse */ - public function testParse() + public function testParse(): void { $this->Loader->setFilepath($this->fixturePath . 'all.env'); $this->Loader->parse(); @@ -100,7 +107,8 @@ public function testParse() $this->assertEquals('bar', $environment['CFOO']); $this->assertEquals('with spaces', $environment['CSPACED']); $this->assertEquals('a value with a # character', $environment['CQUOTES']); - $this->assertEquals('a value with a # character & a quote " character inside quotes', $environment['CQUOTESWITHQUOTE']); + $this->assertEquals('a value with a # character & a quote " ' . + 'character inside quotes', $environment['CQUOTESWITHQUOTE']); $this->assertSame(null, $environment['CNULL']); $this->assertEquals(array( @@ -155,30 +163,45 @@ public function testParse() $environment = $this->Loader->toArray(); $this->assertEquals('app', $environment['APP_NAME']); $this->assertSame(2, $environment['DEBUG']); - $this->assertInternalType('int', $environment['DEBUG']); + $this->assertIsInt($environment['DEBUG']); $this->assertEquals('DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi', $environment['SECURITY_SALT']); $this->assertEquals('76859309657453542496749683645', $environment['SECURITY_CIPHER_SEED']); - $this->assertEquals('mysql://user:password@localhost/database_name?encoding=utf8', $environment['DATABASE_URL']); - $this->assertEquals('mysql://user:password@localhost/test_database_name?encoding=utf8', $environment['DATABASE_TEST_URL']); - $this->assertEquals('file:///vagrant/app/tmp/?prefix=app_&duration=+2 minutes', $environment['CACHE_URL']); - $this->assertEquals('file:///vagrant/app/tmp/?prefix=app_debug_kit_&duration=+2 minutes', $environment['CACHE_DEBUG_KIT_URL']); - $this->assertEquals('file:///vagrant/app/tmp/?prefix=app_cake_core_&duration=+2 minutes', $environment['CACHE_CAKE_CORE_URL']); - $this->assertEquals('file:///vagrant/app/tmp/?prefix=app_cake_model_&duration=+2 minutes', $environment['CACHE_CAKE_MODEL_URL']); - $this->assertEquals('file:///vagrant/app/logs/?types=notice,info,debug&file=debug', $environment['LOG_URL']); - $this->assertEquals('file:///vagrant/app/logs/?types=warning,error,critical,alert,emergency&file=error', $environment['LOG_ERROR_URL']); - $this->assertEquals('mail://localhost/?from=you@localhost', $environment['EMAIL_URL']); - $this->assertEquals('smtp://user:secret@localhost:25/?from[site@localhost]=My+Site&timeout=30', $environment['EMAIL_SMTP_URL']); - $this->assertEquals('smtp://user:secret@localhost:25/?from=you@localhost&messageId=1&template=0&layout=0&timeout=30', $environment['EMAIL_FAST_URL']); + // lines are split to make phpcs happy + // | WARNING | Line exceeds 120 characters; contains xxx characters + $this->assertEquals('mysql://user:password@localhost' . + '/database_name?encoding=utf8', $environment['DATABASE_URL']); + $this->assertEquals('mysql://user:password@localhost' . + '/test_database_name?encoding=utf8', $environment['DATABASE_TEST_URL']); + $this->assertEquals('file:///vagrant/app/tmp/' . + '?prefix=app_&duration=+2 minutes', $environment['CACHE_URL']); + $this->assertEquals('file:///vagrant/app/tmp/' . + '?prefix=app_debug_kit_&duration=+2 minutes', $environment['CACHE_DEBUG_KIT_URL']); + $this->assertEquals('file:///vagrant/app/tmp/' . + '?prefix=app_cake_core_&duration=+2 minutes', $environment['CACHE_CAKE_CORE_URL']); + $this->assertEquals('file:///vagrant/app/tmp/' . + '?prefix=app_cake_model_&duration=+2 minutes', $environment['CACHE_CAKE_MODEL_URL']); + $this->assertEquals('file:///vagrant/app/logs/' . + '?types=notice,info,debug&file=debug', $environment['LOG_URL']); + $this->assertEquals('file:///vagrant/app/logs/' . + '?types=warning,error,critical,alert,emergency&file=error', $environment['LOG_ERROR_URL']); + $this->assertEquals('mail://localhost/?' . + 'from=you@localhost', $environment['EMAIL_URL']); + $this->assertEquals('smtp://user:secret@localhost:25/' . + '?from[site@localhost]=My+Site&timeout=30', $environment['EMAIL_SMTP_URL']); + $this->assertEquals('smtp://user:secret@localhost:25/' . + '?from=you@localhost&messageId=1&template=0&layout=0&timeout=30', $environment['EMAIL_FAST_URL']); } /** * @covers \josegonzalez\Dotenv\Loader::parse * @expectedException M1\Env\Exception\ParseException - * @expectedExceptionMessage Key can only contain alphanumeric and underscores and can not start with a number: 01SKIPPED near 01SKIPPED at line 1 + * @expectedExceptionMessage Key can only contain alphanumeric + * and underscores and can not start with a number: 01SKIPPED near 01SKIPPED at line 1 */ - public function testParseException() + public function testParseException(): void { + $this->expectException(\M1\Env\Exception\ParseException::class); $this->Loader->setFilepath($this->fixturePath . 'parse_exception.env'); $this->Loader->parse(); } @@ -188,8 +211,9 @@ public function testParseException() * @expectedException InvalidArgumentException * @expectedExceptionMessage Environment file '.env' is not found */ - public function testParseFileNotFound() + public function testParseFileNotFound(): void { + $this->expectException(\InvalidArgumentException::class); $this->Loader->setFilepath('.env'); $this->Loader->parse(); } @@ -199,8 +223,9 @@ public function testParseFileNotFound() * @expectedException InvalidArgumentException * @expectedExceptionMessage Environment file '/tmp' is a directory. Should be a file */ - public function testParseFileIsDirectory() + public function testParseFileIsDirectory(): void { + $this->expectException(\InvalidArgumentException::class); $this->Loader->setFilepath('/tmp'); $this->Loader->parse(); } @@ -210,8 +235,9 @@ public function testParseFileIsDirectory() * @expectedException InvalidArgumentException * @expectedExceptionMessage Environment file '/tmp/php-dotenv-unreadable' is not readable */ - public function testParseFileIsUnreadable() + public function testParseFileIsUnreadable(): void { + $this->expectException(\InvalidArgumentException::class); touch('/tmp/php-dotenv-unreadable'); chmod('/tmp/php-dotenv-unreadable', 0000); $this->Loader->setFilepath('/tmp/php-dotenv-unreadable'); @@ -221,7 +247,7 @@ public function testParseFileIsUnreadable() /** * @covers \josegonzalez\Dotenv\Loader::filters */ - public function testFilters() + public function testFilters(): void { $this->assertSame(array(), $this->Loader->filters()); } @@ -229,7 +255,7 @@ public function testFilters() /** * @covers \josegonzalez\Dotenv\Loader::setFilters */ - public function testSetFilters() + public function testSetFilters(): void { $this->assertSame(array(), $this->Loader->filters()); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( @@ -257,8 +283,9 @@ function () { * @expectedException LogicException * @expectedExceptionMessage Invalid filter class SomeFilter */ - public function testSetFilterNonexistentFilter() + public function testSetFilterNonexistentFilter(): void { + $this->expectException(\LogicException::class); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'SomeFilter' ))); @@ -269,8 +296,9 @@ public function testSetFilterNonexistentFilter() * @expectedException LogicException * @expectedExceptionMessage Invalid filter class */ - public function testSetFilterInvalidCallable() + public function testSetFilterInvalidCallable(): void { + $this->expectException(\LogicException::class); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( $this ))); @@ -280,7 +308,7 @@ public function testSetFilterInvalidCallable() * @covers \josegonzalez\Dotenv\Loader::filter * @covers \josegonzalez\Dotenv\Filter\NullFilter::__invoke */ - public function testFilter() + public function testFilter(): void { $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', @@ -300,7 +328,7 @@ public function testFilter() * @covers \josegonzalez\Dotenv\Loader::filter * @covers \josegonzalez\Dotenv\Filter\CallableFilter::__invoke */ - public function testFilterCallable() + public function testFilterCallable(): void { $this->assertEquals($this->Loader, $this->Loader->setFilters(array( function () { @@ -315,7 +343,7 @@ function () { /** * @covers \josegonzalez\Dotenv\Filter\LowercaseKeyFilter::__invoke */ - public function testLowercaseKeyFilter() + public function testLowercaseKeyFilter(): void { $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', @@ -334,7 +362,7 @@ public function testLowercaseKeyFilter() /** * @covers \josegonzalez\Dotenv\Filter\NullFilter::__invoke */ - public function testNullFilter() + public function testNullFilter(): void { $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', @@ -354,7 +382,7 @@ public function testNullFilter() /** * @covers \josegonzalez\Dotenv\Filter\RemapKeysFilter::__invoke */ - public function testRemapKeysFilter() + public function testRemapKeysFilter(): void { $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\RemapKeysFilter' => array( @@ -375,7 +403,7 @@ public function testRemapKeysFilter() /** * @covers \josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter::__invoke */ - public function testUppercaseFirstKeyFilter() + public function testUppercaseFirstKeyFilter(): void { $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', @@ -396,7 +424,7 @@ public function testUppercaseFirstKeyFilter() * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::__invoke * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get */ - public function testUrlParseFilter() + public function testUrlParseFilter(): void { $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UrlParseFilter', @@ -430,7 +458,7 @@ public function testUrlParseFilter() /** * @covers \josegonzalez\Dotenv\Filter\UnderscoreArrayFilter::__invoke */ - public function testUnderscoreArrayFilter() + public function testUnderscoreArrayFilter(): void { $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter', @@ -465,7 +493,7 @@ public function testUnderscoreArrayFilter() * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get * @covers \josegonzalez\Dotenv\Filter\UnderscoreArrayFilter::__invoke */ - public function testMultipleFilters() + public function testMultipleFilters(): void { $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UrlParseFilter', @@ -506,7 +534,7 @@ public function testMultipleFilters() /** * @covers \josegonzalez\Dotenv\Loader::expect */ - public function testExpect() + public function testExpect(): void { $this->Loader->parse(); $this->assertInstanceOf('josegonzalez\Dotenv\Loader', $this->Loader->expect('FOO')); @@ -517,8 +545,9 @@ public function testExpect() * @expectedException LogicException * @expectedExceptionMessage Environment must be parsed before calling expect() */ - public function testExpectRequireParse() + public function testExpectRequireParse(): void { + $this->expectException(\LogicException::class); $this->Loader->expect(); } @@ -527,8 +556,9 @@ public function testExpectRequireParse() * @expectedException LogicException * @expectedExceptionMessage No arguments were passed to expect() */ - public function testExpectLogicException() + public function testExpectLogicException(): void { + $this->expectException(\LogicException::class); $this->Loader->parse(); $this->Loader->expect(); } @@ -538,8 +568,9 @@ public function testExpectLogicException() * @expectedException RuntimeException * @expectedExceptionMessage Required ENV vars missing: ['INVALID'] */ - public function testExpectRuntimeException() + public function testExpectRuntimeException(): void { + $this->expectException(\RuntimeException::class); $this->Loader->parse(); $this->Loader->expect('INVALID'); } @@ -547,7 +578,7 @@ public function testExpectRuntimeException() /** * @covers \josegonzalez\Dotenv\Loader::apacheSetenv */ - public function testToApacheSetenvExceptionUnavailable() + public function testToApacheSetenvExceptionUnavailable(): void { if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); @@ -562,7 +593,7 @@ public function testToApacheSetenvExceptionUnavailable() /** * @covers \josegonzalez\Dotenv\Loader::apacheSetenv */ - public function testToApacheSetenv() + public function testToApacheSetenv(): void { if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); @@ -597,7 +628,7 @@ function ($key, $value) { /** * @covers \josegonzalez\Dotenv\Loader::apacheSetenv */ - public function testToApacheSetenvSkip() + public function testToApacheSetenvSkip(): void { if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); @@ -636,7 +667,7 @@ function ($key, $value) { * @expectedException LogicException * @expectedExceptionMessage Key "FOO" has already been defined in apache_getenv() */ - public function testToApacheSetenvException() + public function testToApacheSetenvException(): void { if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); @@ -659,6 +690,7 @@ function ($key, $value) { } ); + $this->expectException(\LogicException::class); $this->Loader->parse(); $this->Loader->apacheSetenv(false); $this->Loader->apacheSetenv(false); @@ -668,7 +700,7 @@ function ($key, $value) { /** * @covers \josegonzalez\Dotenv\Loader::putenv */ - public function testToApacheSetenvPreserveZeros() + public function testToApacheSetenvPreserveZeros(): void { if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); @@ -709,7 +741,7 @@ function ($key, $value) { /** * @covers \josegonzalez\Dotenv\Loader::define */ - public function testDefine() + public function testDefine(): void { $this->Loader->parse(); $this->Loader->define(); @@ -723,7 +755,7 @@ public function testDefine() /** * @covers \josegonzalez\Dotenv\Loader::define */ - public function testDefineSkip() + public function testDefineSkip(): void { $this->Loader->parse(); $this->Loader->skipExisting('define'); @@ -740,8 +772,9 @@ public function testDefineSkip() * @expectedException LogicException * @expectedExceptionMessage Key "FOO" has already been defined */ - public function testDefineException() + public function testDefineException(): void { + $this->expectException(\LogicException::class); $this->Loader->parse(); $this->Loader->define(); } @@ -749,7 +782,7 @@ public function testDefineException() /** * @covers \josegonzalez\Dotenv\Loader::putenv */ - public function testToPutenv() + public function testToPutenv(): void { $this->Loader->parse(); $this->Loader->putenv(false); @@ -763,7 +796,7 @@ public function testToPutenv() /** * @covers \josegonzalez\Dotenv\Loader::putenv */ - public function testToPutenvSkip() + public function testToPutenvSkip(): void { $this->Loader->parse(); $this->Loader->skipExisting('putenv'); @@ -781,8 +814,9 @@ public function testToPutenvSkip() * @expectedException LogicException * @expectedExceptionMessage Key "FOO" has already been defined in getenv() */ - public function testToPutenvException() + public function testToPutenvException(): void { + $this->expectException(\LogicException::class); $this->Loader->parse(); $this->Loader->putenv(false); $this->Loader->putenv(false); @@ -791,7 +825,7 @@ public function testToPutenvException() /** * @covers \josegonzalez\Dotenv\Loader::putenv */ - public function testToPutenvPreserveZeros() + public function testToPutenvPreserveZeros(): void { $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); @@ -811,7 +845,7 @@ public function testToPutenvPreserveZeros() /** * @covers \josegonzalez\Dotenv\Loader::toEnv */ - public function testToEnv() + public function testToEnv(): void { $this->Loader->parse(); $this->Loader->toEnv(false); @@ -825,7 +859,7 @@ public function testToEnv() /** * @covers \josegonzalez\Dotenv\Loader::toEnv */ - public function testToEnvSkip() + public function testToEnvSkip(): void { $this->Loader->parse(); $this->Loader->skipExisting('toEnv'); @@ -843,8 +877,9 @@ public function testToEnvSkip() * @expectedException LogicException * @expectedExceptionMessage Key "FOO" has already been defined in $_ENV */ - public function testToEnvException() + public function testToEnvException(): void { + $this->expectException(\LogicException::class); $this->Loader->parse(); $this->Loader->toEnv(false); $this->Loader->toEnv(false); @@ -853,7 +888,7 @@ public function testToEnvException() /** * @covers \josegonzalez\Dotenv\Loader::toEnv */ - public function testToEnvPreserveZeros() + public function testToEnvPreserveZeros(): void { $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); @@ -873,7 +908,7 @@ public function testToEnvPreserveZeros() /** * @covers \josegonzalez\Dotenv\Loader::toServer */ - public function testToServer() + public function testToServer(): void { $this->Loader->parse(); $this->Loader->toServer(false); @@ -887,7 +922,7 @@ public function testToServer() /** * @covers \josegonzalez\Dotenv\Loader::toServer */ - public function testToServerSkip() + public function testToServerSkip(): void { $this->Loader->parse(); $this->Loader->skipExisting('toServer'); @@ -905,8 +940,9 @@ public function testToServerSkip() * @expectedException LogicException * @expectedExceptionMessage Key "FOO" has already been defined in $_SERVER */ - public function testToServerException() + public function testToServerException(): void { + $this->expectException(\LogicException::class); $this->Loader->parse(); $this->Loader->toServer(false); $this->Loader->toServer(false); @@ -915,7 +951,7 @@ public function testToServerException() /** * @covers \josegonzalez\Dotenv\Loader::toServer */ - public function testToServerPreserveZeros() + public function testToServerPreserveZeros(): void { $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); @@ -936,7 +972,7 @@ public function testToServerPreserveZeros() * @covers \josegonzalez\Dotenv\Loader::skipped * @covers \josegonzalez\Dotenv\Loader::skipExisting */ - public function testSkipExisting() + public function testSkipExisting(): void { $this->assertEquals(array(), $this->Loader->skipped()); @@ -954,7 +990,7 @@ public function testSkipExisting() * @covers \josegonzalez\Dotenv\Loader::prefix * @covers \josegonzalez\Dotenv\Loader::prefixed */ - public function testPrefix() + public function testPrefix(): void { $this->assertEquals('KEY', $this->Loader->prefixed('KEY')); @@ -968,7 +1004,7 @@ public function testPrefix() /** * @covers \josegonzalez\Dotenv\Loader::toArray */ - public function testToArray() + public function testToArray(): void { $this->Loader->parse(); $this->assertEquals(array( @@ -983,27 +1019,31 @@ public function testToArray() * @expectedException LogicException * @expectedExceptionMessage Environment must be parsed before calling toArray() */ - public function testToArrayRequireParse() + public function testToArrayRequireParse(): void { + $this->expectException(\LogicException::class); $this->Loader->toArray(); } /** * @covers \josegonzalez\Dotenv\Loader::__toString */ - public function testToString() + public function testToString(): void { $this->assertEquals('[]', $this->Loader->__toString()); $this->Loader->parse(); - $this->assertEquals('{"FOO":"bar","BAR":"baz","SPACED":"with spaces","EQUALS":"pgsql:host=localhost;dbname=test"}', $this->Loader->__toString()); + // phpcs error: | WARNING | Line exceeds 120 characters; contains 153 characters + $this->assertEquals('{"FOO":"bar","BAR":"baz","SPACED":"with spaces",' . + '"EQUALS":"pgsql:host=localhost;dbname=test"}', $this->Loader->__toString()); } /** * @covers \josegonzalez\Dotenv\Loader::requireParse */ - public function testRequireParse() + public function testRequireParse(): void { + $this->expectNotToPerformAssertions(); $this->Loader->parse(); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); } @@ -1012,16 +1052,18 @@ public function testRequireParse() * @expectedException LogicException * @expectedExceptionMessage Environment must be parsed before calling toEnv() */ - public function testRequireParseException() + public function testRequireParseException(): void { + $this->expectException(\LogicException::class); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); } /** * @covers \josegonzalez\Dotenv\Loader::raiseExceptions */ - public function testRequireParseNoException() + public function testRequireParseNoException(): void { + $this->expectNotToPerformAssertions(); $this->Loader->raiseExceptions(false); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); } @@ -1030,8 +1072,9 @@ public function testRequireParseNoException() * @expectedException LogicException * @expectedExceptionMessage derp */ - public function testRaise() + public function testRaise(): void { + $this->expectException(\LogicException::class); $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp')); } @@ -1039,13 +1082,14 @@ public function testRaise() * @covers \josegonzalez\Dotenv\Loader::raiseExceptions * @covers \josegonzalez\Dotenv\Loader::raise */ - public function testRaiseNoException() + public function testRaiseNoException(): void { + $this->expectNotToPerformAssertions(); $this->Loader->raiseExceptions(false); $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp')); } - public function testStatic() + public function testStatic(): void { $dotenv = Loader::load(array( 'raiseExceptions' => false @@ -1133,7 +1177,7 @@ public function testStatic() /** * Call a protected method on an object * - * @param Object $object object + * @param object $object object * @param string $name method to call * @param array $args arguments to pass to the method * @return mixed From ce5d5be721180fe03a3638e5b1e86bc19468c564 Mon Sep 17 00:00:00 2001 From: Brian French Date: Wed, 15 Feb 2023 19:17:15 -0500 Subject: [PATCH 02/42] Multiple changes, see description. - intended to be a major version update - removed support for php 5.x - added support for php 8.2 - added phpstan @level 7 - added typehints - removed travis - added github actions - added scripts to composer.json - renamed markdown extensions TODO: - update README - pass all tests - probably more stuff. --- .github/workflows/ci.yml | 113 ++++++++ .gitignore | 1 + .phpunit.result.cache | 1 - .travis.yml | 27 -- CONTRIBUTING.markdown => CONTRIBUTING.md | 0 README.markdown => README.md | 0 composer.json | 13 +- phpstan.neon | 9 + src/josegonzalez/Dotenv/Expect.php | 33 ++- .../Dotenv/Filter/CallableFilter.php | 10 +- src/josegonzalez/Dotenv/Filter/Filter.php | 18 ++ .../Dotenv/Filter/LowercaseKeyFilter.php | 11 +- src/josegonzalez/Dotenv/Filter/NullFilter.php | 9 +- .../Dotenv/Filter/RemapKeysFilter.php | 10 +- .../Dotenv/Filter/UnderscoreArrayFilter.php | 23 +- .../Dotenv/Filter/UppercaseFirstKeyFilter.php | 11 +- .../Dotenv/Filter/UrlParseFilter.php | 37 ++- src/josegonzalez/Dotenv/Loader.php | 215 +++++++++++++-- tests/josegonzalez/Dotenv/ExpectTest.php | 7 +- tests/josegonzalez/Dotenv/LoaderTest.php | 249 +++++++++--------- 20 files changed, 573 insertions(+), 224 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .phpunit.result.cache delete mode 100644 .travis.yml rename CONTRIBUTING.markdown => CONTRIBUTING.md (100%) rename README.markdown => README.md (100%) create mode 100644 phpstan.neon create mode 100644 src/josegonzalez/Dotenv/Filter/Filter.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..df71fd8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,113 @@ +name: CI + +on: + pull_request: + branches: + - '*' + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + php-version: ['5.5', '5.6', '7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + name: Test PHP ${{ matrix.php-version }} + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + coverage: none + + - name: Composer install + run: composer install + + - name: Run PHPUnit + run: composer run-script test + + coverage-php: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + php-version: ['5.5', '5.6', '7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + name: Coverage PHP ${{ matrix.php-version }} + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + coverage: pcov + + - name: Composer install + run: composer install + + - name: Run PHPUnit + run: composer run-script coverage-clover + + - name: Upload to Codecov + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODE_COV_TOKEN }} + files: ./tmp/coverage.xml + verbose: true + + coding-standard: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + php-version: ['5.5', '5.6', '7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + name: Coding Standard ${{ matrix.php-version }} + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + coverage: none + + - name: Composer install + run: composer install + + - name: Run PHP CodeSniffer + run: composer run-script cs-checkstyle | vendor/bin/cs2pr + + static-analysis: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + php-version: ['5.5', '5.6', '7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + name: Static Analysis - PHP ${{ matrix.php-version }} + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + coverage: none + + - name: Composer install + run: composer install + + - name: Run PHP Analyzer + run: composer run-script phpstan-github \ No newline at end of file diff --git a/.gitignore b/.gitignore index ed30b22..ae40efe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build composer.lock tmp vendor +.phpunit.result.cache \ No newline at end of file diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index f52d24c..0000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"defects":{"josegonzalez\\Dotenv\\ExpectTest::testExpectLogicException":4,"josegonzalez\\Dotenv\\ExpectTest::testExpectRuntimeException":4,"josegonzalez\\Dotenv\\LoaderTest::testParse":4,"josegonzalez\\Dotenv\\LoaderTest::testParseException":4,"josegonzalez\\Dotenv\\LoaderTest::testParseFileNotFound":4,"josegonzalez\\Dotenv\\LoaderTest::testParseFileIsDirectory":4,"josegonzalez\\Dotenv\\LoaderTest::testParseFileIsUnreadable":4,"josegonzalez\\Dotenv\\LoaderTest::testSetFilterNonexistentFilter":4,"josegonzalez\\Dotenv\\LoaderTest::testSetFilterInvalidCallable":4,"josegonzalez\\Dotenv\\LoaderTest::testExpectRequireParse":4,"josegonzalez\\Dotenv\\LoaderTest::testExpectLogicException":4,"josegonzalez\\Dotenv\\LoaderTest::testExpectRuntimeException":4,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenvException":3,"josegonzalez\\Dotenv\\LoaderTest::testDefineException":4,"josegonzalez\\Dotenv\\LoaderTest::testToPutenvException":4,"josegonzalez\\Dotenv\\LoaderTest::testToEnvException":4,"josegonzalez\\Dotenv\\LoaderTest::testToServerException":4,"josegonzalez\\Dotenv\\LoaderTest::testToArrayRequireParse":4,"josegonzalez\\Dotenv\\LoaderTest::testRequireParse":5,"josegonzalez\\Dotenv\\LoaderTest::testRequireParseException":4,"josegonzalez\\Dotenv\\LoaderTest::testRequireParseNoException":5,"josegonzalez\\Dotenv\\LoaderTest::testRaise":4,"josegonzalez\\Dotenv\\LoaderTest::testRaiseNoException":5},"times":{"josegonzalez\\Dotenv\\ExpectTest::testExpect":0.013,"josegonzalez\\Dotenv\\ExpectTest::testExpectLogicException":0.003,"josegonzalez\\Dotenv\\ExpectTest::testExpectRuntimeException":0,"josegonzalez\\Dotenv\\LoaderTest::testFilepath":0.003,"josegonzalez\\Dotenv\\LoaderTest::testFilepaths":0,"josegonzalez\\Dotenv\\LoaderTest::testSetFilepath":0.001,"josegonzalez\\Dotenv\\LoaderTest::testParse":0.01,"josegonzalez\\Dotenv\\LoaderTest::testParseException":0.002,"josegonzalez\\Dotenv\\LoaderTest::testParseFileNotFound":0,"josegonzalez\\Dotenv\\LoaderTest::testParseFileIsDirectory":0,"josegonzalez\\Dotenv\\LoaderTest::testParseFileIsUnreadable":0,"josegonzalez\\Dotenv\\LoaderTest::testFilters":0,"josegonzalez\\Dotenv\\LoaderTest::testSetFilters":0.001,"josegonzalez\\Dotenv\\LoaderTest::testSetFilterNonexistentFilter":0,"josegonzalez\\Dotenv\\LoaderTest::testSetFilterInvalidCallable":0,"josegonzalez\\Dotenv\\LoaderTest::testFilter":0.009,"josegonzalez\\Dotenv\\LoaderTest::testFilterCallable":0.002,"josegonzalez\\Dotenv\\LoaderTest::testLowercaseKeyFilter":0.002,"josegonzalez\\Dotenv\\LoaderTest::testNullFilter":0.001,"josegonzalez\\Dotenv\\LoaderTest::testRemapKeysFilter":0.002,"josegonzalez\\Dotenv\\LoaderTest::testUppercaseFirstKeyFilter":0.002,"josegonzalez\\Dotenv\\LoaderTest::testUrlParseFilter":0.002,"josegonzalez\\Dotenv\\LoaderTest::testUnderscoreArrayFilter":0.003,"josegonzalez\\Dotenv\\LoaderTest::testMultipleFilters":0.001,"josegonzalez\\Dotenv\\LoaderTest::testExpect":0.001,"josegonzalez\\Dotenv\\LoaderTest::testExpectRequireParse":0,"josegonzalez\\Dotenv\\LoaderTest::testExpectLogicException":0.001,"josegonzalez\\Dotenv\\LoaderTest::testExpectRuntimeException":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenvExceptionUnavailable":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenv":0.028,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenvSkip":0.003,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenvException":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToApacheSetenvPreserveZeros":0.003,"josegonzalez\\Dotenv\\LoaderTest::testDefine":0.001,"josegonzalez\\Dotenv\\LoaderTest::testDefineSkip":0.001,"josegonzalez\\Dotenv\\LoaderTest::testDefineException":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToPutenv":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToPutenvSkip":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToPutenvException":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToPutenvPreserveZeros":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToEnv":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToEnvSkip":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToEnvException":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToEnvPreserveZeros":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToServer":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToServerSkip":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToServerException":0.001,"josegonzalez\\Dotenv\\LoaderTest::testToServerPreserveZeros":0.002,"josegonzalez\\Dotenv\\LoaderTest::testSkipExisting":0,"josegonzalez\\Dotenv\\LoaderTest::testPrefix":0,"josegonzalez\\Dotenv\\LoaderTest::testToArray":0.002,"josegonzalez\\Dotenv\\LoaderTest::testToArrayRequireParse":0,"josegonzalez\\Dotenv\\LoaderTest::testToString":0.003,"josegonzalez\\Dotenv\\LoaderTest::testRequireParse":0.002,"josegonzalez\\Dotenv\\LoaderTest::testRequireParseException":0,"josegonzalez\\Dotenv\\LoaderTest::testRequireParseNoException":0,"josegonzalez\\Dotenv\\LoaderTest::testRaise":0,"josegonzalez\\Dotenv\\LoaderTest::testRaiseNoException":0,"josegonzalez\\Dotenv\\LoaderTest::testStatic":0.006}} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 130a69a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: php - -php: - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - 7.4 - - 8.0 - - 8.1 - - 8.2 - - hhvm - -matrix: - allow_failures: - - php: hhvm - -before_script: - - composer self-update - - composer install - -script: - - composer cs-check - - composet test - -after_success: - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then composer coveralls -v; fi diff --git a/CONTRIBUTING.markdown b/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.markdown rename to CONTRIBUTING.md diff --git a/README.markdown b/README.md similarity index 100% rename from README.markdown rename to README.md diff --git a/composer.json b/composer.json index aa9be49..8211bd1 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,9 @@ "php": ">=7", "squizlabs/php_codesniffer": "2.*|3.*", "php-coveralls/php-coveralls": "~2.5", - "php-mock/php-mock-phpunit": "~2.6" + "php-mock/php-mock-phpunit": "~2.6", + "phpstan/phpstan": "^1.9", + "staabm/annotate-pull-request-from-checkstyle": "^1.8" }, "autoload": { "psr-0": { @@ -29,9 +31,18 @@ } }, "scripts": { + "ci": [ + "@cs-check", + "@phpstan", + "@test" + ], "cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 ./src ./tests", + "cs-checkstyle": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --report=checkstyle ./src ./tests", "cs-fix": "php -d memory_limit=-1 ./vendor/bin/phpcbf --standard=psr2 ./src ./tests", + "phpstan": "php -d memory_limit=-1 ./vendor/bin/phpstan --no-progress -vvv", + "phpstan-github": "php -d memory_limit=-1 ./vendor/bin/phpstan --no-progress -vvv --error-format=github", "test": "php -d memory_limit=-1 ./vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml", + "coverage-clover": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-clover=tmp/coverage.xml --testdox", "coveralls": "php -d memory_limit=-1 ./vendor/bin/vendor/bin/coveralls -v" } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..14ce3b5 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,9 @@ +parameters: + level: 7 + parallel: + processTimeout: 900.0 + paths: + - src + - tests + ignoreErrors: + - '#Constant [A-Z_]+ not found.#' diff --git a/src/josegonzalez/Dotenv/Expect.php b/src/josegonzalez/Dotenv/Expect.php index 4d6a6cd..89d0d5c 100644 --- a/src/josegonzalez/Dotenv/Expect.php +++ b/src/josegonzalez/Dotenv/Expect.php @@ -7,16 +7,33 @@ class Expect { + + /** @var array The parsed variables. */ protected $environment = []; + /** @var bool If we should throw exceptions or not. */ protected $raise = true; - public function __construct($environment, $raise = true) + + /** + * Checks the environment ans throws an exception of something is missing. + * + * @param array $environment The variables to check + * @param bool $raise If we should throw exceptions or not. + * @return void + */ + public function __construct(array $environment, $raise = true) { $this->environment = $environment; $this->raise = $raise; } + /** + * Checks the environment ans throws an exception of something is missing. + * + * @return bool Actually always false + * @throws \RuntimeException|\LogicException + */ public function __invoke() { $args = func_get_args(); @@ -29,7 +46,7 @@ public function __invoke() } $keys = (array) $args; - $missingEnvs = array(); + $missingEnvs = []; foreach ($keys as $key) { if (!isset($this->environment[$key])) { @@ -47,9 +64,19 @@ public function __invoke() return true; } - protected function raise($exception, $message) + /** + * Throw and track exceptions + * + * @param \Exception|string $exception + * @param string $message The message send with the exception. + * @return bool Actually always false + * @throws \Exception + */ + protected function raise($exception, string $message): bool { if ($this->raise) { + // @todo Figure out how to properly define this line so phpstan can understand it. + // @phpstan-ignore-next-line throw new $exception($message); } diff --git a/src/josegonzalez/Dotenv/Filter/CallableFilter.php b/src/josegonzalez/Dotenv/Filter/CallableFilter.php index 5251926..e8d0968 100644 --- a/src/josegonzalez/Dotenv/Filter/CallableFilter.php +++ b/src/josegonzalez/Dotenv/Filter/CallableFilter.php @@ -2,16 +2,16 @@ namespace josegonzalez\Dotenv\Filter; -class CallableFilter +class CallableFilter extends Filter { /** * Wraps a callable and invokes it upon the environment. * - * @param array $environment Array of environment data - * @param array $config Array of configuration data that includes the callable - * @return array + * @param array $environment Array of environment data + * @param array $config Array of configuration data that includes the callable + * @return array|object */ - public function __invoke(array $environment, array $config) + public function __invoke(array $environment, $config = []) { $callable = $config['callable']; return $callable($environment, $config); diff --git a/src/josegonzalez/Dotenv/Filter/Filter.php b/src/josegonzalez/Dotenv/Filter/Filter.php new file mode 100644 index 0000000..5cd8065 --- /dev/null +++ b/src/josegonzalez/Dotenv/Filter/Filter.php @@ -0,0 +1,18 @@ + $environment Array of environment data + * @param null|array $config Config values. + * @return array + */ + public function __invoke(array $environment, $config = null) + { + return $environment; + } +} diff --git a/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php b/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php index 66f5d8b..705b7fc 100644 --- a/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php +++ b/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php @@ -2,17 +2,18 @@ namespace josegonzalez\Dotenv\Filter; -class LowercaseKeyFilter +class LowercaseKeyFilter extends Filter { /** * Lowercases all the keys for an environment to a single-depth. * - * @param array $environment Array of environment data - * @return array + * @param array $environment Array of environment data + * @param null|array $config Config values. Here to be compatible with Filter. + * @return array */ - public function __invoke(array $environment) + public function __invoke(array $environment, $config = null) { - $newEnvironment = array(); + $newEnvironment = []; foreach ($environment as $key => $value) { $newEnvironment[strtolower($key)] = $value; } diff --git a/src/josegonzalez/Dotenv/Filter/NullFilter.php b/src/josegonzalez/Dotenv/Filter/NullFilter.php index d6b82dd..3043a7f 100644 --- a/src/josegonzalez/Dotenv/Filter/NullFilter.php +++ b/src/josegonzalez/Dotenv/Filter/NullFilter.php @@ -2,15 +2,16 @@ namespace josegonzalez\Dotenv\Filter; -class NullFilter +class NullFilter extends Filter { /** * Returns the environment data without any changes. * - * @param array $environment Array of environment data - * @return array + * @param array $environment Array of environment data + * @param null|array $config Config values. Here to be compatible with Filter. + * @return array */ - public function __invoke(array $environment) + public function __invoke(array $environment, $config = []) { return $environment; } diff --git a/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php b/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php index 790156e..24758f0 100644 --- a/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php +++ b/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php @@ -2,16 +2,16 @@ namespace josegonzalez\Dotenv\Filter; -class RemapKeysFilter +class RemapKeysFilter extends Filter { /** * Remaps specific keys in a $config array to a set of values at a single-depth. * - * @param array $environment Array of environment data - * @param array $config Array of keys to remap to specific values - * @return array + * @param array $environment Array of environment data + * @param array $config Config values. + * @return array */ - public function __invoke(array $environment, array $config) + public function __invoke(array $environment, $config = []) { foreach ($config as $key => $value) { if (array_key_exists($key, $environment)) { diff --git a/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php b/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php index 37777f5..1f3d11e 100644 --- a/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php +++ b/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php @@ -2,7 +2,7 @@ namespace josegonzalez\Dotenv\Filter; -class UnderscoreArrayFilter +class UnderscoreArrayFilter extends Filter { /** * Expands a flat array to a nested array. @@ -10,32 +10,33 @@ class UnderscoreArrayFilter * For example, `['0_Foo_Bar' => 'Far']` becomes * `[['Foo' => ['Bar' => 'Far']]]`. * - * @param array $environment Array of environment data - * @return array + * @param array $environment Array of environment data + * @param null|array $config Config values. Here to be compatible with Filter. + * @return array */ - public function __invoke(array $environment) + public function __invoke(array $environment, $config = null) { - $result = array(); + $result = []; foreach ($environment as $flat => $value) { $keys = explode('_', $flat); $keys = array_reverse($keys); - $child = array( + $child = [ $keys[0] => $value - ); + ]; array_shift($keys); foreach ($keys as $k) { - $child = array( + $child = [ $k => $child - ); + ]; } - $stack = array(array($child, &$result)); + $stack = [[$child, &$result]]; while (!empty($stack)) { foreach ($stack as $curKey => &$curMerge) { foreach ($curMerge[0] as $key => &$val) { $hasKey = !empty($curMerge[1][$key]); if ($hasKey && (array)$curMerge[1][$key] === $curMerge[1][$key] && (array)$val === $val) { - $stack[] = array(&$val, &$curMerge[1][$key]); + $stack[] = [&$val, &$curMerge[1][$key]]; } else { $curMerge[1][$key] = $val; } diff --git a/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php b/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php index 07ae17f..734910c 100644 --- a/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php +++ b/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php @@ -2,17 +2,18 @@ namespace josegonzalez\Dotenv\Filter; -class UppercaseFirstKeyFilter +class UppercaseFirstKeyFilter extends Filter { /** * Uppercases the first letter for all the keys for an environment to a single-depth. * - * @param array $environment Array of environment data - * @return array + * @param array $environment Array of environment data + * @param null|array $config Config values. Here to be compatible with Filter. + * @return array */ - public function __invoke(array $environment) + public function __invoke(array $environment, $config = null) { - $newEnvironment = array(); + $newEnvironment = []; foreach ($environment as $key => $value) { $newEnvironment[ucfirst($key)] = $value; } diff --git a/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php b/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php index 8a67440..fd17182 100644 --- a/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php +++ b/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php @@ -2,36 +2,47 @@ namespace josegonzalez\Dotenv\Filter; -class UrlParseFilter +class UrlParseFilter extends Filter { /** * When there is a key with the suffix `_URL`, this filter uses `parse_url` * to add extra data to the environment. * - * @param array $environment Array of environment data - * @return array + * @param array $environment Array of environment data + * @param null|array $config Config values. Here to be compatible with Filter. + * @return array */ - public function __invoke(array $environment) + public function __invoke(array $environment, $config = null) { - $newEnvironment = array(); + $newEnvironment = []; foreach ($environment as $key => $value) { $newEnvironment[$key] = $value; if (substr($key, -4) === '_URL') { $prefix = substr($key, 0, -3); $url = parse_url($value); - $newEnvironment[$prefix . 'SCHEME'] = $this->get($url, 'scheme', ''); - $newEnvironment[$prefix . 'HOST'] = $this->get($url, 'host', ''); - $newEnvironment[$prefix . 'PORT'] = $this->get($url, 'port', ''); - $newEnvironment[$prefix . 'USER'] = $this->get($url, 'user', ''); - $newEnvironment[$prefix . 'PASS'] = $this->get($url, 'pass', ''); - $newEnvironment[$prefix . 'PATH'] = $this->get($url, 'path', ''); - $newEnvironment[$prefix . 'QUERY'] = $this->get($url, 'query', ''); - $newEnvironment[$prefix . 'FRAGMENT'] = $this->get($url, 'fragment', ''); + if (is_array($url)) { + $newEnvironment[$prefix . 'SCHEME'] = $this->get($url, 'scheme', ''); + $newEnvironment[$prefix . 'HOST'] = $this->get($url, 'host', ''); + $newEnvironment[$prefix . 'PORT'] = $this->get($url, 'port', ''); + $newEnvironment[$prefix . 'USER'] = $this->get($url, 'user', ''); + $newEnvironment[$prefix . 'PASS'] = $this->get($url, 'pass', ''); + $newEnvironment[$prefix . 'PATH'] = $this->get($url, 'path', ''); + $newEnvironment[$prefix . 'QUERY'] = $this->get($url, 'query', ''); + $newEnvironment[$prefix . 'FRAGMENT'] = $this->get($url, 'fragment', ''); + } } } return $newEnvironment; } + /** + * Gets the filter + * + * @param array $data The array to look at + * @param int|string $key The key in $data to look for + * @param null|mixed $default The default value to return if key isn't found + * @return null|mixed The found value or $default + */ public function get(array $data, $key, $default = null) { if (isset($data[$key])) { diff --git a/src/josegonzalez/Dotenv/Loader.php b/src/josegonzalez/Dotenv/Loader.php index fb0209f..c9b83c9 100644 --- a/src/josegonzalez/Dotenv/Loader.php +++ b/src/josegonzalez/Dotenv/Loader.php @@ -1,4 +1,8 @@ List of thrown exceptsions being tracked. */ protected $exceptions = []; + /** @var null|array The parsed variables. */ protected $environment = null; + /** @var array|null A list of file paths to use to fine the .env file. */ protected $filepaths = null; - protected $filters = array(); + /** @var array List of filters to use. */ + protected $filters = []; + /** @var null|string The prefix we should use for keys. */ protected $prefix = null; + /** @var bool If we should raise exceptions. */ protected $raise = true; - protected $skip = array( + /** @var array Available sources and if they should be skipped. */ + protected $skip = [ 'apacheSetenv' => false, 'define' => false, 'putenv' => false, 'toEnv' => false, 'toServer' => false, - ); - + ]; + + /** + * Constructor + * + * @param null|string|array $filepaths + * @return void + */ public function __construct($filepaths = null) { $this->setFilepaths($filepaths); } + /** + * Creates the Loader object with a set of options. + * + * @param null|string|array $options + * @return \josegonzalez\Dotenv\Loader + */ public static function load($options = null) { $filepaths = null; if (is_string($options)) { $filepaths = $options; - $options = array(); + $options = []; } elseif (isset($options['filepath'])) { $filepaths = (array)$options['filepath']; unset($options['filepath']); @@ -62,7 +85,7 @@ public static function load($options = null) $dotenv->filter(); } - $methods = array( + $methods = [ 'skipExisting', 'prefix', 'expect', @@ -71,7 +94,8 @@ public static function load($options = null) 'putenv', 'toEnv', 'toServer', - ); + ]; + foreach ($methods as $method) { if (array_key_exists($method, $options)) { $dotenv->$method($options[$method]); @@ -81,43 +105,77 @@ public static function load($options = null) return $dotenv; } + /** + * Gets the current file path from the list. + * + * @return string + */ public function filepath() { return current($this->filepaths); } + /** + * Gets the list of files paths. + * + * @return array|null + */ public function filepaths() { return $this->filepaths; } - public function setFilepath($filepath = null) + /** + * Sets a single file path + * + * @param null|string $filepath The path to add to the list. + * @return self + */ + public function setFilepath(?string $filepath = null) { return $this->setFilepaths($filepath); } + /** + * Sets the list of paths to look for the .env file + * + * @param null|string|array $filepaths One or more file paths to look in. + * @return self + */ public function setFilepaths($filepaths = null) { if ($filepaths == null) { - $filepaths = array(__DIR__ . DIRECTORY_SEPARATOR . '.env'); + $filepaths = [__DIR__ . DIRECTORY_SEPARATOR . '.env']; } if (is_string($filepaths)) { - $filepaths = array($filepaths); + $filepaths = [$filepaths]; } $this->filepaths = $filepaths; return $this; } + /** + * gets the filters to use. + * + * @return array The defined list of filters. + */ public function filters() { return $this->filters; } + /** + * Sets the filters to use. + * + * @param array $filters An array of filters to use. + * @return self|bool + * @throws \LogicException + */ public function setFilters(array $filters) { - $newList = array(); + $newList = []; $keys = array_keys($filters); $count = count($keys); for ($i = 0; $i < $count; $i++) { @@ -126,9 +184,9 @@ public function setFilters(array $filters) if (is_string($filter)) { $newList[$filter] = null; } else { - $newList['__callable__' . $i] = array( + $newList['__callable__' . $i] = [ 'callable' => $filter - ); + ]; } } else { $newList[$keys[$i]] = $filters[$keys[$i]]; @@ -161,6 +219,12 @@ public function setFilters(array $filters) return $this; } + /** + * Filter variables + * + * @return self + * @throws \InvalidArgumentException + */ public function filter() { $this->requireParse('filter'); @@ -176,6 +240,7 @@ public function filter() $filter = new $filterClass; } } + /** @var \josegonzalez\Dotenv\Filter\Filter $filter */ $environment = $filter($environment, $config); } @@ -183,9 +248,15 @@ public function filter() return $this; } + /** + * Parses the .env file into the environment variable + * + * @return self|bool + * @throws \InvalidArgumentException + */ public function parse() { - $contents = false; + $contents = ''; $filepaths = $this->filepaths(); foreach ($filepaths as $i => $filepath) { @@ -216,12 +287,19 @@ public function parse() } } + /** @var string $contents Come on phpstan. */ $parser = new Parser($contents); $this->environment = $parser->getContent(); return $this; } + /** + * Used to create an Expect object + * + * @return self|bool + * @throws \Exception + */ public function expect() { $this->requireParse('expect'); @@ -232,6 +310,13 @@ public function expect() return $this; } + /** + * Uses apache_setenv() to set variables + * + * @param bool $overwrite If we should overwrite variables via apache_setenv() + * @return self|bool + * @throws \Exception + */ public function apacheSetenv($overwrite = false) { $this->requireParse('apache_setenv'); @@ -254,6 +339,12 @@ public function apacheSetenv($overwrite = false) return $this; } + /** + * Uses define() to set variables + * + * @return self|bool + * @throws \Exception + */ public function define() { $this->requireParse('define'); @@ -276,6 +367,13 @@ public function define() return $this; } + /** + * Uses putenv() to set variables + * + * @param bool $overwrite If we should overwrite variables via putenv() + * @return self|bool + * @throws \Exception + */ public function putenv($overwrite = false) { $this->requireParse('putenv'); @@ -298,6 +396,13 @@ public function putenv($overwrite = false) return $this; } + /** + * Updates $_ENV + * + * @param bool $overwrite If we should overwrite the initial value of $_ENV values + * @return self|bool + * @throws \Exception + */ public function toEnv($overwrite = false) { $this->requireParse('toEnv'); @@ -320,6 +425,13 @@ public function toEnv($overwrite = false) return $this; } + /** + * Updates $_SERVER + * + * @param bool $overwrite If we should overwrite the initial value of $_SERVER values + * @return self|bool + * @throws \Exception + */ public function toServer($overwrite = false) { $this->requireParse('toServer'); @@ -342,6 +454,12 @@ public function toServer($overwrite = false) return $this; } + /** + * Sets what types to skip + * + * @param mixed $types The types to skip + * @return self + */ public function skipExisting($types = null) { $args = func_get_args(); @@ -354,6 +472,7 @@ public function skipExisting($types = null) $types = array_keys($this->skip); } + /** @var string $type */ foreach ((array)$types as $type) { $this->skip[$type] = true; } @@ -361,9 +480,14 @@ public function skipExisting($types = null) return $this; } + /** + * Returns list of variables to skip. + * + * @return array + */ public function skipped() { - $skipped = array(); + $skipped = []; foreach ($this->skip as $key => $value) { if ($value == true) { $skipped[] = $key; @@ -372,13 +496,25 @@ public function skipped() return $skipped; } - public function prefix($prefix = null) + /** + * Sets the prefix. + * + * @param string|null $prefix + * @return self + */ + public function prefix(?string $prefix = null) { $this->prefix = $prefix; return $this; } - public function prefixed($key) + /** + * Add prefix to a key + * + * @param string $key The key that may need to be prefixed. + * @return string The modified key. + */ + public function prefixed(string $key) { if (!!$this->prefix) { $key = $this->prefix . $key; @@ -387,12 +523,24 @@ public function prefixed($key) return $key; } + /** + * Flags if we should raise exceptions, or ignore them + * + * @param bool $raise If we should allow exceptions + * @return self + */ public function raiseExceptions($raise = true) { $this->raise = $raise; return $this; } + /** + * Creates and return an array from the known environment. + * + * @return array|null + * @throws \Exception + */ public function toArray() { $this->requireParse('toArray'); @@ -400,25 +548,38 @@ public function toArray() return null; } - $environment = array(); + $environment = []; foreach ($this->environment as $key => $value) { $environment[$this->prefixed($key)] = $value; } return $environment; } + /** + * Converts array to json string + * + * @return string + */ public function __toString() { try { $data = $this->toArray(); } catch (LogicException $e) { - $data = array(); + $data = []; } - return json_encode($data); + $json = json_encode($data); + return $json ? $json : ''; } - protected function requireParse($method) + /** + * Requires the the .env has been parsed first. + * + * @param string $method The message send with the exception. + * @return void|bool + * @throws \Exception + */ + protected function requireParse(string $method) { if (!is_array($this->environment)) { return $this->raise( @@ -428,9 +589,19 @@ protected function requireParse($method) } } - protected function raise($exception, $message) + /** + * Throw and track exceptions + * + * @param \Exception|string $exception + * @param string $message The message send with the exception. + * @return bool Actually always false + * @throws \Exception + */ + protected function raise($exception, string $message): bool { if ($this->raise) { + // @todo Figure out how to properly define this line so phpstan can understand it. + // @phpstan-ignore-next-line throw new $exception($message); } diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index 53f0b3d..c36af06 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -7,8 +7,11 @@ class ExpectTest extends TestCase { + + /** @var array */ protected $env = []; + /** @var array */ protected $server = []; public function setUp(): void @@ -34,11 +37,11 @@ public function testExpect(): void { $expect = new Expect($this->server); $this->assertTrue($expect('USER')); - $this->assertTrue($expect(array('USER', 'HOME'))); + $this->assertTrue($expect(['USER', 'HOME'])); $expect = new Expect($this->server, false); $this->assertFalse($expect('FOO')); - $this->assertFalse($expect(array('USER', 'FOO'))); + $this->assertFalse($expect(['USER', 'FOO'])); } /** diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index fc13a33..393f7b7 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -6,6 +6,11 @@ use phpmock\phpunit\PHPMock; use PHPUnit\Framework\TestCase; +/** + * Just return what was handed to it. + * @param mixed $data basically anything + * @return mixed Whatever was in $data + */ function doNothing($data) { return $data; @@ -15,12 +20,16 @@ class LoaderTest extends TestCase { use PHPMock; + /** @var array */ protected $env = []; + /** @var array */ protected $server = []; + /** @var string */ protected $fixturePath = ''; + /** @var \josegonzalez\Dotenv\Loader */ protected $Loader; public function setUp(): void @@ -29,7 +38,7 @@ public function setUp(): void $this->server = $_SERVER; $this->fixturePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR; $this->Loader = new Loader($this->fixturePath . '.env'); - $GLOBALS['apache_test_data'] = array(); + $GLOBALS['apache_test_data'] = []; } public function tearDown(): void @@ -55,7 +64,7 @@ public function testFilepath(): void */ public function testFilepaths(): void { - $this->assertEquals(array($this->fixturePath . '.env'), $this->Loader->filepaths()); + $this->assertEquals([$this->fixturePath . '.env'], $this->Loader->filepaths()); } /** @@ -68,11 +77,11 @@ public function testSetFilepath(): void $this->assertEquals('/tmp/.env', $this->Loader->filepath()); $this->Loader->setFilepath(null); - $basePath = realpath(implode(DIRECTORY_SEPARATOR, array( + $basePath = realpath(implode(DIRECTORY_SEPARATOR, [ __DIR__, '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..', 'src' . DIRECTORY_SEPARATOR . 'josegonzalez' . DIRECTORY_SEPARATOR . 'Dotenv', - ))); + ])); $this->assertEquals($basePath . DIRECTORY_SEPARATOR .'.env', $this->Loader->filepath()); } @@ -111,7 +120,7 @@ public function testParse(): void 'character inside quotes', $environment['CQUOTESWITHQUOTE']); $this->assertSame(null, $environment['CNULL']); - $this->assertEquals(array( + $this->assertEquals([ 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'unquotedwithspaces spaces', @@ -156,7 +165,7 @@ public function testParse(): void 'STRING_EMPTY' => '', 'STRING_EMPTY_2' => '', 'NO_VALUE_INLINE_COMMENT' => null, - ), $environment); + ], $environment); $this->Loader->setFilepath($this->fixturePath . 'cake.env'); $this->Loader->parse(); @@ -249,7 +258,7 @@ public function testParseFileIsUnreadable(): void */ public function testFilters(): void { - $this->assertSame(array(), $this->Loader->filters()); + $this->assertSame([], $this->Loader->filters()); } /** @@ -257,25 +266,25 @@ public function testFilters(): void */ public function testSetFilters(): void { - $this->assertSame(array(), $this->Loader->filters()); - $this->assertEquals($this->Loader, $this->Loader->setFilters(array( + $this->assertSame([], $this->Loader->filters()); + $this->assertEquals($this->Loader, $this->Loader->setFilters([ 'josegonzalez\Dotenv\Filter\NullFilter', - ))); + ])); - $this->assertEquals($this->Loader, $this->Loader->setFilters(array( + $this->assertEquals($this->Loader, $this->Loader->setFilters([ 'josegonzalez\Dotenv\doNothing', - ))); + ])); - $this->assertEquals($this->Loader, $this->Loader->setFilters(array( - 'josegonzalez\Dotenv\doNothing' => array('key' => 'value'), - ))); + $this->assertEquals($this->Loader, $this->Loader->setFilters([ + 'josegonzalez\Dotenv\doNothing' => ['key' => 'value'], + ])); - $this->assertEquals($this->Loader, $this->Loader->setFilters(array( + $this->assertEquals($this->Loader, $this->Loader->setFilters([ function () { - return array(); + return []; } - ))); + ])); } /** @@ -286,9 +295,9 @@ function () { public function testSetFilterNonexistentFilter(): void { $this->expectException(\LogicException::class); - $this->assertEquals($this->Loader, $this->Loader->setFilters(array( + $this->assertEquals($this->Loader, $this->Loader->setFilters([ 'SomeFilter' - ))); + ])); } /** @@ -299,9 +308,9 @@ public function testSetFilterNonexistentFilter(): void public function testSetFilterInvalidCallable(): void { $this->expectException(\LogicException::class); - $this->assertEquals($this->Loader, $this->Loader->setFilters(array( + $this->assertEquals($this->Loader, $this->Loader->setFilters([ $this - ))); + ])); } /** @@ -310,17 +319,17 @@ public function testSetFilterInvalidCallable(): void */ public function testFilter(): void { - $this->assertEquals($this->Loader, $this->Loader->setFilters(array( + $this->assertEquals($this->Loader, $this->Loader->setFilters([ 'josegonzalez\Dotenv\Filter\NullFilter', - ))); + ])); $this->Loader->parse(); $this->Loader->filter(); - $this->assertEquals(array( + $this->assertEquals([ 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ), $this->Loader->toArray()); + ], $this->Loader->toArray()); } @@ -330,14 +339,14 @@ public function testFilter(): void */ public function testFilterCallable(): void { - $this->assertEquals($this->Loader, $this->Loader->setFilters(array( + $this->assertEquals($this->Loader, $this->Loader->setFilters([ function () { - return array('FOO' => 'BAR'); + return ['FOO' => 'BAR']; } - ))); + ])); $this->Loader->parse(); $this->Loader->filter(); - $this->assertEquals(array('FOO' => 'BAR'), $this->Loader->toArray()); + $this->assertEquals(['FOO' => 'BAR'], $this->Loader->toArray()); } /** @@ -345,18 +354,18 @@ function () { */ public function testLowercaseKeyFilter(): void { - $this->Loader->setFilters(array( + $this->Loader->setFilters([ 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', - )); + ]); $this->Loader->setFilepath($this->fixturePath . '.env'); $this->Loader->parse(); $this->Loader->filter(); - $this->assertEquals(array( + $this->assertEquals([ 'foo' => 'bar', 'bar' => 'baz', 'spaced' => 'with spaces', 'equals' => 'pgsql:host=localhost;dbname=test', - ), $this->Loader->toArray()); + ], $this->Loader->toArray()); } /** @@ -364,18 +373,18 @@ public function testLowercaseKeyFilter(): void */ public function testNullFilter(): void { - $this->Loader->setFilters(array( + $this->Loader->setFilters([ 'josegonzalez\Dotenv\Filter\NullFilter', - )); + ]); $this->Loader->setFilepath($this->fixturePath . '.env'); $this->Loader->parse(); $this->Loader->filter(); - $this->assertEquals(array( + $this->assertEquals([ 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ), $this->Loader->toArray()); + ], $this->Loader->toArray()); } @@ -384,20 +393,20 @@ public function testNullFilter(): void */ public function testRemapKeysFilter(): void { - $this->Loader->setFilters(array( - 'josegonzalez\Dotenv\Filter\RemapKeysFilter' => array( + $this->Loader->setFilters([ + 'josegonzalez\Dotenv\Filter\RemapKeysFilter' => [ 'FOO' => 'QUX' - ), - )); + ], + ]); $this->Loader->setFilepath($this->fixturePath . '.env'); $this->Loader->parse(); $this->Loader->filter(); - $this->assertEquals(array( + $this->assertEquals([ 'QUX' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ), $this->Loader->toArray()); + ], $this->Loader->toArray()); } /** @@ -405,19 +414,19 @@ public function testRemapKeysFilter(): void */ public function testUppercaseFirstKeyFilter(): void { - $this->Loader->setFilters(array( + $this->Loader->setFilters([ 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', 'josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter', - )); + ]); $this->Loader->setFilepath($this->fixturePath . '.env'); $this->Loader->parse(); $this->Loader->filter(); - $this->assertEquals(array( + $this->assertEquals([ 'Foo' => 'bar', 'Bar' => 'baz', 'Spaced' => 'with spaces', 'Equals' => 'pgsql:host=localhost;dbname=test', - ), $this->Loader->toArray()); + ], $this->Loader->toArray()); } /** @@ -426,14 +435,14 @@ public function testUppercaseFirstKeyFilter(): void */ public function testUrlParseFilter(): void { - $this->Loader->setFilters(array( + $this->Loader->setFilters([ 'josegonzalez\Dotenv\Filter\UrlParseFilter', - )); + ]); $this->Loader->setFilepath($this->fixturePath . 'url_parse_filter.env'); $this->Loader->parse(); $this->Loader->filter(); $environment = $this->Loader->toArray(); - $this->assertSame(array( + $this->assertSame([ 'READ_DATABASE_URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'READ_DATABASE_SCHEME' => 'mysql', 'READ_DATABASE_HOST' => 'localhost', @@ -452,7 +461,7 @@ public function testUrlParseFilter(): void 'DATABASE_PATH' => '/database_name', 'DATABASE_QUERY' => 'encoding=utf8', 'DATABASE_FRAGMENT' => '', - ), $environment); + ], $environment); } /** @@ -460,32 +469,32 @@ public function testUrlParseFilter(): void */ public function testUnderscoreArrayFilter(): void { - $this->Loader->setFilters(array( + $this->Loader->setFilters([ 'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter', - )); + ]); $this->Loader->setFilepath($this->fixturePath . 'underscore_array_filter.env'); $this->Loader->parse(); $this->Loader->filter(); $environment = $this->Loader->toArray(); - $this->assertEquals(array( - 'DATABASE' => array( + $this->assertEquals([ + 'DATABASE' => [ 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', - 0 => array( + 0 => [ 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'OTHERURL' => 'mysql://user:password@localhost/database_name?encoding=utf8', - ), - 1 => array( + ], + 1 => [ 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'OTHERURL' => 'mysql://user:password@localhost/database_name?encoding=utf8', - ), - ), - 'DATA' => array( - 'BASE' => array( + ], + ], + 'DATA' => [ + 'BASE' => [ 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8' - ), - ), + ], + ], - ), $environment); + ], $environment); } /** @@ -495,16 +504,16 @@ public function testUnderscoreArrayFilter(): void */ public function testMultipleFilters(): void { - $this->Loader->setFilters(array( + $this->Loader->setFilters([ 'josegonzalez\Dotenv\Filter\UrlParseFilter', 'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter', - )); + ]); $this->Loader->setFilepath($this->fixturePath . 'filter.env'); $this->Loader->parse(); $this->Loader->filter(); $environment = $this->Loader->toArray(); - $this->assertSame(array( - 'DATABASE' => array( + $this->assertSame([ + 'DATABASE' => [ 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'SCHEME' => 'mysql', 'HOST' => 'localhost', @@ -514,9 +523,9 @@ public function testMultipleFilters(): void 'PATH' => '/database_name', 'QUERY' => 'encoding=utf8', 'FRAGMENT' => '', - ), - 'DATA' => array( - 'BASE' => array( + ], + 'DATA' => [ + 'BASE' => [ 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'SCHEME' => 'mysql', 'HOST' => 'localhost', @@ -526,9 +535,9 @@ public function testMultipleFilters(): void 'PATH' => '/database_name', 'QUERY' => 'encoding=utf8', 'FRAGMENT' => '', - ), - ), - ), $environment); + ], + ], + ], $environment); } /** @@ -538,7 +547,7 @@ public function testExpect(): void { $this->Loader->parse(); $this->assertInstanceOf('josegonzalez\Dotenv\Loader', $this->Loader->expect('FOO')); - $this->assertInstanceOf('josegonzalez\Dotenv\Loader', $this->Loader->expect(array('FOO', 'BAR'))); + $this->assertInstanceOf('josegonzalez\Dotenv\Loader', $this->Loader->expect(['FOO', 'BAR'])); } /** @@ -974,16 +983,16 @@ public function testToServerPreserveZeros(): void */ public function testSkipExisting(): void { - $this->assertEquals(array(), $this->Loader->skipped()); + $this->assertEquals([], $this->Loader->skipped()); $this->Loader->skipExisting('toEnv'); - $this->assertEquals(array('toEnv'), $this->Loader->skipped()); + $this->assertEquals(['toEnv'], $this->Loader->skipped()); - $this->Loader->skipExisting(array('toEnv')); - $this->assertEquals(array('toEnv'), $this->Loader->skipped()); + $this->Loader->skipExisting(['toEnv']); + $this->assertEquals(['toEnv'], $this->Loader->skipped()); $this->Loader->skipExisting(); - $this->assertEquals(array('apacheSetenv', 'define', 'putenv', 'toEnv', 'toServer'), $this->Loader->skipped()); + $this->assertEquals(['apacheSetenv', 'define', 'putenv', 'toEnv', 'toServer'], $this->Loader->skipped()); } /** @@ -1007,12 +1016,12 @@ public function testPrefix(): void public function testToArray(): void { $this->Loader->parse(); - $this->assertEquals(array( + $this->assertEquals([ 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ), $this->Loader->toArray()); + ], $this->Loader->toArray()); } /** @@ -1045,7 +1054,7 @@ public function testRequireParse(): void { $this->expectNotToPerformAssertions(); $this->Loader->parse(); - $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); + $this->protectedMethodCall($this->Loader, 'requireParse', ['toEnv']); } /** @@ -1055,7 +1064,7 @@ public function testRequireParse(): void public function testRequireParseException(): void { $this->expectException(\LogicException::class); - $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); + $this->protectedMethodCall($this->Loader, 'requireParse', ['toEnv']); } /** @@ -1065,7 +1074,7 @@ public function testRequireParseNoException(): void { $this->expectNotToPerformAssertions(); $this->Loader->raiseExceptions(false); - $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); + $this->protectedMethodCall($this->Loader, 'requireParse', ['toEnv']); } /** @@ -1075,7 +1084,7 @@ public function testRequireParseNoException(): void public function testRaise(): void { $this->expectException(\LogicException::class); - $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp')); + $this->protectedMethodCall($this->Loader, 'raise', ['LogicException', 'derp']); } /** @@ -1086,73 +1095,73 @@ public function testRaiseNoException(): void { $this->expectNotToPerformAssertions(); $this->Loader->raiseExceptions(false); - $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp')); + $this->protectedMethodCall($this->Loader, 'raise', ['LogicException', 'derp']); } public function testStatic(): void { - $dotenv = Loader::load(array( + $dotenv = Loader::load([ 'raiseExceptions' => false - )); + ]); $this->assertNull($dotenv->toArray()); $dotenv = Loader::load($this->fixturePath . '.env'); - $this->assertEquals(array( + $this->assertEquals([ 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ), $dotenv->toArray()); + ], $dotenv->toArray()); - $dotenv = Loader::load(array( + $dotenv = Loader::load([ 'filepath' => $this->fixturePath . '.env', - )); - $this->assertEquals(array( + ]); + $this->assertEquals([ 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ), $dotenv->toArray()); + ], $dotenv->toArray()); - $dotenv = Loader::load(array( - 'filepaths' => array($this->fixturePath . '.env'), - )); - $this->assertEquals(array( + $dotenv = Loader::load([ + 'filepaths' => [$this->fixturePath . '.env'], + ]); + $this->assertEquals([ 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ), $dotenv->toArray()); + ], $dotenv->toArray()); - $dotenv = Loader::load(array( - 'filepaths' => array( + $dotenv = Loader::load([ + 'filepaths' => [ $this->fixturePath . '.env.nonexistent', $this->fixturePath . '.env', - ), - )); - $this->assertEquals(array( + ], + ]); + $this->assertEquals([ 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ), $dotenv->toArray()); + ], $dotenv->toArray()); - $dotenv = Loader::load(array( + $dotenv = Loader::load([ 'filepath' => $this->fixturePath . '.env', 'prefix' => 'PREFIX_' - )); - $this->assertEquals(array( + ]); + $this->assertEquals([ 'PREFIX_FOO' => 'bar', 'PREFIX_BAR' => 'baz', 'PREFIX_SPACED' => 'with spaces', 'PREFIX_EQUALS' => 'pgsql:host=localhost;dbname=test', - ), $dotenv->toArray()); + ], $dotenv->toArray()); - $dotenv = Loader::load(array( + $dotenv = Loader::load([ 'filepath' => $this->fixturePath . 'url_parse_filter.env', - 'filters' => array('josegonzalez\Dotenv\Filter\UrlParseFilter'), - )); - $this->assertSame(array( + 'filters' => ['josegonzalez\Dotenv\Filter\UrlParseFilter'], + ]); + $this->assertSame([ 'READ_DATABASE_URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'READ_DATABASE_SCHEME' => 'mysql', 'READ_DATABASE_HOST' => 'localhost', @@ -1171,18 +1180,18 @@ public function testStatic(): void 'DATABASE_PATH' => '/database_name', 'DATABASE_QUERY' => 'encoding=utf8', 'DATABASE_FRAGMENT' => '', - ), $dotenv->toArray()); + ], $dotenv->toArray()); } /** * Call a protected method on an object * - * @param object $object object + * @param object $obj object * @param string $name method to call - * @param array $args arguments to pass to the method + * @param array $args arguments to pass to the method * @return mixed */ - public function protectedMethodCall($obj, $name, array $args) + public function protectedMethodCall(object $obj, string $name, array $args = []) { $class = new \ReflectionClass($obj); $method = $class->getMethod($name); From 5ddb91ed5e5e7ee1821ddcf51bf3ce9c4e2fc455 Mon Sep 17 00:00:00 2001 From: Brian French Date: Wed, 15 Feb 2023 19:18:29 -0500 Subject: [PATCH 03/42] Update ci.yml --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df71fd8..de79813 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['5.5', '5.6', '7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + php-version: ['7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] name: Test PHP ${{ matrix.php-version }} steps: @@ -38,7 +38,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['5.5', '5.6', '7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + php-version: ['7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] name: Coverage PHP ${{ matrix.php-version }} steps: @@ -69,7 +69,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['5.5', '5.6', '7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + php-version: ['7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] name: Coding Standard ${{ matrix.php-version }} steps: @@ -93,7 +93,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['5.5', '5.6', '7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + php-version: ['7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] name: Static Analysis - PHP ${{ matrix.php-version }} steps: From 9d70e50e14ea8e998ef81ea302b81568eaede046 Mon Sep 17 00:00:00 2001 From: Brian French Date: Wed, 15 Feb 2023 19:20:43 -0500 Subject: [PATCH 04/42] Update ci.yml --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de79813..6f761b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,9 @@ on: pull_request: branches: - '*' + push: + branches: + - master permissions: contents: read From 45df3e22137f1e11b9126f91398eb40e0850b989 Mon Sep 17 00:00:00 2001 From: Brian French Date: Wed, 15 Feb 2023 19:23:44 -0500 Subject: [PATCH 05/42] Update ci.yml --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f761b2..74a330c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + php-version: ['7.2', '7.4', '8.0', '8.1', '8.2'] name: Test PHP ${{ matrix.php-version }} steps: @@ -41,7 +41,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + php-version: ['7.2', '7.4', '8.0', '8.1', '8.2'] name: Coverage PHP ${{ matrix.php-version }} steps: @@ -72,7 +72,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + php-version: ['7.2', '7.4', '8.0', '8.1', '8.2'] name: Coding Standard ${{ matrix.php-version }} steps: @@ -96,7 +96,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['7.0', '7.1', '7.4', '8.0', '8.1', '8.2'] + php-version: ['7.2', '7.4', '8.0', '8.1', '8.2'] name: Static Analysis - PHP ${{ matrix.php-version }} steps: From 16da1d620d78c8eef910e2aab326ab1923df2c79 Mon Sep 17 00:00:00 2001 From: Brian French Date: Wed, 15 Feb 2023 19:31:21 -0500 Subject: [PATCH 06/42] Update README.md --- README.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ee97d2c..001e2ef 100644 --- a/README.md +++ b/README.md @@ -13,20 +13,29 @@ A `.env` file parsing and loading library for PHP. ## Requirements -* PHP 5.5+ +* PHP 5.5+|7.2+ ## Installation _[Using [Composer](http://getcomposer.org/)]_ -Run `composer require josegonzalez/dotenv:dev-master` +Run `composer require josegonzalez/dotenv` Or add the plugin to your project's `composer.json` - something like this: -```javascript +For php 5.5 -> 7.4 +```json { "require": { - "josegonzalez/dotenv": "dev-master" + "josegonzalez/dotenv": ~3.2" + } + } +``` +For php 7.4 -> 8.2+ +```json + { + "require": { + "josegonzalez/dotenv": ~4.0" } } ``` From b7dc5704bb828d22c92b7a9cea6b804d8634fe20 Mon Sep 17 00:00:00 2001 From: Brian French Date: Wed, 15 Feb 2023 19:43:22 -0500 Subject: [PATCH 07/42] Updating annotations to be compatibly with phpunit 9.x --- tests/josegonzalez/Dotenv/ExpectTest.php | 6 +-- tests/josegonzalez/Dotenv/LoaderTest.php | 60 ++++++++++-------------- 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index c36af06..bd7c4f9 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -47,12 +47,11 @@ public function testExpect(): void /** * @covers \josegonzalez\Dotenv\Expect::__invoke * @covers \josegonzalez\Dotenv\Expect::raise - * @expectedException LogicException - * @expectedExceptionMessage No arguments were passed to expect() */ public function testExpectLogicException(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('No arguments were passed to expect()'); $expect = new Expect($this->server); $expect(); } @@ -60,12 +59,11 @@ public function testExpectLogicException(): void /** * @covers \josegonzalez\Dotenv\Expect::__invoke * @covers \josegonzalez\Dotenv\Expect::raise - * @expectedException RuntimeException - * @expectedExceptionMessage Required ENV vars missing: ['INVALID'] */ public function testExpectRuntimeException(): void { $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']"); $expect = new Expect($this->server); $expect('INVALID'); } diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index 393f7b7..42c39e3 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -204,49 +204,46 @@ public function testParse(): void /** * @covers \josegonzalez\Dotenv\Loader::parse - * @expectedException M1\Env\Exception\ParseException - * @expectedExceptionMessage Key can only contain alphanumeric - * and underscores and can not start with a number: 01SKIPPED near 01SKIPPED at line 1 + * @expectedExceptionMessage */ public function testParseException(): void { $this->expectException(\M1\Env\Exception\ParseException::class); - $this->Loader->setFilepath($this->fixturePath . 'parse_exception.env'); + $this->expectExceptionMessage('Key can only contain alphanumeric' . + ' and underscores and can not start with a number: 01SKIPPED near 01SKIPPED at line 1'); + $this->Loader->setFilepath($this->fixturePath . 'parse_exception.env '); $this->Loader->parse(); } /** * @covers \josegonzalez\Dotenv\Loader::parse - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Environment file '.env' is not found */ public function testParseFileNotFound(): void { $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("Environment file '.env' is not found"); $this->Loader->setFilepath('.env'); $this->Loader->parse(); } /** * @covers \josegonzalez\Dotenv\Loader::parse - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Environment file '/tmp' is a directory. Should be a file */ public function testParseFileIsDirectory(): void { $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("Environment file '/tmp' is a directory. Should be a file"); $this->Loader->setFilepath('/tmp'); $this->Loader->parse(); } /** * @covers \josegonzalez\Dotenv\Loader::parse - * @expectedException InvalidArgumentException - * @expectedExceptionMessage Environment file '/tmp/php-dotenv-unreadable' is not readable */ public function testParseFileIsUnreadable(): void { $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("Environment file '/tmp/php-dotenv-unreadable' is not readable"); touch('/tmp/php-dotenv-unreadable'); chmod('/tmp/php-dotenv-unreadable', 0000); $this->Loader->setFilepath('/tmp/php-dotenv-unreadable'); @@ -289,12 +286,11 @@ function () { /** * @covers \josegonzalez\Dotenv\Loader::setFilters - * @expectedException LogicException - * @expectedExceptionMessage Invalid filter class SomeFilter */ public function testSetFilterNonexistentFilter(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Invalid filter class SomeFilter'); $this->assertEquals($this->Loader, $this->Loader->setFilters([ 'SomeFilter' ])); @@ -302,12 +298,11 @@ public function testSetFilterNonexistentFilter(): void /** * @covers \josegonzalez\Dotenv\Loader::setFilters - * @expectedException LogicException - * @expectedExceptionMessage Invalid filter class */ public function testSetFilterInvalidCallable(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Invalid filter class'); $this->assertEquals($this->Loader, $this->Loader->setFilters([ $this ])); @@ -551,35 +546,33 @@ public function testExpect(): void } /** - * @expectedException LogicException - * @expectedExceptionMessage Environment must be parsed before calling expect() + * @covers \josegonzalez\Dotenv\Loader::expect With no parsing done yet. */ public function testExpectRequireParse(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Environment must be parsed before calling expect()'); $this->Loader->expect(); } /** * @covers \josegonzalez\Dotenv\Loader::expect - * @expectedException LogicException - * @expectedExceptionMessage No arguments were passed to expect() */ public function testExpectLogicException(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('No arguments were passed to expect()'); $this->Loader->parse(); $this->Loader->expect(); } /** * @covers \josegonzalez\Dotenv\Loader::expect - * @expectedException RuntimeException - * @expectedExceptionMessage Required ENV vars missing: ['INVALID'] */ public function testExpectRuntimeException(): void { $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']"); $this->Loader->parse(); $this->Loader->expect('INVALID'); } @@ -673,8 +666,6 @@ function ($key, $value) { /** * @covers \josegonzalez\Dotenv\Loader::apacheSetenv - * @expectedException LogicException - * @expectedExceptionMessage Key "FOO" has already been defined in apache_getenv() */ public function testToApacheSetenvException(): void { @@ -700,6 +691,7 @@ function ($key, $value) { ); $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Key "FOO" has already been defined in apache_getenv()'); $this->Loader->parse(); $this->Loader->apacheSetenv(false); $this->Loader->apacheSetenv(false); @@ -778,12 +770,11 @@ public function testDefineSkip(): void /** * @covers \josegonzalez\Dotenv\Loader::define - * @expectedException LogicException - * @expectedExceptionMessage Key "FOO" has already been defined */ public function testDefineException(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Key "FOO" has already been defined'); $this->Loader->parse(); $this->Loader->define(); } @@ -820,12 +811,11 @@ public function testToPutenvSkip(): void /** * @covers \josegonzalez\Dotenv\Loader::putenv - * @expectedException LogicException - * @expectedExceptionMessage Key "FOO" has already been defined in getenv() */ public function testToPutenvException(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Key "FOO" has already been defined in getenv()'); $this->Loader->parse(); $this->Loader->putenv(false); $this->Loader->putenv(false); @@ -883,12 +873,11 @@ public function testToEnvSkip(): void /** * @covers \josegonzalez\Dotenv\Loader::toEnv - * @expectedException LogicException - * @expectedExceptionMessage Key "FOO" has already been defined in $_ENV */ public function testToEnvException(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Key "FOO" has already been defined in $_ENV'); $this->Loader->parse(); $this->Loader->toEnv(false); $this->Loader->toEnv(false); @@ -946,12 +935,11 @@ public function testToServerSkip(): void /** * @covers \josegonzalez\Dotenv\Loader::toServer - * @expectedException LogicException - * @expectedExceptionMessage Key "FOO" has already been defined in $_SERVER */ public function testToServerException(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Key "FOO" has already been defined in $_SERVER'); $this->Loader->parse(); $this->Loader->toServer(false); $this->Loader->toServer(false); @@ -1025,12 +1013,12 @@ public function testToArray(): void } /** - * @expectedException LogicException - * @expectedExceptionMessage Environment must be parsed before calling toArray() + * @covers \josegonzalez\Dotenv\Loader::toArray With no parsing done yet. */ public function testToArrayRequireParse(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Environment must be parsed before calling toArray()'); $this->Loader->toArray(); } @@ -1058,12 +1046,12 @@ public function testRequireParse(): void } /** - * @expectedException LogicException - * @expectedExceptionMessage Environment must be parsed before calling toEnv() + * @covers \josegonzalez\Dotenv\Loader::requireParse With no parsing done yet. */ public function testRequireParseException(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Environment must be parsed before calling toEnv()'); $this->protectedMethodCall($this->Loader, 'requireParse', ['toEnv']); } @@ -1078,12 +1066,12 @@ public function testRequireParseNoException(): void } /** - * @expectedException LogicException - * @expectedExceptionMessage derp + * @covers \josegonzalez\Dotenv\Loader::raise */ public function testRaise(): void { $this->expectException(\LogicException::class); + $this->expectExceptionMessage('derp'); $this->protectedMethodCall($this->Loader, 'raise', ['LogicException', 'derp']); } From aa33e8f11a17075a974c3478630e1619313771fc Mon Sep 17 00:00:00 2001 From: Brian French Date: Wed, 15 Feb 2023 19:54:23 -0500 Subject: [PATCH 08/42] Tests passing locally. --- src/josegonzalez/Dotenv/Loader.php | 2 +- tests/josegonzalez/Dotenv/LoaderTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/josegonzalez/Dotenv/Loader.php b/src/josegonzalez/Dotenv/Loader.php index c9b83c9..2593cb8 100644 --- a/src/josegonzalez/Dotenv/Loader.php +++ b/src/josegonzalez/Dotenv/Loader.php @@ -256,7 +256,7 @@ public function filter() */ public function parse() { - $contents = ''; + $contents = false; $filepaths = $this->filepaths(); foreach ($filepaths as $i => $filepath) { diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index 42c39e3..c100439 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -211,7 +211,7 @@ public function testParseException(): void $this->expectException(\M1\Env\Exception\ParseException::class); $this->expectExceptionMessage('Key can only contain alphanumeric' . ' and underscores and can not start with a number: 01SKIPPED near 01SKIPPED at line 1'); - $this->Loader->setFilepath($this->fixturePath . 'parse_exception.env '); + $this->Loader->setFilepath($this->fixturePath . 'parse_exception.env'); $this->Loader->parse(); } @@ -1122,6 +1122,7 @@ public function testStatic(): void ], $dotenv->toArray()); $dotenv = Loader::load([ + 'raiseExceptions' => true, 'filepaths' => [ $this->fixturePath . '.env.nonexistent', $this->fixturePath . '.env', From f9a7ea914f2d27404b4b4fd6c24ec09049a2b2a1 Mon Sep 17 00:00:00 2001 From: Brian French Date: Wed, 15 Feb 2023 20:24:16 -0500 Subject: [PATCH 09/42] Bug fix for php 8.2.2 --- .github/workflows/ci.yml | 116 +++++++++++++++++++++++++++++ .travis.yml | 23 ------ composer.json | 12 +++ src/josegonzalez/Dotenv/Expect.php | 2 + 4 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a8d0e21 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,116 @@ +name: CI + +on: + pull_request: + branches: + - '*' + push: + branches: + - master + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] + name: Test PHP ${{ matrix.php-version }} + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + coverage: none + + - name: Composer install + run: composer install + + - name: Run PHPUnit + run: composer run-script test + + coverage-php: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] + name: Coverage PHP ${{ matrix.php-version }} + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + coverage: pcov + + - name: Composer install + run: composer install + + - name: Run PHPUnit + run: composer run-script coverage-clover + + - name: Upload to Codecov + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODE_COV_TOKEN }} + files: ./tmp/coverage.xml + verbose: true + + coding-standard: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] + name: Coding Standard ${{ matrix.php-version }} + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + coverage: none + + - name: Composer install + run: composer install + + - name: Run PHP CodeSniffer + run: composer run-script cs-checkstyle | vendor/bin/cs2pr + + static-analysis: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] + name: Static Analysis - PHP ${{ matrix.php-version }} + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl + coverage: none + + - name: Composer install + run: composer install + + - name: Run PHP Analyzer + run: composer run-script phpstan-github \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 231644f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -language: php - -php: - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - hhvm - -matrix: - allow_failures: - - php: hhvm - -before_script: - - composer self-update - - composer install - -script: - - vendor/bin/phpcs --standard=psr2 src/ - - phpunit --coverage-text --coverage-clover build/logs/clover.xml - -after_success: - - if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then php vendor/bin/coveralls -v; fi diff --git a/composer.json b/composer.json index 347e6d4..4a76cc4 100644 --- a/composer.json +++ b/composer.json @@ -26,5 +26,17 @@ "psr-0": { "josegonzalez\\Dotenv": ["src", "tests"] } + }, + "scripts": { + "ci": [ + "@cs-check", + "@test" + ], + "cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 ./src ./tests", + "cs-checkstyle": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --report=checkstyle ./src ./tests", + "cs-fix": "php -d memory_limit=-1 ./vendor/bin/phpcbf --standard=psr2 ./src ./tests", + "test": "php -d memory_limit=-1 ./vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml", + "coverage-clover": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-clover=tmp/coverage.xml --testdox", + "coveralls": "php -d memory_limit=-1 ./vendor/bin/vendor/bin/coveralls -v" } } diff --git a/src/josegonzalez/Dotenv/Expect.php b/src/josegonzalez/Dotenv/Expect.php index 7389f1a..4d6a6cd 100644 --- a/src/josegonzalez/Dotenv/Expect.php +++ b/src/josegonzalez/Dotenv/Expect.php @@ -7,6 +7,8 @@ class Expect { + protected $environment = []; + protected $raise = true; public function __construct($environment, $raise = true) From f1244bdf28fc02d731c8e5f9eedbd9afd37ef8d3 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 14:19:58 -0500 Subject: [PATCH 10/42] Update ci.yml --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8d0e21..2f5fc2a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: - '*' push: branches: - - master + - '*' permissions: contents: read @@ -35,7 +35,7 @@ jobs: - name: Run PHPUnit run: composer run-script test - + coverage-php: runs-on: ubuntu-22.04 strategy: @@ -113,4 +113,4 @@ jobs: run: composer install - name: Run PHP Analyzer - run: composer run-script phpstan-github \ No newline at end of file + run: composer run-script phpstan-github From b884833b2c19b0798dc5febda099555ba93956f7 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 14:34:35 -0500 Subject: [PATCH 11/42] Updating package requirements and github actions. --- .github/workflows/ci.yml | 24 ------------------------ composer.json | 6 +++--- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f5fc2a..9fc9774 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -90,27 +90,3 @@ jobs: - name: Run PHP CodeSniffer run: composer run-script cs-checkstyle | vendor/bin/cs2pr - - static-analysis: - runs-on: ubuntu-22.04 - strategy: - fail-fast: false - matrix: - php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] - name: Static Analysis - PHP ${{ matrix.php-version }} - - steps: - - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, intl - coverage: none - - - name: Composer install - run: composer install - - - name: Run PHP Analyzer - run: composer run-script phpstan-github diff --git a/composer.json b/composer.json index 4a76cc4..b409cf1 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,9 @@ "m1/env": "2.*" }, "require-dev": { - "squizlabs/php_codesniffer": "2.*", - "satooshi/php-coveralls": "1.*", - "php-mock/php-mock-phpunit": "^1.1" + "squizlabs/php_codesniffer": "~2.9||~3.7", + "php-coveralls/php-coveralls": "~2.0", + "php-mock/php-mock-phpunit": "~1.1||~2.0" }, "autoload": { "psr-0": { From f75c5cdbb5012c0b03f75401617ac430693693ee Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 14:39:26 -0500 Subject: [PATCH 12/42] CS Updates --- composer.json | 2 +- tests/josegonzalez/Dotenv/ExpectTest.php | 1 - tests/josegonzalez/Dotenv/LoaderTest.php | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index b409cf1..976f364 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "@cs-check", "@test" ], - "cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 ./src ./tests", + "cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --exclude=Generic.Files.LineLength ./src ./tests", "cs-checkstyle": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --report=checkstyle ./src ./tests", "cs-fix": "php -d memory_limit=-1 ./vendor/bin/phpcbf --standard=psr2 ./src ./tests", "test": "php -d memory_limit=-1 ./vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml", diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index 0cd5c7c..ac04dd1 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -61,5 +61,4 @@ public function testExpectRuntimeException() $expect = new Expect($this->server); $expect('INVALID'); } - } diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index b3894c5..f890037 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -22,7 +22,6 @@ public function setUp() $this->fixturePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR; $this->Loader = new Loader($this->fixturePath . '.env'); $GLOBALS['apache_test_data'] = array(); - } public function tearDown() From 7465f1008150338a24946ec6698ab174080db172 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 14:41:14 -0500 Subject: [PATCH 13/42] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9fc9774..066705e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,4 +89,4 @@ jobs: run: composer install - name: Run PHP CodeSniffer - run: composer run-script cs-checkstyle | vendor/bin/cs2pr + run: composer run-script cs-check From ba29d1e7feca50f99fe3780df9519976bc9ada8a Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 14:48:40 -0500 Subject: [PATCH 14/42] See if this will work for php 5.x --- tests/josegonzalez/Dotenv/ExpectTest.php | 2 +- tests/josegonzalez/Dotenv/LoaderTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index ac04dd1..e0db461 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -3,7 +3,7 @@ namespace josegonzalez\Dotenv; use josegonzalez\Dotenv\Expect; -use \PHPUnit_Framework_TestCase; +use \PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase; class ExpectTest extends PHPUnit_Framework_TestCase { diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index f890037..6b9c61e 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -4,7 +4,7 @@ use josegonzalez\Dotenv\Loader; use phpmock\phpunit\PHPMock; -use PHPUnit_Framework_TestCase; +use \PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase; function doNothing($data) { From 8177f1cd765a2fe02df86e89bbd6445f799b2c21 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 15:12:46 -0500 Subject: [PATCH 15/42] Closer to being compatible with 5.x -> 8.x --- .gitignore | 1 + phpunit.xml | 14 --- src/josegonzalez/Dotenv/Loader.php | 2 + tests/josegonzalez/Dotenv/ExpectTest.php | 20 +++- tests/josegonzalez/Dotenv/LoaderTest.php | 133 ++++++++++++++++++++++- 5 files changed, 151 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index ed30b22..74d37e6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build composer.lock tmp vendor +.phpunit.result.cache diff --git a/phpunit.xml b/phpunit.xml index b055268..63336b0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="./tests/bootstrap.php" > @@ -15,17 +14,4 @@ tests/josegonzalez/Dotenv - - - ./docs - ./vendor - ./tests/bootstrap.php - - - - src - - diff --git a/src/josegonzalez/Dotenv/Loader.php b/src/josegonzalez/Dotenv/Loader.php index a9519e3..f5d8e33 100644 --- a/src/josegonzalez/Dotenv/Loader.php +++ b/src/josegonzalez/Dotenv/Loader.php @@ -13,6 +13,8 @@ class Loader protected $environment = null; + protected $exceptions = array(); + protected $filepaths = null; protected $filters = array(); diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index e0db461..cb46e94 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -7,14 +7,25 @@ class ExpectTest extends PHPUnit_Framework_TestCase { + protected $env = array(); - public function setUp() + protected $server = array(); + + /** + * Hopefully this will allow php > 7.1 to run. + * Phpunit >= *.0 uses setUp(): void which this needs to match, but will break php 5.x + */ + public function _setUp() { $this->env = $_ENV; $this->server = $_SERVER; } - public function tearDown() + /** + * Hopefully this will allow php > 7.1 to run. + * Phpunit >= *.0 uses tearDown(): void which this needs to match, but will break php 5.x + */ + public function _tearDown() { $_ENV = $this->env; $_SERVER = $this->server; @@ -29,6 +40,7 @@ public function tearDown() */ public function testExpect() { + $this->_setUp(); $expect = new Expect($this->server); $this->assertTrue($expect('USER')); $this->assertTrue($expect(array('USER', 'HOME'))); @@ -46,8 +58,10 @@ public function testExpect() */ public function testExpectLogicException() { + $this->_setUp(); $expect = new Expect($this->server); $expect(); + $this->_tearDown(); } /** @@ -58,7 +72,9 @@ public function testExpectLogicException() */ public function testExpectRuntimeException() { + $this->_setUp(); $expect = new Expect($this->server); $expect('INVALID'); + $this->_tearDown(); } } diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index 6b9c61e..13cb77b 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -14,8 +14,19 @@ function doNothing($data) class LoaderTest extends PHPUnit_Framework_TestCase { use PHPMock; + protected $env = []; - public function setUp() + protected $server = []; + + protected $fixturePath = ''; + + protected $Loader; + + /** + * Hopefully this will allow php > 7.1 to run. + * Phpunit >= *.0 uses setUp(): void which this needs to match, but will break php 5.x + */ + public function _setUp() { $this->env = $_ENV; $this->server = $_SERVER; @@ -24,7 +35,11 @@ public function setUp() $GLOBALS['apache_test_data'] = array(); } - public function tearDown() + /** + * Hopefully this will allow php > 7.1 to run. + * Phpunit >= *.0 uses tearDown(): void which this needs to match, but will break php 5.x + */ + public function _tearDown() { $_ENV = $this->env; $_SERVER = $this->server; @@ -39,7 +54,9 @@ public function tearDown() */ public function testFilepath() { + $this->_setUp(); $this->assertEquals($this->fixturePath . '.env', $this->Loader->filepath()); + $this->_tearDown(); } /** @@ -47,7 +64,9 @@ public function testFilepath() */ public function testFilepaths() { + $this->_setUp(); $this->assertEquals(array($this->fixturePath . '.env'), $this->Loader->filepaths()); + $this->_tearDown(); } /** @@ -56,6 +75,7 @@ public function testFilepaths() */ public function testSetFilepath() { + $this->_setUp(); $this->Loader->setFilepath('/tmp/.env'); $this->assertEquals('/tmp/.env', $this->Loader->filepath()); @@ -66,6 +86,7 @@ public function testSetFilepath() 'src' . DIRECTORY_SEPARATOR . 'josegonzalez' . DIRECTORY_SEPARATOR . 'Dotenv', ))); $this->assertEquals($basePath . DIRECTORY_SEPARATOR .'.env', $this->Loader->filepath()); + $this->_tearDown(); } /** @@ -73,6 +94,7 @@ public function testSetFilepath() */ public function testParse() { + $this->_setUp(); $this->Loader->setFilepath($this->fixturePath . 'all.env'); $this->Loader->parse(); $environment = $this->Loader->toArray(); @@ -168,6 +190,7 @@ public function testParse() $this->assertEquals('mail://localhost/?from=you@localhost', $environment['EMAIL_URL']); $this->assertEquals('smtp://user:secret@localhost:25/?from[site@localhost]=My+Site&timeout=30', $environment['EMAIL_SMTP_URL']); $this->assertEquals('smtp://user:secret@localhost:25/?from=you@localhost&messageId=1&template=0&layout=0&timeout=30', $environment['EMAIL_FAST_URL']); + $this->_tearDown(); } @@ -178,8 +201,10 @@ public function testParse() */ public function testParseException() { + $this->_setUp(); $this->Loader->setFilepath($this->fixturePath . 'parse_exception.env'); $this->Loader->parse(); + $this->_tearDown(); } /** @@ -189,8 +214,10 @@ public function testParseException() */ public function testParseFileNotFound() { + $this->_setUp(); $this->Loader->setFilepath('.env'); $this->Loader->parse(); + $this->_tearDown(); } /** @@ -200,8 +227,10 @@ public function testParseFileNotFound() */ public function testParseFileIsDirectory() { + $this->_setUp(); $this->Loader->setFilepath('/tmp'); $this->Loader->parse(); + $this->_tearDown(); } /** @@ -211,10 +240,12 @@ public function testParseFileIsDirectory() */ public function testParseFileIsUnreadable() { + $this->_setUp(); touch('/tmp/php-dotenv-unreadable'); chmod('/tmp/php-dotenv-unreadable', 0000); $this->Loader->setFilepath('/tmp/php-dotenv-unreadable'); $this->Loader->parse(); + $this->_tearDown(); } /** @@ -222,7 +253,9 @@ public function testParseFileIsUnreadable() */ public function testFilters() { + $this->_setUp(); $this->assertSame(array(), $this->Loader->filters()); + $this->_tearDown(); } /** @@ -230,6 +263,7 @@ public function testFilters() */ public function testSetFilters() { + $this->_setUp(); $this->assertSame(array(), $this->Loader->filters()); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', @@ -249,6 +283,7 @@ function () { return array(); } ))); + $this->_tearDown(); } /** @@ -258,9 +293,11 @@ function () { */ public function testSetFilterNonexistentFilter() { + $this->_setUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'SomeFilter' ))); + $this->_tearDown(); } /** @@ -270,9 +307,11 @@ public function testSetFilterNonexistentFilter() */ public function testSetFilterInvalidCallable() { + $this->_setUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( $this ))); + $this->_tearDown(); } /** @@ -281,6 +320,7 @@ public function testSetFilterInvalidCallable() */ public function testFilter() { + $this->_setUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', ))); @@ -292,6 +332,7 @@ public function testFilter() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->_tearDown(); } @@ -301,6 +342,7 @@ public function testFilter() */ public function testFilterCallable() { + $this->_setUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( function () { return array('FOO' => 'BAR'); @@ -309,6 +351,7 @@ function () { $this->Loader->parse(); $this->Loader->filter(); $this->assertEquals(array('FOO' => 'BAR'), $this->Loader->toArray()); + $this->_tearDown(); } /** @@ -316,6 +359,7 @@ function () { */ public function testLowercaseKeyFilter() { + $this->_setUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', )); @@ -328,6 +372,7 @@ public function testLowercaseKeyFilter() 'spaced' => 'with spaces', 'equals' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->_tearDown(); } /** @@ -335,6 +380,7 @@ public function testLowercaseKeyFilter() */ public function testNullFilter() { + $this->_setUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', )); @@ -347,6 +393,7 @@ public function testNullFilter() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->_tearDown(); } @@ -355,6 +402,7 @@ public function testNullFilter() */ public function testRemapKeysFilter() { + $this->_setUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\RemapKeysFilter' => array( 'FOO' => 'QUX' @@ -369,6 +417,7 @@ public function testRemapKeysFilter() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->_tearDown(); } /** @@ -376,6 +425,7 @@ public function testRemapKeysFilter() */ public function testUppercaseFirstKeyFilter() { + $this->_setUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', 'josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter', @@ -389,6 +439,7 @@ public function testUppercaseFirstKeyFilter() 'Spaced' => 'with spaces', 'Equals' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->_tearDown(); } /** @@ -397,6 +448,7 @@ public function testUppercaseFirstKeyFilter() */ public function testUrlParseFilter() { + $this->_setUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UrlParseFilter', )); @@ -424,6 +476,7 @@ public function testUrlParseFilter() 'DATABASE_QUERY' => 'encoding=utf8', 'DATABASE_FRAGMENT' => '', ), $environment); + $this->_tearDown(); } /** @@ -431,6 +484,7 @@ public function testUrlParseFilter() */ public function testUnderscoreArrayFilter() { + $this->_setUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter', )); @@ -457,6 +511,7 @@ public function testUnderscoreArrayFilter() ), ), $environment); + $this->_tearDown(); } /** @@ -466,6 +521,7 @@ public function testUnderscoreArrayFilter() */ public function testMultipleFilters() { + $this->_setUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UrlParseFilter', 'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter', @@ -500,6 +556,7 @@ public function testMultipleFilters() ), ), ), $environment); + $this->_tearDown(); } /** @@ -507,9 +564,11 @@ public function testMultipleFilters() */ public function testExpect() { + $this->_setUp(); $this->Loader->parse(); $this->assertInstanceOf('josegonzalez\Dotenv\Loader', $this->Loader->expect('FOO')); $this->assertInstanceOf('josegonzalez\Dotenv\Loader', $this->Loader->expect(array('FOO', 'BAR'))); + $this->_tearDown(); } /** @@ -518,7 +577,9 @@ public function testExpect() */ public function testExpectRequireParse() { + $this->_setUp(); $this->Loader->expect(); + $this->_tearDown(); } /** @@ -528,8 +589,10 @@ public function testExpectRequireParse() */ public function testExpectLogicException() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->expect(); + $this->_tearDown(); } /** @@ -539,8 +602,10 @@ public function testExpectLogicException() */ public function testExpectRuntimeException() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->expect('INVALID'); + $this->_tearDown(); } /** @@ -548,6 +613,7 @@ public function testExpectRuntimeException() */ public function testToApacheSetenvExceptionUnavailable() { + $this->_setUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } @@ -556,6 +622,7 @@ public function testToApacheSetenvExceptionUnavailable() $this->expectExceptionMessage('Call to undefined function josegonzalez\Dotenv\apache_getenv()'); $this->Loader->parse(); $this->Loader->apacheSetenv(false); + $this->_tearDown(); } /** @@ -563,6 +630,7 @@ public function testToApacheSetenvExceptionUnavailable() */ public function testToApacheSetenv() { + $this->_setUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } @@ -591,6 +659,7 @@ function ($key, $value) { $this->assertEquals('baz', apache_getenv('BAR')); $this->assertEquals('with spaces', apache_getenv('SPACED')); $this->assertEquals('pgsql:host=localhost;dbname=test', apache_getenv('EQUALS')); + $this->_tearDown(); } /** @@ -598,6 +667,7 @@ function ($key, $value) { */ public function testToApacheSetenvSkip() { + $this->_setUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } @@ -628,6 +698,7 @@ function ($key, $value) { $this->assertEquals('baz', apache_getenv('BAR')); $this->assertEquals('with spaces', apache_getenv('SPACED')); $this->assertEquals('pgsql:host=localhost;dbname=test', apache_getenv('EQUALS')); + $this->_tearDown(); } /** @@ -637,6 +708,7 @@ function ($key, $value) { */ public function testToApacheSetenvException() { + $this->_setUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } @@ -661,6 +733,7 @@ function ($key, $value) { $this->Loader->parse(); $this->Loader->apacheSetenv(false); $this->Loader->apacheSetenv(false); + $this->_tearDown(); } @@ -669,6 +742,7 @@ function ($key, $value) { */ public function testToApacheSetenvPreserveZeros() { + $this->_setUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } @@ -703,6 +777,7 @@ function ($key, $value) { $this->assertEquals('', apache_getenv('Z_BOOL')); $this->assertEquals('', apache_getenv('Z_STRING')); $this->assertEquals('', apache_getenv('Z_NULLABLE')); + $this->_tearDown(); } /** @@ -710,6 +785,7 @@ function ($key, $value) { */ public function testDefine() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->define(); @@ -717,6 +793,7 @@ public function testDefine() $this->assertEquals('baz', BAR); $this->assertEquals('with spaces', SPACED); $this->assertEquals('pgsql:host=localhost;dbname=test', EQUALS); + $this->_tearDown(); } /** @@ -724,6 +801,7 @@ public function testDefine() */ public function testDefineSkip() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->skipExisting('define'); $this->Loader->define(); @@ -732,6 +810,7 @@ public function testDefineSkip() $this->assertEquals('baz', BAR); $this->assertEquals('with spaces', SPACED); $this->assertEquals('pgsql:host=localhost;dbname=test', EQUALS); + $this->_tearDown(); } /** @@ -741,8 +820,10 @@ public function testDefineSkip() */ public function testDefineException() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->define(); + $this->_tearDown(); } /** @@ -750,6 +831,7 @@ public function testDefineException() */ public function testToPutenv() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->putenv(false); @@ -757,6 +839,7 @@ public function testToPutenv() $this->assertEquals('baz', getenv('BAR')); $this->assertEquals('with spaces', getenv('SPACED')); $this->assertEquals('pgsql:host=localhost;dbname=test', getenv('EQUALS')); + $this->_tearDown(); } /** @@ -764,6 +847,7 @@ public function testToPutenv() */ public function testToPutenvSkip() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->skipExisting('putenv'); $this->Loader->putenv(false); @@ -773,6 +857,7 @@ public function testToPutenvSkip() $this->assertEquals('baz', getenv('BAR')); $this->assertEquals('with spaces', getenv('SPACED')); $this->assertEquals('pgsql:host=localhost;dbname=test', getenv('EQUALS')); + $this->_tearDown(); } /** @@ -782,9 +867,11 @@ public function testToPutenvSkip() */ public function testToPutenvException() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->putenv(false); $this->Loader->putenv(false); + $this->_tearDown(); } /** @@ -792,6 +879,7 @@ public function testToPutenvException() */ public function testToPutenvPreserveZeros() { + $this->_setUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); $this->Loader->putenv(false); @@ -805,6 +893,7 @@ public function testToPutenvPreserveZeros() $this->assertEquals('', getenv('Z_BOOL')); $this->assertEquals('', getenv('Z_STRING')); $this->assertEquals('', getenv('Z_NULLABLE')); + $this->_tearDown(); } /** @@ -812,6 +901,7 @@ public function testToPutenvPreserveZeros() */ public function testToEnv() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->toEnv(false); @@ -819,6 +909,7 @@ public function testToEnv() $this->assertEquals('baz', $_ENV['BAR']); $this->assertEquals('with spaces', $_ENV['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']); + $this->_tearDown(); } /** @@ -826,6 +917,7 @@ public function testToEnv() */ public function testToEnvSkip() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->skipExisting('toEnv'); $this->Loader->toEnv(false); @@ -835,6 +927,7 @@ public function testToEnvSkip() $this->assertEquals('baz', $_ENV['BAR']); $this->assertEquals('with spaces', $_ENV['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']); + $this->_tearDown(); } /** @@ -844,9 +937,11 @@ public function testToEnvSkip() */ public function testToEnvException() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->toEnv(false); $this->Loader->toEnv(false); + $this->_tearDown(); } /** @@ -854,6 +949,7 @@ public function testToEnvException() */ public function testToEnvPreserveZeros() { + $this->_setUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); $this->Loader->toEnv(false); @@ -867,6 +963,7 @@ public function testToEnvPreserveZeros() $this->assertEquals(false, $_ENV['Z_BOOL']); $this->assertEquals('', $_ENV['Z_STRING']); $this->assertEquals(null, $_ENV['Z_NULLABLE']); + $this->_tearDown(); } /** @@ -874,6 +971,7 @@ public function testToEnvPreserveZeros() */ public function testToServer() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->toServer(false); @@ -881,6 +979,7 @@ public function testToServer() $this->assertEquals('baz', $_SERVER['BAR']); $this->assertEquals('with spaces', $_SERVER['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_SERVER['EQUALS']); + $this->_tearDown(); } /** @@ -888,6 +987,7 @@ public function testToServer() */ public function testToServerSkip() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->skipExisting('toServer'); $this->Loader->toServer(false); @@ -897,6 +997,7 @@ public function testToServerSkip() $this->assertEquals('baz', $_SERVER['BAR']); $this->assertEquals('with spaces', $_SERVER['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_SERVER['EQUALS']); + $this->_tearDown(); } /** @@ -906,9 +1007,11 @@ public function testToServerSkip() */ public function testToServerException() { + $this->_setUp(); $this->Loader->parse(); $this->Loader->toServer(false); $this->Loader->toServer(false); + $this->_tearDown(); } /** @@ -916,6 +1019,7 @@ public function testToServerException() */ public function testToServerPreserveZeros() { + $this->_setUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); $this->Loader->toServer(false); @@ -929,6 +1033,7 @@ public function testToServerPreserveZeros() $this->assertEquals(false, $_SERVER['Z_BOOL']); $this->assertEquals('', $_SERVER['Z_STRING']); $this->assertEquals(null, $_SERVER['Z_NULLABLE']); + $this->_tearDown(); } /** @@ -937,6 +1042,7 @@ public function testToServerPreserveZeros() */ public function testSkipExisting() { + $this->_setUp(); $this->assertEquals(array(), $this->Loader->skipped()); $this->Loader->skipExisting('toEnv'); @@ -947,6 +1053,7 @@ public function testSkipExisting() $this->Loader->skipExisting(); $this->assertEquals(array('apacheSetenv', 'define', 'putenv', 'toEnv', 'toServer'), $this->Loader->skipped()); + $this->_tearDown(); } /** @@ -955,6 +1062,7 @@ public function testSkipExisting() */ public function testPrefix() { + $this->_setUp(); $this->assertEquals('KEY', $this->Loader->prefixed('KEY')); $this->Loader->prefix('PREFIX_'); @@ -962,6 +1070,7 @@ public function testPrefix() $this->Loader->prefix('PREFIX_TWO_'); $this->assertEquals('PREFIX_TWO_KEY', $this->Loader->prefixed('KEY')); + $this->_tearDown(); } /** @@ -969,6 +1078,7 @@ public function testPrefix() */ public function testToArray() { + $this->_setUp(); $this->Loader->parse(); $this->assertEquals(array( 'FOO' => 'bar', @@ -976,6 +1086,7 @@ public function testToArray() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->_tearDown(); } /** @@ -984,7 +1095,9 @@ public function testToArray() */ public function testToArrayRequireParse() { + $this->_setUp(); $this->Loader->toArray(); + $this->_tearDown(); } /** @@ -992,10 +1105,12 @@ public function testToArrayRequireParse() */ public function testToString() { + $this->_setUp(); $this->assertEquals('[]', $this->Loader->__toString()); $this->Loader->parse(); $this->assertEquals('{"FOO":"bar","BAR":"baz","SPACED":"with spaces","EQUALS":"pgsql:host=localhost;dbname=test"}', $this->Loader->__toString()); + $this->_tearDown(); } /** @@ -1003,8 +1118,10 @@ public function testToString() */ public function testRequireParse() { + $this->_setUp(); $this->Loader->parse(); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); + $this->_tearDown(); } /** @@ -1013,7 +1130,9 @@ public function testRequireParse() */ public function testRequireParseException() { + $this->_setUp(); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); + $this->_tearDown(); } /** @@ -1021,8 +1140,10 @@ public function testRequireParseException() */ public function testRequireParseNoException() { + $this->_setUp(); $this->Loader->raiseExceptions(false); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); + $this->_tearDown(); } /** @@ -1031,7 +1152,9 @@ public function testRequireParseNoException() */ public function testRaise() { + $this->_setUp(); $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp')); + $this->_tearDown(); } /** @@ -1040,12 +1163,15 @@ public function testRaise() */ public function testRaiseNoException() { + $this->_setUp(); $this->Loader->raiseExceptions(false); $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp')); + $this->_tearDown(); } public function testStatic() { + $this->_setUp(); $dotenv = Loader::load(array( 'raiseExceptions' => false )); @@ -1127,12 +1253,13 @@ public function testStatic() 'DATABASE_QUERY' => 'encoding=utf8', 'DATABASE_FRAGMENT' => '', ), $dotenv->toArray()); + $this->_tearDown(); } /** * Call a protected method on an object * - * @param Object $object object + * @param object $obj object * @param string $name method to call * @param array $args arguments to pass to the method * @return mixed From c2079f70658df2018be7dcde2bb674a983b106f8 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 15:29:06 -0500 Subject: [PATCH 16/42] It didn't like the '_' prefix. --- .github/workflows/ci.yml | 40 ++-- tests/josegonzalez/Dotenv/ExpectTest.php | 14 +- tests/josegonzalez/Dotenv/LoaderTest.php | 228 +++++++++++------------ 3 files changed, 141 insertions(+), 141 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 066705e..7019bb9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,13 +12,13 @@ permissions: contents: read jobs: - test: + coding-standard: runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] - name: Test PHP ${{ matrix.php-version }} + name: Coding Standard ${{ matrix.php-version }} steps: - uses: actions/checkout@v3 @@ -33,16 +33,16 @@ jobs: - name: Composer install run: composer install - - name: Run PHPUnit - run: composer run-script test + - name: Run PHP CodeSniffer + run: composer run-script cs-check - coverage-php: + test: runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] - name: Coverage PHP ${{ matrix.php-version }} + name: Test PHP ${{ matrix.php-version }} steps: - uses: actions/checkout@v3 @@ -52,28 +52,21 @@ jobs: with: php-version: ${{ matrix.php-version }} extensions: mbstring, intl - coverage: pcov + coverage: none - name: Composer install run: composer install - name: Run PHPUnit - run: composer run-script coverage-clover - - - name: Upload to Codecov - uses: codecov/codecov-action@v2 - with: - token: ${{ secrets.CODE_COV_TOKEN }} - files: ./tmp/coverage.xml - verbose: true + run: composer run-script test - coding-standard: + coverage-php: runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] - name: Coding Standard ${{ matrix.php-version }} + name: Coverage PHP ${{ matrix.php-version }} steps: - uses: actions/checkout@v3 @@ -83,10 +76,17 @@ jobs: with: php-version: ${{ matrix.php-version }} extensions: mbstring, intl - coverage: none + coverage: pcov - name: Composer install run: composer install - - name: Run PHP CodeSniffer - run: composer run-script cs-check + - name: Run PHPUnit + run: composer run-script coverage-clover + + - name: Upload to Codecov + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODE_COV_TOKEN }} + files: ./tmp/coverage.xml + verbose: true diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index cb46e94..f4762d8 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -15,7 +15,7 @@ class ExpectTest extends PHPUnit_Framework_TestCase * Hopefully this will allow php > 7.1 to run. * Phpunit >= *.0 uses setUp(): void which this needs to match, but will break php 5.x */ - public function _setUp() + public function compatibleSetUp() { $this->env = $_ENV; $this->server = $_SERVER; @@ -25,7 +25,7 @@ public function _setUp() * Hopefully this will allow php > 7.1 to run. * Phpunit >= *.0 uses tearDown(): void which this needs to match, but will break php 5.x */ - public function _tearDown() + public function compatibleTearDown() { $_ENV = $this->env; $_SERVER = $this->server; @@ -40,7 +40,7 @@ public function _tearDown() */ public function testExpect() { - $this->_setUp(); + $this->compatibleSetUp(); $expect = new Expect($this->server); $this->assertTrue($expect('USER')); $this->assertTrue($expect(array('USER', 'HOME'))); @@ -58,10 +58,10 @@ public function testExpect() */ public function testExpectLogicException() { - $this->_setUp(); + $this->compatibleSetUp(); $expect = new Expect($this->server); $expect(); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -72,9 +72,9 @@ public function testExpectLogicException() */ public function testExpectRuntimeException() { - $this->_setUp(); + $this->compatibleSetUp(); $expect = new Expect($this->server); $expect('INVALID'); - $this->_tearDown(); + $this->compatibleTearDown(); } } diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index 13cb77b..9bd7e09 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -26,7 +26,7 @@ class LoaderTest extends PHPUnit_Framework_TestCase * Hopefully this will allow php > 7.1 to run. * Phpunit >= *.0 uses setUp(): void which this needs to match, but will break php 5.x */ - public function _setUp() + public function compatibleSetUp() { $this->env = $_ENV; $this->server = $_SERVER; @@ -39,7 +39,7 @@ public function _setUp() * Hopefully this will allow php > 7.1 to run. * Phpunit >= *.0 uses tearDown(): void which this needs to match, but will break php 5.x */ - public function _tearDown() + public function compatibleTearDown() { $_ENV = $this->env; $_SERVER = $this->server; @@ -54,9 +54,9 @@ public function _tearDown() */ public function testFilepath() { - $this->_setUp(); + $this->compatibleSetUp(); $this->assertEquals($this->fixturePath . '.env', $this->Loader->filepath()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -64,9 +64,9 @@ public function testFilepath() */ public function testFilepaths() { - $this->_setUp(); + $this->compatibleSetUp(); $this->assertEquals(array($this->fixturePath . '.env'), $this->Loader->filepaths()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -75,7 +75,7 @@ public function testFilepaths() */ public function testSetFilepath() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilepath('/tmp/.env'); $this->assertEquals('/tmp/.env', $this->Loader->filepath()); @@ -86,7 +86,7 @@ public function testSetFilepath() 'src' . DIRECTORY_SEPARATOR . 'josegonzalez' . DIRECTORY_SEPARATOR . 'Dotenv', ))); $this->assertEquals($basePath . DIRECTORY_SEPARATOR .'.env', $this->Loader->filepath()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -94,7 +94,7 @@ public function testSetFilepath() */ public function testParse() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilepath($this->fixturePath . 'all.env'); $this->Loader->parse(); $environment = $this->Loader->toArray(); @@ -190,7 +190,7 @@ public function testParse() $this->assertEquals('mail://localhost/?from=you@localhost', $environment['EMAIL_URL']); $this->assertEquals('smtp://user:secret@localhost:25/?from[site@localhost]=My+Site&timeout=30', $environment['EMAIL_SMTP_URL']); $this->assertEquals('smtp://user:secret@localhost:25/?from=you@localhost&messageId=1&template=0&layout=0&timeout=30', $environment['EMAIL_FAST_URL']); - $this->_tearDown(); + $this->compatibleTearDown(); } @@ -201,10 +201,10 @@ public function testParse() */ public function testParseException() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilepath($this->fixturePath . 'parse_exception.env'); $this->Loader->parse(); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -214,10 +214,10 @@ public function testParseException() */ public function testParseFileNotFound() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilepath('.env'); $this->Loader->parse(); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -227,10 +227,10 @@ public function testParseFileNotFound() */ public function testParseFileIsDirectory() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilepath('/tmp'); $this->Loader->parse(); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -240,12 +240,12 @@ public function testParseFileIsDirectory() */ public function testParseFileIsUnreadable() { - $this->_setUp(); + $this->compatibleSetUp(); touch('/tmp/php-dotenv-unreadable'); chmod('/tmp/php-dotenv-unreadable', 0000); $this->Loader->setFilepath('/tmp/php-dotenv-unreadable'); $this->Loader->parse(); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -253,9 +253,9 @@ public function testParseFileIsUnreadable() */ public function testFilters() { - $this->_setUp(); + $this->compatibleSetUp(); $this->assertSame(array(), $this->Loader->filters()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -263,7 +263,7 @@ public function testFilters() */ public function testSetFilters() { - $this->_setUp(); + $this->compatibleSetUp(); $this->assertSame(array(), $this->Loader->filters()); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', @@ -283,7 +283,7 @@ function () { return array(); } ))); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -293,11 +293,11 @@ function () { */ public function testSetFilterNonexistentFilter() { - $this->_setUp(); + $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'SomeFilter' ))); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -307,11 +307,11 @@ public function testSetFilterNonexistentFilter() */ public function testSetFilterInvalidCallable() { - $this->_setUp(); + $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( $this ))); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -320,7 +320,7 @@ public function testSetFilterInvalidCallable() */ public function testFilter() { - $this->_setUp(); + $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', ))); @@ -332,7 +332,7 @@ public function testFilter() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); - $this->_tearDown(); + $this->compatibleTearDown(); } @@ -342,7 +342,7 @@ public function testFilter() */ public function testFilterCallable() { - $this->_setUp(); + $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( function () { return array('FOO' => 'BAR'); @@ -351,7 +351,7 @@ function () { $this->Loader->parse(); $this->Loader->filter(); $this->assertEquals(array('FOO' => 'BAR'), $this->Loader->toArray()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -359,7 +359,7 @@ function () { */ public function testLowercaseKeyFilter() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', )); @@ -372,7 +372,7 @@ public function testLowercaseKeyFilter() 'spaced' => 'with spaces', 'equals' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -380,7 +380,7 @@ public function testLowercaseKeyFilter() */ public function testNullFilter() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', )); @@ -393,7 +393,7 @@ public function testNullFilter() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); - $this->_tearDown(); + $this->compatibleTearDown(); } @@ -402,7 +402,7 @@ public function testNullFilter() */ public function testRemapKeysFilter() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\RemapKeysFilter' => array( 'FOO' => 'QUX' @@ -417,7 +417,7 @@ public function testRemapKeysFilter() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -425,7 +425,7 @@ public function testRemapKeysFilter() */ public function testUppercaseFirstKeyFilter() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', 'josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter', @@ -439,7 +439,7 @@ public function testUppercaseFirstKeyFilter() 'Spaced' => 'with spaces', 'Equals' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -448,7 +448,7 @@ public function testUppercaseFirstKeyFilter() */ public function testUrlParseFilter() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UrlParseFilter', )); @@ -476,7 +476,7 @@ public function testUrlParseFilter() 'DATABASE_QUERY' => 'encoding=utf8', 'DATABASE_FRAGMENT' => '', ), $environment); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -484,7 +484,7 @@ public function testUrlParseFilter() */ public function testUnderscoreArrayFilter() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter', )); @@ -511,7 +511,7 @@ public function testUnderscoreArrayFilter() ), ), $environment); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -521,7 +521,7 @@ public function testUnderscoreArrayFilter() */ public function testMultipleFilters() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UrlParseFilter', 'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter', @@ -556,7 +556,7 @@ public function testMultipleFilters() ), ), ), $environment); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -564,11 +564,11 @@ public function testMultipleFilters() */ public function testExpect() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->assertInstanceOf('josegonzalez\Dotenv\Loader', $this->Loader->expect('FOO')); $this->assertInstanceOf('josegonzalez\Dotenv\Loader', $this->Loader->expect(array('FOO', 'BAR'))); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -577,9 +577,9 @@ public function testExpect() */ public function testExpectRequireParse() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->expect(); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -589,10 +589,10 @@ public function testExpectRequireParse() */ public function testExpectLogicException() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->expect(); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -602,10 +602,10 @@ public function testExpectLogicException() */ public function testExpectRuntimeException() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->expect('INVALID'); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -613,7 +613,7 @@ public function testExpectRuntimeException() */ public function testToApacheSetenvExceptionUnavailable() { - $this->_setUp(); + $this->compatibleSetUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } @@ -622,7 +622,7 @@ public function testToApacheSetenvExceptionUnavailable() $this->expectExceptionMessage('Call to undefined function josegonzalez\Dotenv\apache_getenv()'); $this->Loader->parse(); $this->Loader->apacheSetenv(false); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -630,7 +630,7 @@ public function testToApacheSetenvExceptionUnavailable() */ public function testToApacheSetenv() { - $this->_setUp(); + $this->compatibleSetUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } @@ -659,7 +659,7 @@ function ($key, $value) { $this->assertEquals('baz', apache_getenv('BAR')); $this->assertEquals('with spaces', apache_getenv('SPACED')); $this->assertEquals('pgsql:host=localhost;dbname=test', apache_getenv('EQUALS')); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -667,7 +667,7 @@ function ($key, $value) { */ public function testToApacheSetenvSkip() { - $this->_setUp(); + $this->compatibleSetUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } @@ -698,7 +698,7 @@ function ($key, $value) { $this->assertEquals('baz', apache_getenv('BAR')); $this->assertEquals('with spaces', apache_getenv('SPACED')); $this->assertEquals('pgsql:host=localhost;dbname=test', apache_getenv('EQUALS')); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -708,7 +708,7 @@ function ($key, $value) { */ public function testToApacheSetenvException() { - $this->_setUp(); + $this->compatibleSetUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } @@ -733,7 +733,7 @@ function ($key, $value) { $this->Loader->parse(); $this->Loader->apacheSetenv(false); $this->Loader->apacheSetenv(false); - $this->_tearDown(); + $this->compatibleTearDown(); } @@ -742,7 +742,7 @@ function ($key, $value) { */ public function testToApacheSetenvPreserveZeros() { - $this->_setUp(); + $this->compatibleSetUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } @@ -777,7 +777,7 @@ function ($key, $value) { $this->assertEquals('', apache_getenv('Z_BOOL')); $this->assertEquals('', apache_getenv('Z_STRING')); $this->assertEquals('', apache_getenv('Z_NULLABLE')); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -785,7 +785,7 @@ function ($key, $value) { */ public function testDefine() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->define(); @@ -793,7 +793,7 @@ public function testDefine() $this->assertEquals('baz', BAR); $this->assertEquals('with spaces', SPACED); $this->assertEquals('pgsql:host=localhost;dbname=test', EQUALS); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -801,7 +801,7 @@ public function testDefine() */ public function testDefineSkip() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->skipExisting('define'); $this->Loader->define(); @@ -810,7 +810,7 @@ public function testDefineSkip() $this->assertEquals('baz', BAR); $this->assertEquals('with spaces', SPACED); $this->assertEquals('pgsql:host=localhost;dbname=test', EQUALS); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -820,10 +820,10 @@ public function testDefineSkip() */ public function testDefineException() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->define(); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -831,7 +831,7 @@ public function testDefineException() */ public function testToPutenv() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->putenv(false); @@ -839,7 +839,7 @@ public function testToPutenv() $this->assertEquals('baz', getenv('BAR')); $this->assertEquals('with spaces', getenv('SPACED')); $this->assertEquals('pgsql:host=localhost;dbname=test', getenv('EQUALS')); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -847,7 +847,7 @@ public function testToPutenv() */ public function testToPutenvSkip() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->skipExisting('putenv'); $this->Loader->putenv(false); @@ -857,7 +857,7 @@ public function testToPutenvSkip() $this->assertEquals('baz', getenv('BAR')); $this->assertEquals('with spaces', getenv('SPACED')); $this->assertEquals('pgsql:host=localhost;dbname=test', getenv('EQUALS')); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -867,11 +867,11 @@ public function testToPutenvSkip() */ public function testToPutenvException() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->putenv(false); $this->Loader->putenv(false); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -879,7 +879,7 @@ public function testToPutenvException() */ public function testToPutenvPreserveZeros() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); $this->Loader->putenv(false); @@ -893,7 +893,7 @@ public function testToPutenvPreserveZeros() $this->assertEquals('', getenv('Z_BOOL')); $this->assertEquals('', getenv('Z_STRING')); $this->assertEquals('', getenv('Z_NULLABLE')); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -901,7 +901,7 @@ public function testToPutenvPreserveZeros() */ public function testToEnv() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->toEnv(false); @@ -909,7 +909,7 @@ public function testToEnv() $this->assertEquals('baz', $_ENV['BAR']); $this->assertEquals('with spaces', $_ENV['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -917,7 +917,7 @@ public function testToEnv() */ public function testToEnvSkip() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->skipExisting('toEnv'); $this->Loader->toEnv(false); @@ -927,7 +927,7 @@ public function testToEnvSkip() $this->assertEquals('baz', $_ENV['BAR']); $this->assertEquals('with spaces', $_ENV['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -937,11 +937,11 @@ public function testToEnvSkip() */ public function testToEnvException() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->toEnv(false); $this->Loader->toEnv(false); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -949,7 +949,7 @@ public function testToEnvException() */ public function testToEnvPreserveZeros() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); $this->Loader->toEnv(false); @@ -963,7 +963,7 @@ public function testToEnvPreserveZeros() $this->assertEquals(false, $_ENV['Z_BOOL']); $this->assertEquals('', $_ENV['Z_STRING']); $this->assertEquals(null, $_ENV['Z_NULLABLE']); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -971,7 +971,7 @@ public function testToEnvPreserveZeros() */ public function testToServer() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->toServer(false); @@ -979,7 +979,7 @@ public function testToServer() $this->assertEquals('baz', $_SERVER['BAR']); $this->assertEquals('with spaces', $_SERVER['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_SERVER['EQUALS']); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -987,7 +987,7 @@ public function testToServer() */ public function testToServerSkip() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->skipExisting('toServer'); $this->Loader->toServer(false); @@ -997,7 +997,7 @@ public function testToServerSkip() $this->assertEquals('baz', $_SERVER['BAR']); $this->assertEquals('with spaces', $_SERVER['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_SERVER['EQUALS']); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1007,11 +1007,11 @@ public function testToServerSkip() */ public function testToServerException() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->toServer(false); $this->Loader->toServer(false); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1019,7 +1019,7 @@ public function testToServerException() */ public function testToServerPreserveZeros() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); $this->Loader->toServer(false); @@ -1033,7 +1033,7 @@ public function testToServerPreserveZeros() $this->assertEquals(false, $_SERVER['Z_BOOL']); $this->assertEquals('', $_SERVER['Z_STRING']); $this->assertEquals(null, $_SERVER['Z_NULLABLE']); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1042,7 +1042,7 @@ public function testToServerPreserveZeros() */ public function testSkipExisting() { - $this->_setUp(); + $this->compatibleSetUp(); $this->assertEquals(array(), $this->Loader->skipped()); $this->Loader->skipExisting('toEnv'); @@ -1053,7 +1053,7 @@ public function testSkipExisting() $this->Loader->skipExisting(); $this->assertEquals(array('apacheSetenv', 'define', 'putenv', 'toEnv', 'toServer'), $this->Loader->skipped()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1062,7 +1062,7 @@ public function testSkipExisting() */ public function testPrefix() { - $this->_setUp(); + $this->compatibleSetUp(); $this->assertEquals('KEY', $this->Loader->prefixed('KEY')); $this->Loader->prefix('PREFIX_'); @@ -1070,7 +1070,7 @@ public function testPrefix() $this->Loader->prefix('PREFIX_TWO_'); $this->assertEquals('PREFIX_TWO_KEY', $this->Loader->prefixed('KEY')); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1078,7 +1078,7 @@ public function testPrefix() */ public function testToArray() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->assertEquals(array( 'FOO' => 'bar', @@ -1086,7 +1086,7 @@ public function testToArray() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1095,9 +1095,9 @@ public function testToArray() */ public function testToArrayRequireParse() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->toArray(); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1105,12 +1105,12 @@ public function testToArrayRequireParse() */ public function testToString() { - $this->_setUp(); + $this->compatibleSetUp(); $this->assertEquals('[]', $this->Loader->__toString()); $this->Loader->parse(); $this->assertEquals('{"FOO":"bar","BAR":"baz","SPACED":"with spaces","EQUALS":"pgsql:host=localhost;dbname=test"}', $this->Loader->__toString()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1118,10 +1118,10 @@ public function testToString() */ public function testRequireParse() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->parse(); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1130,9 +1130,9 @@ public function testRequireParse() */ public function testRequireParseException() { - $this->_setUp(); + $this->compatibleSetUp(); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1140,10 +1140,10 @@ public function testRequireParseException() */ public function testRequireParseNoException() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->raiseExceptions(false); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1152,9 +1152,9 @@ public function testRequireParseNoException() */ public function testRaise() { - $this->_setUp(); + $this->compatibleSetUp(); $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp')); - $this->_tearDown(); + $this->compatibleTearDown(); } /** @@ -1163,15 +1163,15 @@ public function testRaise() */ public function testRaiseNoException() { - $this->_setUp(); + $this->compatibleSetUp(); $this->Loader->raiseExceptions(false); $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp')); - $this->_tearDown(); + $this->compatibleTearDown(); } public function testStatic() { - $this->_setUp(); + $this->compatibleSetUp(); $dotenv = Loader::load(array( 'raiseExceptions' => false )); @@ -1253,7 +1253,7 @@ public function testStatic() 'DATABASE_QUERY' => 'encoding=utf8', 'DATABASE_FRAGMENT' => '', ), $dotenv->toArray()); - $this->_tearDown(); + $this->compatibleTearDown(); } /** From bae6a0850a9c99a8b260494afabb9790545caa4f Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 15:47:39 -0500 Subject: [PATCH 17/42] Trying to be compatible with more phpunit versions. --- src/josegonzalez/Dotenv/Loader.php | 1 - tests/josegonzalez/Dotenv/ExpectTest.php | 8 +++ tests/josegonzalez/Dotenv/LoaderTest.php | 71 +++++++++++++++++++++++- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/src/josegonzalez/Dotenv/Loader.php b/src/josegonzalez/Dotenv/Loader.php index f5d8e33..2fd4b00 100644 --- a/src/josegonzalez/Dotenv/Loader.php +++ b/src/josegonzalez/Dotenv/Loader.php @@ -34,7 +34,6 @@ class Loader public function __construct($filepaths = null) { $this->setFilepaths($filepaths); - return $this; } public static function load($options = null) diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index f4762d8..77533ad 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -58,6 +58,10 @@ public function testExpect() */ public function testExpectLogicException() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('No arguments were passed to expect()'); + } $this->compatibleSetUp(); $expect = new Expect($this->server); $expect(); @@ -72,6 +76,10 @@ public function testExpectLogicException() */ public function testExpectRuntimeException() { + if (method_exists($this, 'expectException')) { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']"); + } $this->compatibleSetUp(); $expect = new Expect($this->server); $expect('INVALID'); diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index 9bd7e09..b4ed52a 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -201,6 +201,11 @@ public function testParse() */ public function testParseException() { + if (method_exists($this, 'expectException')) { + $this->expectException(\M1\Env\Exception\ParseException::class); + $this->expectExceptionMessage('Key can only contain alphanumeric' . + ' and underscores and can not start with a number: 01SKIPPED near 01SKIPPED at line 1'); + } $this->compatibleSetUp(); $this->Loader->setFilepath($this->fixturePath . 'parse_exception.env'); $this->Loader->parse(); @@ -214,6 +219,10 @@ public function testParseException() */ public function testParseFileNotFound() { + if (method_exists($this, 'expectException')) { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("Environment file '.env' is not found"); + } $this->compatibleSetUp(); $this->Loader->setFilepath('.env'); $this->Loader->parse(); @@ -227,6 +236,10 @@ public function testParseFileNotFound() */ public function testParseFileIsDirectory() { + if (method_exists($this, 'expectException')) { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("Environment file '/tmp' is a directory. Should be a file"); + } $this->compatibleSetUp(); $this->Loader->setFilepath('/tmp'); $this->Loader->parse(); @@ -240,6 +253,10 @@ public function testParseFileIsDirectory() */ public function testParseFileIsUnreadable() { + if (method_exists($this, 'expectException')) { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("Environment file '/tmp/php-dotenv-unreadable' is not readable"); + } $this->compatibleSetUp(); touch('/tmp/php-dotenv-unreadable'); chmod('/tmp/php-dotenv-unreadable', 0000); @@ -293,6 +310,10 @@ function () { */ public function testSetFilterNonexistentFilter() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Invalid filter class SomeFilter'); + } $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'SomeFilter' @@ -307,6 +328,10 @@ public function testSetFilterNonexistentFilter() */ public function testSetFilterInvalidCallable() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Invalid filter class'); + } $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( $this @@ -577,6 +602,10 @@ public function testExpect() */ public function testExpectRequireParse() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Environment must be parsed before calling expect()'); + } $this->compatibleSetUp(); $this->Loader->expect(); $this->compatibleTearDown(); @@ -589,6 +618,10 @@ public function testExpectRequireParse() */ public function testExpectLogicException() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('No arguments were passed to expect()'); + } $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->expect(); @@ -602,6 +635,10 @@ public function testExpectLogicException() */ public function testExpectRuntimeException() { + if (method_exists($this, 'expectException')) { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']"); + } $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->expect('INVALID'); @@ -708,10 +745,14 @@ function ($key, $value) { */ public function testToApacheSetenvException() { - $this->compatibleSetUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Key "FOO" has already been defined in apache_getenv()'); + } + $this->compatibleSetUp(); $apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv'); $apacheGetenv->expects($this->any())->willReturnCallback( @@ -820,6 +861,10 @@ public function testDefineSkip() */ public function testDefineException() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Key "FOO" has already been defined'); + } $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->define(); @@ -867,6 +912,10 @@ public function testToPutenvSkip() */ public function testToPutenvException() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Key "FOO" has already been defined in getenv()'); + } $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->putenv(false); @@ -937,6 +986,10 @@ public function testToEnvSkip() */ public function testToEnvException() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Key "FOO" has already been defined in $_ENV'); + } $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->toEnv(false); @@ -1007,6 +1060,10 @@ public function testToServerSkip() */ public function testToServerException() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Key "FOO" has already been defined in $_SERVER'); + } $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->toServer(false); @@ -1095,6 +1152,10 @@ public function testToArray() */ public function testToArrayRequireParse() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Environment must be parsed before calling toArray()'); + } $this->compatibleSetUp(); $this->Loader->toArray(); $this->compatibleTearDown(); @@ -1130,6 +1191,10 @@ public function testRequireParse() */ public function testRequireParseException() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Environment must be parsed before calling toEnv()'); + } $this->compatibleSetUp(); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); $this->compatibleTearDown(); @@ -1152,6 +1217,10 @@ public function testRequireParseNoException() */ public function testRaise() { + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('derp'); + } $this->compatibleSetUp(); $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp')); $this->compatibleTearDown(); From e9ddfb35238ff2d17b855a131a28b1c17aad00d9 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 15:50:10 -0500 Subject: [PATCH 18/42] Update LoaderTest.php --- tests/josegonzalez/Dotenv/LoaderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index b4ed52a..2a47db8 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -175,8 +175,8 @@ public function testParse() $this->Loader->parse(); $environment = $this->Loader->toArray(); $this->assertEquals('app', $environment['APP_NAME']); + $this->assertIsInt($environment['DEBUG']); $this->assertSame(2, $environment['DEBUG']); - $this->assertInternalType('int', $environment['DEBUG']); $this->assertEquals('DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi', $environment['SECURITY_SALT']); $this->assertEquals('76859309657453542496749683645', $environment['SECURITY_CIPHER_SEED']); $this->assertEquals('mysql://user:password@localhost/database_name?encoding=utf8', $environment['DATABASE_URL']); From 8ae90f82faf864f44148970a57d43a8eac3db078 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 15:58:33 -0500 Subject: [PATCH 19/42] Update LoaderTest.php --- tests/josegonzalez/Dotenv/LoaderTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index 2a47db8..9bb43f5 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -176,7 +176,10 @@ public function testParse() $environment = $this->Loader->toArray(); $this->assertEquals('app', $environment['APP_NAME']); $this->assertIsInt($environment['DEBUG']); - $this->assertSame(2, $environment['DEBUG']); + if (method_exists($this, 'assertInternalType')) { + $this->assertInternalType('int', $environment['DEBUG']); + } + $this->assertSame(2, $environment['DEBUG']); // this also tests the typecast, in this case, an int. $this->assertEquals('DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi', $environment['SECURITY_SALT']); $this->assertEquals('76859309657453542496749683645', $environment['SECURITY_CIPHER_SEED']); $this->assertEquals('mysql://user:password@localhost/database_name?encoding=utf8', $environment['DATABASE_URL']); From c43cb9c33bd56b595b2b05247798e1b1a73e2718 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 16:00:43 -0500 Subject: [PATCH 20/42] Forgot to remove that. --- tests/josegonzalez/Dotenv/LoaderTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index 9bb43f5..5e09bc7 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -175,7 +175,6 @@ public function testParse() $this->Loader->parse(); $environment = $this->Loader->toArray(); $this->assertEquals('app', $environment['APP_NAME']); - $this->assertIsInt($environment['DEBUG']); if (method_exists($this, 'assertInternalType')) { $this->assertInternalType('int', $environment['DEBUG']); } From f8e80bec9c70fc615719ce9dd1b7ba0711c8484f Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 16:02:46 -0500 Subject: [PATCH 21/42] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7019bb9..e755b2a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] + php-version: ['5.5', '5.6', '7.2', '7.4', '8.0', '8.1', '8.2'] # removed 7.1 as it seems to have an issue with no code coverage driver. name: Coverage PHP ${{ matrix.php-version }} steps: From fc6159d43a5df407c85027c87fd502339c1a8e19 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 16:49:31 -0500 Subject: [PATCH 22/42] Trying to get coverage to work - get it to work with either coveralls or codecov. --- .gitignore | 2 + composer.json | 4 +- phpunit.xml | 42 ++- phpunit.xml.old | 17 ++ tests/josegonzalez/Dotenv/ExpectTest.php | 2 + tests/josegonzalez/Dotenv/LoaderTest.php | 353 +++++++++++++++++++++++ 6 files changed, 402 insertions(+), 18 deletions(-) create mode 100644 phpunit.xml.old diff --git a/.gitignore b/.gitignore index 74d37e6..804b73b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ composer.lock tmp vendor .phpunit.result.cache +/.phpunit.cache +coverage.xml diff --git a/composer.json b/composer.json index 976f364..61b3a9c 100644 --- a/composer.json +++ b/composer.json @@ -35,8 +35,8 @@ "cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --exclude=Generic.Files.LineLength ./src ./tests", "cs-checkstyle": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --report=checkstyle ./src ./tests", "cs-fix": "php -d memory_limit=-1 ./vendor/bin/phpcbf --standard=psr2 ./src ./tests", - "test": "php -d memory_limit=-1 ./vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml", - "coverage-clover": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-clover=tmp/coverage.xml --testdox", + "test": "php -d memory_limit=-1 ./vendor/bin/phpunit --testdox", + "coverage-clover": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml --testdox", "coveralls": "php -d memory_limit=-1 ./vendor/bin/vendor/bin/coveralls -v" } } diff --git a/phpunit.xml b/phpunit.xml index 63336b0..18e59c6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,17 +1,27 @@ - - - - - tests/josegonzalez/Dotenv - - + + + + + tests + + + + + + src + + diff --git a/phpunit.xml.old b/phpunit.xml.old new file mode 100644 index 0000000..63336b0 --- /dev/null +++ b/phpunit.xml.old @@ -0,0 +1,17 @@ + + + + + tests/josegonzalez/Dotenv + + + diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index 77533ad..83ecc13 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -51,6 +51,7 @@ public function testExpect() } /** + * @covers \josegonzalez\Dotenv\Expect::__construct * @covers \josegonzalez\Dotenv\Expect::__invoke * @covers \josegonzalez\Dotenv\Expect::raise * @expectedException LogicException @@ -69,6 +70,7 @@ public function testExpectLogicException() } /** + * @covers \josegonzalez\Dotenv\Expect::__construct * @covers \josegonzalez\Dotenv\Expect::__invoke * @covers \josegonzalez\Dotenv\Expect::raise * @expectedException RuntimeException diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index 5e09bc7..eca6e60 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -50,6 +50,8 @@ public function compatibleTearDown() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::filepath */ public function testFilepath() @@ -60,6 +62,8 @@ public function testFilepath() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::filepaths */ public function testFilepaths() @@ -70,8 +74,10 @@ public function testFilepaths() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct * @covers \josegonzalez\Dotenv\Loader::setFilepath * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::filepath */ public function testSetFilepath() { @@ -90,6 +96,13 @@ public function testSetFilepath() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Loader::parse */ public function testParse() @@ -197,6 +210,10 @@ public function testParse() /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::parse * @expectedException M1\Env\Exception\ParseException * @expectedExceptionMessage Key can only contain alphanumeric and underscores and can not start with a number: 01SKIPPED near 01SKIPPED at line 1 @@ -215,6 +232,11 @@ public function testParseException() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::parse * @expectedException InvalidArgumentException * @expectedExceptionMessage Environment file '.env' is not found @@ -232,6 +254,11 @@ public function testParseFileNotFound() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::parse * @expectedException InvalidArgumentException * @expectedExceptionMessage Environment file '/tmp' is a directory. Should be a file @@ -249,6 +276,11 @@ public function testParseFileIsDirectory() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::parse * @expectedException InvalidArgumentException * @expectedExceptionMessage Environment file '/tmp/php-dotenv-unreadable' is not readable @@ -268,6 +300,8 @@ public function testParseFileIsUnreadable() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::filters */ public function testFilters() @@ -278,6 +312,9 @@ public function testFilters() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filters + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::setFilters */ public function testSetFilters() @@ -306,6 +343,9 @@ function () { } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::setFilters * @expectedException LogicException * @expectedExceptionMessage Invalid filter class SomeFilter @@ -324,6 +364,9 @@ public function testSetFilterNonexistentFilter() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::setFilters * @expectedException LogicException * @expectedExceptionMessage Invalid filter class @@ -342,6 +385,14 @@ public function testSetFilterInvalidCallable() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::setFilters + * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Loader::filter * @covers \josegonzalez\Dotenv\Filter\NullFilter::__invoke */ @@ -364,6 +415,14 @@ public function testFilter() /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::setFilters + * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Loader::filter * @covers \josegonzalez\Dotenv\Filter\CallableFilter::__invoke */ @@ -382,6 +441,16 @@ function () { } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::filter + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::setFilters + * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\LowercaseKeyFilter::__invoke */ public function testLowercaseKeyFilter() @@ -403,6 +472,16 @@ public function testLowercaseKeyFilter() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::filter + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::setFilters + * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\NullFilter::__invoke */ public function testNullFilter() @@ -425,6 +504,16 @@ public function testNullFilter() /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::filter + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::setFilters + * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\RemapKeysFilter::__invoke */ public function testRemapKeysFilter() @@ -448,6 +537,17 @@ public function testRemapKeysFilter() } /** + * @covers \josegonzalez\Dotenv\Filter\LowercaseKeyFilter::__invoke + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::filter + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::setFilters + * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter::__invoke */ public function testUppercaseFirstKeyFilter() @@ -470,6 +570,16 @@ public function testUppercaseFirstKeyFilter() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::filter + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::setFilters + * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::__invoke * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get */ @@ -507,6 +617,16 @@ public function testUrlParseFilter() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::filter + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::setFilters + * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\UnderscoreArrayFilter::__invoke */ public function testUnderscoreArrayFilter() @@ -542,6 +662,16 @@ public function testUnderscoreArrayFilter() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::filter + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepath + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::setFilters + * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::__invoke * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get * @covers \josegonzalez\Dotenv\Filter\UnderscoreArrayFilter::__invoke @@ -587,6 +717,13 @@ public function testMultipleFilters() } /** + * @covers \josegonzalez\Dotenv\Expect::__construct + * @covers \josegonzalez\Dotenv\Expect::__invoke + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::expect */ public function testExpect() @@ -599,6 +736,11 @@ public function testExpect() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::expect * @expectedException LogicException * @expectedExceptionMessage Environment must be parsed before calling expect() */ @@ -614,6 +756,14 @@ public function testExpectRequireParse() } /** + * @covers \josegonzalez\Dotenv\Expect::__construct + * @covers \josegonzalez\Dotenv\Expect::__invoke + * @covers \josegonzalez\Dotenv\Expect::raise + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::expect * @expectedException LogicException * @expectedExceptionMessage No arguments were passed to expect() @@ -631,6 +781,14 @@ public function testExpectLogicException() } /** + * @covers \josegonzalez\Dotenv\Expect::__construct + * @covers \josegonzalez\Dotenv\Expect::__invoke + * @covers \josegonzalez\Dotenv\Expect::raise + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::expect * @expectedException RuntimeException * @expectedExceptionMessage Required ENV vars missing: ['INVALID'] @@ -648,6 +806,12 @@ public function testExpectRuntimeException() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::apacheSetenv */ public function testToApacheSetenvExceptionUnavailable() @@ -665,6 +829,12 @@ public function testToApacheSetenvExceptionUnavailable() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::apacheSetenv */ public function testToApacheSetenv() @@ -702,6 +872,13 @@ function ($key, $value) { } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::apacheSetenv */ public function testToApacheSetenvSkip() @@ -741,6 +918,13 @@ function ($key, $value) { } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::apacheSetenv * @expectedException LogicException * @expectedExceptionMessage Key "FOO" has already been defined in apache_getenv() @@ -781,6 +965,14 @@ function ($key, $value) { /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::apacheSetenv + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::putenv */ public function testToApacheSetenvPreserveZeros() @@ -824,6 +1016,12 @@ function ($key, $value) { } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::define */ public function testDefine() @@ -840,6 +1038,13 @@ public function testDefine() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::define */ public function testDefineSkip() @@ -857,6 +1062,13 @@ public function testDefineSkip() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::define * @expectedException LogicException * @expectedExceptionMessage Key "FOO" has already been defined @@ -874,6 +1086,12 @@ public function testDefineException() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::putenv */ public function testToPutenv() @@ -890,6 +1108,13 @@ public function testToPutenv() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::putenv */ public function testToPutenvSkip() @@ -908,6 +1133,13 @@ public function testToPutenvSkip() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::putenv * @expectedException LogicException * @expectedExceptionMessage Key "FOO" has already been defined in getenv() @@ -926,6 +1158,13 @@ public function testToPutenvException() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::putenv */ public function testToPutenvPreserveZeros() @@ -948,6 +1187,12 @@ public function testToPutenvPreserveZeros() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::toEnv */ public function testToEnv() @@ -964,6 +1209,13 @@ public function testToEnv() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::toEnv */ public function testToEnvSkip() @@ -982,6 +1234,13 @@ public function testToEnvSkip() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::toEnv * @expectedException LogicException * @expectedExceptionMessage Key "FOO" has already been defined in $_ENV @@ -1000,6 +1259,13 @@ public function testToEnvException() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::toEnv */ public function testToEnvPreserveZeros() @@ -1022,6 +1288,12 @@ public function testToEnvPreserveZeros() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::toServer */ public function testToServer() @@ -1038,6 +1310,13 @@ public function testToServer() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::toServer */ public function testToServerSkip() @@ -1056,6 +1335,13 @@ public function testToServerSkip() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::toServer * @expectedException LogicException * @expectedExceptionMessage Key "FOO" has already been defined in $_SERVER @@ -1074,6 +1360,13 @@ public function testToServerException() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::toServer */ public function testToServerPreserveZeros() @@ -1096,6 +1389,8 @@ public function testToServerPreserveZeros() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::skipped * @covers \josegonzalez\Dotenv\Loader::skipExisting */ @@ -1116,6 +1411,8 @@ public function testSkipExisting() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::prefix * @covers \josegonzalez\Dotenv\Loader::prefixed */ @@ -1133,6 +1430,12 @@ public function testPrefix() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::toArray */ public function testToArray() @@ -1149,6 +1452,11 @@ public function testToArray() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::toArray * @expectedException LogicException * @expectedExceptionMessage Environment must be parsed before calling toArray() */ @@ -1164,6 +1472,14 @@ public function testToArrayRequireParse() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Loader::__toString */ public function testToString() @@ -1177,6 +1493,10 @@ public function testToString() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::requireParse */ public function testRequireParse() @@ -1184,10 +1504,15 @@ public function testRequireParse() $this->compatibleSetUp(); $this->Loader->parse(); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); + $this->assertSame(true, true); $this->compatibleTearDown(); } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::requireParse * @expectedException LogicException * @expectedExceptionMessage Environment must be parsed before calling toEnv() */ @@ -1203,6 +1528,10 @@ public function testRequireParseException() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::raiseExceptions */ public function testRequireParseNoException() @@ -1210,10 +1539,14 @@ public function testRequireParseNoException() $this->compatibleSetUp(); $this->Loader->raiseExceptions(false); $this->protectedMethodCall($this->Loader, 'requireParse', array('toEnv')); + $this->assertSame(true, true); $this->compatibleTearDown(); } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::raise * @expectedException LogicException * @expectedExceptionMessage derp */ @@ -1229,6 +1562,8 @@ public function testRaise() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::raiseExceptions * @covers \josegonzalez\Dotenv\Loader::raise */ @@ -1237,9 +1572,27 @@ public function testRaiseNoException() $this->compatibleSetUp(); $this->Loader->raiseExceptions(false); $this->protectedMethodCall($this->Loader, 'raise', array('LogicException', 'derp')); + $this->assertSame(true, true); $this->compatibleTearDown(); } + /** + * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::__invoke + * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filepaths + * @covers \josegonzalez\Dotenv\Loader::filter + * @covers \josegonzalez\Dotenv\Loader::parse + * @covers \josegonzalez\Dotenv\Loader::prefix + * @covers \josegonzalez\Dotenv\Loader::prefixed + * @covers \josegonzalez\Dotenv\Loader::raise + * @covers \josegonzalez\Dotenv\Loader::raiseExceptions + * @covers \josegonzalez\Dotenv\Loader::requireParse + * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::setFilters + * @covers \josegonzalez\Dotenv\Loader::load + * @covers \josegonzalez\Dotenv\Loader::toArray + */ public function testStatic() { $this->compatibleSetUp(); From f64de7ed0e086d176f3c9e19bd3a66181fc940ec Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 17:06:54 -0500 Subject: [PATCH 23/42] Minor updates to the testing. --- .gitignore | 1 + composer.json | 5 +++-- phpunit.xml | 2 +- tests/josegonzalez/Dotenv/ExpectTest.php | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 804b73b..5e779ee 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ vendor .phpunit.result.cache /.phpunit.cache coverage.xml +unitreport.xml diff --git a/composer.json b/composer.json index 61b3a9c..a9d5cd3 100644 --- a/composer.json +++ b/composer.json @@ -30,12 +30,13 @@ "scripts": { "ci": [ "@cs-check", - "@test" + "@test", + "@coverage-clover" ], "cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --exclude=Generic.Files.LineLength ./src ./tests", "cs-checkstyle": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --report=checkstyle ./src ./tests", "cs-fix": "php -d memory_limit=-1 ./vendor/bin/phpcbf --standard=psr2 ./src ./tests", - "test": "php -d memory_limit=-1 ./vendor/bin/phpunit --testdox", + "test": "php -d memory_limit=-1 ./vendor/bin/phpunit --colors=always --log-junit unitreport.xml --testdox", "coverage-clover": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml --testdox", "coveralls": "php -d memory_limit=-1 ./vendor/bin/vendor/bin/coveralls -v" } diff --git a/phpunit.xml b/phpunit.xml index 18e59c6..6916e40 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -9,7 +9,7 @@ beStrictAboutOutputDuringTests="true" beStrictAboutTodoAnnotatedTests="true" convertDeprecationsToExceptions="true" - failOnRisky="true" + failOnRisky="false" failOnWarning="true" verbose="true"> diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index 83ecc13..d83c26b 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -48,6 +48,7 @@ public function testExpect() $expect = new Expect($this->server, false); $this->assertFalse($expect('FOO')); $this->assertFalse($expect(array('USER', 'FOO'))); + $this->compatibleTearDown(); } /** From 6a320f95fbb7f8d9a4fbbf49288ac0fc7554511a Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 17:09:17 -0500 Subject: [PATCH 24/42] Maybe a caching issue? --- phpunit.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 6916e40..75b7022 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,7 +2,6 @@ tests - - - - src - - From c05860073dae5d24dcb626e5aacd425cf5908833 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 17:42:49 -0500 Subject: [PATCH 25/42] See if it's failing elsewhere. --- .github/workflows/ci.yml | 3 +-- phpunit.xml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e755b2a..e6ce760 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,8 +65,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['5.5', '5.6', '7.2', '7.4', '8.0', '8.1', '8.2'] # removed 7.1 as it seems to have an issue with no code coverage driver. - name: Coverage PHP ${{ matrix.php-version }} + php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] steps: - uses: actions/checkout@v3 diff --git a/phpunit.xml b/phpunit.xml index 75b7022..e034265 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,6 +10,7 @@ convertDeprecationsToExceptions="true" failOnRisky="false" failOnWarning="true" + stopOnFailure="false" verbose="true"> From a4ac20bd8b114743d0d33d9a0cef7344ffc975bf Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 17:54:38 -0500 Subject: [PATCH 26/42] Should fix issue with variables already set. --- tests/josegonzalez/Dotenv/ExpectTest.php | 8 +++--- tests/josegonzalez/Dotenv/LoaderTest.php | 33 ++++++++++++------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index d83c26b..5220fad 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -13,7 +13,7 @@ class ExpectTest extends PHPUnit_Framework_TestCase /** * Hopefully this will allow php > 7.1 to run. - * Phpunit >= *.0 uses setUp(): void which this needs to match, but will break php 5.x + * Phpunit >= 8.0 uses setUp(): void which this needs to match, but will break php 5.x */ public function compatibleSetUp() { @@ -23,7 +23,7 @@ public function compatibleSetUp() /** * Hopefully this will allow php > 7.1 to run. - * Phpunit >= *.0 uses tearDown(): void which this needs to match, but will break php 5.x + * Phpunit >= 8.0 uses tearDown(): void which this needs to match, but will break php 5.x */ public function compatibleTearDown() { @@ -60,11 +60,11 @@ public function testExpect() */ public function testExpectLogicException() { + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); $this->expectExceptionMessage('No arguments were passed to expect()'); } - $this->compatibleSetUp(); $expect = new Expect($this->server); $expect(); $this->compatibleTearDown(); @@ -79,11 +79,11 @@ public function testExpectLogicException() */ public function testExpectRuntimeException() { + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']"); } - $this->compatibleSetUp(); $expect = new Expect($this->server); $expect('INVALID'); $this->compatibleTearDown(); diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index eca6e60..026fc4e 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -24,7 +24,7 @@ class LoaderTest extends PHPUnit_Framework_TestCase /** * Hopefully this will allow php > 7.1 to run. - * Phpunit >= *.0 uses setUp(): void which this needs to match, but will break php 5.x + * Phpunit >= 8.0 uses setUp(): void which this needs to match, but will break php 5.x */ public function compatibleSetUp() { @@ -37,7 +37,7 @@ public function compatibleSetUp() /** * Hopefully this will allow php > 7.1 to run. - * Phpunit >= *.0 uses tearDown(): void which this needs to match, but will break php 5.x + * Phpunit >= 8.0 uses tearDown(): void which this needs to match, but will break php 5.x */ public function compatibleTearDown() { @@ -220,12 +220,12 @@ public function testParse() */ public function testParseException() { + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\M1\Env\Exception\ParseException::class); $this->expectExceptionMessage('Key can only contain alphanumeric' . ' and underscores and can not start with a number: 01SKIPPED near 01SKIPPED at line 1'); } - $this->compatibleSetUp(); $this->Loader->setFilepath($this->fixturePath . 'parse_exception.env'); $this->Loader->parse(); $this->compatibleTearDown(); @@ -243,11 +243,11 @@ public function testParseException() */ public function testParseFileNotFound() { + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage("Environment file '.env' is not found"); } - $this->compatibleSetUp(); $this->Loader->setFilepath('.env'); $this->Loader->parse(); $this->compatibleTearDown(); @@ -265,11 +265,11 @@ public function testParseFileNotFound() */ public function testParseFileIsDirectory() { + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage("Environment file '/tmp' is a directory. Should be a file"); } - $this->compatibleSetUp(); $this->Loader->setFilepath('/tmp'); $this->Loader->parse(); $this->compatibleTearDown(); @@ -287,11 +287,11 @@ public function testParseFileIsDirectory() */ public function testParseFileIsUnreadable() { + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage("Environment file '/tmp/php-dotenv-unreadable' is not readable"); } - $this->compatibleSetUp(); touch('/tmp/php-dotenv-unreadable'); chmod('/tmp/php-dotenv-unreadable', 0000); $this->Loader->setFilepath('/tmp/php-dotenv-unreadable'); @@ -352,11 +352,11 @@ function () { */ public function testSetFilterNonexistentFilter() { + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Invalid filter class SomeFilter'); } - $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'SomeFilter' ))); @@ -373,11 +373,11 @@ public function testSetFilterNonexistentFilter() */ public function testSetFilterInvalidCallable() { + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Invalid filter class'); } - $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( $this ))); @@ -746,11 +746,11 @@ public function testExpect() */ public function testExpectRequireParse() { + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Environment must be parsed before calling expect()'); } - $this->compatibleSetUp(); $this->Loader->expect(); $this->compatibleTearDown(); } @@ -770,11 +770,11 @@ public function testExpectRequireParse() */ public function testExpectLogicException() { + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); $this->expectExceptionMessage('No arguments were passed to expect()'); } - $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->expect(); $this->compatibleTearDown(); @@ -795,11 +795,11 @@ public function testExpectLogicException() */ public function testExpectRuntimeException() { + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']"); } - $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->expect('INVALID'); $this->compatibleTearDown(); @@ -816,11 +816,11 @@ public function testExpectRuntimeException() */ public function testToApacheSetenvExceptionUnavailable() { - $this->compatibleSetUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } + $this->compatibleSetUp(); $this->expectException(\Error::class); $this->expectExceptionMessage('Call to undefined function josegonzalez\Dotenv\apache_getenv()'); $this->Loader->parse(); @@ -839,11 +839,11 @@ public function testToApacheSetenvExceptionUnavailable() */ public function testToApacheSetenv() { - $this->compatibleSetUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } + $this->compatibleSetUp(); $apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv'); $apacheGetenv->expects($this->any())->willReturnCallback( function ($key) { @@ -883,11 +883,11 @@ function ($key, $value) { */ public function testToApacheSetenvSkip() { - $this->compatibleSetUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } + $this->compatibleSetUp(); $apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv'); $apacheGetenv->expects($this->any())->willReturnCallback( function ($key) { @@ -934,11 +934,12 @@ public function testToApacheSetenvException() if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } + + $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Key "FOO" has already been defined in apache_getenv()'); } - $this->compatibleSetUp(); $apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv'); $apacheGetenv->expects($this->any())->willReturnCallback( @@ -977,11 +978,11 @@ function ($key, $value) { */ public function testToApacheSetenvPreserveZeros() { - $this->compatibleSetUp(); if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); } + $this->compatibleSetUp(); $apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv'); $apacheGetenv->expects($this->any())->willReturnCallback( function ($key) { From 1546faa41518f7c52244fc8dade5739400555036 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 18:07:23 -0500 Subject: [PATCH 27/42] Try this for phpunit 8 --- .gitignore | 1 + phpunit.xml | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 5e779ee..4d3c86d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ vendor /.phpunit.cache coverage.xml unitreport.xml +.vscode diff --git a/phpunit.xml b/phpunit.xml index e034265..de5aa1d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -17,4 +17,9 @@ tests + + + ./src + + From d8e74c41469e5cac417b9e9bfe5e85d91c450016 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 18:18:01 -0500 Subject: [PATCH 28/42] Update phpunit.xml --- phpunit.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml b/phpunit.xml index de5aa1d..514c1a7 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,6 +11,7 @@ failOnRisky="false" failOnWarning="true" stopOnFailure="false" + backupGlobals="false" verbose="true"> From a6af27848af23c4182a5cdece04834b7e2643867 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 18:19:51 -0500 Subject: [PATCH 29/42] From the original config. --- phpunit.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 514c1a7..fd8447d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,8 +10,14 @@ convertDeprecationsToExceptions="true" failOnRisky="false" failOnWarning="true" - stopOnFailure="false" backupGlobals="false" + backupStaticAttributes="false" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + processIsolation="false" + stopOnFailure="false" verbose="true"> From f4d6156158d2e085b4f6935ee23f1a6d996258bc Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 18:27:49 -0500 Subject: [PATCH 30/42] Will fail, but testing something. --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6ce760..57f25c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,14 +58,15 @@ jobs: run: composer install - name: Run PHPUnit - run: composer run-script test + run: composer run-script test-${{ matrix.php-version }} coverage-php: runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: - php-version: ['5.5', '5.6', '7.1', '7.2', '7.4', '8.0', '8.1', '8.2'] + php-version: ['5.5', '5.6', '7.2', '7.4', '8.0', '8.1', '8.2'] # removed 7.1 as it seems to have an issue with no code coverage driver. + name: Coverage PHP ${{ matrix.php-version }} steps: - uses: actions/checkout@v3 @@ -81,7 +82,7 @@ jobs: run: composer install - name: Run PHPUnit - run: composer run-script coverage-clover + run: composer run-script coverage--${{ matrix.php-version }} - name: Upload to Codecov uses: codecov/codecov-action@v2 From 585dbc95d264b965a9fcbd201f7e2896e5bf922c Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 18:36:39 -0500 Subject: [PATCH 31/42] See if we can use php-specific configs. --- composer.json | 13 ++++++++++++- phpunit.xml.old => phpunit.5.xml | 0 phpunit.7.xml | 31 +++++++++++++++++++++++++++++++ phpunit.8.xml | 13 +++++++++++++ phpunit.xml => phpunit.8.xml.bak | 0 5 files changed, 56 insertions(+), 1 deletion(-) rename phpunit.xml.old => phpunit.5.xml (100%) create mode 100644 phpunit.7.xml create mode 100644 phpunit.8.xml rename phpunit.xml => phpunit.8.xml.bak (100%) diff --git a/composer.json b/composer.json index a9d5cd3..c9247a4 100644 --- a/composer.json +++ b/composer.json @@ -33,10 +33,21 @@ "@test", "@coverage-clover" ], + "test-5.5": "@test-5", + "test-5.6": "@test-5", + "test-7.0": "@test-7", + "test-7.1": "@test-7", + "test-7.2": "@test-7", + "test-8.0": "@test-8", + "test-8.1": "@test-8", + "test-8.2": "@test-8", "cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --exclude=Generic.Files.LineLength ./src ./tests", "cs-checkstyle": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --report=checkstyle ./src ./tests", "cs-fix": "php -d memory_limit=-1 ./vendor/bin/phpcbf --standard=psr2 ./src ./tests", - "test": "php -d memory_limit=-1 ./vendor/bin/phpunit --colors=always --log-junit unitreport.xml --testdox", + "test": "@test-8", + "test-5": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.5.xml --colors=always --log-junit unitreport.xml --testdox", + "test-7": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.7.xml --colors=always --log-junit unitreport.xml --testdox", + "test-8": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.8.xml --colors=always --log-junit unitreport.xml --testdox", "coverage-clover": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml --testdox", "coveralls": "php -d memory_limit=-1 ./vendor/bin/vendor/bin/coveralls -v" } diff --git a/phpunit.xml.old b/phpunit.5.xml similarity index 100% rename from phpunit.xml.old rename to phpunit.5.xml diff --git a/phpunit.7.xml b/phpunit.7.xml new file mode 100644 index 0000000..b055268 --- /dev/null +++ b/phpunit.7.xml @@ -0,0 +1,31 @@ + + + + + tests/josegonzalez/Dotenv + + + + + ./docs + ./vendor + ./tests/bootstrap.php + + + + src + + + diff --git a/phpunit.8.xml b/phpunit.8.xml new file mode 100644 index 0000000..d685d4a --- /dev/null +++ b/phpunit.8.xml @@ -0,0 +1,13 @@ + + + + + ./src + + + + + tests + + + diff --git a/phpunit.xml b/phpunit.8.xml.bak similarity index 100% rename from phpunit.xml rename to phpunit.8.xml.bak From d299310cae20a4fad88f73f17d14d526268105a6 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 18:39:50 -0500 Subject: [PATCH 32/42] Adding coverage --- .github/workflows/ci.yml | 2 +- composer.json | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57f25c8..c7cb144 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,7 @@ jobs: run: composer install - name: Run PHPUnit - run: composer run-script coverage--${{ matrix.php-version }} + run: composer run-script coverage-${{ matrix.php-version }} - name: Upload to Codecov uses: codecov/codecov-action@v2 diff --git a/composer.json b/composer.json index c9247a4..e4f17b2 100644 --- a/composer.json +++ b/composer.json @@ -38,9 +38,19 @@ "test-7.0": "@test-7", "test-7.1": "@test-7", "test-7.2": "@test-7", + "test-7.4": "@test-7", "test-8.0": "@test-8", "test-8.1": "@test-8", "test-8.2": "@test-8", + "coverage-5.5": "@coverage-5", + "coverage-5.6": "@coverage-5", + "coverage-7.0": "@coverage-7", + "coverage-7.1": "@coverage-7", + "coverage-7.2": "@coverage-7", + "coverage-7.4": "@coverage-7", + "coverage-8.0": "@coverage-8", + "coverage-8.1": "@coverage-8", + "coverage-8.2": "@coverage-8", "cs-check": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --exclude=Generic.Files.LineLength ./src ./tests", "cs-checkstyle": "php -d memory_limit=-1 ./vendor/bin/phpcs --standard=psr2 --report=checkstyle ./src ./tests", "cs-fix": "php -d memory_limit=-1 ./vendor/bin/phpcbf --standard=psr2 ./src ./tests", @@ -48,7 +58,9 @@ "test-5": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.5.xml --colors=always --log-junit unitreport.xml --testdox", "test-7": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.7.xml --colors=always --log-junit unitreport.xml --testdox", "test-8": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.8.xml --colors=always --log-junit unitreport.xml --testdox", - "coverage-clover": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml --testdox", + "coverage-5": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.5.xml --coverage-text --coverage-clover=coverage.xml --testdox", + "coverage-7": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.7.xml --coverage-text --coverage-clover=coverage.xml --testdox", + "coverage-8": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.8.xml --coverage-text --coverage-clover=coverage.xml --testdox", "coveralls": "php -d memory_limit=-1 ./vendor/bin/vendor/bin/coveralls -v" } } From 4960665bddd027f1c92d1634ffa2c2fd6b47ffe0 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 18:44:28 -0500 Subject: [PATCH 33/42] Adding for specific phpunit testing. --- phpunit.5.xml | 13 +++++++++++++ phpunit.8.xml | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/phpunit.5.xml b/phpunit.5.xml index 63336b0..c7eb229 100644 --- a/phpunit.5.xml +++ b/phpunit.5.xml @@ -14,4 +14,17 @@ tests/josegonzalez/Dotenv + + + ./docs + ./vendor + ./tests/bootstrap.php + + + + src + + diff --git a/phpunit.8.xml b/phpunit.8.xml index d685d4a..5c67fb0 100644 --- a/phpunit.8.xml +++ b/phpunit.8.xml @@ -7,7 +7,7 @@ - tests + tests/josegonzalez/Dotenv From 9a7ce786944facf4e8bc0ef4624361f60e82399d Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 18:47:09 -0500 Subject: [PATCH 34/42] Fix config warning for 7.x --- phpunit.7.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phpunit.7.xml b/phpunit.7.xml index b055268..3dca3e1 100644 --- a/phpunit.7.xml +++ b/phpunit.7.xml @@ -7,7 +7,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="./tests/bootstrap.php" > @@ -16,11 +15,6 @@ - - ./docs - ./vendor - ./tests/bootstrap.php - From 93e4d8b6d94aa75076a0f3a5044b5dc97c67064f Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 18:51:04 -0500 Subject: [PATCH 35/42] So codecov can find the coverage report. --- .gitignore | 3 ++- composer.json | 6 +++--- tmp/.gitkeep | 0 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 tmp/.gitkeep diff --git a/.gitignore b/.gitignore index 4d3c86d..06f69f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ .DS_Store build composer.lock -tmp +tmp/* +!tmp/.gitkeep vendor .phpunit.result.cache /.phpunit.cache diff --git a/composer.json b/composer.json index e4f17b2..5305cc3 100644 --- a/composer.json +++ b/composer.json @@ -58,9 +58,9 @@ "test-5": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.5.xml --colors=always --log-junit unitreport.xml --testdox", "test-7": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.7.xml --colors=always --log-junit unitreport.xml --testdox", "test-8": "php -d memory_limit=-1 ./vendor/bin/phpunit -c phpunit.8.xml --colors=always --log-junit unitreport.xml --testdox", - "coverage-5": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.5.xml --coverage-text --coverage-clover=coverage.xml --testdox", - "coverage-7": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.7.xml --coverage-text --coverage-clover=coverage.xml --testdox", - "coverage-8": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.8.xml --coverage-text --coverage-clover=coverage.xml --testdox", + "coverage-5": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.5.xml --coverage-text --coverage-clover=./tmp/coverage.xml --testdox", + "coverage-7": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.7.xml --coverage-text --coverage-clover=./tmp/coverage.xml --testdox", + "coverage-8": "php -d memory_limit=-1 -d xdebug.mode=coverage ./vendor/bin/phpunit -c phpunit.8.xml --coverage-text --coverage-clover=./tmp/coverage.xml --testdox", "coveralls": "php -d memory_limit=-1 ./vendor/bin/vendor/bin/coveralls -v" } } diff --git a/tmp/.gitkeep b/tmp/.gitkeep new file mode 100644 index 0000000..e69de29 From 87b2030578bc7c20d83b7035172c47992e3ac68f Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 18:59:17 -0500 Subject: [PATCH 36/42] Allow codecov --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7cb144..27f1f68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,8 +85,8 @@ jobs: run: composer run-script coverage-${{ matrix.php-version }} - name: Upload to Codecov - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v3 with: - token: ${{ secrets.CODE_COV_TOKEN }} + token: ${{ secrets.CODECOV_TOKEN }} files: ./tmp/coverage.xml verbose: true From e8ed8e5d13a3025a4d25aefe1ebd6761d17b3100 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 19:14:29 -0500 Subject: [PATCH 37/42] Seems like no real changes. --- phpunit.8.xml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/phpunit.8.xml b/phpunit.8.xml index 5c67fb0..82b80b3 100644 --- a/phpunit.8.xml +++ b/phpunit.8.xml @@ -1,5 +1,26 @@ - + ./src From 8091e60341610f45a3b29f9cd3bc3745cd89accc Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 19:22:19 -0500 Subject: [PATCH 38/42] Revert "Seems like no real changes." This reverts commit e8ed8e5d13a3025a4d25aefe1ebd6761d17b3100. --- phpunit.8.xml | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/phpunit.8.xml b/phpunit.8.xml index 82b80b3..5c67fb0 100644 --- a/phpunit.8.xml +++ b/phpunit.8.xml @@ -1,26 +1,5 @@ - + ./src From a58894ebcf02f6836bdeef9839454dd75dc0dd60 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 19:23:08 -0500 Subject: [PATCH 39/42] Revert "Merge branch 'master' into issue-52" This reverts commit 071b8c0cf6ba39390d7ed61e4253c23b94735d52, reversing changes made to 87b2030578bc7c20d83b7035172c47992e3ac68f. --- CONTRIBUTING.md => CONTRIBUTING.markdown | 0 README.md => README.markdown | 17 +- phpstan.neon | 9 - phpunit.5.xml | 13 + src/josegonzalez/Dotenv/Expect.php | 30 +- .../Dotenv/Filter/CallableFilter.php | 10 +- src/josegonzalez/Dotenv/Filter/Filter.php | 18 -- .../Dotenv/Filter/LowercaseKeyFilter.php | 11 +- src/josegonzalez/Dotenv/Filter/NullFilter.php | 9 +- .../Dotenv/Filter/RemapKeysFilter.php | 10 +- .../Dotenv/Filter/UnderscoreArrayFilter.php | 23 +- .../Dotenv/Filter/UppercaseFirstKeyFilter.php | 11 +- .../Dotenv/Filter/UrlParseFilter.php | 37 +-- src/josegonzalez/Dotenv/Loader.php | 213 ++---------- tests/josegonzalez/Dotenv/ExpectTest.php | 14 +- tests/josegonzalez/Dotenv/LoaderTest.php | 305 +++++++++--------- 16 files changed, 258 insertions(+), 472 deletions(-) rename CONTRIBUTING.md => CONTRIBUTING.markdown (100%) rename README.md => README.markdown (98%) delete mode 100644 phpstan.neon delete mode 100644 src/josegonzalez/Dotenv/Filter/Filter.php diff --git a/CONTRIBUTING.md b/CONTRIBUTING.markdown similarity index 100% rename from CONTRIBUTING.md rename to CONTRIBUTING.markdown diff --git a/README.md b/README.markdown similarity index 98% rename from README.md rename to README.markdown index 001e2ef..ee97d2c 100644 --- a/README.md +++ b/README.markdown @@ -13,29 +13,20 @@ A `.env` file parsing and loading library for PHP. ## Requirements -* PHP 5.5+|7.2+ +* PHP 5.5+ ## Installation _[Using [Composer](http://getcomposer.org/)]_ -Run `composer require josegonzalez/dotenv` +Run `composer require josegonzalez/dotenv:dev-master` Or add the plugin to your project's `composer.json` - something like this: -For php 5.5 -> 7.4 -```json +```javascript { "require": { - "josegonzalez/dotenv": ~3.2" - } - } -``` -For php 7.4 -> 8.2+ -```json - { - "require": { - "josegonzalez/dotenv": ~4.0" + "josegonzalez/dotenv": "dev-master" } } ``` diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index 14ce3b5..0000000 --- a/phpstan.neon +++ /dev/null @@ -1,9 +0,0 @@ -parameters: - level: 7 - parallel: - processTimeout: 900.0 - paths: - - src - - tests - ignoreErrors: - - '#Constant [A-Z_]+ not found.#' diff --git a/phpunit.5.xml b/phpunit.5.xml index 63336b0..c7eb229 100644 --- a/phpunit.5.xml +++ b/phpunit.5.xml @@ -14,4 +14,17 @@ tests/josegonzalez/Dotenv + + + ./docs + ./vendor + ./tests/bootstrap.php + + + + src + + diff --git a/src/josegonzalez/Dotenv/Expect.php b/src/josegonzalez/Dotenv/Expect.php index acba398..4d6a6cd 100644 --- a/src/josegonzalez/Dotenv/Expect.php +++ b/src/josegonzalez/Dotenv/Expect.php @@ -11,26 +11,12 @@ class Expect protected $raise = true; - - /** - * Checks the environment ans throws an exception of something is missing. - * - * @param array $environment The variables to check - * @param bool $raise If we should throw exceptions or not. - * @return void - */ - public function __construct(array $environment, $raise = true) + public function __construct($environment, $raise = true) { $this->environment = $environment; $this->raise = $raise; } - /** - * Checks the environment ans throws an exception of something is missing. - * - * @return bool Actually always false - * @throws \RuntimeException|\LogicException - */ public function __invoke() { $args = func_get_args(); @@ -43,7 +29,7 @@ public function __invoke() } $keys = (array) $args; - $missingEnvs = []; + $missingEnvs = array(); foreach ($keys as $key) { if (!isset($this->environment[$key])) { @@ -61,19 +47,9 @@ public function __invoke() return true; } - /** - * Throw and track exceptions - * - * @param \Exception|string $exception - * @param string $message The message send with the exception. - * @return bool Actually always false - * @throws \Exception - */ - protected function raise($exception, string $message): bool + protected function raise($exception, $message) { if ($this->raise) { - // @todo Figure out how to properly define this line so phpstan can understand it. - // @phpstan-ignore-next-line throw new $exception($message); } diff --git a/src/josegonzalez/Dotenv/Filter/CallableFilter.php b/src/josegonzalez/Dotenv/Filter/CallableFilter.php index e8d0968..5251926 100644 --- a/src/josegonzalez/Dotenv/Filter/CallableFilter.php +++ b/src/josegonzalez/Dotenv/Filter/CallableFilter.php @@ -2,16 +2,16 @@ namespace josegonzalez\Dotenv\Filter; -class CallableFilter extends Filter +class CallableFilter { /** * Wraps a callable and invokes it upon the environment. * - * @param array $environment Array of environment data - * @param array $config Array of configuration data that includes the callable - * @return array|object + * @param array $environment Array of environment data + * @param array $config Array of configuration data that includes the callable + * @return array */ - public function __invoke(array $environment, $config = []) + public function __invoke(array $environment, array $config) { $callable = $config['callable']; return $callable($environment, $config); diff --git a/src/josegonzalez/Dotenv/Filter/Filter.php b/src/josegonzalez/Dotenv/Filter/Filter.php deleted file mode 100644 index 5cd8065..0000000 --- a/src/josegonzalez/Dotenv/Filter/Filter.php +++ /dev/null @@ -1,18 +0,0 @@ - $environment Array of environment data - * @param null|array $config Config values. - * @return array - */ - public function __invoke(array $environment, $config = null) - { - return $environment; - } -} diff --git a/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php b/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php index 705b7fc..66f5d8b 100644 --- a/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php +++ b/src/josegonzalez/Dotenv/Filter/LowercaseKeyFilter.php @@ -2,18 +2,17 @@ namespace josegonzalez\Dotenv\Filter; -class LowercaseKeyFilter extends Filter +class LowercaseKeyFilter { /** * Lowercases all the keys for an environment to a single-depth. * - * @param array $environment Array of environment data - * @param null|array $config Config values. Here to be compatible with Filter. - * @return array + * @param array $environment Array of environment data + * @return array */ - public function __invoke(array $environment, $config = null) + public function __invoke(array $environment) { - $newEnvironment = []; + $newEnvironment = array(); foreach ($environment as $key => $value) { $newEnvironment[strtolower($key)] = $value; } diff --git a/src/josegonzalez/Dotenv/Filter/NullFilter.php b/src/josegonzalez/Dotenv/Filter/NullFilter.php index 3043a7f..d6b82dd 100644 --- a/src/josegonzalez/Dotenv/Filter/NullFilter.php +++ b/src/josegonzalez/Dotenv/Filter/NullFilter.php @@ -2,16 +2,15 @@ namespace josegonzalez\Dotenv\Filter; -class NullFilter extends Filter +class NullFilter { /** * Returns the environment data without any changes. * - * @param array $environment Array of environment data - * @param null|array $config Config values. Here to be compatible with Filter. - * @return array + * @param array $environment Array of environment data + * @return array */ - public function __invoke(array $environment, $config = []) + public function __invoke(array $environment) { return $environment; } diff --git a/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php b/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php index 24758f0..790156e 100644 --- a/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php +++ b/src/josegonzalez/Dotenv/Filter/RemapKeysFilter.php @@ -2,16 +2,16 @@ namespace josegonzalez\Dotenv\Filter; -class RemapKeysFilter extends Filter +class RemapKeysFilter { /** * Remaps specific keys in a $config array to a set of values at a single-depth. * - * @param array $environment Array of environment data - * @param array $config Config values. - * @return array + * @param array $environment Array of environment data + * @param array $config Array of keys to remap to specific values + * @return array */ - public function __invoke(array $environment, $config = []) + public function __invoke(array $environment, array $config) { foreach ($config as $key => $value) { if (array_key_exists($key, $environment)) { diff --git a/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php b/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php index 1f3d11e..37777f5 100644 --- a/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php +++ b/src/josegonzalez/Dotenv/Filter/UnderscoreArrayFilter.php @@ -2,7 +2,7 @@ namespace josegonzalez\Dotenv\Filter; -class UnderscoreArrayFilter extends Filter +class UnderscoreArrayFilter { /** * Expands a flat array to a nested array. @@ -10,33 +10,32 @@ class UnderscoreArrayFilter extends Filter * For example, `['0_Foo_Bar' => 'Far']` becomes * `[['Foo' => ['Bar' => 'Far']]]`. * - * @param array $environment Array of environment data - * @param null|array $config Config values. Here to be compatible with Filter. - * @return array + * @param array $environment Array of environment data + * @return array */ - public function __invoke(array $environment, $config = null) + public function __invoke(array $environment) { - $result = []; + $result = array(); foreach ($environment as $flat => $value) { $keys = explode('_', $flat); $keys = array_reverse($keys); - $child = [ + $child = array( $keys[0] => $value - ]; + ); array_shift($keys); foreach ($keys as $k) { - $child = [ + $child = array( $k => $child - ]; + ); } - $stack = [[$child, &$result]]; + $stack = array(array($child, &$result)); while (!empty($stack)) { foreach ($stack as $curKey => &$curMerge) { foreach ($curMerge[0] as $key => &$val) { $hasKey = !empty($curMerge[1][$key]); if ($hasKey && (array)$curMerge[1][$key] === $curMerge[1][$key] && (array)$val === $val) { - $stack[] = [&$val, &$curMerge[1][$key]]; + $stack[] = array(&$val, &$curMerge[1][$key]); } else { $curMerge[1][$key] = $val; } diff --git a/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php b/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php index 734910c..07ae17f 100644 --- a/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php +++ b/src/josegonzalez/Dotenv/Filter/UppercaseFirstKeyFilter.php @@ -2,18 +2,17 @@ namespace josegonzalez\Dotenv\Filter; -class UppercaseFirstKeyFilter extends Filter +class UppercaseFirstKeyFilter { /** * Uppercases the first letter for all the keys for an environment to a single-depth. * - * @param array $environment Array of environment data - * @param null|array $config Config values. Here to be compatible with Filter. - * @return array + * @param array $environment Array of environment data + * @return array */ - public function __invoke(array $environment, $config = null) + public function __invoke(array $environment) { - $newEnvironment = []; + $newEnvironment = array(); foreach ($environment as $key => $value) { $newEnvironment[ucfirst($key)] = $value; } diff --git a/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php b/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php index fd17182..8a67440 100644 --- a/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php +++ b/src/josegonzalez/Dotenv/Filter/UrlParseFilter.php @@ -2,47 +2,36 @@ namespace josegonzalez\Dotenv\Filter; -class UrlParseFilter extends Filter +class UrlParseFilter { /** * When there is a key with the suffix `_URL`, this filter uses `parse_url` * to add extra data to the environment. * - * @param array $environment Array of environment data - * @param null|array $config Config values. Here to be compatible with Filter. - * @return array + * @param array $environment Array of environment data + * @return array */ - public function __invoke(array $environment, $config = null) + public function __invoke(array $environment) { - $newEnvironment = []; + $newEnvironment = array(); foreach ($environment as $key => $value) { $newEnvironment[$key] = $value; if (substr($key, -4) === '_URL') { $prefix = substr($key, 0, -3); $url = parse_url($value); - if (is_array($url)) { - $newEnvironment[$prefix . 'SCHEME'] = $this->get($url, 'scheme', ''); - $newEnvironment[$prefix . 'HOST'] = $this->get($url, 'host', ''); - $newEnvironment[$prefix . 'PORT'] = $this->get($url, 'port', ''); - $newEnvironment[$prefix . 'USER'] = $this->get($url, 'user', ''); - $newEnvironment[$prefix . 'PASS'] = $this->get($url, 'pass', ''); - $newEnvironment[$prefix . 'PATH'] = $this->get($url, 'path', ''); - $newEnvironment[$prefix . 'QUERY'] = $this->get($url, 'query', ''); - $newEnvironment[$prefix . 'FRAGMENT'] = $this->get($url, 'fragment', ''); - } + $newEnvironment[$prefix . 'SCHEME'] = $this->get($url, 'scheme', ''); + $newEnvironment[$prefix . 'HOST'] = $this->get($url, 'host', ''); + $newEnvironment[$prefix . 'PORT'] = $this->get($url, 'port', ''); + $newEnvironment[$prefix . 'USER'] = $this->get($url, 'user', ''); + $newEnvironment[$prefix . 'PASS'] = $this->get($url, 'pass', ''); + $newEnvironment[$prefix . 'PATH'] = $this->get($url, 'path', ''); + $newEnvironment[$prefix . 'QUERY'] = $this->get($url, 'query', ''); + $newEnvironment[$prefix . 'FRAGMENT'] = $this->get($url, 'fragment', ''); } } return $newEnvironment; } - /** - * Gets the filter - * - * @param array $data The array to look at - * @param int|string $key The key in $data to look for - * @param null|mixed $default The default value to return if key isn't found - * @return null|mixed The found value or $default - */ public function get(array $data, $key, $default = null) { if (isset($data[$key])) { diff --git a/src/josegonzalez/Dotenv/Loader.php b/src/josegonzalez/Dotenv/Loader.php index 456eb62..2fd4b00 100644 --- a/src/josegonzalez/Dotenv/Loader.php +++ b/src/josegonzalez/Dotenv/Loader.php @@ -1,8 +1,4 @@ List of thrown exceptsions being tracked. */ - protected $exceptions = []; - /** @var null|array The parsed variables. */ protected $environment = null; protected $exceptions = array(); protected $filepaths = null; - /** @var array List of filters to use. */ - protected $filters = []; + protected $filters = array(); - /** @var null|string The prefix we should use for keys. */ protected $prefix = null; - /** @var bool If we should raise exceptions. */ protected $raise = true; - /** @var array Available sources and if they should be skipped. */ - protected $skip = [ + protected $skip = array( 'apacheSetenv' => false, 'define' => false, 'putenv' => false, 'toEnv' => false, 'toServer' => false, - ]; - - /** - * Constructor - * - * @param null|string|array $filepaths - * @return void - */ + ); + public function __construct($filepaths = null) { $this->setFilepaths($filepaths); } - /** - * Creates the Loader object with a set of options. - * - * @param null|string|array $options - * @return \josegonzalez\Dotenv\Loader - */ public static function load($options = null) { $filepaths = null; if (is_string($options)) { $filepaths = $options; - $options = []; + $options = array(); } elseif (isset($options['filepath'])) { $filepaths = (array)$options['filepath']; unset($options['filepath']); @@ -86,7 +63,7 @@ public static function load($options = null) $dotenv->filter(); } - $methods = [ + $methods = array( 'skipExisting', 'prefix', 'expect', @@ -95,8 +72,7 @@ public static function load($options = null) 'putenv', 'toEnv', 'toServer', - ]; - + ); foreach ($methods as $method) { if (array_key_exists($method, $options)) { $dotenv->$method($options[$method]); @@ -106,77 +82,43 @@ public static function load($options = null) return $dotenv; } - /** - * Gets the current file path from the list. - * - * @return string - */ public function filepath() { return current($this->filepaths); } - /** - * Gets the list of files paths. - * - * @return array|null - */ public function filepaths() { return $this->filepaths; } - /** - * Sets a single file path - * - * @param null|string $filepath The path to add to the list. - * @return self - */ - public function setFilepath(?string $filepath = null) + public function setFilepath($filepath = null) { return $this->setFilepaths($filepath); } - /** - * Sets the list of paths to look for the .env file - * - * @param null|string|array $filepaths One or more file paths to look in. - * @return self - */ public function setFilepaths($filepaths = null) { if ($filepaths == null) { - $filepaths = [__DIR__ . DIRECTORY_SEPARATOR . '.env']; + $filepaths = array(__DIR__ . DIRECTORY_SEPARATOR . '.env'); } if (is_string($filepaths)) { - $filepaths = [$filepaths]; + $filepaths = array($filepaths); } $this->filepaths = $filepaths; return $this; } - /** - * gets the filters to use. - * - * @return array The defined list of filters. - */ public function filters() { return $this->filters; } - /** - * Sets the filters to use. - * - * @param array $filters An array of filters to use. - * @return self|bool - * @throws \LogicException - */ public function setFilters(array $filters) { - $newList = []; + $newList = array(); $keys = array_keys($filters); $count = count($keys); for ($i = 0; $i < $count; $i++) { @@ -185,9 +127,9 @@ public function setFilters(array $filters) if (is_string($filter)) { $newList[$filter] = null; } else { - $newList['__callable__' . $i] = [ + $newList['__callable__' . $i] = array( 'callable' => $filter - ]; + ); } } else { $newList[$keys[$i]] = $filters[$keys[$i]]; @@ -220,12 +162,6 @@ public function setFilters(array $filters) return $this; } - /** - * Filter variables - * - * @return self - * @throws \InvalidArgumentException - */ public function filter() { $this->requireParse('filter'); @@ -241,7 +177,6 @@ public function filter() $filter = new $filterClass; } } - /** @var \josegonzalez\Dotenv\Filter\Filter $filter */ $environment = $filter($environment, $config); } @@ -249,12 +184,6 @@ public function filter() return $this; } - /** - * Parses the .env file into the environment variable - * - * @return self|bool - * @throws \InvalidArgumentException - */ public function parse() { $contents = false; @@ -288,19 +217,12 @@ public function parse() } } - /** @var string $contents Come on phpstan. */ $parser = new Parser($contents); $this->environment = $parser->getContent(); return $this; } - /** - * Used to create an Expect object - * - * @return self|bool - * @throws \Exception - */ public function expect() { $this->requireParse('expect'); @@ -311,13 +233,6 @@ public function expect() return $this; } - /** - * Uses apache_setenv() to set variables - * - * @param bool $overwrite If we should overwrite variables via apache_setenv() - * @return self|bool - * @throws \Exception - */ public function apacheSetenv($overwrite = false) { $this->requireParse('apache_setenv'); @@ -340,12 +255,6 @@ public function apacheSetenv($overwrite = false) return $this; } - /** - * Uses define() to set variables - * - * @return self|bool - * @throws \Exception - */ public function define() { $this->requireParse('define'); @@ -368,13 +277,6 @@ public function define() return $this; } - /** - * Uses putenv() to set variables - * - * @param bool $overwrite If we should overwrite variables via putenv() - * @return self|bool - * @throws \Exception - */ public function putenv($overwrite = false) { $this->requireParse('putenv'); @@ -397,13 +299,6 @@ public function putenv($overwrite = false) return $this; } - /** - * Updates $_ENV - * - * @param bool $overwrite If we should overwrite the initial value of $_ENV values - * @return self|bool - * @throws \Exception - */ public function toEnv($overwrite = false) { $this->requireParse('toEnv'); @@ -426,13 +321,6 @@ public function toEnv($overwrite = false) return $this; } - /** - * Updates $_SERVER - * - * @param bool $overwrite If we should overwrite the initial value of $_SERVER values - * @return self|bool - * @throws \Exception - */ public function toServer($overwrite = false) { $this->requireParse('toServer'); @@ -455,12 +343,6 @@ public function toServer($overwrite = false) return $this; } - /** - * Sets what types to skip - * - * @param mixed $types The types to skip - * @return self - */ public function skipExisting($types = null) { $args = func_get_args(); @@ -473,7 +355,6 @@ public function skipExisting($types = null) $types = array_keys($this->skip); } - /** @var string $type */ foreach ((array)$types as $type) { $this->skip[$type] = true; } @@ -481,14 +362,9 @@ public function skipExisting($types = null) return $this; } - /** - * Returns list of variables to skip. - * - * @return array - */ public function skipped() { - $skipped = []; + $skipped = array(); foreach ($this->skip as $key => $value) { if ($value == true) { $skipped[] = $key; @@ -497,25 +373,13 @@ public function skipped() return $skipped; } - /** - * Sets the prefix. - * - * @param string|null $prefix - * @return self - */ - public function prefix(?string $prefix = null) + public function prefix($prefix = null) { $this->prefix = $prefix; return $this; } - /** - * Add prefix to a key - * - * @param string $key The key that may need to be prefixed. - * @return string The modified key. - */ - public function prefixed(string $key) + public function prefixed($key) { if (!!$this->prefix) { $key = $this->prefix . $key; @@ -524,24 +388,12 @@ public function prefixed(string $key) return $key; } - /** - * Flags if we should raise exceptions, or ignore them - * - * @param bool $raise If we should allow exceptions - * @return self - */ public function raiseExceptions($raise = true) { $this->raise = $raise; return $this; } - /** - * Creates and return an array from the known environment. - * - * @return array|null - * @throws \Exception - */ public function toArray() { $this->requireParse('toArray'); @@ -549,38 +401,25 @@ public function toArray() return null; } - $environment = []; + $environment = array(); foreach ($this->environment as $key => $value) { $environment[$this->prefixed($key)] = $value; } return $environment; } - /** - * Converts array to json string - * - * @return string - */ public function __toString() { try { $data = $this->toArray(); } catch (LogicException $e) { - $data = []; + $data = array(); } - $json = json_encode($data); - return $json ? $json : ''; + return json_encode($data); } - /** - * Requires the the .env has been parsed first. - * - * @param string $method The message send with the exception. - * @return void|bool - * @throws \Exception - */ - protected function requireParse(string $method) + protected function requireParse($method) { if (!is_array($this->environment)) { return $this->raise( @@ -590,19 +429,9 @@ protected function requireParse(string $method) } } - /** - * Throw and track exceptions - * - * @param \Exception|string $exception - * @param string $message The message send with the exception. - * @return bool Actually always false - * @throws \Exception - */ - protected function raise($exception, string $message): bool + protected function raise($exception, $message) { if ($this->raise) { - // @todo Figure out how to properly define this line so phpstan can understand it. - // @phpstan-ignore-next-line throw new $exception($message); } diff --git a/tests/josegonzalez/Dotenv/ExpectTest.php b/tests/josegonzalez/Dotenv/ExpectTest.php index e303bb6..5220fad 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -5,7 +5,7 @@ use josegonzalez\Dotenv\Expect; use \PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase; -class ExpectTest extends TestCase +class ExpectTest extends PHPUnit_Framework_TestCase { protected $env = array(); @@ -38,12 +38,12 @@ public function compatibleTearDown() * @covers \josegonzalez\Dotenv\Expect::__invoke * @covers \josegonzalez\Dotenv\Expect::raise */ - public function testExpect(): void + public function testExpect() { $this->compatibleSetUp(); $expect = new Expect($this->server); $this->assertTrue($expect('USER')); - $this->assertTrue($expect(['USER', 'HOME'])); + $this->assertTrue($expect(array('USER', 'HOME'))); $expect = new Expect($this->server, false); $this->assertFalse($expect('FOO')); @@ -55,8 +55,10 @@ public function testExpect(): void * @covers \josegonzalez\Dotenv\Expect::__construct * @covers \josegonzalez\Dotenv\Expect::__invoke * @covers \josegonzalez\Dotenv\Expect::raise + * @expectedException LogicException + * @expectedExceptionMessage No arguments were passed to expect() */ - public function testExpectLogicException(): void + public function testExpectLogicException() { $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { @@ -72,8 +74,10 @@ public function testExpectLogicException(): void * @covers \josegonzalez\Dotenv\Expect::__construct * @covers \josegonzalez\Dotenv\Expect::__invoke * @covers \josegonzalez\Dotenv\Expect::raise + * @expectedException RuntimeException + * @expectedExceptionMessage Required ENV vars missing: ['INVALID'] */ - public function testExpectRuntimeException(): void + public function testExpectRuntimeException() { $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index a7753ff..026fc4e 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -6,17 +6,12 @@ use phpmock\phpunit\PHPMock; use \PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase; -/** - * Just return what was handed to it. - * @param mixed $data basically anything - * @return mixed Whatever was in $data - */ function doNothing($data) { return $data; } -class LoaderTest extends TestCase +class LoaderTest extends PHPUnit_Framework_TestCase { use PHPMock; protected $env = []; @@ -59,7 +54,7 @@ public function compatibleTearDown() * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::filepath */ - public function testFilepath(): void + public function testFilepath() { $this->compatibleSetUp(); $this->assertEquals($this->fixturePath . '.env', $this->Loader->filepath()); @@ -71,7 +66,7 @@ public function testFilepath(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::filepaths */ - public function testFilepaths(): void + public function testFilepaths() { $this->compatibleSetUp(); $this->assertEquals(array($this->fixturePath . '.env'), $this->Loader->filepaths()); @@ -84,18 +79,18 @@ public function testFilepaths(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::filepath */ - public function testSetFilepath(): void + public function testSetFilepath() { $this->compatibleSetUp(); $this->Loader->setFilepath('/tmp/.env'); $this->assertEquals('/tmp/.env', $this->Loader->filepath()); $this->Loader->setFilepath(null); - $basePath = realpath(implode(DIRECTORY_SEPARATOR, [ + $basePath = realpath(implode(DIRECTORY_SEPARATOR, array( __DIR__, '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..', 'src' . DIRECTORY_SEPARATOR . 'josegonzalez' . DIRECTORY_SEPARATOR . 'Dotenv', - ])); + ))); $this->assertEquals($basePath . DIRECTORY_SEPARATOR .'.env', $this->Loader->filepath()); $this->compatibleTearDown(); } @@ -110,7 +105,7 @@ public function testSetFilepath(): void * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Loader::parse */ - public function testParse(): void + public function testParse() { $this->compatibleSetUp(); $this->Loader->setFilepath($this->fixturePath . 'all.env'); @@ -139,11 +134,10 @@ public function testParse(): void $this->assertEquals('bar', $environment['CFOO']); $this->assertEquals('with spaces', $environment['CSPACED']); $this->assertEquals('a value with a # character', $environment['CQUOTES']); - $this->assertEquals('a value with a # character & a quote " ' . - 'character inside quotes', $environment['CQUOTESWITHQUOTE']); + $this->assertEquals('a value with a # character & a quote " character inside quotes', $environment['CQUOTESWITHQUOTE']); $this->assertSame(null, $environment['CNULL']); - $this->assertEquals([ + $this->assertEquals(array( 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'unquotedwithspaces spaces', @@ -188,7 +182,7 @@ public function testParse(): void 'STRING_EMPTY' => '', 'STRING_EMPTY_2' => '', 'NO_VALUE_INLINE_COMMENT' => null, - ], $environment); + ), $environment); $this->Loader->setFilepath($this->fixturePath . 'cake.env'); $this->Loader->parse(); @@ -221,9 +215,10 @@ public function testParse(): void * @covers \josegonzalez\Dotenv\Loader::setFilepath * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::parse - * @expectedExceptionMessage + * @expectedException M1\Env\Exception\ParseException + * @expectedExceptionMessage Key can only contain alphanumeric and underscores and can not start with a number: 01SKIPPED near 01SKIPPED at line 1 */ - public function testParseException(): void + public function testParseException() { $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { @@ -243,8 +238,10 @@ public function testParseException(): void * @covers \josegonzalez\Dotenv\Loader::setFilepath * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::parse + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Environment file '.env' is not found */ - public function testParseFileNotFound(): void + public function testParseFileNotFound() { $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { @@ -263,8 +260,10 @@ public function testParseFileNotFound(): void * @covers \josegonzalez\Dotenv\Loader::setFilepath * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::parse + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Environment file '/tmp' is a directory. Should be a file */ - public function testParseFileIsDirectory(): void + public function testParseFileIsDirectory() { $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { @@ -283,8 +282,10 @@ public function testParseFileIsDirectory(): void * @covers \josegonzalez\Dotenv\Loader::setFilepath * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::parse + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Environment file '/tmp/php-dotenv-unreadable' is not readable */ - public function testParseFileIsUnreadable(): void + public function testParseFileIsUnreadable() { $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { @@ -303,7 +304,7 @@ public function testParseFileIsUnreadable(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::filters */ - public function testFilters(): void + public function testFilters() { $this->compatibleSetUp(); $this->assertSame(array(), $this->Loader->filters()); @@ -316,26 +317,26 @@ public function testFilters(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::setFilters */ - public function testSetFilters(): void + public function testSetFilters() { $this->compatibleSetUp(); $this->assertSame(array(), $this->Loader->filters()); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', - ])); + ))); - $this->assertEquals($this->Loader, $this->Loader->setFilters([ + $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'josegonzalez\Dotenv\doNothing', - ])); + ))); - $this->assertEquals($this->Loader, $this->Loader->setFilters([ - 'josegonzalez\Dotenv\doNothing' => ['key' => 'value'], - ])); + $this->assertEquals($this->Loader, $this->Loader->setFilters(array( + 'josegonzalez\Dotenv\doNothing' => array('key' => 'value'), + ))); - $this->assertEquals($this->Loader, $this->Loader->setFilters([ + $this->assertEquals($this->Loader, $this->Loader->setFilters(array( function () { - return []; + return array(); } ))); $this->compatibleTearDown(); @@ -346,8 +347,10 @@ function () { * @covers \josegonzalez\Dotenv\Loader::raise * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::setFilters + * @expectedException LogicException + * @expectedExceptionMessage Invalid filter class SomeFilter */ - public function testSetFilterNonexistentFilter(): void + public function testSetFilterNonexistentFilter() { $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { @@ -365,8 +368,10 @@ public function testSetFilterNonexistentFilter(): void * @covers \josegonzalez\Dotenv\Loader::raise * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::setFilters + * @expectedException LogicException + * @expectedExceptionMessage Invalid filter class */ - public function testSetFilterInvalidCallable(): void + public function testSetFilterInvalidCallable() { $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { @@ -391,15 +396,15 @@ public function testSetFilterInvalidCallable(): void * @covers \josegonzalez\Dotenv\Loader::filter * @covers \josegonzalez\Dotenv\Filter\NullFilter::__invoke */ - public function testFilter(): void + public function testFilter() { $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', - ])); + ))); $this->Loader->parse(); $this->Loader->filter(); - $this->assertEquals([ + $this->assertEquals(array( 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', @@ -421,14 +426,14 @@ public function testFilter(): void * @covers \josegonzalez\Dotenv\Loader::filter * @covers \josegonzalez\Dotenv\Filter\CallableFilter::__invoke */ - public function testFilterCallable(): void + public function testFilterCallable() { $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( function () { - return ['FOO' => 'BAR']; + return array('FOO' => 'BAR'); } - ])); + ))); $this->Loader->parse(); $this->Loader->filter(); $this->assertEquals(array('FOO' => 'BAR'), $this->Loader->toArray()); @@ -448,16 +453,16 @@ function () { * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\LowercaseKeyFilter::__invoke */ - public function testLowercaseKeyFilter(): void + public function testLowercaseKeyFilter() { $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', - ]); + )); $this->Loader->setFilepath($this->fixturePath . '.env'); $this->Loader->parse(); $this->Loader->filter(); - $this->assertEquals([ + $this->assertEquals(array( 'foo' => 'bar', 'bar' => 'baz', 'spaced' => 'with spaces', @@ -479,16 +484,16 @@ public function testLowercaseKeyFilter(): void * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\NullFilter::__invoke */ - public function testNullFilter(): void + public function testNullFilter() { $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', - ]); + )); $this->Loader->setFilepath($this->fixturePath . '.env'); $this->Loader->parse(); $this->Loader->filter(); - $this->assertEquals([ + $this->assertEquals(array( 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', @@ -511,18 +516,18 @@ public function testNullFilter(): void * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\RemapKeysFilter::__invoke */ - public function testRemapKeysFilter(): void + public function testRemapKeysFilter() { $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\RemapKeysFilter' => array( 'FOO' => 'QUX' - ], - ]); + ), + )); $this->Loader->setFilepath($this->fixturePath . '.env'); $this->Loader->parse(); $this->Loader->filter(); - $this->assertEquals([ + $this->assertEquals(array( 'QUX' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', @@ -545,17 +550,17 @@ public function testRemapKeysFilter(): void * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter::__invoke */ - public function testUppercaseFirstKeyFilter(): void + public function testUppercaseFirstKeyFilter() { $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', 'josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter', - ]); + )); $this->Loader->setFilepath($this->fixturePath . '.env'); $this->Loader->parse(); $this->Loader->filter(); - $this->assertEquals([ + $this->assertEquals(array( 'Foo' => 'bar', 'Bar' => 'baz', 'Spaced' => 'with spaces', @@ -578,17 +583,17 @@ public function testUppercaseFirstKeyFilter(): void * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::__invoke * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get */ - public function testUrlParseFilter(): void + public function testUrlParseFilter() { $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UrlParseFilter', - ]); + )); $this->Loader->setFilepath($this->fixturePath . 'url_parse_filter.env'); $this->Loader->parse(); $this->Loader->filter(); $environment = $this->Loader->toArray(); - $this->assertSame([ + $this->assertSame(array( 'READ_DATABASE_URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'READ_DATABASE_SCHEME' => 'mysql', 'READ_DATABASE_HOST' => 'localhost', @@ -624,33 +629,33 @@ public function testUrlParseFilter(): void * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Filter\UnderscoreArrayFilter::__invoke */ - public function testUnderscoreArrayFilter(): void + public function testUnderscoreArrayFilter() { $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter', - ]); + )); $this->Loader->setFilepath($this->fixturePath . 'underscore_array_filter.env'); $this->Loader->parse(); $this->Loader->filter(); $environment = $this->Loader->toArray(); - $this->assertEquals([ - 'DATABASE' => [ + $this->assertEquals(array( + 'DATABASE' => array( 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', - 0 => [ + 0 => array( 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'OTHERURL' => 'mysql://user:password@localhost/database_name?encoding=utf8', - ], - 1 => [ + ), + 1 => array( 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'OTHERURL' => 'mysql://user:password@localhost/database_name?encoding=utf8', - ], - ], - 'DATA' => [ - 'BASE' => [ + ), + ), + 'DATA' => array( + 'BASE' => array( 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8' - ], - ], + ), + ), ), $environment); $this->compatibleTearDown(); @@ -671,19 +676,19 @@ public function testUnderscoreArrayFilter(): void * @covers \josegonzalez\Dotenv\Filter\UrlParseFilter::get * @covers \josegonzalez\Dotenv\Filter\UnderscoreArrayFilter::__invoke */ - public function testMultipleFilters(): void + public function testMultipleFilters() { $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UrlParseFilter', 'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter', - ]); + )); $this->Loader->setFilepath($this->fixturePath . 'filter.env'); $this->Loader->parse(); $this->Loader->filter(); $environment = $this->Loader->toArray(); - $this->assertSame([ - 'DATABASE' => [ + $this->assertSame(array( + 'DATABASE' => array( 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'SCHEME' => 'mysql', 'HOST' => 'localhost', @@ -693,9 +698,9 @@ public function testMultipleFilters(): void 'PATH' => '/database_name', 'QUERY' => 'encoding=utf8', 'FRAGMENT' => '', - ], - 'DATA' => [ - 'BASE' => [ + ), + 'DATA' => array( + 'BASE' => array( 'URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'SCHEME' => 'mysql', 'HOST' => 'localhost', @@ -721,7 +726,7 @@ public function testMultipleFilters(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::expect */ - public function testExpect(): void + public function testExpect() { $this->compatibleSetUp(); $this->Loader->parse(); @@ -739,7 +744,7 @@ public function testExpect(): void * @expectedException LogicException * @expectedExceptionMessage Environment must be parsed before calling expect() */ - public function testExpectRequireParse(): void + public function testExpectRequireParse() { $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { @@ -760,8 +765,10 @@ public function testExpectRequireParse(): void * @covers \josegonzalez\Dotenv\Loader::requireParse * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::expect + * @expectedException LogicException + * @expectedExceptionMessage No arguments were passed to expect() */ - public function testExpectLogicException(): void + public function testExpectLogicException() { $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { @@ -783,8 +790,10 @@ public function testExpectLogicException(): void * @covers \josegonzalez\Dotenv\Loader::requireParse * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::expect + * @expectedException RuntimeException + * @expectedExceptionMessage Required ENV vars missing: ['INVALID'] */ - public function testExpectRuntimeException(): void + public function testExpectRuntimeException() { $this->compatibleSetUp(); if (method_exists($this, 'expectException')) { @@ -805,7 +814,7 @@ public function testExpectRuntimeException(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::apacheSetenv */ - public function testToApacheSetenvExceptionUnavailable(): void + public function testToApacheSetenvExceptionUnavailable() { if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); @@ -828,7 +837,7 @@ public function testToApacheSetenvExceptionUnavailable(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::apacheSetenv */ - public function testToApacheSetenv(): void + public function testToApacheSetenv() { if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); @@ -872,7 +881,7 @@ function ($key, $value) { * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::apacheSetenv */ - public function testToApacheSetenvSkip(): void + public function testToApacheSetenvSkip() { if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); @@ -917,8 +926,10 @@ function ($key, $value) { * @covers \josegonzalez\Dotenv\Loader::requireParse * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::apacheSetenv + * @expectedException LogicException + * @expectedExceptionMessage Key "FOO" has already been defined in apache_getenv() */ - public function testToApacheSetenvException(): void + public function testToApacheSetenvException() { if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); @@ -947,8 +958,6 @@ function ($key, $value) { } ); - $this->expectException(\LogicException::class); - $this->expectExceptionMessage('Key "FOO" has already been defined in apache_getenv()'); $this->Loader->parse(); $this->Loader->apacheSetenv(false); $this->Loader->apacheSetenv(false); @@ -967,7 +976,7 @@ function ($key, $value) { * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::putenv */ - public function testToApacheSetenvPreserveZeros(): void + public function testToApacheSetenvPreserveZeros() { if (version_compare(PHP_VERSION, '7.0', '<')) { $this->markTestSkipped('Unable to mock bare php functions'); @@ -1016,7 +1025,7 @@ function ($key, $value) { * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::define */ - public function testDefine(): void + public function testDefine() { $this->compatibleSetUp(); $this->Loader->parse(); @@ -1039,7 +1048,7 @@ public function testDefine(): void * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::define */ - public function testDefineSkip(): void + public function testDefineSkip() { $this->compatibleSetUp(); $this->Loader->parse(); @@ -1062,8 +1071,10 @@ public function testDefineSkip(): void * @covers \josegonzalez\Dotenv\Loader::requireParse * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::define + * @expectedException LogicException + * @expectedExceptionMessage Key "FOO" has already been defined */ - public function testDefineException(): void + public function testDefineException() { if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); @@ -1084,7 +1095,7 @@ public function testDefineException(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::putenv */ - public function testToPutenv(): void + public function testToPutenv() { $this->compatibleSetUp(); $this->Loader->parse(); @@ -1107,7 +1118,7 @@ public function testToPutenv(): void * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::putenv */ - public function testToPutenvSkip(): void + public function testToPutenvSkip() { $this->compatibleSetUp(); $this->Loader->parse(); @@ -1131,8 +1142,10 @@ public function testToPutenvSkip(): void * @covers \josegonzalez\Dotenv\Loader::requireParse * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::putenv + * @expectedException LogicException + * @expectedExceptionMessage Key "FOO" has already been defined in getenv() */ - public function testToPutenvException(): void + public function testToPutenvException() { if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); @@ -1155,7 +1168,7 @@ public function testToPutenvException(): void * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::putenv */ - public function testToPutenvPreserveZeros(): void + public function testToPutenvPreserveZeros() { $this->compatibleSetUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); @@ -1183,7 +1196,7 @@ public function testToPutenvPreserveZeros(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::toEnv */ - public function testToEnv(): void + public function testToEnv() { $this->compatibleSetUp(); $this->Loader->parse(); @@ -1206,7 +1219,7 @@ public function testToEnv(): void * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::toEnv */ - public function testToEnvSkip(): void + public function testToEnvSkip() { $this->compatibleSetUp(); $this->Loader->parse(); @@ -1230,8 +1243,10 @@ public function testToEnvSkip(): void * @covers \josegonzalez\Dotenv\Loader::requireParse * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::toEnv + * @expectedException LogicException + * @expectedExceptionMessage Key "FOO" has already been defined in $_ENV */ - public function testToEnvException(): void + public function testToEnvException() { if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); @@ -1254,7 +1269,7 @@ public function testToEnvException(): void * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::toEnv */ - public function testToEnvPreserveZeros(): void + public function testToEnvPreserveZeros() { $this->compatibleSetUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); @@ -1282,7 +1297,7 @@ public function testToEnvPreserveZeros(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::toServer */ - public function testToServer(): void + public function testToServer() { $this->compatibleSetUp(); $this->Loader->parse(); @@ -1305,7 +1320,7 @@ public function testToServer(): void * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::toServer */ - public function testToServerSkip(): void + public function testToServerSkip() { $this->compatibleSetUp(); $this->Loader->parse(); @@ -1329,8 +1344,10 @@ public function testToServerSkip(): void * @covers \josegonzalez\Dotenv\Loader::requireParse * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::toServer + * @expectedException LogicException + * @expectedExceptionMessage Key "FOO" has already been defined in $_SERVER */ - public function testToServerException(): void + public function testToServerException() { if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); @@ -1353,7 +1370,7 @@ public function testToServerException(): void * @covers \josegonzalez\Dotenv\Loader::skipExisting * @covers \josegonzalez\Dotenv\Loader::toServer */ - public function testToServerPreserveZeros(): void + public function testToServerPreserveZeros() { $this->compatibleSetUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); @@ -1378,16 +1395,16 @@ public function testToServerPreserveZeros(): void * @covers \josegonzalez\Dotenv\Loader::skipped * @covers \josegonzalez\Dotenv\Loader::skipExisting */ - public function testSkipExisting(): void + public function testSkipExisting() { $this->compatibleSetUp(); $this->assertEquals(array(), $this->Loader->skipped()); $this->Loader->skipExisting('toEnv'); - $this->assertEquals(['toEnv'], $this->Loader->skipped()); + $this->assertEquals(array('toEnv'), $this->Loader->skipped()); - $this->Loader->skipExisting(['toEnv']); - $this->assertEquals(['toEnv'], $this->Loader->skipped()); + $this->Loader->skipExisting(array('toEnv')); + $this->assertEquals(array('toEnv'), $this->Loader->skipped()); $this->Loader->skipExisting(); $this->assertEquals(array('apacheSetenv', 'define', 'putenv', 'toEnv', 'toServer'), $this->Loader->skipped()); @@ -1400,7 +1417,7 @@ public function testSkipExisting(): void * @covers \josegonzalez\Dotenv\Loader::prefix * @covers \josegonzalez\Dotenv\Loader::prefixed */ - public function testPrefix(): void + public function testPrefix() { $this->compatibleSetUp(); $this->assertEquals('KEY', $this->Loader->prefixed('KEY')); @@ -1422,11 +1439,11 @@ public function testPrefix(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::toArray */ - public function testToArray(): void + public function testToArray() { $this->compatibleSetUp(); $this->Loader->parse(); - $this->assertEquals([ + $this->assertEquals(array( 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', @@ -1444,7 +1461,7 @@ public function testToArray(): void * @expectedException LogicException * @expectedExceptionMessage Environment must be parsed before calling toArray() */ - public function testToArrayRequireParse(): void + public function testToArrayRequireParse() { if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); @@ -1466,7 +1483,7 @@ public function testToArrayRequireParse(): void * @covers \josegonzalez\Dotenv\Loader::toArray * @covers \josegonzalez\Dotenv\Loader::__toString */ - public function testToString(): void + public function testToString() { $this->compatibleSetUp(); $this->assertEquals('[]', $this->Loader->__toString()); @@ -1483,7 +1500,7 @@ public function testToString(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::requireParse */ - public function testRequireParse(): void + public function testRequireParse() { $this->compatibleSetUp(); $this->Loader->parse(); @@ -1500,7 +1517,7 @@ public function testRequireParse(): void * @expectedException LogicException * @expectedExceptionMessage Environment must be parsed before calling toEnv() */ - public function testRequireParseException(): void + public function testRequireParseException() { if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); @@ -1518,7 +1535,7 @@ public function testRequireParseException(): void * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::raiseExceptions */ - public function testRequireParseNoException(): void + public function testRequireParseNoException() { $this->compatibleSetUp(); $this->Loader->raiseExceptions(false); @@ -1534,7 +1551,7 @@ public function testRequireParseNoException(): void * @expectedException LogicException * @expectedExceptionMessage derp */ - public function testRaise(): void + public function testRaise() { if (method_exists($this, 'expectException')) { $this->expectException(\LogicException::class); @@ -1551,7 +1568,7 @@ public function testRaise(): void * @covers \josegonzalez\Dotenv\Loader::raiseExceptions * @covers \josegonzalez\Dotenv\Loader::raise */ - public function testRaiseNoException(): void + public function testRaiseNoException() { $this->compatibleSetUp(); $this->Loader->raiseExceptions(false); @@ -1582,67 +1599,66 @@ public function testStatic() $this->compatibleSetUp(); $dotenv = Loader::load(array( 'raiseExceptions' => false - ]); + )); $this->assertNull($dotenv->toArray()); $dotenv = Loader::load($this->fixturePath . '.env'); - $this->assertEquals([ + $this->assertEquals(array( 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ], $dotenv->toArray()); + ), $dotenv->toArray()); - $dotenv = Loader::load([ + $dotenv = Loader::load(array( 'filepath' => $this->fixturePath . '.env', - ]); - $this->assertEquals([ + )); + $this->assertEquals(array( 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ], $dotenv->toArray()); + ), $dotenv->toArray()); - $dotenv = Loader::load([ - 'filepaths' => [$this->fixturePath . '.env'], - ]); - $this->assertEquals([ + $dotenv = Loader::load(array( + 'filepaths' => array($this->fixturePath . '.env'), + )); + $this->assertEquals(array( 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ], $dotenv->toArray()); + ), $dotenv->toArray()); - $dotenv = Loader::load([ - 'raiseExceptions' => true, - 'filepaths' => [ + $dotenv = Loader::load(array( + 'filepaths' => array( $this->fixturePath . '.env.nonexistent', $this->fixturePath . '.env', - ], - ]); - $this->assertEquals([ + ), + )); + $this->assertEquals(array( 'FOO' => 'bar', 'BAR' => 'baz', 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', - ], $dotenv->toArray()); + ), $dotenv->toArray()); - $dotenv = Loader::load([ + $dotenv = Loader::load(array( 'filepath' => $this->fixturePath . '.env', 'prefix' => 'PREFIX_' - ]); - $this->assertEquals([ + )); + $this->assertEquals(array( 'PREFIX_FOO' => 'bar', 'PREFIX_BAR' => 'baz', 'PREFIX_SPACED' => 'with spaces', 'PREFIX_EQUALS' => 'pgsql:host=localhost;dbname=test', - ], $dotenv->toArray()); + ), $dotenv->toArray()); - $dotenv = Loader::load([ + $dotenv = Loader::load(array( 'filepath' => $this->fixturePath . 'url_parse_filter.env', - 'filters' => ['josegonzalez\Dotenv\Filter\UrlParseFilter'], - ]); - $this->assertSame([ + 'filters' => array('josegonzalez\Dotenv\Filter\UrlParseFilter'), + )); + $this->assertSame(array( 'READ_DATABASE_URL' => 'mysql://user:password@localhost/database_name?encoding=utf8', 'READ_DATABASE_SCHEME' => 'mysql', 'READ_DATABASE_HOST' => 'localhost', @@ -1669,12 +1685,11 @@ public function testStatic() * Call a protected method on an object * * @param object $obj object - * @param object $obj object * @param string $name method to call - * @param array $args arguments to pass to the method + * @param array $args arguments to pass to the method * @return mixed */ - public function protectedMethodCall(object $obj, string $name, array $args = []) + public function protectedMethodCall($obj, $name, array $args) { $class = new \ReflectionClass($obj); $method = $class->getMethod($name); From cb75cfc7615a6074516fe132c1120c191914a507 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 19:25:41 -0500 Subject: [PATCH 40/42] Don't loose support for php 5. --- src/josegonzalez/Dotenv/Expect.php | 2 +- tests/josegonzalez/Dotenv/LoaderTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/josegonzalez/Dotenv/Expect.php b/src/josegonzalez/Dotenv/Expect.php index 4d6a6cd..f94eacd 100644 --- a/src/josegonzalez/Dotenv/Expect.php +++ b/src/josegonzalez/Dotenv/Expect.php @@ -7,7 +7,7 @@ class Expect { - protected $environment = []; + protected $environment = array(); protected $raise = true; diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index 026fc4e..558a173 100644 --- a/tests/josegonzalez/Dotenv/LoaderTest.php +++ b/tests/josegonzalez/Dotenv/LoaderTest.php @@ -14,9 +14,9 @@ function doNothing($data) class LoaderTest extends PHPUnit_Framework_TestCase { use PHPMock; - protected $env = []; + protected $env = array(); - protected $server = []; + protected $server = array(); protected $fixturePath = ''; From e1897815e6ef2875a7600a54f7c5e34dad8f1f43 Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 19:36:16 -0500 Subject: [PATCH 41/42] Delete phpunit.8.xml.bak --- phpunit.8.xml.bak | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 phpunit.8.xml.bak diff --git a/phpunit.8.xml.bak b/phpunit.8.xml.bak deleted file mode 100644 index fd8447d..0000000 --- a/phpunit.8.xml.bak +++ /dev/null @@ -1,32 +0,0 @@ - - - - - tests - - - - - ./src - - - From 01db3acfc192162a30ea7a6428e5ba1ec3c2a36b Mon Sep 17 00:00:00 2001 From: Brian French Date: Thu, 16 Feb 2023 19:42:39 -0500 Subject: [PATCH 42/42] Update README.markdown --- README.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index ee97d2c..aa43335 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,5 @@ [![Build Status](https://img.shields.io/travis/josegonzalez/php-dotenv/master.svg?branch=master&style=flat-square)](https://travis-ci.org/josegonzalez/php-dotenv) -[![Coverage Status](https://img.shields.io/coveralls/josegonzalez/php-dotenv.svg?branch=master&style=flat-square)](https://coveralls.io/r/josegonzalez/php-dotenv?branch=master) +[![Coverage Status](https://img.shields.io/codecov/c/github/josegonzalez/dotenv.svg?style=flat-square)](https://codecov.io/github/josegonzalez/dotenv) [![Total Downloads](https://img.shields.io/packagist/dt/josegonzalez/dotenv.svg?style=flat-square)](https://packagist.org/packages/josegonzalez/dotenv) [![Latest Stable Version](https://img.shields.io/packagist/v/josegonzalez/dotenv.svg?style=flat-square)](https://packagist.org/packages/josegonzalez/dotenv) @@ -19,14 +19,14 @@ A `.env` file parsing and loading library for PHP. _[Using [Composer](http://getcomposer.org/)]_ -Run `composer require josegonzalez/dotenv:dev-master` +Run `composer require josegonzalez/dotenv:` Or add the plugin to your project's `composer.json` - something like this: ```javascript { "require": { - "josegonzalez/dotenv": "dev-master" + "josegonzalez/dotenv": "3.3.0" } } ```