diff --git a/.gitignore b/.gitignore index 5c81b2a..e912ccf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ composer.lock composer.phar # CS +.php_cs .php_cs.cache diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 73067ef..0000000 --- a/.php_cs +++ /dev/null @@ -1,39 +0,0 @@ - - -For the full copyright and license information, please view the LICENSE -file that was distributed with this source code. -EOF; - -Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header); - -$finder = Symfony\CS\Finder\DefaultFinder::create() - ->in(array(__DIR__)) -; - -return Symfony\CS\Config\Config::create() - // Set to Symfony Level (PSR1 PSR2) - ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) - ->fixers(array( - 'header_comment', // Add the provided header comment ($header) - 'newline_after_open_tag', // Force new line after setUsingCache(true) - ->finder($finder) -; diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..40a42b7 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,35 @@ + + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +EOF; + +$finder = PhpCsFixer\Finder::create() + ->in([__DIR__]) +; + +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], // Replace array() by [] + 'blank_line_after_opening_tag' => true, // Force new line after ['spacing' => 'one'], // Force space around concatenation operator + 'header_comment' => ['header' => $header], // Add the provided header comment ($header) + 'heredoc_to_nowdoc' => false, // Do not convert heredoc to nowdoc + 'no_superfluous_phpdoc_tags' => false, // Ensure complete PHPDoc annotations for all params + 'phpdoc_order' => true, // Order "use" statements alphabetically + 'simplified_null_return' => false, // Keep return null; + 'single_line_throw' => false, // Allow throwing exceptions in more than one row + 'strict_comparison' => true, // Strict comparison + 'strict_param' => true, // Functions should use $strict param + 'yoda_style' => null, // Ignore comparison style checks + ]) + ->setUsingCache(true) + ->setFinder($finder) +; diff --git a/.travis.yml b/.travis.yml index 0d06c92..6422677 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,8 @@ matrix: - php: 7.2 env: check_cs=true - php: 7.3 + - php: 7.4 + dist: bionic env: global: @@ -33,7 +35,12 @@ script: - if [ "$coverage" = "true" ]; then vendor/bin/phpunit --coverage-clover=coverage; fi; - if [ "$coverage" = "true" ]; then xdebug-disable; fi; - if [ "$coverage" != "true" ]; then vendor/bin/phpunit; fi; - - if [ "$check_cs" = "true" ]; then vendor/bin/php-cs-fixer fix --config-file=.php_cs --dry-run --diff; fi; + - | + if [ "$check_cs" = "true" ]; then + wget https://cs.symfony.com/download/php-cs-fixer-v2.phar -O php-cs-fixer + chmod +x php-cs-fixer + ./php-cs-fixer fix --config=.php_cs.dist --dry-run --diff + fi; after_script: - if [ "$coverage" = "true" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi; diff --git a/CHANGELOG.md b/CHANGELOG.md index a9b3f6d..aa2fc1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changes between versions +## Unreleased + +* Add support for Composer ^2.0 + ## 1.7.0 (2019-10-21) * Display VCS Revision for dev version ([#64](https://github.com/pyrech/composer-changelogs/pull/64)) diff --git a/composer.json b/composer.json index d6e7aae..0640a2b 100644 --- a/composer.json +++ b/composer.json @@ -17,13 +17,12 @@ ], "require": { "php": ">=7.1.0", - "composer-plugin-api": "^1.0 || ^1.1" + "composer-plugin-api": "^1.0 || ^2.0" }, "require-dev": { - "composer/composer": "~1.0.0-alpha10@dev", - "composer/semver": "1.2.0", - "friendsofphp/php-cs-fixer": "~1.5", - "phpunit/phpunit": "^4.8" + "composer/composer": "^1.0.0-alpha10@dev || ^2.0@dev", + "composer/semver": "^1.2 || ^2.0", + "phpunit/phpunit": "^7.5" }, "config": { "sort-packages": true diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 57ad60e..db9e51e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,7 @@ diff --git a/src/ChangelogsPlugin.php b/src/ChangelogsPlugin.php index 5ea8b2f..0a466a7 100644 --- a/src/ChangelogsPlugin.php +++ b/src/ChangelogsPlugin.php @@ -59,6 +59,14 @@ public function activate(Composer $composer, IOInterface $io) $this->outputter = Factory::createOutputter($this->config->getGitlabHosts()); } + public function deactivate(Composer $composer, IOInterface $io) + { + } + + public function uninstall(Composer $composer, IOInterface $io) + { + } + /** * {@inheritdoc} */ diff --git a/tests/ChangelogsPluginTest.php b/tests/ChangelogsPluginTest.php index 81b3f09..936fe59 100644 --- a/tests/ChangelogsPluginTest.php +++ b/tests/ChangelogsPluginTest.php @@ -26,10 +26,12 @@ use Composer\Plugin\PluginInterface; use Composer\Plugin\PluginManager; use Composer\Repository\CompositeRepository; +use Composer\Repository\RepositoryInterface; use Composer\Script\ScriptEvents; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\ChangelogsPlugin; -class ChangelogsPluginTest extends \PHPUnit_Framework_TestCase +class ChangelogsPluginTest extends TestCase { /** @var BufferIO */ private $io; @@ -46,7 +48,7 @@ class ChangelogsPluginTest extends \PHPUnit_Framework_TestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { $this->tempDir = __DIR__ . '/temp'; $this->config = new Config(false, realpath(__DIR__ . '/fixtures/local')); @@ -71,7 +73,7 @@ protected function setUp() /** * {@inheritdoc} */ - protected function tearDown() + protected function tearDown(): void { self::cleanTempDir(); } @@ -98,8 +100,6 @@ public function test_it_is_registered_and_activated() $this->addComposerPlugin($plugin); $this->assertSame([$plugin], $this->composer->getPluginManager()->getPlugins()); - $this->assertAttributeInstanceOf('Composer\IO\IOInterface', 'io', $plugin); - $this->assertAttributeInstanceOf('Pyrech\ComposerChangelogs\Outputter', 'outputter', $plugin); } public function test_it_receives_event() @@ -108,16 +108,7 @@ public function test_it_receives_event() $operation = $this->getUpdateOperation(); - $this->composer->getEventDispatcher()->dispatchPackageEvent( - PackageEvents::POST_PACKAGE_UPDATE, - false, - new DefaultPolicy(false, false), - new Pool(), - new CompositeRepository([]), - new Request(new Pool()), - [$operation], - $operation - ); + $this->dispatchPostPackageUpdateEvent($operation); $this->composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_UPDATE_CMD); @@ -141,18 +132,8 @@ public function test_events_are_handled() $operation = $this->getUpdateOperation(); - $packageEvent = new PackageEvent( - PackageEvents::POST_PACKAGE_UPDATE, - $this->composer, - $this->io, - false, - new DefaultPolicy(false, false), - new Pool(), - new CompositeRepository([]), - new Request(new Pool()), - [$operation], - $operation - ); + $packageEvent = $this->createPostPackageUpdateEvent($operation); + $plugin->postPackageOperation($packageEvent); $plugin->postUpdate(); @@ -202,18 +183,8 @@ public function test_it_commits_with_always_option() $operation = $this->getUpdateOperation(); - $packageEvent = new PackageEvent( - PackageEvents::POST_PACKAGE_UPDATE, - $this->composer, - $this->io, - false, - new DefaultPolicy(false, false), - new Pool(), - new CompositeRepository([]), - new Request(new Pool()), - [$operation], - $operation - ); + $packageEvent = $this->createPostPackageUpdateEvent($operation); + $plugin->postPackageOperation($packageEvent); $plugin->postUpdate(); @@ -234,18 +205,8 @@ public function test_it_commits_with_default_commit_message() $operation = $this->getUpdateOperation(); - $packageEvent = new PackageEvent( - PackageEvents::POST_PACKAGE_UPDATE, - $this->composer, - $this->io, - false, - new DefaultPolicy(false, false), - new Pool(), - new CompositeRepository([]), - new Request(new Pool()), - [$operation], - $operation - ); + $packageEvent = $this->createPostPackageUpdateEvent($operation); + $plugin->postPackageOperation($packageEvent); $plugin->postUpdate(); @@ -268,18 +229,8 @@ public function test_it_commits_with_custom_commit_message() $operation = $this->getUpdateOperation(); - $packageEvent = new PackageEvent( - PackageEvents::POST_PACKAGE_UPDATE, - $this->composer, - $this->io, - false, - new DefaultPolicy(false, false), - new Pool(), - new CompositeRepository([]), - new Request(new Pool()), - [$operation], - $operation - ); + $packageEvent = $this->createPostPackageUpdateEvent($operation); + $plugin->postPackageOperation($packageEvent); $plugin->postUpdate(); @@ -310,4 +261,58 @@ private function getUpdateOperation() return new UpdateOperation($initialPackage, $targetPackage); } + + private function createPostPackageUpdateEvent($operation) + { + if (version_compare(PluginInterface::PLUGIN_API_VERSION, '2.0.0') >= 0) { + return new PackageEvent( + PackageEvents::POST_PACKAGE_UPDATE, + $this->composer, + $this->io, + false, + $this->createMock(RepositoryInterface::class), + [$operation], + $operation + ); + } + + return new PackageEvent( + PackageEvents::POST_PACKAGE_UPDATE, + $this->composer, + $this->io, + false, + new DefaultPolicy(false, false), + new Pool(), + new CompositeRepository([]), + new Request(new Pool()), + [$operation], + $operation + ); + } + + private function dispatchPostPackageUpdateEvent($operation) + { + if (version_compare(PluginInterface::PLUGIN_API_VERSION, '2.0.0') >= 0) { + $this->composer->getEventDispatcher()->dispatchPackageEvent( + PackageEvents::POST_PACKAGE_UPDATE, + false, + $this->createMock(RepositoryInterface::class), + [$operation], + $operation + ); + + return; + } + + $this->composer->getEventDispatcher()->dispatchPackageEvent( + PackageEvents::POST_PACKAGE_UPDATE, + false, + new DefaultPolicy(false, false), + new Pool(), + new CompositeRepository([]), + new Request(new Pool()), + [$operation], + $operation + ); + } } diff --git a/tests/Config/ConfigBuilderTest.php b/tests/Config/ConfigBuilderTest.php index 8fa044b..0192ae0 100644 --- a/tests/Config/ConfigBuilderTest.php +++ b/tests/Config/ConfigBuilderTest.php @@ -11,9 +11,10 @@ namespace Pyrech\ComposerChangelogs\tests\Config; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\Config\ConfigBuilder; -class ConfigBuilderTest extends \PHPUnit_Framework_TestCase +class ConfigBuilderTest extends TestCase { const COMMIT_BIN_FILE = '../fixtures/bin/fake.sh'; @@ -23,7 +24,7 @@ class ConfigBuilderTest extends \PHPUnit_Framework_TestCase /** @var ConfigBuilder */ private $SUT; - public function setUp() + protected function setUp(): void { $this->absoluteCommitBinFile = realpath(__DIR__ . '/' . self::COMMIT_BIN_FILE); $this->SUT = new ConfigBuilder(); @@ -35,13 +36,13 @@ public function test_it_has_a_default_setup() $config = $this->SUT->build($extra, __DIR__); - static::assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); - static::assertSame('never', $config->getCommitAuto()); - static::assertNull($config->getCommitBinFile()); - static::assertEmpty($config->getGitlabHosts()); - static::assertEquals(-1, $config->getPostUpdatePriority()); + $this->assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); + $this->assertSame('never', $config->getCommitAuto()); + $this->assertNull($config->getCommitBinFile()); + $this->assertEmpty($config->getGitlabHosts()); + $this->assertEquals(-1, $config->getPostUpdatePriority()); - static::assertCount(0, $this->SUT->getWarnings()); + $this->assertCount(0, $this->SUT->getWarnings()); } public function test_it_warns_when_commit_auto_option_is_invalid() @@ -52,14 +53,14 @@ public function test_it_warns_when_commit_auto_option_is_invalid() $config = $this->SUT->build($extra, __DIR__); - static::assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); - static::assertSame('never', $config->getCommitAuto()); - static::assertNull($config->getCommitBinFile()); - static::assertEmpty($config->getGitlabHosts()); - static::assertEquals(-1, $config->getPostUpdatePriority()); + $this->assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); + $this->assertSame('never', $config->getCommitAuto()); + $this->assertNull($config->getCommitBinFile()); + $this->assertEmpty($config->getGitlabHosts()); + $this->assertEquals(-1, $config->getPostUpdatePriority()); - static::assertCount(1, $this->SUT->getWarnings()); - static::assertContains('Invalid value "foo" for option "commit-auto"', $this->SUT->getWarnings()[0]); + $this->assertCount(1, $this->SUT->getWarnings()); + $this->assertStringContainsString('Invalid value "foo" for option "commit-auto"', $this->SUT->getWarnings()[0]); } public function test_it_warns_when_specifying_commit_bin_file_and_never_auto_commit() @@ -71,14 +72,14 @@ public function test_it_warns_when_specifying_commit_bin_file_and_never_auto_com $config = $this->SUT->build($extra, __DIR__); - static::assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); - static::assertSame('never', $config->getCommitAuto()); - static::assertNull($config->getCommitBinFile()); - static::assertEmpty($config->getGitlabHosts()); - static::assertEquals(-1, $config->getPostUpdatePriority()); + $this->assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); + $this->assertSame('never', $config->getCommitAuto()); + $this->assertNull($config->getCommitBinFile()); + $this->assertEmpty($config->getGitlabHosts()); + $this->assertEquals(-1, $config->getPostUpdatePriority()); - static::assertCount(1, $this->SUT->getWarnings()); - static::assertContains('"commit-bin-file" is specified but "commit-auto" option is set to "never". Ignoring.', $this->SUT->getWarnings()[0]); + $this->assertCount(1, $this->SUT->getWarnings()); + $this->assertStringContainsString('"commit-bin-file" is specified but "commit-auto" option is set to "never". Ignoring.', $this->SUT->getWarnings()[0]); } public function test_it_warns_when_specified_commit_bin_file_was_not_found() @@ -90,14 +91,14 @@ public function test_it_warns_when_specified_commit_bin_file_was_not_found() $config = $this->SUT->build($extra, __DIR__); - static::assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); - static::assertSame('always', $config->getCommitAuto()); - static::assertNull($config->getCommitBinFile()); - static::assertEmpty($config->getGitlabHosts()); - static::assertEquals(-1, $config->getPostUpdatePriority()); + $this->assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); + $this->assertSame('always', $config->getCommitAuto()); + $this->assertNull($config->getCommitBinFile()); + $this->assertEmpty($config->getGitlabHosts()); + $this->assertEquals(-1, $config->getPostUpdatePriority()); - static::assertCount(1, $this->SUT->getWarnings()); - static::assertContains('The file pointed by the option "commit-bin-file" was not found. Ignoring.', $this->SUT->getWarnings()[0]); + $this->assertCount(1, $this->SUT->getWarnings()); + $this->assertStringContainsString('The file pointed by the option "commit-bin-file" was not found. Ignoring.', $this->SUT->getWarnings()[0]); } public function test_it_warns_when_commit_bin_file_should_have_been_specified() @@ -108,14 +109,14 @@ public function test_it_warns_when_commit_bin_file_should_have_been_specified() $config = $this->SUT->build($extra, __DIR__); - static::assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); - static::assertSame('ask', $config->getCommitAuto()); - static::assertNull($config->getCommitBinFile()); - static::assertEmpty($config->getGitlabHosts()); - static::assertEquals(-1, $config->getPostUpdatePriority()); + $this->assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); + $this->assertSame('ask', $config->getCommitAuto()); + $this->assertNull($config->getCommitBinFile()); + $this->assertEmpty($config->getGitlabHosts()); + $this->assertEquals(-1, $config->getPostUpdatePriority()); - static::assertCount(1, $this->SUT->getWarnings()); - static::assertContains('"commit-auto" is set to "ask" but "commit-bin-file" was not specified.', $this->SUT->getWarnings()[0]); + $this->assertCount(1, $this->SUT->getWarnings()); + $this->assertStringContainsString('"commit-auto" is set to "ask" but "commit-bin-file" was not specified.', $this->SUT->getWarnings()[0]); } public function test_it_warns_when_commit_event_priority_value_is_invalid() @@ -126,14 +127,14 @@ public function test_it_warns_when_commit_event_priority_value_is_invalid() $config = $this->SUT->build($extra, __DIR__); - static::assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); - static::assertSame('never', $config->getCommitAuto()); - static::assertNull($config->getCommitBinFile()); - static::assertEmpty($config->getGitlabHosts()); - static::assertEquals(-1, $config->getPostUpdatePriority()); + $this->assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); + $this->assertSame('never', $config->getCommitAuto()); + $this->assertNull($config->getCommitBinFile()); + $this->assertEmpty($config->getGitlabHosts()); + $this->assertEquals(-1, $config->getPostUpdatePriority()); - static::assertCount(1, $this->SUT->getWarnings()); - static::assertContains('"post-update-priority" is specified but not an integer. Ignoring and using default commit event priority.', $this->SUT->getWarnings()[0]); + $this->assertCount(1, $this->SUT->getWarnings()); + $this->assertStringContainsString('"post-update-priority" is specified but not an integer. Ignoring and using default commit event priority.', $this->SUT->getWarnings()[0]); } public function test_it_warns_when_gitlab_hosts_is_not_an_array() @@ -144,14 +145,14 @@ public function test_it_warns_when_gitlab_hosts_is_not_an_array() $config = $this->SUT->build($extra, __DIR__); - static::assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); - static::assertSame('never', $config->getCommitAuto()); - static::assertNull($config->getCommitBinFile()); - static::assertEmpty($config->getGitlabHosts()); - static::assertEquals(-1, $config->getPostUpdatePriority()); + $this->assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); + $this->assertSame('never', $config->getCommitAuto()); + $this->assertNull($config->getCommitBinFile()); + $this->assertEmpty($config->getGitlabHosts()); + $this->assertEquals(-1, $config->getPostUpdatePriority()); - static::assertCount(1, $this->SUT->getWarnings()); - static::assertContains('"gitlab-hosts" is specified but should be an array. Ignoring.', $this->SUT->getWarnings()[0]); + $this->assertCount(1, $this->SUT->getWarnings()); + $this->assertStringContainsString('"gitlab-hosts" is specified but should be an array. Ignoring.', $this->SUT->getWarnings()[0]); } public function test_it_accepts_valid_setup() @@ -165,12 +166,12 @@ public function test_it_accepts_valid_setup() $config = $this->SUT->build($extra, __DIR__); - static::assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); - static::assertSame('ask', $config->getCommitAuto()); - static::assertSame($this->absoluteCommitBinFile, $config->getCommitBinFile()); - static::assertCount(2, $config->getGitlabHosts()); - static::assertEquals(-1337, $config->getPostUpdatePriority()); + $this->assertInstanceOf('Pyrech\ComposerChangelogs\Config\Config', $config); + $this->assertSame('ask', $config->getCommitAuto()); + $this->assertSame($this->absoluteCommitBinFile, $config->getCommitBinFile()); + $this->assertCount(2, $config->getGitlabHosts()); + $this->assertEquals(-1337, $config->getPostUpdatePriority()); - static::assertCount(0, $this->SUT->getWarnings()); + $this->assertCount(0, $this->SUT->getWarnings()); } } diff --git a/tests/Config/ConfigLocatorTest.php b/tests/Config/ConfigLocatorTest.php index 020e7aa..8328e8c 100644 --- a/tests/Config/ConfigLocatorTest.php +++ b/tests/Config/ConfigLocatorTest.php @@ -14,9 +14,10 @@ use Composer\Composer; use Composer\Config; use Composer\Package\RootPackage; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\Config\ConfigLocator; -class ConfigLocatorTest extends \PHPUnit_Framework_TestCase +class ConfigLocatorTest extends TestCase { /** @var string */ private $localConfigPath; @@ -36,7 +37,7 @@ class ConfigLocatorTest extends \PHPUnit_Framework_TestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { $this->localConfigPath = realpath(__DIR__ . '/../fixtures/local'); $this->globalConfigPath = realpath(__DIR__ . '/../fixtures/home'); @@ -66,29 +67,29 @@ public function test_it_locates_local_config() { $key = 'my-local-config'; - static::assertTrue($this->SUT->locate($key)); + $this->assertTrue($this->SUT->locate($key)); - static::assertSame($this->localConfigPath, $this->SUT->getPath($key)); - static::assertSame(['foo' => 'bar'], $this->SUT->getConfig($key)); + $this->assertSame($this->localConfigPath, $this->SUT->getPath($key)); + $this->assertSame(['foo' => 'bar'], $this->SUT->getConfig($key)); } public function test_it_locates_global_config() { $key = 'my-global-config'; - static::assertTrue($this->SUT->locate($key)); + $this->assertTrue($this->SUT->locate($key)); - static::assertSame($this->globalConfigPath, $this->SUT->getPath($key)); - static::assertSame(['bar' => 'foo'], $this->SUT->getConfig($key)); + $this->assertSame($this->globalConfigPath, $this->SUT->getPath($key)); + $this->assertSame(['bar' => 'foo'], $this->SUT->getConfig($key)); } public function test_it_does_not_locate_non_existing_config() { $key = 'my-non-existing-config'; - static::assertFalse($this->SUT->locate($key)); + $this->assertFalse($this->SUT->locate($key)); - static::assertNull($this->SUT->getPath($key)); - static::assertSame([], $this->SUT->getConfig($key)); + $this->assertNull($this->SUT->getPath($key)); + $this->assertSame([], $this->SUT->getConfig($key)); } } diff --git a/tests/OperationHandler/InstallHandlerTest.php b/tests/OperationHandler/InstallHandlerTest.php index 58ac65e..912bdd1 100644 --- a/tests/OperationHandler/InstallHandlerTest.php +++ b/tests/OperationHandler/InstallHandlerTest.php @@ -13,16 +13,18 @@ use Composer\DependencyResolver\Operation\InstallOperation; use Composer\Package\Package; +use LogicException; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\OperationHandler\InstallHandler; use Pyrech\ComposerChangelogs\tests\resources\FakeOperation; use Pyrech\ComposerChangelogs\tests\resources\FakeUrlGenerator; -class InstallHandlerTest extends \PHPUnit_Framework_TestCase +class InstallHandlerTest extends TestCase { /** @var InstallHandler */ private $SUT; - protected function setUp() + protected function setUp(): void { $this->SUT = new InstallHandler(); } @@ -54,12 +56,11 @@ public function test_it_extracts_source_url() ); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Operation should be an instance of InstallOperation - */ public function test_it_throws_exception_when_extracting_source_url_from_non_install_operation() { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Operation should be an instance of InstallOperation'); + $this->SUT->extractSourceUrl(new FakeOperation('')); } @@ -148,12 +149,11 @@ public function test_it_gets_output_with_url_generator_supporting_all_urls() ); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Operation should be an instance of InstallOperation - */ public function test_it_throws_exception_when_getting_output_from_non_install_operation() { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Operation should be an instance of InstallOperation'); + $this->SUT->getOutput(new FakeOperation('')); } } diff --git a/tests/OperationHandler/UninstallHandlerTest.php b/tests/OperationHandler/UninstallHandlerTest.php index 1d7d0db..59f740b 100644 --- a/tests/OperationHandler/UninstallHandlerTest.php +++ b/tests/OperationHandler/UninstallHandlerTest.php @@ -13,16 +13,18 @@ use Composer\DependencyResolver\Operation\UninstallOperation; use Composer\Package\Package; +use LogicException; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\OperationHandler\UninstallHandler; use Pyrech\ComposerChangelogs\tests\resources\FakeOperation; use Pyrech\ComposerChangelogs\tests\resources\FakeUrlGenerator; -class UninstallHandlerTest extends \PHPUnit_Framework_TestCase +class UninstallHandlerTest extends TestCase { /** @var UninstallHandler */ private $SUT; - protected function setUp() + protected function setUp(): void { $this->SUT = new UninstallHandler(); } @@ -54,12 +56,11 @@ public function test_it_extracts_source_url() ); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Operation should be an instance of UninstallOperation - */ public function test_it_throws_exception_when_extracting_source_url_from_non_uninstall_operation() { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Operation should be an instance of UninstallOperation'); + $this->SUT->extractSourceUrl(new FakeOperation('')); } @@ -146,12 +147,11 @@ public function test_it_gets_output_with_url_generator_supporting_all_urls() ); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Operation should be an instance of UninstallOperation - */ public function test_it_throws_exception_when_getting_output_from_non_uninstall_operation() { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Operation should be an instance of UninstallOperation'); + $this->SUT->getOutput(new FakeOperation('')); } } diff --git a/tests/OperationHandler/UpdateHandlerTest.php b/tests/OperationHandler/UpdateHandlerTest.php index 8ee8ca9..c416e52 100644 --- a/tests/OperationHandler/UpdateHandlerTest.php +++ b/tests/OperationHandler/UpdateHandlerTest.php @@ -13,16 +13,18 @@ use Composer\DependencyResolver\Operation\UpdateOperation; use Composer\Package\Package; +use LogicException; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\OperationHandler\UpdateHandler; use Pyrech\ComposerChangelogs\tests\resources\FakeOperation; use Pyrech\ComposerChangelogs\tests\resources\FakeUrlGenerator; -class UpdateHandlerTest extends \PHPUnit_Framework_TestCase +class UpdateHandlerTest extends TestCase { /** @var UpdateHandler */ private $SUT; - protected function setUp() + protected function setUp(): void { $this->SUT = new UpdateHandler(); } @@ -58,12 +60,11 @@ public function test_it_extracts_source_url() ); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Operation should be an instance of UpdateOperation - */ public function test_it_throws_exception_when_extracting_source_url_from_non_update_operation() { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Operation should be an instance of UpdateOperation'); + $this->SUT->extractSourceUrl(new FakeOperation('')); } @@ -160,12 +161,11 @@ public function test_it_gets_output_with_url_generator_supporting_all_urls() ); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Operation should be an instance of UpdateOperation - */ public function test_it_throws_exception_when_getting_output_from_non_update_operation() { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Operation should be an instance of UpdateOperation'); + $this->SUT->getOutput(new FakeOperation('')); } diff --git a/tests/OutputterTest.php b/tests/OutputterTest.php index 418da3d..696e287 100644 --- a/tests/OutputterTest.php +++ b/tests/OutputterTest.php @@ -11,6 +11,7 @@ namespace Pyrech\ComposerChangelogs\tests; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\OperationHandler\OperationHandler; use Pyrech\ComposerChangelogs\Outputter; use Pyrech\ComposerChangelogs\tests\resources\FakeHandler; @@ -18,7 +19,7 @@ use Pyrech\ComposerChangelogs\tests\resources\FakeUrlGenerator; use Pyrech\ComposerChangelogs\UrlGenerator\UrlGenerator; -class OutputterTest extends \PHPUnit_Framework_TestCase +class OutputterTest extends TestCase { /** @var Outputter */ private $SUT; @@ -29,7 +30,7 @@ class OutputterTest extends \PHPUnit_Framework_TestCase /** @var UrlGenerator[] */ private $urlGenerators; - protected function setUp() + protected function setUp(): void { $this->operationHandlers = [ new FakeHandler(false, 'http://domain1', 'Output handler 1'), @@ -48,22 +49,27 @@ protected function setUp() public function test_it_adds_operation() { - $this->assertAttributeSame([], 'operations', $this->SUT); - $operation1 = new FakeOperation(''); $this->SUT->addOperation($operation1); - $this->assertAttributeSame([ - $operation1, - ], 'operations', $this->SUT); - $operation2 = new FakeOperation(''); $this->SUT->addOperation($operation2); - $this->assertAttributeSame([ - $operation1, - $operation2, - ], 'operations', $this->SUT); + $expectedOutput = <<Changelogs summary: + + - Output handler 2, + /compare-url2 + /release-url2 + + - Output handler 2, + /compare-url2 + /release-url2 + +TEXT; + + $this->assertFalse($this->SUT->isEmpty()); + $this->assertSame($expectedOutput, $this->SUT->getOutput()); } public function test_it_outputs_with_no_supported_url_generator() diff --git a/tests/UrlGenerator/BitbucketUrlGeneratorTest.php b/tests/UrlGenerator/BitbucketUrlGeneratorTest.php index 81fdc0d..827ac02 100644 --- a/tests/UrlGenerator/BitbucketUrlGeneratorTest.php +++ b/tests/UrlGenerator/BitbucketUrlGeneratorTest.php @@ -11,15 +11,17 @@ namespace Pyrech\ComposerChangelogs\tests\UrlGenerator; +use LogicException; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\UrlGenerator\BitbucketUrlGenerator; use Pyrech\ComposerChangelogs\Version; -class BitbucketUrlGeneratorTest extends \PHPUnit_Framework_TestCase +class BitbucketUrlGeneratorTest extends TestCase { /** @var BitbucketUrlGenerator */ private $SUT; - protected function setUp() + protected function setUp(): void { $this->SUT = new BitbucketUrlGenerator(); } @@ -145,12 +147,11 @@ public function test_it_does_not_generate_compare_urls_for_unsupported_url() ); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Unrecognized url format for bitbucket.org ("https://bitbucket.org/acme2") - */ public function test_it_throws_exception_when_generating_compare_urls_across_forks_if_a_source_url_is_invalid() { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Unrecognized url format for bitbucket.org ("https://bitbucket.org/acme2")'); + $versionFrom = new Version('v1.0.0.0', 'v1.0.0', 'v1.0.0'); $versionTo = new Version('v1.0.1.0', 'v1.0.1', 'v1.0.1'); diff --git a/tests/UrlGenerator/GithubUrlGeneratorTest.php b/tests/UrlGenerator/GithubUrlGeneratorTest.php index 5361410..f0bb4e7 100644 --- a/tests/UrlGenerator/GithubUrlGeneratorTest.php +++ b/tests/UrlGenerator/GithubUrlGeneratorTest.php @@ -11,15 +11,17 @@ namespace Pyrech\ComposerChangelogs\tests\UrlGenerator; +use LogicException; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\UrlGenerator\GithubUrlGenerator; use Pyrech\ComposerChangelogs\Version; -class GithubUrlGeneratorTest extends \PHPUnit_Framework_TestCase +class GithubUrlGeneratorTest extends TestCase { /** @var GithubUrlGenerator */ private $SUT; - protected function setUp() + protected function setUp(): void { $this->SUT = new GithubUrlGenerator(); } @@ -145,12 +147,11 @@ public function test_it_does_not_generate_compare_urls_for_unsupported_url() ); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Unrecognized url format for github.com ("https://github.com/acme2") - */ public function test_it_throws_exception_when_generating_compare_urls_across_forks_if_a_source_url_is_invalid() { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Unrecognized url format for github.com ("https://github.com/acme2")'); + $versionFrom = new Version('v1.0.0.0', 'v1.0.0', 'v1.0.0'); $versionTo = new Version('v1.0.1.0', 'v1.0.1', 'v1.0.1'); diff --git a/tests/UrlGenerator/GitlabUrlGeneratorTest.php b/tests/UrlGenerator/GitlabUrlGeneratorTest.php index 95b45ad..7d3eace 100644 --- a/tests/UrlGenerator/GitlabUrlGeneratorTest.php +++ b/tests/UrlGenerator/GitlabUrlGeneratorTest.php @@ -11,15 +11,16 @@ namespace Pyrech\ComposerChangelogs\tests\UrlGenerator; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\UrlGenerator\GitlabUrlGenerator; use Pyrech\ComposerChangelogs\Version; -class GitlabUrlGeneratorTest extends \PHPUnit_Framework_TestCase +class GitlabUrlGeneratorTest extends TestCase { /** @var GitlabUrlGenerator */ private $SUT; - protected function setUp() + protected function setUp(): void { $this->SUT = new GitlabUrlGenerator('gitlab.company.org'); } diff --git a/tests/UrlGenerator/WordPressUrlGeneratorTest.php b/tests/UrlGenerator/WordPressUrlGeneratorTest.php index f1402dd..259013b 100644 --- a/tests/UrlGenerator/WordPressUrlGeneratorTest.php +++ b/tests/UrlGenerator/WordPressUrlGeneratorTest.php @@ -11,17 +11,18 @@ namespace Pyrech\ComposerChangelogs\tests\UrlGenerator; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\UrlGenerator\WordPressUrlGenerator; use Pyrech\ComposerChangelogs\Version; -class WordPressUrlGeneratorTest extends \PHPUnit_Framework_TestCase +class WordPressUrlGeneratorTest extends TestCase { /** * @var WordPressUrlGenerator */ private $SUT; - protected function setUp() + protected function setUp(): void { $this->SUT = new WordPressUrlGenerator(); } diff --git a/tests/Util/FileSystemHelperTest.php b/tests/Util/FileSystemHelperTest.php index dd4c8be..9cf5446 100644 --- a/tests/Util/FileSystemHelperTest.php +++ b/tests/Util/FileSystemHelperTest.php @@ -11,18 +11,19 @@ namespace Pyrech\ComposerChangelogs\tests\Util; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\Util\FileSystemHelper; -class FileSystemHelperTest extends \PHPUnit_Framework_TestCase +class FileSystemHelperTest extends TestCase { public function test_it_correctly_differentiates_absolute_paths_from_relative_ones() { - static::assertTrue(FileSystemHelper::isAbsolute('/var/lib')); - static::assertTrue(FileSystemHelper::isAbsolute('c:\\\\var\\lib')); - static::assertTrue(FileSystemHelper::isAbsolute('\\var\\lib')); + $this->assertTrue(FileSystemHelper::isAbsolute('/var/lib')); + $this->assertTrue(FileSystemHelper::isAbsolute('c:\\\\var\\lib')); + $this->assertTrue(FileSystemHelper::isAbsolute('\\var\\lib')); - static::assertFalse(FileSystemHelper::isAbsolute('var/lib')); - static::assertFalse(FileSystemHelper::isAbsolute('../var/lib')); - static::assertFalse(FileSystemHelper::isAbsolute('')); + $this->assertFalse(FileSystemHelper::isAbsolute('var/lib')); + $this->assertFalse(FileSystemHelper::isAbsolute('../var/lib')); + $this->assertFalse(FileSystemHelper::isAbsolute('')); } } diff --git a/tests/VersionTest.php b/tests/VersionTest.php index b73a678..b96229e 100644 --- a/tests/VersionTest.php +++ b/tests/VersionTest.php @@ -11,9 +11,10 @@ namespace Pyrech\ComposerChangelogs\tests; +use PHPUnit\Framework\TestCase; use Pyrech\ComposerChangelogs\Version; -class VersionTest extends \PHPUnit_Framework_TestCase +class VersionTest extends TestCase { /** @var Version */ private $SUT; diff --git a/tests/resources/FakeOperation.php b/tests/resources/FakeOperation.php index 8084220..037976e 100644 --- a/tests/resources/FakeOperation.php +++ b/tests/resources/FakeOperation.php @@ -26,6 +26,11 @@ public function __construct($text) $this->text = $text; } + public function getOperationType() + { + return ''; + } + /** * @return string */ @@ -50,6 +55,11 @@ public function getReason() return ''; } + public function show($lock) + { + return ''; + } + /** * {@inheritdoc} */