Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issue with uninstall #57 #60

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions src/VersionsCheckPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,30 @@ final class VersionsCheckPlugin implements PluginInterface, EventSubscriberInter
*/
private $options = array();

/** @var boolean */
private $disabled = false;

/**
* @var array
*/
private $classes = array(
"SLLH\ComposerVersionsCheck\VersionsCheckPlugin",
"SLLH\ComposerVersionsCheck\VersionsCheck",
"SLLH\ComposerVersionsCheck\OutdatedPackage"
);

/**
* {@inheritdoc}
*/
public function activate(Composer $composer, IOInterface $io)
{
// guard for self-update problem
foreach ($this->classes as $class) {
if (!class_exists($class)) {
return $this->disable();
}
}

$this->composer = $composer;
$this->io = $io;
$this->versionsCheck = new VersionsCheck();
Expand All @@ -74,6 +93,10 @@ public static function getSubscribedEvents()
*/
public function command(CommandEvent $event)
{
if ($this->disabled) {
return;
}

$input = $event->getInput();
$this->preferLowest = $input->hasOption('prefer-lowest') && true === $input->getOption('prefer-lowest');
}
Expand All @@ -83,7 +106,7 @@ public function command(CommandEvent $event)
*/
public function postUpdate(Event $event)
{
if (true === $this->preferLowest) {
if ($this->disabled || true === $this->preferLowest) {
return;
}

Expand All @@ -97,6 +120,10 @@ public function postUpdate(Event $event)
*/
private function resolveOptions()
{
if ($this->disabled) {
return;
}

$pluginConfig = $this->composer->getConfig()
? $this->composer->getConfig()->get('sllh-composer-versions-check')
: null
Expand All @@ -121,6 +148,10 @@ private function resolveOptions()
*/
private function checkVersions(RepositoryManager $repositoryManager, RootPackageInterface $rootPackage)
{
if ($this->disabled) {
return;
}

foreach ($repositoryManager->getRepositories() as $repository) {
$this->versionsCheck->checkPackages(
$repository,
Expand All @@ -131,4 +162,9 @@ private function checkVersions(RepositoryManager $repositoryManager, RootPackage

$this->io->write($this->versionsCheck->getOutput($this->options['show-links']), false);
}
}

public function disable()
{
$this->disabled = true;
}
}
6 changes: 3 additions & 3 deletions tests/OutdatedPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public function testCreation()
$actual = new Package('foo/bar', '1.0.0', 'v1.0.0');
$last = new Package('foo/bar', '2.4.3', 'v2.4.3');
$links = array(
$this->getMock('Composer\Package\PackageInterface'),
$this->getMock('Composer\Package\PackageInterface'),
$this->getMock('Composer\Package\PackageInterface'),
$this->createMock('Composer\Package\PackageInterface'),
$this->createMock('Composer\Package\PackageInterface'),
$this->createMock('Composer\Package\PackageInterface'),
);

$outdatedPackage = new OutdatedPackage($actual, $last, $links);
Expand Down
2 changes: 1 addition & 1 deletion tests/VersionsCheckPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class VersionsCheckPluginTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->io = new BufferIO();
$this->composer = $this->getMock('Composer\Composer');
$this->composer = $this->createMock('Composer\Composer');
$this->config = new Config(false);

$this->composer->expects($this->any())->method('getConfig')
Expand Down