Skip to content

Commit

Permalink
Merge pull request #9 from dotenv-org/tests
Browse files Browse the repository at this point in the history
Add phpunit
  • Loading branch information
motdotla authored Nov 3, 2023
2 parents a9aa772 + a81fdb1 commit dff3ebf
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ phpstan.tests.neon
phpunit.xml
vendor

.vscode
.vscode

.phpunit.cache
8 changes: 8 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
33 changes: 33 additions & 0 deletions ci.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"DotenvVault\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"DotenvVault\\Tests\\": "tests/"
}
},
"authors": [
{
"name": "dotenv",
Expand All @@ -27,6 +32,6 @@
"vlucas/phpdotenv": "^5.5"
},
"require-dev": {
"orchestra/testbench": "^3.8"
"phpunit/phpunit": "^10.4"
}
}
14 changes: 14 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="vendor/autoload.php" colors="true" failOnRisky="true" failOnWarning="false" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage/>
<testsuites>
<testsuite name="PHP DotenvVault Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/DotenvVault.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
42 changes: 42 additions & 0 deletions tests/DotenvVault/DotenvVaultTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace DotenvVault\Tests;

// phpdotenv-vault libs
use DotenvVault\DotenvVault;

// phpdotenv libs
use Dotenv;

use PHPUnit\Framework\TestCase;

final class DotenvVaultTest extends TestCase
{
/**
* @var string
*/
private static $folder;

/**
* @beforeClass
*
* @return void
*/
public static function setFolder()
{
self::$folder = \dirname(__DIR__).'/fixtures/env';
}

public function testDotenvThrowsExceptionIfUnableToLoadFile()
{
$dotenv = DotenvVault::createMutable(__DIR__);

$this->expectException(Dotenv\Exception\InvalidPathException::class);
$this->expectExceptionMessage('Unable to read any of the environment file(s) at');

$dotenv->load();
}
}
?>

0 comments on commit dff3ebf

Please sign in to comment.