From a2e4301be3c9778d535cfb50798f40e1765d33dc Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Fri, 26 Apr 2024 18:54:07 +0800 Subject: [PATCH] Add more docs, refactor formatters --- README.md | 7 + docs/CONTRIBUTING.md | 49 +++ docs/formatters.md | 357 +++++++++++++++++++++ docs/url-generators.md | 17 + src/Command/DiffCommand.php | 22 +- src/Formatter/FormatterContainer.php | 40 +++ src/Url/GeneratorContainer.php | 2 +- src/Url/UrlGenerator.php | 8 + tests/Formatter/FormatterContainerTest.php | 32 ++ 9 files changed, 517 insertions(+), 17 deletions(-) create mode 100644 docs/CONTRIBUTING.md create mode 100644 docs/formatters.md create mode 100644 docs/url-generators.md create mode 100644 src/Formatter/FormatterContainer.php create mode 100644 tests/Formatter/FormatterContainerTest.php diff --git a/README.md b/README.md index e4a9a9e..0b34af9 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,8 @@ composer diff -p # include platform dependencies composer diff -f json # Output as JSON instead of table ``` +You can find more documentation in the [docs](docs) directory. + ### Strict mode To help you control your dependencies, you may pass `--strict` option when running in CI. If there are any changes detected, a non-zero exit code will be returned. @@ -99,6 +101,11 @@ Exit code of the command is built using following bit flags: You may check for individual flags or simply check if the status is greater or equal 8 if you don't want to downgrade any package. +# Contributing + +Composer Diff is an open source project that welcomes pull requests and issues from anyone. +Before opening pull requests, please consider reading our short [Contribution Guidelines](docs/CONTRIBUTING.md). + # Similar packages While there are several existing packages offering similar functionality: diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md new file mode 100644 index 0000000..1ed3f20 --- /dev/null +++ b/docs/CONTRIBUTING.md @@ -0,0 +1,49 @@ +# Contributing guidelines + +Any contributions (issues, pull requests, code review, ideas, etc.) are welcome. +Here are a few guidelines to be aware of: + +- Include tests for any new features or bug fixes. +- All new features should target the `main` branch. +- All code must follow the project coding style standards which will be enforced by [StyleCI](https://styleci.io/). + +Since this project has rather strict coding standards, which include: + - PHPStan level 6 + - 100% test coverage + - 100% MSI (Mutation Score Indicator) + - Compatibility with PHP 5.3.2 up to 8.0 and newer + +It might be a bit challenging to get started but fret not, +as the maintainers will be happy to assist you should you have any questions or need help with your contribution. +Even if the tests fail, don't worry, as the maintainers will help you fix them. + +## Getting started + +1. Fork the repository on GitHub. +2. Clone your fork locally. +3. Run `composer install` to install the dependencies. +4. Create a new branch for your feature or bug fix. +5. Write code and tests for your new feature or bug fix. +6. Run the tests (`vendor/bin/simple-phpunit`) to be sure everything is working. +7. Push your branch to your fork on GitHub. +8. Create a pull request to the `main` branch. +9. Wait for the maintainers to review your pull request. + +## Testing against a real project + +Sometimes it's easier to check your changes when you have an actual project where a bug occurs rather than reproducing it in a test. +While this package works as a Composer plugin, it might seem difficult to test your changes against a real project. + +Consider a following example: + +- `~/work/my-project` - path to my project +- `~/work/composer-diff` - path to this repository + +Running the `composer-diff` command with your changes against your project is as simple as: + +```shell +cd ~/work/my-project # Navigate to your project directory +~/work/composer-diff/composer-diff # Run the composer-diff command from this repository +``` + +You can specify any other options as well like `--no-dev`, `--with-platform`, etc. diff --git a/docs/formatters.md b/docs/formatters.md new file mode 100644 index 0000000..3ae916a --- /dev/null +++ b/docs/formatters.md @@ -0,0 +1,357 @@ +# Output formatters + +There are currently four output formats available: + +- `mdtable` - Markdown table (default) +- `mdlist` - Markdown list +- `json` - JSON +- `github` - GitHub Annotations + +You can select the output format using the `--format` (`-f`) option. + +```shell script +composer diff --format mdlist +composer diff -f json +``` + +## Markdown table (mdtable) + +This is the default output format. It will display the changes in a table format. + +Example output: + +``` +| Prod Packages | Operation | Base | Target | +|------------------------------------|-----------|--------------------|--------------------| +| psr/event-dispatcher | New | - | 1.0.0 | +| roave/security-advisories | Changed | dev-master 3c97c13 | dev-master ac36586 | +| symfony/deprecation-contracts | New | - | v2.1.2 | +| symfony/event-dispatcher | Upgraded | v2.8.52 | v5.1.2 | +| symfony/event-dispatcher-contracts | New | - | v2.1.2 | +| symfony/polyfill-php80 | New | - | v1.17.1 | + +| Dev Packages | Operation | Base | Target | +|------------------------------------|------------|-------|--------| +| phpunit/php-code-coverage | Downgraded | 8.0.2 | 7.0.10 | +| phpunit/php-file-iterator | Downgraded | 3.0.2 | 2.0.2 | +| phpunit/php-text-template | Downgraded | 2.0.1 | 1.2.1 | +| phpunit/php-timer | Downgraded | 5.0.0 | 2.1.2 | +| phpunit/php-token-stream | Downgraded | 4.0.2 | 3.1.1 | +| phpunit/phpunit | Downgraded | 9.2.5 | 8.5.8 | +| sebastian/code-unit-reverse-lookup | Downgraded | 2.0.1 | 1.0.1 | +| sebastian/comparator | Downgraded | 4.0.2 | 3.0.2 | +| sebastian/diff | Downgraded | 4.0.1 | 3.0.2 | +| sebastian/environment | Downgraded | 5.1.1 | 4.2.3 | +| sebastian/exporter | Downgraded | 4.0.1 | 3.1.2 | +| sebastian/global-state | Downgraded | 4.0.0 | 3.0.0 | +| sebastian/object-enumerator | Downgraded | 4.0.1 | 3.0.3 | +| sebastian/object-reflector | Downgraded | 2.0.1 | 1.1.1 | +| sebastian/recursion-context | Downgraded | 4.0.1 | 3.0.0 | +| sebastian/resource-operations | Downgraded | 3.0.1 | 2.0.1 | +| sebastian/type | Downgraded | 2.1.0 | 1.1.3 | +| sebastian/version | Downgraded | 3.0.0 | 2.0.1 | +| phpunit/php-invoker | Removed | 3.0.1 | - | +| sebastian/code-unit | Removed | 1.0.3 | - | +``` + +Rendered output: + +| Prod Packages | Operation | Base | Target | +|------------------------------------|-----------|--------------------|--------------------| +| psr/event-dispatcher | New | - | 1.0.0 | +| roave/security-advisories | Changed | dev-master 3c97c13 | dev-master ac36586 | +| symfony/deprecation-contracts | New | - | v2.1.2 | +| symfony/event-dispatcher | Upgraded | v2.8.52 | v5.1.2 | +| symfony/event-dispatcher-contracts | New | - | v2.1.2 | +| symfony/polyfill-php80 | New | - | v1.17.1 | + +| Dev Packages | Operation | Base | Target | +|------------------------------------|------------|-------|--------| +| phpunit/php-code-coverage | Downgraded | 8.0.2 | 7.0.10 | +| phpunit/php-file-iterator | Downgraded | 3.0.2 | 2.0.2 | +| phpunit/php-text-template | Downgraded | 2.0.1 | 1.2.1 | +| phpunit/php-timer | Downgraded | 5.0.0 | 2.1.2 | +| phpunit/php-token-stream | Downgraded | 4.0.2 | 3.1.1 | +| phpunit/phpunit | Downgraded | 9.2.5 | 8.5.8 | +| sebastian/code-unit-reverse-lookup | Downgraded | 2.0.1 | 1.0.1 | +| sebastian/comparator | Downgraded | 4.0.2 | 3.0.2 | +| sebastian/diff | Downgraded | 4.0.1 | 3.0.2 | +| sebastian/environment | Downgraded | 5.1.1 | 4.2.3 | +| sebastian/exporter | Downgraded | 4.0.1 | 3.1.2 | +| sebastian/global-state | Downgraded | 4.0.0 | 3.0.0 | +| sebastian/object-enumerator | Downgraded | 4.0.1 | 3.0.3 | +| sebastian/object-reflector | Downgraded | 2.0.1 | 1.1.1 | +| sebastian/recursion-context | Downgraded | 4.0.1 | 3.0.0 | +| sebastian/resource-operations | Downgraded | 3.0.1 | 2.0.1 | +| sebastian/type | Downgraded | 2.1.0 | 1.1.3 | +| sebastian/version | Downgraded | 3.0.0 | 2.0.1 | +| phpunit/php-invoker | Removed | 3.0.1 | - | +| sebastian/code-unit | Removed | 1.0.3 | - | + +## Markdown list (mdlist) + +This format will display the changes in a markdown list format. + +Example output: + +``` +Prod Packages +============= + + - Install psr/event-dispatcher (1.0.0) + - Change roave/security-advisories (dev-master 3c97c13 => dev-master ac36586) + - Install symfony/deprecation-contracts (v2.1.2) + - Upgrade symfony/event-dispatcher (v2.8.52 => v5.1.2) + - Install symfony/event-dispatcher-contracts (v2.1.2) + - Install symfony/polyfill-php80 (v1.17.1) + +Dev Packages +============ + + - Downgrade phpunit/php-code-coverage (8.0.2 => 7.0.10) + - Downgrade phpunit/php-file-iterator (3.0.2 => 2.0.2) + - Downgrade phpunit/php-text-template (2.0.1 => 1.2.1) + - Downgrade phpunit/php-timer (5.0.0 => 2.1.2) + - Downgrade phpunit/php-token-stream (4.0.2 => 3.1.1) + - Downgrade phpunit/phpunit (9.2.5 => 8.5.8) + - Downgrade sebastian/code-unit-reverse-lookup (2.0.1 => 1.0.1) + - Downgrade sebastian/comparator (4.0.2 => 3.0.2) + - Downgrade sebastian/diff (4.0.1 => 3.0.2) + - Downgrade sebastian/environment (5.1.1 => 4.2.3) + - Downgrade sebastian/exporter (4.0.1 => 3.1.2) + - Downgrade sebastian/global-state (4.0.0 => 3.0.0) + - Downgrade sebastian/object-enumerator (4.0.1 => 3.0.3) + - Downgrade sebastian/object-reflector (2.0.1 => 1.1.1) + - Downgrade sebastian/recursion-context (4.0.1 => 3.0.0) + - Downgrade sebastian/resource-operations (3.0.1 => 2.0.1) + - Downgrade sebastian/type (2.1.0 => 1.1.3) + - Downgrade sebastian/version (3.0.0 => 2.0.1) + - Uninstall phpunit/php-invoker (3.0.1) + - Uninstall sebastian/code-unit (1.0.3) +``` + +Rendered output: + +Prod Packages +============= + +- Install psr/event-dispatcher (1.0.0) +- Change roave/security-advisories (dev-master 3c97c13 => dev-master ac36586) +- Install symfony/deprecation-contracts (v2.1.2) +- Upgrade symfony/event-dispatcher (v2.8.52 => v5.1.2) +- Install symfony/event-dispatcher-contracts (v2.1.2) +- Install symfony/polyfill-php80 (v1.17.1) + +Dev Packages +============ + +- Downgrade phpunit/php-code-coverage (8.0.2 => 7.0.10) +- Downgrade phpunit/php-file-iterator (3.0.2 => 2.0.2) +- Downgrade phpunit/php-text-template (2.0.1 => 1.2.1) +- Downgrade phpunit/php-timer (5.0.0 => 2.1.2) +- Downgrade phpunit/php-token-stream (4.0.2 => 3.1.1) +- Downgrade phpunit/phpunit (9.2.5 => 8.5.8) +- Downgrade sebastian/code-unit-reverse-lookup (2.0.1 => 1.0.1) +- Downgrade sebastian/comparator (4.0.2 => 3.0.2) +- Downgrade sebastian/diff (4.0.1 => 3.0.2) +- Downgrade sebastian/environment (5.1.1 => 4.2.3) +- Downgrade sebastian/exporter (4.0.1 => 3.1.2) +- Downgrade sebastian/global-state (4.0.0 => 3.0.0) +- Downgrade sebastian/object-enumerator (4.0.1 => 3.0.3) +- Downgrade sebastian/object-reflector (2.0.1 => 1.1.1) +- Downgrade sebastian/recursion-context (4.0.1 => 3.0.0) +- Downgrade sebastian/resource-operations (3.0.1 => 2.0.1) +- Downgrade sebastian/type (2.1.0 => 1.1.3) +- Downgrade sebastian/version (3.0.0 => 2.0.1) +- Uninstall phpunit/php-invoker (3.0.1) +- Uninstall sebastian/code-unit (1.0.3) + + +## JSON (json) + +This format will display the changes in a JSON format for parsing by other tools. + +Example output: + +```json +{ + "packages": { + "psr\/event-dispatcher": { + "name": "psr\/event-dispatcher", + "operation": "install", + "version_base": null, + "version_target": "1.0.0" + }, + "roave\/security-advisories": { + "name": "roave\/security-advisories", + "operation": "change", + "version_base": "dev-master 3c97c13", + "version_target": "dev-master ac36586" + }, + "symfony\/deprecation-contracts": { + "name": "symfony\/deprecation-contracts", + "operation": "install", + "version_base": null, + "version_target": "v2.1.2" + }, + "symfony\/event-dispatcher": { + "name": "symfony\/event-dispatcher", + "operation": "upgrade", + "version_base": "v2.8.52", + "version_target": "v5.1.2" + }, + "symfony\/event-dispatcher-contracts": { + "name": "symfony\/event-dispatcher-contracts", + "operation": "install", + "version_base": null, + "version_target": "v2.1.2" + }, + "symfony\/polyfill-php80": { + "name": "symfony\/polyfill-php80", + "operation": "install", + "version_base": null, + "version_target": "v1.17.1" + } + }, + "packages-dev": { + "phpunit\/php-code-coverage": { + "name": "phpunit\/php-code-coverage", + "operation": "downgrade", + "version_base": "8.0.2", + "version_target": "7.0.10" + }, + "phpunit\/php-file-iterator": { + "name": "phpunit\/php-file-iterator", + "operation": "downgrade", + "version_base": "3.0.2", + "version_target": "2.0.2" + }, + "phpunit\/php-text-template": { + "name": "phpunit\/php-text-template", + "operation": "downgrade", + "version_base": "2.0.1", + "version_target": "1.2.1" + }, + "phpunit\/php-timer": { + "name": "phpunit\/php-timer", + "operation": "downgrade", + "version_base": "5.0.0", + "version_target": "2.1.2" + }, + "phpunit\/php-token-stream": { + "name": "phpunit\/php-token-stream", + "operation": "downgrade", + "version_base": "4.0.2", + "version_target": "3.1.1" + }, + "phpunit\/phpunit": { + "name": "phpunit\/phpunit", + "operation": "downgrade", + "version_base": "9.2.5", + "version_target": "8.5.8" + }, + "sebastian\/code-unit-reverse-lookup": { + "name": "sebastian\/code-unit-reverse-lookup", + "operation": "downgrade", + "version_base": "2.0.1", + "version_target": "1.0.1" + }, + "sebastian\/comparator": { + "name": "sebastian\/comparator", + "operation": "downgrade", + "version_base": "4.0.2", + "version_target": "3.0.2" + }, + "sebastian\/diff": { + "name": "sebastian\/diff", + "operation": "downgrade", + "version_base": "4.0.1", + "version_target": "3.0.2" + }, + "sebastian\/environment": { + "name": "sebastian\/environment", + "operation": "downgrade", + "version_base": "5.1.1", + "version_target": "4.2.3" + }, + "sebastian\/exporter": { + "name": "sebastian\/exporter", + "operation": "downgrade", + "version_base": "4.0.1", + "version_target": "3.1.2" + }, + "sebastian\/global-state": { + "name": "sebastian\/global-state", + "operation": "downgrade", + "version_base": "4.0.0", + "version_target": "3.0.0" + }, + "sebastian\/object-enumerator": { + "name": "sebastian\/object-enumerator", + "operation": "downgrade", + "version_base": "4.0.1", + "version_target": "3.0.3" + }, + "sebastian\/object-reflector": { + "name": "sebastian\/object-reflector", + "operation": "downgrade", + "version_base": "2.0.1", + "version_target": "1.1.1" + }, + "sebastian\/recursion-context": { + "name": "sebastian\/recursion-context", + "operation": "downgrade", + "version_base": "4.0.1", + "version_target": "3.0.0" + }, + "sebastian\/resource-operations": { + "name": "sebastian\/resource-operations", + "operation": "downgrade", + "version_base": "3.0.1", + "version_target": "2.0.1" + }, + "sebastian\/type": { + "name": "sebastian\/type", + "operation": "downgrade", + "version_base": "2.1.0", + "version_target": "1.1.3" + }, + "sebastian\/version": { + "name": "sebastian\/version", + "operation": "downgrade", + "version_base": "3.0.0", + "version_target": "2.0.1" + }, + "phpunit\/php-invoker": { + "name": "phpunit\/php-invoker", + "operation": "remove", + "version_base": "3.0.1", + "version_target": null + }, + "sebastian\/code-unit": { + "name": "sebastian\/code-unit", + "operation": "remove", + "version_base": "1.0.3", + "version_target": null + } + } +} +``` + +## GitHub Annotations (github) + +This format will display the changes in a format that can be used as GitHub annotation notices. + +Example output: + +``` +::notice title=Prod Packages:: - Install psr/event-dispatcher (1.0.0)%0A - Change roave/security-advisories (dev-master 3c97c13 => dev-master ac36586)%0A - Install symfony/deprecation-contracts (v2.1.2)%0A - Upgrade symfony/event-dispatcher (v2.8.52 => v5.1.2)%0A - Install symfony/event-dispatcher-contracts (v2.1.2)%0A - Install symfony/polyfill-php80 (v1.17.1) +::notice title=Dev Packages:: - Downgrade phpunit/php-code-coverage (8.0.2 => 7.0.10)%0A - Downgrade phpunit/php-file-iterator (3.0.2 => 2.0.2)%0A - Downgrade phpunit/php-text-template (2.0.1 => 1.2.1)%0A - Downgrade phpunit/php-timer (5.0.0 => 2.1.2)%0A - Downgrade phpunit/php-token-stream (4.0.2 => 3.1.1)%0A - Downgrade phpunit/phpunit (9.2.5 => 8.5.8)%0A - Downgrade sebastian/code-unit-reverse-lookup (2.0.1 => 1.0.1)%0A - Downgrade sebastian/comparator (4.0.2 => 3.0.2)%0A - Downgrade sebastian/diff (4.0.1 => 3.0.2)%0A - Downgrade sebastian/environment (5.1.1 => 4.2.3)%0A - Downgrade sebastian/exporter (4.0.1 => 3.1.2)%0A - Downgrade sebastian/global-state (4.0.0 => 3.0.0)%0A - Downgrade sebastian/object-enumerator (4.0.1 => 3.0.3)%0A - Downgrade sebastian/object-reflector (2.0.1 => 1.1.1)%0A - Downgrade sebastian/recursion-context (4.0.1 => 3.0.0)%0A - Downgrade sebastian/resource-operations (3.0.1 => 2.0.1)%0A - Downgrade sebastian/type (2.1.0 => 1.1.3)%0A - Downgrade sebastian/version (3.0.0 => 2.0.1)%0A - Uninstall phpunit/php-invoker (3.0.1)%0A - Uninstall sebastian/code-unit (1.0.3) +``` + +# Contributing + +All formatters are implemented as separate classes in the `IonBazan\ComposerDiff\Formatter` namespace +and must implement the `IonBazan\ComposerDiff\Formatter\FormatterInterface` interface. + +If you would like to create a new formatter, create a new class in the `Formatter` namespace and register it in `FormatterContainer`. diff --git a/docs/url-generators.md b/docs/url-generators.md new file mode 100644 index 0000000..7987117 --- /dev/null +++ b/docs/url-generators.md @@ -0,0 +1,17 @@ +# URL Generators + +URL generators are used to generate URLs for the packages listed in a diff: + +- `GitHubGenerator`: Generates URLs for GitHub repositories. +- `GitLabGenerator`: Generates URLs for GitLab repositories. Supports custom domains. +- `BitbucketGenerator`: Generates URLs for Bitbucket repositories. +- `DrupalGenerator`: Generates URLs for Drupal packages. + +They are chosen automatically based on the package URL or other conditions specified in `supportsPackage()` method. + +Each generator must have following methods: + +- `supportsPackage()`: Checks if the generator supports the package. +- `getCompareUrl()`: Generates URL for comparing two versions of the package. +- `getReleaseUrl()`: Generates URL for viewing a release or commit of a package. +- `getProjectUrl()`: Mainly used to generate URL to the project repository root. diff --git a/src/Command/DiffCommand.php b/src/Command/DiffCommand.php index 6c66691..bb6f767 100644 --- a/src/Command/DiffCommand.php +++ b/src/Command/DiffCommand.php @@ -5,10 +5,7 @@ use IonBazan\ComposerDiff\Diff\DiffEntries; use IonBazan\ComposerDiff\Diff\DiffEntry; use IonBazan\ComposerDiff\Formatter\Formatter; -use IonBazan\ComposerDiff\Formatter\GitHubFormatter; -use IonBazan\ComposerDiff\Formatter\JsonFormatter; -use IonBazan\ComposerDiff\Formatter\MarkdownListFormatter; -use IonBazan\ComposerDiff\Formatter\MarkdownTableFormatter; +use IonBazan\ComposerDiff\Formatter\FormatterContainer; use IonBazan\ComposerDiff\PackageDiff; use IonBazan\ComposerDiff\Url\GeneratorContainer; use Symfony\Component\Console\Input\InputArgument; @@ -142,7 +139,9 @@ protected function handle(InputInterface $input, OutputInterface $output) $withUrls = $input->getOption('with-links'); $this->gitlabDomains = array_merge($this->gitlabDomains, $input->getOption('gitlab-domains')); - $formatter = $this->getFormatter($input, $output); + $urlGenerators = new GeneratorContainer($this->gitlabDomains); + $formatters = new FormatterContainer($output, $urlGenerators); + $formatter = $formatters->getFormatter($input->getOption('format')); $prodOperations = new DiffEntries(array()); $devOperations = new DiffEntries(array()); @@ -207,17 +206,8 @@ private function hasDowngrades(DiffEntries $entries) private function getFormatter(InputInterface $input, OutputInterface $output) { $urlGenerators = new GeneratorContainer($this->gitlabDomains); + $formatters = new FormatterContainer($output, $urlGenerators); - switch ($input->getOption('format')) { - case 'json': - return new JsonFormatter($output, $urlGenerators); - case 'mdlist': - return new MarkdownListFormatter($output, $urlGenerators); - case 'github': - return new GitHubFormatter($output, $urlGenerators); - // case 'mdtable': - default: - return new MarkdownTableFormatter($output, $urlGenerators); - } + return $formatters->getFormatter($input->getOption('format')); } } diff --git a/src/Formatter/FormatterContainer.php b/src/Formatter/FormatterContainer.php new file mode 100644 index 0000000..0b727c7 --- /dev/null +++ b/src/Formatter/FormatterContainer.php @@ -0,0 +1,40 @@ + + */ + private $formatters; + + public function __construct(OutputInterface $output, GeneratorContainer $generators) + { + $this->formatters = array( + 'mdtable' => new MarkdownTableFormatter($output, $generators), + 'mdlist' => new MarkdownListFormatter($output, $generators), + 'github' => new GitHubFormatter($output, $generators), + 'json' => new JsonFormatter($output, $generators), + ); + } + + /** + * @param string $name + * + * @return Formatter + */ + public function getFormatter($name) + { + if (!isset($this->formatters[$name])) { + return $this->formatters[self::DEFAULT_FORMATTER]; + } + + return $this->formatters[$name]; + } +} diff --git a/src/Url/GeneratorContainer.php b/src/Url/GeneratorContainer.php index ebe9a75..0d204c0 100644 --- a/src/Url/GeneratorContainer.php +++ b/src/Url/GeneratorContainer.php @@ -14,7 +14,7 @@ class GeneratorContainer implements UrlGenerator /** * @param string[] $gitlabDomains */ - public function __construct(array $gitlabDomains) + public function __construct(array $gitlabDomains = array()) { $generators = array( new DrupalGenerator(), diff --git a/src/Url/UrlGenerator.php b/src/Url/UrlGenerator.php index 0599bf9..9190053 100644 --- a/src/Url/UrlGenerator.php +++ b/src/Url/UrlGenerator.php @@ -7,21 +7,29 @@ interface UrlGenerator { /** + * Determines if the generator supports the given package. + * * @return bool */ public function supportsPackage(PackageInterface $package); /** + * Generates a compare URL for two versions of the same package. + * * @return string|null */ public function getCompareUrl(PackageInterface $initialPackage, PackageInterface $targetPackage); /** + * Generates URL for viewing a release or commit of a package. + * * @return string|null */ public function getReleaseUrl(PackageInterface $package); /** + * Generates URL for viewing the project page of a package (usually repository root). + * * @return string|null */ public function getProjectUrl(PackageInterface $package); diff --git a/tests/Formatter/FormatterContainerTest.php b/tests/Formatter/FormatterContainerTest.php new file mode 100644 index 0000000..5dbe533 --- /dev/null +++ b/tests/Formatter/FormatterContainerTest.php @@ -0,0 +1,32 @@ +getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock(); + $generators = $this->getMockBuilder('IonBazan\ComposerDiff\Url\GeneratorContainer')->getMock(); + $container = new FormatterContainer($output, $generators); + + $this->assertInstanceOf($expectedFormatter, $container->getFormatter($code)); + } + + public static function formatterProvider() + { + return array( + array('IonBazan\ComposerDiff\Formatter\MarkdownTableFormatter', 'mdtable'), + array('IonBazan\ComposerDiff\Formatter\MarkdownListFormatter', 'mdlist'), + array('IonBazan\ComposerDiff\Formatter\JsonFormatter', 'json'), + array('IonBazan\ComposerDiff\Formatter\GitHubFormatter', 'github'), + array('IonBazan\ComposerDiff\Formatter\MarkdownTableFormatter', 'anything-else'), + ); + } +}