diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..16be5cc --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,46 @@ +name: CI + +on: [push] + +jobs: + lint: + 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: michaelw90/PHP-Lint@master + 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: php-actions/phpunit@v3 + with: + php-version: ${{ matrix.php-versions }} + bootstrap: vendor/autoload.php + log_junit: 1 + testdox_text: 1 + args: tests/Unit/ \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 95a5e04..0000000 --- a/.travis.yml +++ /dev/null @@ -1,49 +0,0 @@ -language: php - -php: - - 7.2 - - 7.3 - - 7.4 - - 8.0 - - 8.1 - - 8.2 - - 8.3 - -addons: - apt: - packages: - - parallel - -sudo: false -cache: - directories: - - $HOME/.composer/cache - -# Do not build feature branches or alpha/beta releases -branches: - only: - - master - - develop - - /^([0-9]+\.){1,2}(x|[0-9]+)$/ - -notifications: - email: - - typo3@helhum.io - -before_install: - - phpenv config-rm xdebug.ini - - composer self-update - - composer --version - -before_script: - - composer install - -script: - - > - echo; - echo "Running unit tests"; - vendor/bin/phpunit tests/Unit/ - - > - echo; - echo "Running php lint"; - find . -name \*.php ! -path "./vendor/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \; diff --git a/composer.json b/composer.json index 48582d0..3872e41 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/tests/Unit/IncludeFileTest.php b/tests/Unit/IncludeFileTest.php index edb1d8c..fc2d264 100644 --- a/tests/Unit/IncludeFileTest.php +++ b/tests/Unit/IncludeFileTest.php @@ -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'); @@ -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)); } @@ -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)); @@ -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/.no-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)); @@ -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/.no-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)); @@ -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()); } }