diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..27f1f68 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,92 @@ +name: CI + +on: + pull_request: + branches: + - '*' + push: + branches: + - '*' + +permissions: + contents: read + +jobs: + 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-check + + 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-${{ matrix.php-version }} + + coverage-php: + runs-on: ubuntu-22.04 + 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 }} + + 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-${{ matrix.php-version }} + + - name: Upload to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./tmp/coverage.xml + verbose: true diff --git a/.gitignore b/.gitignore index ed30b22..06f69f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,11 @@ .DS_Store build composer.lock -tmp +tmp/* +!tmp/.gitkeep vendor +.phpunit.result.cache +/.phpunit.cache +coverage.xml +unitreport.xml +.vscode 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/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" } } ``` diff --git a/composer.json b/composer.json index 347e6d4..5305cc3 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,49 @@ "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": { "josegonzalez\\Dotenv": ["src", "tests"] } + }, + "scripts": { + "ci": [ + "@cs-check", + "@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-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", + "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-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/phpunit.xml b/phpunit.5.xml similarity index 97% rename from phpunit.xml rename to phpunit.5.xml index b055268..c7eb229 100644 --- a/phpunit.xml +++ b/phpunit.5.xml @@ -7,7 +7,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" bootstrap="./tests/bootstrap.php" > diff --git a/phpunit.7.xml b/phpunit.7.xml new file mode 100644 index 0000000..3dca3e1 --- /dev/null +++ b/phpunit.7.xml @@ -0,0 +1,25 @@ + + + + + tests/josegonzalez/Dotenv + + + + + + src + + + diff --git a/phpunit.8.xml b/phpunit.8.xml new file mode 100644 index 0000000..5c67fb0 --- /dev/null +++ b/phpunit.8.xml @@ -0,0 +1,13 @@ + + + + + ./src + + + + + tests/josegonzalez/Dotenv + + + diff --git a/src/josegonzalez/Dotenv/Expect.php b/src/josegonzalez/Dotenv/Expect.php index 7389f1a..f94eacd 100644 --- a/src/josegonzalez/Dotenv/Expect.php +++ b/src/josegonzalez/Dotenv/Expect.php @@ -7,6 +7,8 @@ class Expect { + protected $environment = array(); + 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..2fd4b00 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(); @@ -32,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 0cd5c7c..5220fad 100644 --- a/tests/josegonzalez/Dotenv/ExpectTest.php +++ b/tests/josegonzalez/Dotenv/ExpectTest.php @@ -3,18 +3,29 @@ 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 { + protected $env = array(); - public function setUp() + protected $server = array(); + + /** + * Hopefully this will allow php > 7.1 to run. + * Phpunit >= 8.0 uses setUp(): void which this needs to match, but will break php 5.x + */ + public function compatibleSetUp() { $this->env = $_ENV; $this->server = $_SERVER; } - public function tearDown() + /** + * Hopefully this will allow php > 7.1 to run. + * Phpunit >= 8.0 uses tearDown(): void which this needs to match, but will break php 5.x + */ + public function compatibleTearDown() { $_ENV = $this->env; $_SERVER = $this->server; @@ -29,6 +40,7 @@ public function tearDown() */ public function testExpect() { + $this->compatibleSetUp(); $expect = new Expect($this->server); $this->assertTrue($expect('USER')); $this->assertTrue($expect(array('USER', 'HOME'))); @@ -36,9 +48,11 @@ public function testExpect() $expect = new Expect($this->server, false); $this->assertFalse($expect('FOO')); $this->assertFalse($expect(array('USER', 'FOO'))); + $this->compatibleTearDown(); } /** + * @covers \josegonzalez\Dotenv\Expect::__construct * @covers \josegonzalez\Dotenv\Expect::__invoke * @covers \josegonzalez\Dotenv\Expect::raise * @expectedException LogicException @@ -46,11 +60,18 @@ 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()'); + } $expect = new Expect($this->server); $expect(); + $this->compatibleTearDown(); } /** + * @covers \josegonzalez\Dotenv\Expect::__construct * @covers \josegonzalez\Dotenv\Expect::__invoke * @covers \josegonzalez\Dotenv\Expect::raise * @expectedException RuntimeException @@ -58,8 +79,13 @@ public function testExpectLogicException() */ public function testExpectRuntimeException() { + $this->compatibleSetUp(); + if (method_exists($this, 'expectException')) { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']"); + } $expect = new Expect($this->server); $expect('INVALID'); + $this->compatibleTearDown(); } - } diff --git a/tests/josegonzalez/Dotenv/LoaderTest.php b/tests/josegonzalez/Dotenv/LoaderTest.php index b3894c5..558a173 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) { @@ -14,18 +14,32 @@ function doNothing($data) class LoaderTest extends PHPUnit_Framework_TestCase { use PHPMock; + protected $env = array(); - public function setUp() + protected $server = array(); + + protected $fixturePath = ''; + + protected $Loader; + + /** + * Hopefully this will allow php > 7.1 to run. + * Phpunit >= 8.0 uses setUp(): void which this needs to match, but will break php 5.x + */ + public function compatibleSetUp() { $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() + /** + * Hopefully this will allow php > 7.1 to run. + * Phpunit >= 8.0 uses tearDown(): void which this needs to match, but will break php 5.x + */ + public function compatibleTearDown() { $_ENV = $this->env; $_SERVER = $this->server; @@ -36,27 +50,38 @@ public function tearDown() } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::filepath */ public function testFilepath() { + $this->compatibleSetUp(); $this->assertEquals($this->fixturePath . '.env', $this->Loader->filepath()); + $this->compatibleTearDown(); } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::filepaths */ public function testFilepaths() { + $this->compatibleSetUp(); $this->assertEquals(array($this->fixturePath . '.env'), $this->Loader->filepaths()); + $this->compatibleTearDown(); } /** + * @covers \josegonzalez\Dotenv\Loader::__construct * @covers \josegonzalez\Dotenv\Loader::setFilepath * @covers \josegonzalez\Dotenv\Loader::setFilepaths + * @covers \josegonzalez\Dotenv\Loader::filepath */ public function testSetFilepath() { + $this->compatibleSetUp(); $this->Loader->setFilepath('/tmp/.env'); $this->assertEquals('/tmp/.env', $this->Loader->filepath()); @@ -67,13 +92,22 @@ public function testSetFilepath() 'src' . DIRECTORY_SEPARATOR . 'josegonzalez' . DIRECTORY_SEPARATOR . 'Dotenv', ))); $this->assertEquals($basePath . DIRECTORY_SEPARATOR .'.env', $this->Loader->filepath()); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->setFilepath($this->fixturePath . 'all.env'); $this->Loader->parse(); $environment = $this->Loader->toArray(); @@ -154,8 +188,10 @@ public function testParse() $this->Loader->parse(); $environment = $this->Loader->toArray(); $this->assertEquals('app', $environment['APP_NAME']); - $this->assertSame(2, $environment['DEBUG']); - $this->assertInternalType('int', $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']); @@ -169,68 +205,121 @@ 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->compatibleTearDown(); } /** + * @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 */ 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->Loader->setFilepath($this->fixturePath . 'parse_exception.env'); $this->Loader->parse(); + $this->compatibleTearDown(); } /** + * @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 */ public function testParseFileNotFound() { + $this->compatibleSetUp(); + if (method_exists($this, 'expectException')) { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("Environment file '.env' is not found"); + } $this->Loader->setFilepath('.env'); $this->Loader->parse(); + $this->compatibleTearDown(); } /** + * @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 */ 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->Loader->setFilepath('/tmp'); $this->Loader->parse(); + $this->compatibleTearDown(); } /** + * @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 */ 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"); + } touch('/tmp/php-dotenv-unreadable'); chmod('/tmp/php-dotenv-unreadable', 0000); $this->Loader->setFilepath('/tmp/php-dotenv-unreadable'); $this->Loader->parse(); + $this->compatibleTearDown(); } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::filters */ public function testFilters() { + $this->compatibleSetUp(); $this->assertSame(array(), $this->Loader->filters()); + $this->compatibleTearDown(); } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::filters + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::setFilters */ public function testSetFilters() { + $this->compatibleSetUp(); $this->assertSame(array(), $this->Loader->filters()); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', @@ -250,38 +339,66 @@ function () { return array(); } ))); + $this->compatibleTearDown(); } /** + * @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 */ public function testSetFilterNonexistentFilter() { + $this->compatibleSetUp(); + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Invalid filter class SomeFilter'); + } $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'SomeFilter' ))); + $this->compatibleTearDown(); } /** + * @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 */ public function testSetFilterInvalidCallable() { + $this->compatibleSetUp(); + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Invalid filter class'); + } $this->assertEquals($this->Loader, $this->Loader->setFilters(array( $this ))); + $this->compatibleTearDown(); } /** + * @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 */ public function testFilter() { + $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', ))); @@ -293,15 +410,25 @@ public function testFilter() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->compatibleTearDown(); } /** + * @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 */ public function testFilterCallable() { + $this->compatibleSetUp(); $this->assertEquals($this->Loader, $this->Loader->setFilters(array( function () { return array('FOO' => 'BAR'); @@ -310,13 +437,25 @@ function () { $this->Loader->parse(); $this->Loader->filter(); $this->assertEquals(array('FOO' => 'BAR'), $this->Loader->toArray()); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', )); @@ -329,13 +468,25 @@ public function testLowercaseKeyFilter() 'spaced' => 'with spaces', 'equals' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\NullFilter', )); @@ -348,14 +499,26 @@ public function testNullFilter() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\RemapKeysFilter' => array( 'FOO' => 'QUX' @@ -370,13 +533,26 @@ public function testRemapKeysFilter() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\LowercaseKeyFilter', 'josegonzalez\Dotenv\Filter\UppercaseFirstKeyFilter', @@ -390,14 +566,26 @@ public function testUppercaseFirstKeyFilter() 'Spaced' => 'with spaces', 'Equals' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->compatibleTearDown(); } /** + * @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 */ public function testUrlParseFilter() { + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UrlParseFilter', )); @@ -425,13 +613,25 @@ public function testUrlParseFilter() 'DATABASE_QUERY' => 'encoding=utf8', 'DATABASE_FRAGMENT' => '', ), $environment); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter', )); @@ -458,15 +658,27 @@ public function testUnderscoreArrayFilter() ), ), $environment); + $this->compatibleTearDown(); } /** + * @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 */ public function testMultipleFilters() { + $this->compatibleSetUp(); $this->Loader->setFilters(array( 'josegonzalez\Dotenv\Filter\UrlParseFilter', 'josegonzalez\Dotenv\Filter\UnderscoreArrayFilter', @@ -501,50 +713,105 @@ public function testMultipleFilters() ), ), ), $environment); + $this->compatibleTearDown(); } /** + * @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() { + $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->compatibleTearDown(); } /** + * @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() */ public function testExpectRequireParse() { + $this->compatibleSetUp(); + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Environment must be parsed before calling expect()'); + } $this->Loader->expect(); + $this->compatibleTearDown(); } /** + * @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() */ public function testExpectLogicException() { + $this->compatibleSetUp(); + if (method_exists($this, 'expectException')) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('No arguments were passed to expect()'); + } $this->Loader->parse(); $this->Loader->expect(); + $this->compatibleTearDown(); } /** + * @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'] */ public function testExpectRuntimeException() { + $this->compatibleSetUp(); + if (method_exists($this, 'expectException')) { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage("Required ENV vars missing: ['INVALID']"); + } $this->Loader->parse(); $this->Loader->expect('INVALID'); + $this->compatibleTearDown(); } /** + * @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() @@ -553,13 +820,21 @@ public function testToApacheSetenvExceptionUnavailable() $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(); $this->Loader->apacheSetenv(false); + $this->compatibleTearDown(); } /** + * @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() @@ -568,6 +843,7 @@ public function testToApacheSetenv() $this->markTestSkipped('Unable to mock bare php functions'); } + $this->compatibleSetUp(); $apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv'); $apacheGetenv->expects($this->any())->willReturnCallback( function ($key) { @@ -592,9 +868,17 @@ 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->compatibleTearDown(); } /** + * @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() @@ -603,6 +887,7 @@ public function testToApacheSetenvSkip() $this->markTestSkipped('Unable to mock bare php functions'); } + $this->compatibleSetUp(); $apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv'); $apacheGetenv->expects($this->any())->willReturnCallback( function ($key) { @@ -629,9 +914,17 @@ 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->compatibleTearDown(); } /** + * @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() @@ -642,6 +935,12 @@ public function testToApacheSetenvException() $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()'); + } + $apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv'); $apacheGetenv->expects($this->any())->willReturnCallback( function ($key) { @@ -662,10 +961,19 @@ function ($key, $value) { $this->Loader->parse(); $this->Loader->apacheSetenv(false); $this->Loader->apacheSetenv(false); + $this->compatibleTearDown(); } /** + * @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() @@ -674,6 +982,7 @@ public function testToApacheSetenvPreserveZeros() $this->markTestSkipped('Unable to mock bare php functions'); } + $this->compatibleSetUp(); $apacheGetenv = $this->getFunctionMock(__NAMESPACE__, 'apache_getenv'); $apacheGetenv->expects($this->any())->willReturnCallback( function ($key) { @@ -704,13 +1013,21 @@ function ($key, $value) { $this->assertEquals('', apache_getenv('Z_BOOL')); $this->assertEquals('', apache_getenv('Z_STRING')); $this->assertEquals('', apache_getenv('Z_NULLABLE')); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->define(); @@ -718,13 +1035,22 @@ public function testDefine() $this->assertEquals('baz', BAR); $this->assertEquals('with spaces', SPACED); $this->assertEquals('pgsql:host=localhost;dbname=test', EQUALS); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->skipExisting('define'); $this->Loader->define(); @@ -733,24 +1059,45 @@ public function testDefineSkip() $this->assertEquals('baz', BAR); $this->assertEquals('with spaces', SPACED); $this->assertEquals('pgsql:host=localhost;dbname=test', EQUALS); + $this->compatibleTearDown(); } /** + * @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 */ 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(); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->putenv(false); @@ -758,13 +1105,22 @@ public function testToPutenv() $this->assertEquals('baz', getenv('BAR')); $this->assertEquals('with spaces', getenv('SPACED')); $this->assertEquals('pgsql:host=localhost;dbname=test', getenv('EQUALS')); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->skipExisting('putenv'); $this->Loader->putenv(false); @@ -774,25 +1130,47 @@ public function testToPutenvSkip() $this->assertEquals('baz', getenv('BAR')); $this->assertEquals('with spaces', getenv('SPACED')); $this->assertEquals('pgsql:host=localhost;dbname=test', getenv('EQUALS')); + $this->compatibleTearDown(); } /** + * @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() */ 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); $this->Loader->putenv(false); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); $this->Loader->putenv(false); @@ -806,13 +1184,21 @@ public function testToPutenvPreserveZeros() $this->assertEquals('', getenv('Z_BOOL')); $this->assertEquals('', getenv('Z_STRING')); $this->assertEquals('', getenv('Z_NULLABLE')); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->toEnv(false); @@ -820,13 +1206,22 @@ public function testToEnv() $this->assertEquals('baz', $_ENV['BAR']); $this->assertEquals('with spaces', $_ENV['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->skipExisting('toEnv'); $this->Loader->toEnv(false); @@ -836,25 +1231,47 @@ public function testToEnvSkip() $this->assertEquals('baz', $_ENV['BAR']); $this->assertEquals('with spaces', $_ENV['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_ENV['EQUALS']); + $this->compatibleTearDown(); } /** + * @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 */ 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); $this->Loader->toEnv(false); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); $this->Loader->toEnv(false); @@ -868,13 +1285,21 @@ public function testToEnvPreserveZeros() $this->assertEquals(false, $_ENV['Z_BOOL']); $this->assertEquals('', $_ENV['Z_STRING']); $this->assertEquals(null, $_ENV['Z_NULLABLE']); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->toServer(false); @@ -882,13 +1307,22 @@ public function testToServer() $this->assertEquals('baz', $_SERVER['BAR']); $this->assertEquals('with spaces', $_SERVER['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_SERVER['EQUALS']); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->parse(); $this->Loader->skipExisting('toServer'); $this->Loader->toServer(false); @@ -898,25 +1332,47 @@ public function testToServerSkip() $this->assertEquals('baz', $_SERVER['BAR']); $this->assertEquals('with spaces', $_SERVER['SPACED']); $this->assertEquals('pgsql:host=localhost;dbname=test', $_SERVER['EQUALS']); + $this->compatibleTearDown(); } /** + * @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 */ 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); $this->Loader->toServer(false); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->setFilepaths($this->fixturePath . 'zero_test_0.env'); $this->Loader->parse(); $this->Loader->toServer(false); @@ -930,14 +1386,18 @@ public function testToServerPreserveZeros() $this->assertEquals(false, $_SERVER['Z_BOOL']); $this->assertEquals('', $_SERVER['Z_STRING']); $this->assertEquals(null, $_SERVER['Z_NULLABLE']); + $this->compatibleTearDown(); } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::skipped * @covers \josegonzalez\Dotenv\Loader::skipExisting */ public function testSkipExisting() { + $this->compatibleSetUp(); $this->assertEquals(array(), $this->Loader->skipped()); $this->Loader->skipExisting('toEnv'); @@ -948,14 +1408,18 @@ public function testSkipExisting() $this->Loader->skipExisting(); $this->assertEquals(array('apacheSetenv', 'define', 'putenv', 'toEnv', 'toServer'), $this->Loader->skipped()); + $this->compatibleTearDown(); } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::prefix * @covers \josegonzalez\Dotenv\Loader::prefixed */ public function testPrefix() { + $this->compatibleSetUp(); $this->assertEquals('KEY', $this->Loader->prefixed('KEY')); $this->Loader->prefix('PREFIX_'); @@ -963,13 +1427,21 @@ public function testPrefix() $this->Loader->prefix('PREFIX_TWO_'); $this->assertEquals('PREFIX_TWO_KEY', $this->Loader->prefixed('KEY')); + $this->compatibleTearDown(); } /** + * @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() { + $this->compatibleSetUp(); $this->Loader->parse(); $this->assertEquals(array( 'FOO' => 'bar', @@ -977,76 +1449,154 @@ public function testToArray() 'SPACED' => 'with spaces', 'EQUALS' => 'pgsql:host=localhost;dbname=test', ), $this->Loader->toArray()); + $this->compatibleTearDown(); } /** + * @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() */ 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(); } /** + * @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() { + $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->compatibleTearDown(); } /** + * @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() { + $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() */ 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(); } /** + * @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() { + $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 */ 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(); } /** + * @covers \josegonzalez\Dotenv\Loader::__construct + * @covers \josegonzalez\Dotenv\Loader::setFilepaths * @covers \josegonzalez\Dotenv\Loader::raiseExceptions * @covers \josegonzalez\Dotenv\Loader::raise */ 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(); $dotenv = Loader::load(array( 'raiseExceptions' => false )); @@ -1128,12 +1678,13 @@ public function testStatic() 'DATABASE_QUERY' => 'encoding=utf8', 'DATABASE_FRAGMENT' => '', ), $dotenv->toArray()); + $this->compatibleTearDown(); } /** * 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 diff --git a/tmp/.gitkeep b/tmp/.gitkeep new file mode 100644 index 0000000..e69de29