Skip to content

Commit

Permalink
Merge pull request #55 from 302dev/pr-55
Browse files Browse the repository at this point in the history
Pull request replaces #54
  • Loading branch information
josegonzalez authored May 29, 2023
2 parents f6d2fb6 + 01db3ac commit e97dbd3
Show file tree
Hide file tree
Showing 13 changed files with 771 additions and 43 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
.DS_Store
build
composer.lock
tmp
tmp/*
!tmp/.gitkeep
vendor
.phpunit.result.cache
/.phpunit.cache
coverage.xml
unitreport.xml
.vscode
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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"
}
}
```
Expand Down
42 changes: 39 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
1 change: 0 additions & 1 deletion phpunit.xml → phpunit.5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<testsuites>
Expand Down
25 changes: 25 additions & 0 deletions phpunit.7.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
>
<testsuites>
<testsuite name="Dotenv Test Suite">
<directory suffix=".php">tests/josegonzalez/Dotenv</directory>
</testsuite>
</testsuites>
<filter>
<!-- this is required, even if empty, until
https://github.com/sebastianbergmann/phpunit/issues/1872
is resolved -->
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
13 changes: 13 additions & 0 deletions phpunit.8.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="tests/bootstrap.php" executionOrder="depends,defects" forceCoversAnnotation="true" beStrictAboutCoversAnnotation="true" beStrictAboutOutputDuringTests="true" beStrictAboutTodoAnnotatedTests="true" convertDeprecationsToExceptions="true" failOnRisky="false" failOnWarning="true" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" verbose="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Dotenv Test Suite">
<directory suffix=".php">tests/josegonzalez/Dotenv</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 2 additions & 0 deletions src/josegonzalez/Dotenv/Expect.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class Expect
{
protected $environment = array();

protected $raise = true;

public function __construct($environment, $raise = true)
Expand Down
3 changes: 2 additions & 1 deletion src/josegonzalez/Dotenv/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Loader

protected $environment = null;

protected $exceptions = array();

protected $filepaths = null;

protected $filters = array();
Expand All @@ -32,7 +34,6 @@ class Loader
public function __construct($filepaths = null)
{
$this->setFilepaths($filepaths);
return $this;
}

public static function load($options = null)
Expand Down
34 changes: 30 additions & 4 deletions tests/josegonzalez/Dotenv/ExpectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,37 +40,52 @@ public function tearDown()
*/
public function testExpect()
{
$this->compatibleSetUp();
$expect = new Expect($this->server);
$this->assertTrue($expect('USER'));
$this->assertTrue($expect(array('USER', 'HOME')));

$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
* @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()');
}
$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
* @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']");
}
$expect = new Expect($this->server);
$expect('INVALID');
$this->compatibleTearDown();
}

}
Loading

0 comments on commit e97dbd3

Please sign in to comment.