From e27d65dfbd40d6997894b5917dd8e11b690e5e40 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 3 Nov 2023 09:55:15 -0700 Subject: [PATCH 1/5] Add phpunit --- composer.json | 2 +- src/DotenvVault.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index d05786e..e208daf 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,6 @@ "vlucas/phpdotenv": "^5.5" }, "require-dev": { - "orchestra/testbench": "^3.8" + "phpunit/phpunit": "^10.4" } } diff --git a/src/DotenvVault.php b/src/DotenvVault.php index 0dc2f06..343fea9 100644 --- a/src/DotenvVault.php +++ b/src/DotenvVault.php @@ -45,8 +45,8 @@ public function load() $plaintext = $this->parse_vault(); // parsing plaintext and loading to getenv - $test_entries = $this->parser->parse($plaintext); - $this->loader->load($this->repository, $test_entries); + $vault_entries = $this->parser->parse($plaintext); + $this->loader->load($this->repository, $vault_entries); } else { $entries = $this->parser->parse($this->store->read()); From 372e370a653d9df3847dd1de03205a833ecf73c5 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 3 Nov 2023 09:58:05 -0700 Subject: [PATCH 2/5] Set up composer with test autoloads --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index e208daf..2cb677b 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,11 @@ "DotenvVault\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "DotenvVault\\Tests\\": "tests/" + } + }, "authors": [ { "name": "dotenv", From 33c7f44d24bc1db1e5f22b3707e6c4abcd5f369f Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 3 Nov 2023 10:10:33 -0700 Subject: [PATCH 3/5] Adds functional testing --- DEVELOPMENT.md | 8 ++++++ phpunit.xml.dist | 29 +++++++++++++++++++++ tests/DotenvVault/DotenvVaultTest.php | 37 +++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 phpunit.xml.dist create mode 100644 tests/DotenvVault/DotenvVaultTest.php diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index a4b9307..b84ca90 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -1,5 +1,13 @@ # DEVELOPMENT +## Running tests + +Tests use PHPUnit. + +``` +./vendor/bin/phpunit +``` + ## Publishing Published at [packagist](https://packagist.org/packages/dotenv-org/phpdotenv-vault) diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..b57bcc9 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,29 @@ + + + + + ./tests + + + + + ./src + + + diff --git a/tests/DotenvVault/DotenvVaultTest.php b/tests/DotenvVault/DotenvVaultTest.php new file mode 100644 index 0000000..4eb3905 --- /dev/null +++ b/tests/DotenvVault/DotenvVaultTest.php @@ -0,0 +1,37 @@ +expectException(InvalidPathException::class); + $this->expectExceptionMessage('Unable to read any of the environment file(s) at'); + + $dotenv->load(); + } +} +?> From 256558f8f6dcdf6fe4de612e0d5b40ad2a48a568 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 3 Nov 2023 10:14:10 -0700 Subject: [PATCH 4/5] Passing test --- .gitignore | 4 ++- phpunit.xml.dist | 39 +++++++++------------------ tests/DotenvVault/DotenvVaultTest.php | 7 ++++- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 979d356..290276a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,6 @@ phpstan.tests.neon phpunit.xml vendor -.vscode \ No newline at end of file +.vscode + +.phpunit.cache diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b57bcc9..020141b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,29 +1,14 @@ - - - - ./tests - - - - - ./src - - + + + + + ./tests + + + + + ./src + + diff --git a/tests/DotenvVault/DotenvVaultTest.php b/tests/DotenvVault/DotenvVaultTest.php index 4eb3905..67953e5 100644 --- a/tests/DotenvVault/DotenvVaultTest.php +++ b/tests/DotenvVault/DotenvVaultTest.php @@ -4,7 +4,12 @@ namespace DotenvVault\Tests; +// phpdotenv-vault libs use DotenvVault\DotenvVault; + +// phpdotenv libs +use Dotenv; + use PHPUnit\Framework\TestCase; final class DotenvVaultTest extends TestCase @@ -28,7 +33,7 @@ public function testDotenvThrowsExceptionIfUnableToLoadFile() { $dotenv = DotenvVault::createMutable(__DIR__); - $this->expectException(InvalidPathException::class); + $this->expectException(Dotenv\Exception\InvalidPathException::class); $this->expectExceptionMessage('Unable to read any of the environment file(s) at'); $dotenv->load(); From a81fdb115088ca2462fff513e51f98a920d0c136 Mon Sep 17 00:00:00 2001 From: Scott Motte Date: Fri, 3 Nov 2023 10:18:38 -0700 Subject: [PATCH 5/5] Add GitHub workflow ci --- ci.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ci.yml diff --git a/ci.yml b/ci.yml new file mode 100644 index 0000000..584bb1c --- /dev/null +++ b/ci.yml @@ -0,0 +1,33 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + php: [7.x, 8.x] + + steps: + - uses: actions/checkout@v3 + - name: Use PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + coverage: none + - name: Setup problem matchers + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Install latest dependencies + uses: nick-invision/retry@v2 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --no-interaction --no-progress + - run: vendor/bin/phpunit