Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
added second level message output (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis committed Sep 30, 2018
1 parent 9bd9951 commit b814463
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ProxyConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function buildClassNamesContent(PackageContract $package, array $classes

$content .= $spaces . '\'' . \str_replace('::class', '', $className) . '\' => ' . $class . ",\n";

$this->io->write(\sprintf(' - Enabling [%s] as a %s proxy.', $class, $env), true, IOInterface::VERBOSE);
$this->io->writeError(\sprintf(' - Enabling [%s] as a %s proxy.', $class, $env), true, IOInterface::VERBOSE);
}

return $this->markData($package->getName(), $content, 16);
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceProviderConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private function buildClassNamesContent(PackageContract $package, array $classes
foreach ($classes as $class) {
$content .= ' ' . $class . ",\n";

$this->io->write(\sprintf(' - Enabling [%s] as a %s service provider.', $class, $type), true, IOInterface::VERBOSE);
$this->io->writeError(\sprintf(' - Enabling [%s] as a %s service provider.', $class, $type), true, IOInterface::VERBOSE);
}

return $this->markData($package->getName(), $content);
Expand Down
114 changes: 109 additions & 5 deletions tests/ServiceProviderConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Narrowspark\Automatic\Test\Configurator;

use Composer\Composer;
use Composer\IO\NullIO;
use Composer\IO\IOInterface;
use Narrowspark\Automatic\Common\Package;
use Narrowspark\Automatic\Common\Traits\PhpFileMarkerTrait;
use Narrowspark\Automatic\Configurator\ServiceProviderConfigurator;
Expand All @@ -22,9 +22,9 @@ final class ServiceProviderConfiguratorTest extends MockeryTestCase
private $composer;

/**
* @var \Composer\IO\NullIo
* @var \Composer\IO\IOInterface|\Mockery\MockInterface
*/
private $nullIo;
private $ioMock;

/**
* @var \Narrowspark\Automatic\Configurator\ServiceProviderConfigurator
Expand All @@ -49,14 +49,14 @@ protected function setUp(): void
parent::setUp();

$this->composer = new Composer();
$this->nullIo = new NullIO();
$this->ioMock = $this->mock(IOInterface::class);

$dir = __DIR__ . '/ServiceProviderConfiguratorTest';

$this->globalPath = $dir . '/serviceproviders.php';
$this->localPath = $dir . '/local/serviceproviders.php';

$this->configurator = new ServiceProviderConfigurator($this->composer, $this->nullIo, ['config-dir' => $dir]);
$this->configurator = new ServiceProviderConfigurator($this->composer, $this->ioMock, ['config-dir' => $dir]);
}

/**
Expand Down Expand Up @@ -94,6 +94,13 @@ public function testConfigureWithGlobalProvider(): void
],
]);

$this->ioMock->shouldReceive('writeError')
->once()
->with([' - Enabling the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Test\Configurator\ServiceProviderConfiguratorTest::class] as a global service provider.', true, IOInterface::VERBOSE);

$this->configurator->configure($package);

static::assertTrue($this->isFileMarked('test', $this->globalPath));
Expand All @@ -114,6 +121,16 @@ public function testConfigureWithGlobalAndLocalProvider(): void
],
]);

$this->ioMock->shouldReceive('writeError')
->once()
->with([' - Enabling the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Test\Configurator\ServiceProviderConfiguratorTest::class] as a global service provider.', true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Test\Configurator\ServiceProviderConfiguratorTest::class] as a local service provider.', true, IOInterface::VERBOSE);

$this->configurator->configure($package);

static::assertTrue($this->isFileMarked('test', $this->globalPath));
Expand All @@ -139,6 +156,13 @@ public function testSkipMarkedFiles(): void
],
]);

$this->ioMock->shouldReceive('writeError')
->twice()
->with([' - Enabling the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Test\Configurator\ServiceProviderConfiguratorTest::class] as a global service provider.', true, IOInterface::VERBOSE);

$this->configurator->configure($package);

$array = include $this->globalPath;
Expand All @@ -161,6 +185,13 @@ public function testUpdateAExistedFileWithGlobalProvider(): void
],
]);

$this->ioMock->shouldReceive('writeError')
->once()
->with([' - Enabling the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Test\Configurator\ServiceProviderConfiguratorTest::class] as a global service provider.', true, IOInterface::VERBOSE);

$this->configurator->configure($package);

$array = include $this->globalPath;
Expand All @@ -176,6 +207,13 @@ public function testUpdateAExistedFileWithGlobalProvider(): void
],
]);

$this->ioMock->shouldReceive('writeError')
->once()
->with([' - Enabling the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Common\Package::class] as a global service provider.', true, IOInterface::VERBOSE);

$this->configurator->configure($package);

$array = include $this->globalPath;
Expand All @@ -195,6 +233,16 @@ public function testUpdateAExistedFileWithGlobalAndLocalProvider(): void
],
]);

$this->ioMock->shouldReceive('writeError')
->once()
->with([' - Enabling the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Test\Configurator\ServiceProviderConfiguratorTest::class] as a global service provider.', true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Test\Configurator\ServiceProviderConfiguratorTest::class] as a local service provider.', true, IOInterface::VERBOSE);

$this->configurator->configure($package);

$array = include $this->globalPath;
Expand All @@ -214,6 +262,16 @@ public function testUpdateAExistedFileWithGlobalAndLocalProvider(): void
],
]);

$this->ioMock->shouldReceive('writeError')
->once()
->with([' - Enabling the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Common\Package::class] as a global service provider.', true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Common\Package::class] as a local service provider.', true, IOInterface::VERBOSE);

$this->configurator->configure($package);

$array = include $this->globalPath;
Expand All @@ -237,6 +295,10 @@ public function testConfigureWithEmptyProvidersConfig(): void
],
]);

$this->ioMock->shouldReceive('writeError')
->once()
->with([' - Enabling the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);

$this->configurator->configure($package);

static::assertFileNotExists($this->globalPath);
Expand Down Expand Up @@ -297,7 +359,19 @@ public function testUnconfigureWithGlobalProviders(): void
],
]);

$this->ioMock->shouldReceive('writeError')
->once()
->with([' - Enabling the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Test\Configurator\ServiceProviderConfiguratorTest::class] as a global service provider.', true, IOInterface::VERBOSE);

$this->configurator->configure($package);

$this->ioMock->shouldReceive('writeError')
->once()
->with([' - Disable the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);

$this->configurator->unconfigure($package);

$package = new Package('test2', '^1.0.0');
Expand All @@ -309,6 +383,13 @@ public function testUnconfigureWithGlobalProviders(): void
],
]);

$this->ioMock->shouldReceive('writeError')
->once()
->with([' - Enabling the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->once()
->with(' - Enabling [\Narrowspark\Automatic\Common\Package::class] as a global service provider.', true, IOInterface::VERBOSE);

$this->configurator->configure($package);

$array = include $this->globalPath;
Expand All @@ -329,7 +410,22 @@ public function testUnconfigureAndConfigureAgain(): void
],
]);

$this->ioMock->shouldReceive('writeError')
->twice()
->with([' - Enabling the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->twice()
->with(' - Enabling [\Narrowspark\Automatic\Test\Configurator\ServiceProviderConfiguratorTest::class] as a global service provider.', true, IOInterface::VERBOSE);
$this->ioMock->shouldReceive('writeError')
->twice()
->with(' - Enabling [\Narrowspark\Automatic\Common\Package::class] as a local service provider.', true, IOInterface::VERBOSE);

$this->configurator->configure($package);

$this->ioMock->shouldReceive('writeError')
->once()
->with([' - Disable the package as a Narrowspark service provider'], true, IOInterface::VERBOSE);

$this->configurator->unconfigure($package);

$this->configurator->configure($package);
Expand All @@ -338,4 +434,12 @@ public function testUnconfigureAndConfigureAgain(): void

static::assertFalse(isset($array[0], $array[1]));
}

/**
* {@inheritdoc}
*/
protected function allowMockingNonExistentMethods($allow = false): void
{
parent::allowMockingNonExistentMethods(true);
}
}

0 comments on commit b814463

Please sign in to comment.