diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index be567c4..edd1876 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,6 +54,8 @@ jobs: restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies run: composer update -n --prefer-dist ${{ matrix.composer-flags }} + - name: Set default branch for tests + run: git config --global init.defaultBranch main - name: Run Tests run: vendor/bin/simple-phpunit --coverage-clover coverage.xml --coverage-text - name: Upload coverage to Codecov diff --git a/tests/Formatter/FormatterTest.php b/tests/Formatter/FormatterTest.php index 435ff99..2ec225f 100644 --- a/tests/Formatter/FormatterTest.php +++ b/tests/Formatter/FormatterTest.php @@ -3,6 +3,7 @@ namespace IonBazan\ComposerDiff\Tests\Formatter; use Composer\DependencyResolver\Operation\InstallOperation; +use Composer\DependencyResolver\Operation\OperationInterface; use Composer\DependencyResolver\Operation\UninstallOperation; use Composer\DependencyResolver\Operation\UpdateOperation; use Composer\Package\PackageInterface; @@ -43,29 +44,22 @@ public function testGetProjectUrlReturnsNullForInvalidOperation() /** * @param bool $withUrls + * @param bool $decorated * * @testWith [false] * [true] + * [false, true] + * [true, true] */ - public function testItRendersTheListOfOperations($withUrls) + public function testItRendersTheListOfOperations($withUrls, $decorated = false) { - $output = new StreamOutput(fopen('php://memory', 'wb', false)); - $formatter = $this->getFormatter($output, $this->getGenerators()); - $prodPackages = array( - new InstallOperation($this->getPackage('a/package-1', '1.0.0')), - new InstallOperation($this->getPackage('a/no-link-1', '1.0.0')), - new UpdateOperation($this->getPackage('a/package-2', '1.0.0'), $this->getPackage('a/package-2', '1.2.0')), - new UpdateOperation($this->getPackage('a/package-3', '2.0.0'), $this->getPackage('a/package-3', '1.1.1')), - new UpdateOperation($this->getPackage('a/no-link-2', '2.0.0'), $this->getPackage('a/no-link-2', '1.1.1')), - new UpdateOperation($this->getPackage('php', '>=7.4.6'), $this->getPackage('php', '^8.0')), + $output = new StreamOutput(fopen('php://memory', 'wb', false), OutputInterface::VERBOSITY_NORMAL, $decorated); + $this->getFormatter($output, $this->getGenerators())->render( + $this->getEntries($this->getSampleProdOperations()), + $this->getEntries($this->getSampleDevOperations()), + $withUrls ); - $devPackages = array( - new UpdateOperation($this->getPackage('a/package-5', 'dev-master', 'dev-master 1234567'), $this->getPackage('a/package-5', '1.1.1')), - new UninstallOperation($this->getPackage('a/package-4', '0.1.1')), - new UninstallOperation($this->getPackage('a/no-link-2', '0.1.1')), - ); - $formatter->render($this->getEntries($prodPackages), $this->getEntries($devPackages), $withUrls); - $this->assertSame($this->getSampleOutput($withUrls), $this->getDisplay($output)); + $this->assertSame($this->getSampleOutput($withUrls, $decorated), $this->getDisplay($output)); } public function testItFailsWithInvalidOperation() @@ -84,10 +78,11 @@ abstract protected function getFormatter(OutputInterface $output, GeneratorConta /** * @param bool $withUrls + * @param bool $decorated * * @return string */ - abstract protected function getSampleOutput($withUrls); + abstract protected function getSampleOutput($withUrls, $decorated); /** * @return string @@ -107,6 +102,14 @@ protected function getDisplay(OutputInterface $output) return stream_get_contents($output->getStream()); } + /** + * @return bool + */ + protected function supportsLinks() + { + return method_exists('Symfony\Component\Console\Formatter\OutputFormatterStyle', 'setHref'); + } + /** * @return MockObject|GeneratorContainer */ @@ -138,4 +141,31 @@ protected function getGenerators() return $generators; } + + /** + * @return OperationInterface[] + */ + private function getSampleProdOperations() + { + return array( + new InstallOperation($this->getPackage('a/package-1', '1.0.0')), + new InstallOperation($this->getPackage('a/no-link-1', '1.0.0')), + new UpdateOperation($this->getPackage('a/package-2', '1.0.0'), $this->getPackage('a/package-2', '1.2.0')), + new UpdateOperation($this->getPackage('a/package-3', '2.0.0'), $this->getPackage('a/package-3', '1.1.1')), + new UpdateOperation($this->getPackage('a/no-link-2', '2.0.0'), $this->getPackage('a/no-link-2', '1.1.1')), + new UpdateOperation($this->getPackage('php', '>=7.4.6'), $this->getPackage('php', '^8.0')), + ); + } + + /** + * @return OperationInterface[] + */ + private function getSampleDevOperations() + { + return array( + new UpdateOperation($this->getPackage('a/package-5', 'dev-master', 'dev-master 1234567'), $this->getPackage('a/package-5', '1.1.1')), + new UninstallOperation($this->getPackage('a/package-4', '0.1.1')), + new UninstallOperation($this->getPackage('a/no-link-2', '0.1.1')), + ); + } } diff --git a/tests/Formatter/GitHubFormatterTest.php b/tests/Formatter/GitHubFormatterTest.php index ba925b2..1f7656d 100644 --- a/tests/Formatter/GitHubFormatterTest.php +++ b/tests/Formatter/GitHubFormatterTest.php @@ -8,7 +8,7 @@ class GitHubFormatterTest extends FormatterTest { - protected function getSampleOutput($withUrls) + protected function getSampleOutput($withUrls, $decorated) { if ($withUrls) { return <<getDisplay($output)); } - protected function getSampleOutput($withUrls) + protected function getSampleOutput($withUrls, $decorated) { if ($withUrls) { return self::formatOutput(array( diff --git a/tests/Formatter/MarkdownListFormatterTest.php b/tests/Formatter/MarkdownListFormatterTest.php index 144facf..64098ef 100644 --- a/tests/Formatter/MarkdownListFormatterTest.php +++ b/tests/Formatter/MarkdownListFormatterTest.php @@ -8,9 +8,32 @@ class MarkdownListFormatterTest extends FormatterTest { - protected function getSampleOutput($withUrls) + protected function getSampleOutput($withUrls, $decorated) { if ($withUrls) { + if ($decorated) { + return << 1.2.0) [Compare](https://example.com/c/1.0.0..1.2.0) + - Downgrade [a/package-3](https://example.com/r/a/package-3) (2.0.0 => 1.1.1) [Compare](https://example.com/c/2.0.0..1.1.1) + - Downgrade a/no-link-2 (2.0.0 => 1.1.1) + - Change php (>=7.4.6 => ^8.0) + +Dev Packages +============ + + - Change [a/package-5](https://example.com/r/a/package-5) (dev-master 1234567 => 1.1.1) [Compare](https://example.com/c/dev-master..1.1.1) + - Uninstall [a/package-4](https://example.com/r/a/package-4) (0.1.1) [Compare](https://example.com/r/0.1.1) + - Uninstall a/no-link-2 (0.1.1) + + +OUTPUT; + } + return << 1.2.0) + - Downgrade a/package-3 (2.0.0 => 1.1.1) + - Downgrade a/no-link-2 (2.0.0 => 1.1.1) + - Change php (>=7.4.6 => ^8.0) + +Dev Packages +============ + + - Change a/package-5 (dev-master 1234567 => 1.1.1) + - Uninstall a/package-4 (0.1.1) + - Uninstall a/no-link-2 (0.1.1) + + OUTPUT; } diff --git a/tests/Formatter/MarkdownTableFormatterTest.php b/tests/Formatter/MarkdownTableFormatterTest.php index f8a5873..26036a2 100644 --- a/tests/Formatter/MarkdownTableFormatterTest.php +++ b/tests/Formatter/MarkdownTableFormatterTest.php @@ -8,9 +8,51 @@ class MarkdownTableFormatterTest extends FormatterTest { - protected function getSampleOutput($withUrls) + protected function getSampleOutput($withUrls, $decorated) { if ($withUrls) { + if ($decorated) { + if ($this->supportsLinks()) { + return <<=7.4.6 | ^8.0 | | + +| Dev Packages | Operation | Base | Target | Link | +|--------------------------------------------------|-----------|--------------------|--------|----------------------------------------------------| +| []8;;https://example.com/r/a/package-5\\a/package-5]8;;\\](https://example.com/r/a/package-5) | Changed | dev-master 1234567 | 1.1.1 | [Compare](https://example.com/c/dev-master..1.1.1) | +| []8;;https://example.com/r/a/package-4\\a/package-4]8;;\\](https://example.com/r/a/package-4) | Removed | 0.1.1 | - | [Compare](https://example.com/r/0.1.1) | +| a/no-link-2 | Removed | 0.1.1 | - | | + + +OUTPUT; + } + + return <<=7.4.6 | ^8.0 | | + +| Dev Packages | Operation | Base | Target | Link | +|--------------------------------------------------|-----------|--------------------|--------|----------------------------------------------------| +| [a/package-5](https://example.com/r/a/package-5) | Changed | dev-master 1234567 | 1.1.1 | [Compare](https://example.com/c/dev-master..1.1.1) | +| [a/package-4](https://example.com/r/a/package-4) | Removed | 0.1.1 | - | [Compare](https://example.com/r/0.1.1) | +| a/no-link-2 | Removed | 0.1.1 | - | | + + +OUTPUT; + } + return <<supportsLinks()) { + return <<=7.4.6 | ^8.0 | + +| Dev Packages | Operation | Base | Target | +|--------------|-----------|--------------------|--------| +| ]8;;https://example.com/r/a/package-5\a/package-5]8;;\ | Changed | dev-master 1234567 | 1.1.1 | +| ]8;;https://example.com/r/a/package-4\a/package-4]8;;\ | Removed | 0.1.1 | - | +| a/no-link-2 | Removed | 0.1.1 | - | + + +OUTPUT; + } + + return <<=7.4.6 | ^8.0 | + +| Dev Packages | Operation | Base | Target | +|--------------|-----------|--------------------|--------| +| a/package-5 | Changed | dev-master 1234567 | 1.1.1 | +| a/package-4 | Removed | 0.1.1 | - | +| a/no-link-2 | Removed | 0.1.1 | - | + + OUTPUT; }