Skip to content

Commit

Permalink
Move to from travis GitHub actions and fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
websi committed Dec 7, 2023
1 parent 04c496b commit eb3157c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 87 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI

on: [push]

jobs:
phpunit:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}

steps:
- uses: actions/checkout@v4
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: intl
- uses: php-actions/composer@v6
with:
php-version: ${{ matrix.php-versions }}
- uses: michaelw90/PHP-Lint@v2
- uses: php-actions/phpunit@v3
with:
php-version: ${{ matrix.php-versions }}
bootstrap: vendor/autoload.php
log_junit: 1
testdox_text: 1
args: tests/Unit/
49 changes: 0 additions & 49 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require-dev": {
"composer/composer": "^1.0 || 2.0.*@dev",
"phpunit/phpunit": "^5",
"phpunit/phpunit": "^9",
"mikey179/vfsstream": "^1.6.0",
"composer/semver": "^1.0 || ^2.0 || 3.0.*@dev"
},
Expand Down
91 changes: 54 additions & 37 deletions tests/Unit/IncludeFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Helhum\DotEnvConnector\Adapter\SymfonyDotEnv;
use Helhum\DotEnvConnector\Config;
use Helhum\DotEnvConnector\IncludeFile;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophet;

class IncludeFileTest extends \PHPUnit_Framework_TestCase
class IncludeFileTest extends TestCase
{
protected function tearDown()
protected function tearDown(): void
{
if (file_exists(__DIR__ . '/Fixtures/vendor/helhum/include.php')) {
unlink(__DIR__ . '/Fixtures/vendor/helhum/include.php');
Expand All @@ -28,15 +30,18 @@ protected function tearDown()
*/
public function dumpDumpsFile()
{
$configProphecy = $this->prophesize(Config::class);
$configProphecy->get('env-file')->willReturn(__DIR__ . '/Fixtures/env/.env');
$configProphecy->get('adapter')->willReturn(SymfonyDotEnv::class);
$loaderProphecy = $this->prophesize(ClassLoader::class);
$loaderProphecy->register()->shouldBeCalled();
$loaderProphecy->unregister()->shouldBeCalled();
$config = new Config();
$config->merge(['extra' => ['helhum/dotenv-connector' => [
'env-file' => __DIR__ . '/Fixtures/env/.env',
'adapter' => SymfonyDotEnv::class
]]]);
/** @var ClassLoader|\PHPUnit\Framework\MockObject\MockObject $loaderMock */
$loaderMock = $this->createMock(ClassLoader::class);
$loaderMock->expects($this->once())->method('register');
$loaderMock->expects($this->once())->method('unregister');

$includeFilePath = __DIR__ . '/Fixtures/vendor/helhum/include.php';
$includeFile = new IncludeFile($configProphecy->reveal(), $loaderProphecy->reveal(), $includeFilePath);
$includeFile = new IncludeFile($config, $loaderMock, $includeFilePath);
$includeFile->dump();
$this->assertTrue(file_exists($includeFilePath));
}
Expand All @@ -46,15 +51,18 @@ public function dumpDumpsFile()
*/
public function includingFileExposesEnvVars()
{
$configProphecy = $this->prophesize(Config::class);
$configProphecy->get('env-file')->willReturn(__DIR__ . '/Fixtures/env/.env');
$configProphecy->get('adapter')->willReturn(SymfonyDotEnv::class);
$loaderProphecy = $this->prophesize(ClassLoader::class);
$loaderProphecy->register()->shouldBeCalled();
$loaderProphecy->unregister()->shouldBeCalled();
$config = new Config();
$config->merge(['extra' => ['helhum/dotenv-connector' => [
'env-file' => __DIR__ . '/Fixtures/env/.env',
'adapter' => SymfonyDotEnv::class
]]]);
/** @var ClassLoader|\PHPUnit\Framework\MockObject\MockObject $loaderMock */
$loaderMock = $this->createMock(ClassLoader::class);
$loaderMock->expects($this->once())->method('register');
$loaderMock->expects($this->once())->method('unregister');

$includeFilePath = __DIR__ . '/Fixtures/vendor/helhum/include.php';
$includeFile = new IncludeFile($configProphecy->reveal(), $loaderProphecy->reveal(), $includeFilePath);
$includeFile = new IncludeFile($config, $loaderMock, $includeFilePath);
$includeFile->dump();
$this->assertTrue(file_exists($includeFilePath));

Expand All @@ -67,15 +75,18 @@ public function includingFileExposesEnvVars()
public function includingFileDoesNothingIfEnvVarSet()
{
putenv('APP_ENV=1');
$configProphecy = $this->prophesize(Config::class);
$configProphecy->get('env-file')->willReturn(__DIR__ . '/Fixtures/env/.env');
$configProphecy->get('adapter')->willReturn(SymfonyDotEnv::class);
$loaderProphecy = $this->prophesize(ClassLoader::class);
$loaderProphecy->register()->shouldBeCalled();
$loaderProphecy->unregister()->shouldBeCalled();
$config = new Config();
$config->merge(['extra' => ['helhum/dotenv-connector' => [
'env-file' => __DIR__ . '/Fixtures/env/.env',
'adapter' => SymfonyDotEnv::class
]]]);
/** @var ClassLoader|\PHPUnit\Framework\MockObject\MockObject $loaderMock */
$loaderMock = $this->createMock(ClassLoader::class);
$loaderMock->expects($this->once())->method('register');
$loaderMock->expects($this->once())->method('unregister');

$includeFilePath = __DIR__ . '/Fixtures/vendor/helhum/include.php';
$includeFile = new IncludeFile($configProphecy->reveal(), $loaderProphecy->reveal(), $includeFilePath);
$includeFile = new IncludeFile($config, $loaderMock, $includeFilePath);
$includeFile->dump();
$this->assertTrue(file_exists($includeFilePath));

Expand All @@ -87,15 +98,18 @@ public function includingFileDoesNothingIfEnvVarSet()
*/
public function includingFileDoesNothingIfEnvFileDoesNotExist()
{
$configProphecy = $this->prophesize(Config::class);
$configProphecy->get('env-file')->willReturn(__DIR__ . '/Fixtures/env/.no-env');
$configProphecy->get('adapter')->willReturn(SymfonyDotEnv::class);
$loaderProphecy = $this->prophesize(ClassLoader::class);
$loaderProphecy->register()->shouldBeCalled();
$loaderProphecy->unregister()->shouldBeCalled();
$config = new Config();
$config->merge(['extra' => ['helhum/dotenv-connector' => [
'env-file' => __DIR__ . '/Fixtures/env/.env.not.exist',
'adapter' => SymfonyDotEnv::class
]]]);
/** @var ClassLoader|\PHPUnit\Framework\MockObject\MockObject $loaderMock */
$loaderMock = $this->createMock(ClassLoader::class);
$loaderMock->expects($this->once())->method('register');
$loaderMock->expects($this->once())->method('unregister');

$includeFilePath = __DIR__ . '/Fixtures/vendor/helhum/include.php';
$includeFile = new IncludeFile($configProphecy->reveal(), $loaderProphecy->reveal(), $includeFilePath);
$includeFile = new IncludeFile($config, $loaderMock, $includeFilePath);
$includeFile->dump();
$this->assertTrue(file_exists($includeFilePath));

Expand All @@ -107,16 +121,19 @@ public function includingFileDoesNothingIfEnvFileDoesNotExist()
*/
public function dumpReturnsFalseIfFileCannotBeWritten()
{
$configProphecy = $this->prophesize(Config::class);
$configProphecy->get('env-file')->willReturn(__DIR__ . '/Fixtures/env/.no-env');
$configProphecy->get('adapter')->willReturn(SymfonyDotEnv::class);
$loaderProphecy = $this->prophesize(ClassLoader::class);
$loaderProphecy->register()->shouldBeCalled();
$loaderProphecy->unregister()->shouldBeCalled();
$config = new Config();
$config->merge(['extra' => ['helhum/dotenv-connector' => [
'env-file' => __DIR__ . '/Fixtures/env/.env',
'adapter' => SymfonyDotEnv::class
]]]);
/** @var ClassLoader|\PHPUnit\Framework\MockObject\MockObject $loaderMock */
$loaderMock = $this->createMock(ClassLoader::class);
$loaderMock->expects($this->once())->method('register');
$loaderMock->expects($this->once())->method('unregister');

mkdir(__DIR__ . '/Fixtures/foo', 000);
$includeFilePath = __DIR__ . '/Fixtures/foo/include.php';
$includeFile = new IncludeFile($configProphecy->reveal(), $loaderProphecy->reveal(), $includeFilePath);
$includeFile = new IncludeFile($config, $loaderMock, $includeFilePath);
$this->assertFalse($includeFile->dump());
}
}

0 comments on commit eb3157c

Please sign in to comment.