-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Implement NormalizePlugin
- Loading branch information
1 parent
e63c4a5
commit 26f8dd5
Showing
5 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2018 Andreas Möller. | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/localheinz/composer-normalize | ||
*/ | ||
|
||
namespace Localheinz\Composer\Normalize; | ||
|
||
use Composer\Composer; | ||
use Composer\IO; | ||
use Composer\Plugin; | ||
use Localheinz\Json\Normalizer\AutoFormatNormalizer; | ||
use Localheinz\Json\Normalizer\ChainNormalizer; | ||
|
||
final class NormalizePlugin implements Plugin\PluginInterface, Plugin\Capable, Plugin\Capability\CommandProvider | ||
{ | ||
/** | ||
* @var Composer | ||
*/ | ||
private $composer; | ||
|
||
/** | ||
* @var IO\IOInterface | ||
*/ | ||
private $io; | ||
|
||
public function activate(Composer $composer, IO\IOInterface $io) | ||
{ | ||
$this->composer = $composer; | ||
$this->io = $io; | ||
} | ||
|
||
public function getCapabilities(): array | ||
{ | ||
return [ | ||
Plugin\Capability\CommandProvider::class => self::class, | ||
]; | ||
} | ||
|
||
public function getCommands(): array | ||
{ | ||
return [ | ||
new Command\NormalizeCommand(new AutoFormatNormalizer(new ChainNormalizer( | ||
new Normalizer\ConfigHashNormalizer() | ||
))), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2018 Andreas Möller. | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/localheinz/composer-normalize | ||
*/ | ||
|
||
namespace Localheinz\Composer\Normalize\Test\Unit; | ||
|
||
use Composer\Composer; | ||
use Composer\IO; | ||
use Composer\Plugin; | ||
use Localheinz\Composer\Normalize\Command\NormalizeCommand; | ||
use Localheinz\Composer\Normalize\NormalizePlugin; | ||
use Localheinz\Test\Util\Helper; | ||
use PHPUnit\Framework; | ||
|
||
final class NormalizePluginTest extends Framework\TestCase | ||
{ | ||
use Helper; | ||
|
||
/** | ||
* @dataProvider providerInterfaceName | ||
* | ||
* @param string $interfaceName | ||
*/ | ||
public function testImplementsPluginInterface(string $interfaceName) | ||
{ | ||
$this->assertClassImplementsInterface($interfaceName, NormalizePlugin::class); | ||
} | ||
|
||
public function providerInterfaceName(): \Generator | ||
{ | ||
$interfaces = [ | ||
Plugin\PluginInterface::class, | ||
Plugin\Capable::class, | ||
Plugin\Capability\CommandProvider::class, | ||
]; | ||
|
||
foreach ($interfaces as $interface) { | ||
yield $interface => [ | ||
$interface, | ||
]; | ||
} | ||
} | ||
|
||
public function testGetCapabilitiesReturnsCapabilities() | ||
{ | ||
$plugin = new NormalizePlugin(); | ||
|
||
$plugin->activate( | ||
$this->prophesize(Composer::class)->reveal(), | ||
$this->prophesize(IO\IOInterface::class)->reveal() | ||
); | ||
|
||
$expected = [ | ||
Plugin\Capability\CommandProvider::class => NormalizePlugin::class, | ||
]; | ||
|
||
$this->assertSame($expected, $plugin->getCapabilities()); | ||
} | ||
|
||
public function testProvidesNormalizeCommand() | ||
{ | ||
$plugin = new NormalizePlugin(); | ||
|
||
$plugin->activate( | ||
$this->prophesize(Composer::class)->reveal(), | ||
$this->prophesize(IO\IOInterface::class)->reveal() | ||
); | ||
|
||
$commands = $plugin->getCommands(); | ||
|
||
$this->assertCount(1, $commands); | ||
|
||
$command = \array_shift($commands); | ||
|
||
$this->assertInstanceOf(NormalizeCommand::class, $command); | ||
} | ||
} |