Skip to content

Commit

Permalink
1.) added: full test coverage
Browse files Browse the repository at this point in the history
2.) added: code formatting

PackageEnvLoaderContract:
1.) removed: not needed docblock

PackageEnvLoader:
1.) removed: not needed docblock
2.) added: return type mixed

ExampleIntegration:
1.) added: code format

composer.json:
1.) removed: support for php 7.4
2.) added: support for php 8.x
3.) added: version bump
4.) added: testing scripts
  • Loading branch information
Faks committed Feb 12, 2023
1 parent bc86578 commit d1c291e
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor
composer.lock
14 changes: 10 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Contributions are welcome and will be fully credited.
Contributions are accepted via Pull Requests on [Github](https://github.com/solumdesignum/package-env-loader).

# Things you could do

If you want to contribute but do not know where to start, this list provides some starting points.

- Add license text
- Set up StyleCI, ScrutinizerCI, PHPCS, PHPStan
- Write a comprehensive ReadMe
Expand All @@ -14,13 +16,17 @@ If you want to contribute but do not know where to start, this list provides som

## Pull Requests

- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.
- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept
up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs
is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make
multiple intermediate commits while developing,
please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages)
before submitting.

**Happy coding**!
25 changes: 10 additions & 15 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ MIT License

Copyright (c) Oskars Germovs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)

## Introduction

Framework agnostic environment loader that abstracts PHP dotEnv for faster env loading.

## Installation

To get started, install PackageEnvLoader using the Composer package manager:

```shell
composer require solumdesignum/package-env-loader
```

## Origins
I created this package because, I was very frustrated with this issue that I can't
share my .env file between javascript frameworks due to this package was born.

I created this package because, I was very frustrated with this issue that I can't share my .env file between javascript
frameworks due to this package was born.

## Usage

```php
<?php

Expand Down Expand Up @@ -59,18 +64,22 @@ class ExampleIntegration implements PackageEnvLoaderContract
````

## Contributing
Thank you for considering contributing to the PackageEnvLoader. You can read
the
contribution guidelines [here](CONTRIBUTING.md)

Thank you for considering contributing to the PackageEnvLoader. You can read the contribution
guidelines [here](CONTRIBUTING.md)

## Security

If you discover any security-related issues, please email to [Solum DeSignum](mailto:oskars_germovs@inbox.lv).

## Credits

- [Oskars Germovs](https://github.com/Faks)

## About

[Solum DeSignum](https://solum-designum.eu) is a web design agency based in Latvia, Riga.

## License

PackageEnvLoader is open-sourced software licensed under the [MIT license](LICENSE.md)
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@
"environment"
],
"require": {
"php": "^7.4|^8.0|^8.1"
"php": "^8.0|^8.1|^8.2",
"vlucas/phpdotenv": "^v5.5.0"
},
"require-dev": {
"vlucas/phpdotenv": "^v5.2"
"php": "^8.0|^8.1|^8.2",
"vlucas/phpdotenv": "^v5.5.0",
"phpunit/phpunit": "~8|~9|~10",
"mockery/mockery": "^1.1",
"orchestra/testbench": "~3|~4|~5|~6|~7",
"sempro/phpunit-pretty-print": "^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -33,5 +39,9 @@
"psr-4": {
"SolumDeSignum\\PackageEnvLoader\\Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "phpunit --coverage-html coverage"
}
}
3 changes: 0 additions & 3 deletions src/Contracts/PackageEnvLoaderContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

interface PackageEnvLoaderContract
{
/**
* @return string
*/
public function packageEnvRootPath(): string;
}
7 changes: 1 addition & 6 deletions src/Traits/PackageEnvLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

trait PackageEnvLoader
{
/**
* @param string $environmentFile
*
* @return null[]|string|string[]
*/
final public function createPackageDotenv(string $environmentFile = '.env')
final public function createPackageDotenv(string $environmentFile = '.env'): mixed
{
try {
$response = Dotenv::create(
Expand Down
2 changes: 1 addition & 1 deletion stubs/ExampleIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public function __construct()
*/
final public function packageEnvRootPath(string $path = '/..'): string
{
return __DIR__.$path;
return __DIR__ . $path;
}
}
1 change: 1 addition & 0 deletions tests/.env.first.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PACKAGE_NAME_FIRST="PACKAGE_ENV_LOADER"
1 change: 1 addition & 0 deletions tests/.env.second.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PACKAGE_NAME_SECOND="PACKAGE_ENV_LOADER_SECOND"
83 changes: 83 additions & 0 deletions tests/Unit/PackageEnvLoaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

declare(strict_types=1);

namespace SolumDeSignum\PackageEnvLoader\Tests\Unit;

use Orchestra\Testbench\TestCase;
use SolumDeSignum\PackageEnvLoader\Contracts\PackageEnvLoaderContract;
use SolumDeSignum\PackageEnvLoader\Traits\PackageEnvLoader;

class PackageEnvLoaderTest extends TestCase implements PackageEnvLoaderContract
{
use PackageEnvLoader;

final public function packageEnvRootPath(string $path = '/..'): string
{
return __DIR__ . $path;
}

/**
* @test
*/
final public function firstEnv(): void
{
$this->assertFileExists($this->packageEnvRootPath() . '/.env.first.test');
}

/**
* @test
*/
final public function secondEnv(): void
{
$this->assertFileExists($this->packageEnvRootPath() . '/.env.second.test');
}

/**
* @test
*/
final public function packageName(): void
{
$responsePackageDotenv = $this->createPackageDotenv('.env.first.test');
$this->assertSame('PACKAGE_ENV_LOADER', env('PACKAGE_NAME_FIRST'));
}

/**
* @test
*/
final public function packageDotenv(): void
{
$responsePackageDotenv = $this->createPackageDotenv('.env.first.test');
$this->assertIsArray($responsePackageDotenv);
}

/**
* @test
*/
final public function everything(): void
{
$this->assertFileExists($this->packageEnvRootPath() . '/.env.first.test');

$responsePackageDotenv = $this->createPackageDotenv('.env.first.test');
$this->assertIsArray($responsePackageDotenv);

$this->assertSame('PACKAGE_ENV_LOADER', env('PACKAGE_NAME_FIRST'));
}

/**
* @test
*/
final public function multipleEverything(): void
{
$this->assertFileExists($this->packageEnvRootPath() . '/.env.first.test');
$this->assertFileExists($this->packageEnvRootPath() . '/.env.second.test');

$responsePackageDotenvFirst = $this->createPackageDotenv('.env.first.test');
$this->assertIsArray($responsePackageDotenvFirst);
$this->assertSame('PACKAGE_ENV_LOADER', env('PACKAGE_NAME_FIRST'));

$responsePackageDotenvSecond = $this->createPackageDotenv('.env.second.test');
$this->assertIsArray($responsePackageDotenvSecond);
$this->assertSame('PACKAGE_ENV_LOADER_SECOND', env('PACKAGE_NAME_SECOND'));
}
}

0 comments on commit d1c291e

Please sign in to comment.