From b814463353347f52b4a2a432b3cfdb731d924ad1 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Sun, 30 Sep 2018 15:23:24 +0200 Subject: [PATCH] added second level message output (#7) --- src/ProxyConfigurator.php | 2 +- src/ServiceProviderConfigurator.php | 2 +- tests/ServiceProviderConfiguratorTest.php | 114 +++++++++++++++++++++- 3 files changed, 111 insertions(+), 7 deletions(-) diff --git a/src/ProxyConfigurator.php b/src/ProxyConfigurator.php index f4163cf..e156a92 100644 --- a/src/ProxyConfigurator.php +++ b/src/ProxyConfigurator.php @@ -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); diff --git a/src/ServiceProviderConfigurator.php b/src/ServiceProviderConfigurator.php index ac76daa..25f11c6 100644 --- a/src/ServiceProviderConfigurator.php +++ b/src/ServiceProviderConfigurator.php @@ -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); diff --git a/tests/ServiceProviderConfiguratorTest.php b/tests/ServiceProviderConfiguratorTest.php index fb86dc2..07bd196 100644 --- a/tests/ServiceProviderConfiguratorTest.php +++ b/tests/ServiceProviderConfiguratorTest.php @@ -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; @@ -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 @@ -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]); } /** @@ -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)); @@ -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)); @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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); @@ -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'); @@ -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; @@ -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); @@ -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); + } }