Skip to content

Commit

Permalink
Merge pull request #68 from jeromegamez/composer-2
Browse files Browse the repository at this point in the history
Add support for Composer ^2.0
  • Loading branch information
pyrech committed Apr 27, 2020
2 parents 69afdea + 436b94b commit 413eab0
Show file tree
Hide file tree
Showing 22 changed files with 286 additions and 243 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,4 +6,5 @@ composer.lock
composer.phar

# CS
.php_cs
.php_cs.cache
39 changes: 0 additions & 39 deletions .php_cs

This file was deleted.

35 changes: 35 additions & 0 deletions .php_cs.dist
@@ -0,0 +1,35 @@
<?php

$header = <<<EOF
This file is part of the composer-changelogs project.
(c) Loïck Piera <pyrech@gmail.com>
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 <?php
'concat_space' => ['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)
;
9 changes: 8 additions & 1 deletion .travis.yml
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 --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
@@ -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
9 changes: 4 additions & 5 deletions composer.json
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="false"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php"
>
Expand Down
8 changes: 8 additions & 0 deletions src/ChangelogsPlugin.php
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
131 changes: 68 additions & 63 deletions tests/ChangelogsPluginTest.php
Expand Up @@ -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;
Expand All @@ -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'));
Expand All @@ -71,7 +73,7 @@ protected function setUp()
/**
* {@inheritdoc}
*/
protected function tearDown()
protected function tearDown(): void
{
self::cleanTempDir();
}
Expand All @@ -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()
Expand All @@ -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);

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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
);
}
}

0 comments on commit 413eab0

Please sign in to comment.