diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index e3e6101e..9bbcd040 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -65,5 +65,12 @@ jobs: if: ${{ matrix.dependencies == 'locked' }} run: "composer install --no-interaction --no-progress --no-suggest" + - name: "Compile PHAR" + run: | + php -d phar.readonly=0 vendor/bin/phing phar-build + # We re-run 'composer install' here as phing runs 'composer install --no-dev'. + # Using 'install' (not 'update' with flags) here is correct as the previous update re-wrote wrote the lock file. + composer --no-interaction install --no-progress + - name: "Tests" run: "vendor/bin/phpunit --coverage-clover=clover.xml --coverage-text" diff --git a/test/ComposerRequireCheckerTest/PharTest.php b/test/ComposerRequireCheckerTest/PharTest.php new file mode 100644 index 00000000..52751ecc --- /dev/null +++ b/test/ComposerRequireCheckerTest/PharTest.php @@ -0,0 +1,96 @@ +markTestSkipped('Compiled PHAR not found'); + } + + $this->oldWorkingDirectory = getcwd(); + $this->bin = PHP_BINARY . ' ' . escapeshellarg($phar); + } + + protected function tearDown(): void + { + if ($this->oldWorkingDirectory === getcwd()) { + return; + } + + chdir($this->oldWorkingDirectory); + } + + public function testVersion(): void + { + $command = $this->bin . ' --version'; + exec($command, $output, $return); + $this->assertStringContainsString('ComposerRequireChecker', implode("\n", $output)); + $this->assertSame(0, $return); + } + + public function testSuccess(): void + { + exec($this->bin, $output, $return); + $this->assertSame(0, $return); + } + + public function testUnknownSymbols(): void + { + $path = __DIR__ . '/../fixtures/unknownSymbols/composer.json'; + exec(sprintf('%s check %s 2>&1', $this->bin, $path), $output, $return); + $this->assertStringContainsString('The following 6 unknown symbols were found', implode("\n", $output)); + $this->assertNotEquals(0, $return); + } + + public function testInvalidConfiguration(): void + { + $path = __DIR__ . '/../fixtures/validJson.json'; + exec(sprintf('%s check %s 2>&1', $this->bin, $path), $output, $return); + $this->assertStringContainsString('dependencies have not been installed', implode("\n", $output)); + $this->assertNotEquals(0, $return); + } + + public function testDefaultConfiguration(): void + { + chdir(__DIR__ . '/../fixtures/defaultConfigPath'); + exec(sprintf('%s check 2>&1', $this->bin), $output, $return); + $output = implode("\n", $output); + + $this->assertMatchesRegularExpression('/The following [12] unknown symbols were found/', $output); + $this->assertMatchesRegularExpression('/Composer\\\\InstalledVersions/', $output); + $this->assertNotEquals(0, $return); + } + + public function testMissingCustomConfiguration(): void + { + chdir(__DIR__ . '/../fixtures/noUnknownComposerSymbol'); + exec(sprintf('%s check --config-file=%s 2>&1', $this->bin, 'no-such-file'), $output, $return); + + $this->assertStringContainsString('Configuration file [no-such-file] does not exist.', implode("\n", $output)); + $this->assertNotEquals(0, $return); + } +}