Skip to content

Commit

Permalink
Add support for Composer ^2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Apr 26, 2020
1 parent b32aafd commit 436b94b
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 63 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ matrix:
- php: 7.2
env: check_cs=true
- php: 7.3
- php: 7.4
dist: bionic

env:
global:
Expand All @@ -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.dist --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;
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
],
"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",
"friendsofphp/php-cs-fixer": "^2.16",
"composer/composer": "^1.0.0-alpha10@dev || ^2.0@dev",
"composer/semver": "^1.2 || ^2.0",
"phpunit/phpunit": "^7.5"
},
"config": {
Expand Down
8 changes: 8 additions & 0 deletions src/ChangelogsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
122 changes: 64 additions & 58 deletions tests/ChangelogsPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -107,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);

Expand All @@ -140,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();
Expand Down Expand Up @@ -201,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();
Expand All @@ -233,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();
Expand All @@ -267,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();
Expand Down Expand Up @@ -309,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
);
}
}
10 changes: 10 additions & 0 deletions tests/resources/FakeOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public function __construct($text)
$this->text = $text;
}

public function getOperationType()
{
return '';
}

/**
* @return string
*/
Expand All @@ -50,6 +55,11 @@ public function getReason()
return '';
}

public function show($lock)
{
return '';
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 436b94b

Please sign in to comment.