mezzio-tooling icon indicating copy to clipboard operation
mezzio-tooling copied to clipboard

Update dependency psalm/plugin-mockery to v1

Open renovate[bot] opened this issue 2 years ago • 4 comments

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
psalm/plugin-mockery ^0.11.0 -> ^1.0.0 age adoption passing confidence

Release Notes

psalm/psalm-plugin-mockery (psalm/plugin-mockery)

v1.1.0

Compare Source

What's Changed

Full Changelog: https://github.com/psalm/psalm-plugin-mockery/compare/1.0.0...1.1.0

v1.0.0

Compare Source

What's Changed

Full Changelog: https://github.com/psalm/psalm-plugin-mockery/compare/0.11.0...1.0.0


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • [ ] If you want to rebase/retry this PR, check this box

Read more information about the use of Renovate Bot within Laminas.

renovate[bot] avatar Nov 25 '22 11:11 renovate[bot]

I tried writing a patch to get rid of mockery and failed.

The internal components of mezzio/mezzio-tooling are final and have no interfaces.

I was going down the rabbit hole of extracting all interfaces, but I don't think I'd want to invest more time in it:

diff --git a/src/Module/DeregisterCommand.php b/src/Module/DeregisterCommand.php
index 92190ca..971a239 100644
--- a/src/Module/DeregisterCommand.php
+++ b/src/Module/DeregisterCommand.php
@@ -8,6 +8,7 @@ use Mezzio\Tooling\Composer\ComposerPackageFactoryInterface;
 use Mezzio\Tooling\Composer\ComposerPackageInterface;
 use Mezzio\Tooling\Composer\ComposerProcessFactoryInterface;
 use Mezzio\Tooling\ConfigInjector\ConfigAggregatorInjector;
+use Mezzio\Tooling\ConfigInjector\InjectorInterface;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
@@ -37,14 +38,18 @@ final class DeregisterCommand extends Command
 
     private ComposerProcessFactoryInterface $processFactory;
 
+    private InjectorInterface $injector;
+
     public function __construct(
         string $projectRoot,
         ComposerPackageFactoryInterface $packageFactory,
-        ComposerProcessFactoryInterface $processFactory
+        ComposerProcessFactoryInterface $processFactory,
+        ?InjectorInterface $configInjector = null
     ) {
         $this->projectRoot    = $projectRoot;
         $this->package        = $packageFactory->loadPackage($projectRoot);
         $this->processFactory = $processFactory;
+        $this->injector       = $configInjector ?? new ConfigAggregatorInjector($this->projectRoot);
 
         parent::__construct();
     }
@@ -69,12 +74,11 @@ final class DeregisterCommand extends Command
         $module   = $input->getArgument('module');
         $composer = $input->getOption('composer') ?: 'composer';
 
-        $injector       = new ConfigAggregatorInjector($this->projectRoot);
         $configProvider = sprintf('%s\ConfigProvider', $module);
         assert($configProvider !== '');
 
-        if ($injector->isRegistered($configProvider)) {
-            $injector->remove($configProvider);
+        if ($this->injector->isRegistered($configProvider)) {
+            $this->injector->remove($configProvider);
         }
 
         // If no updates are made to autoloading, no need to update the autoloader.
diff --git a/src/Module/RegisterCommand.php b/src/Module/RegisterCommand.php
index 61e45d1..9371499 100644
--- a/src/Module/RegisterCommand.php
+++ b/src/Module/RegisterCommand.php
@@ -44,15 +44,18 @@ final class RegisterCommand extends Command
     private string $projectRoot;
 
     private ComposerProcessFactoryInterface $processFactory;
+    private InjectorInterface $injector;
 
     public function __construct(
         string $projectRoot,
         ComposerPackageFactoryInterface $packageFactory,
-        ComposerProcessFactoryInterface $processFactory
+        ComposerProcessFactoryInterface $processFactory,
+        ?InjectorInterface $configInjector = null
     ) {
         $this->projectRoot    = $projectRoot;
         $this->package        = $packageFactory->loadPackage($projectRoot);
         $this->processFactory = $processFactory;
+        $this->injector       = $configInjector ?? new ConfigAggregatorInjector($this->projectRoot);
 
         parent::__construct();
     }
@@ -81,11 +84,10 @@ final class RegisterCommand extends Command
         $modulesPath = CommandCommonOptions::getModulesPath($input);
         $exactPath   = $input->getOption('exact-path');
 
-        $injector       = new ConfigAggregatorInjector($this->projectRoot);
         $configProvider = sprintf('%s\ConfigProvider', $module);
         assert($configProvider !== '');
-        if (! $injector->isRegistered($configProvider)) {
-            $injector->inject(
+        if (! $this->injector->isRegistered($configProvider)) {
+            $this->injector->inject(
                 $configProvider,
                 InjectorInterface::TYPE_CONFIG_PROVIDER
             );
diff --git a/test/Module/DeregisterCommandTest.php b/test/Module/DeregisterCommandTest.php
index 076519f..1b1e7de 100644
--- a/test/Module/DeregisterCommandTest.php
+++ b/test/Module/DeregisterCommandTest.php
@@ -9,17 +9,12 @@ use Mezzio\Tooling\Composer\ComposerPackageInterface;
 use Mezzio\Tooling\Composer\ComposerProcessFactoryInterface;
 use Mezzio\Tooling\Composer\ComposerProcessInterface;
 use Mezzio\Tooling\Composer\ComposerProcessResultInterface;
-use Mezzio\Tooling\ConfigInjector\ConfigAggregatorInjector;
+use Mezzio\Tooling\ConfigInjector\InjectorInterface;
 use Mezzio\Tooling\Module\DeregisterCommand;
-use Mockery;
-use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
 use org\bovigo\vfs\vfsStream;
 use org\bovigo\vfs\vfsStreamDirectory;
 use PHPUnit\Framework\MockObject\MockObject;
 use PHPUnit\Framework\TestCase;
-use Prophecy\Argument;
-use Prophecy\PhpUnit\ProphecyTrait;
-use Prophecy\Prophecy\ObjectProphecy;
 use ReflectionMethod;
 use RuntimeException;
 use Symfony\Component\Console\Input\InputInterface;
@@ -28,28 +23,27 @@ use Symfony\Component\Console\Output\ConsoleOutputInterface;
 class DeregisterCommandTest extends TestCase
 {
     use CommonOptionsAndAttributesTrait;
-    use MockeryPHPUnitIntegration;
-    use ProphecyTrait;
 
     private vfsStreamDirectory $dir;
 
-    /** @var ObjectProphecy<InputInterface> */
+    /** @var InputInterface&MockObject */
     private $input;
 
-    /** @var ObjectProphecy<ConsoleOutputInterface> */
+    /** @var InputInterface&ConsoleOutputInterface */
     private $output;
 
-    /** @var DeregisterCommand */
-    private $command;
+    private DeregisterCommand $command;
 
-    /** @var string */
-    private $expectedModuleArgumentDescription;
+    private string $expectedModuleArgumentDescription;
 
     /** @var ComposerPackageInterface&MockObject */
-    private $package;
+    private ComposerPackageInterface $package;
 
     /** @var ComposerProcessFactoryInterface&MockObject */
-    private $processFactory;
+    private ComposerProcessFactoryInterface $processFactory;
+
+    /** @var InjectorInterface&MockObject */
+    private InjectorInterface $injector;
 
     protected function setUp(): void
     {
@@ -58,16 +52,18 @@ class DeregisterCommandTest extends TestCase
         $this->dir            = vfsStream::setup('project');
         $this->package        = $this->createMock(ComposerPackageInterface::class);
         $this->processFactory = $this->createMock(ComposerProcessFactoryInterface::class);
+        $this->injector       = $this->createMock(InjectorInterface::class);
 
         $packageFactory = $this->createMock(ComposerPackageFactoryInterface::class);
         $packageFactory->method('loadPackage')->with($this->dir->url())->willReturn($this->package);
 
-        $this->input                             = $this->prophesize(InputInterface::class);
-        $this->output                            = $this->prophesize(ConsoleOutputInterface::class);
+        $this->input                             = $this->createMock(InputInterface::class);
+        $this->output                            = $this->createMock(ConsoleOutputInterface::class);
         $this->command                           = new DeregisterCommand(
             $this->dir->url(),
             $packageFactory,
-            $this->processFactory
+            $this->processFactory,
+            $this->injector
         );
         $this->expectedModuleArgumentDescription = DeregisterCommand::HELP_ARG_MODULE;
     }
@@ -113,23 +109,24 @@ class DeregisterCommandTest extends TestCase
         $composer       = 'composer.phar';
         $configProvider = $module . '\ConfigProvider';
 
-        $this->input->getArgument('module')->willReturn('MyApp');
-        $this->input->getOption('composer')->willReturn('composer.phar');
+        $this->input->method('getArgument')->with('module')->willReturn('MyApp');
+        $this->input->method('getOption')->with('composer')->willReturn('composer.phar');
 
-        $injectorMock = Mockery::mock('overload:' . ConfigAggregatorInjector::class);
-        $injectorMock
-            ->shouldReceive('isRegistered')
+        $this->injector
+            ->expects(self::once())
+            ->method('isRegistered')
             ->with($configProvider)
-            ->andReturn($removed)
-            ->once();
+            ->willReturn($removed);
+
         if ($removed) {
-            $injectorMock
-                ->shouldReceive('remove')
-                ->with($configProvider)
-                ->once();
+            $this->injector
+                ->expects(self::once())
+                ->method('remove')
+                ->with($configProvider);
         } else {
-            $injectorMock
-                ->shouldNotReceive('remove');
+            $this->injector
+                ->expects(self::never())
+                ->method('remove');
         }
 
         $this->package
@@ -165,10 +162,9 @@ class DeregisterCommandTest extends TestCase
                 ->willReturn($process);
 
             $this->output
-                ->writeln(Argument::containingString(
-                    'Removed config provider and autoloading rules for module ' . $module
-                ))
-                ->shouldBeCalled();
+                ->expects(self::atLeastOnce())
+                ->method('writeln')
+                ->with(self::stringContains('Removed config provider and autoloading rules for module ' . $module));
         }
 
         if ($disabled === false) {
@@ -176,18 +172,17 @@ class DeregisterCommandTest extends TestCase
                 ->expects($this->never())
                 ->method('createProcess');
             $this->output
-                ->writeln(Argument::containingString(
-                    'Removed config provider for module ' . $module
-                ))
-                ->shouldBeCalled();
+                ->expects(self::atLeastOnce())
+                ->method('writeln')
+                ->with(self::stringContains('Removed config provider for module ' . $module));
         }
 
         $method = $this->reflectExecuteMethod();
 
         self::assertSame(0, $method->invoke(
             $this->command,
-            $this->input->reveal(),
-            $this->output->reveal()
+            $this->input,
+            $this->output
         ));
     }
 
@@ -197,16 +192,17 @@ class DeregisterCommandTest extends TestCase
      */
     public function testAllowsExceptionsThrownFromDisableToBubbleUp(): void
     {
-        $this->input->getArgument('module')->willReturn('MyApp');
-        $this->input->getOption('composer')->willReturn('composer.phar');
-        $this->input->getOption('modules-path')->willReturn('./library/modules');
-
-        $injectorMock = Mockery::mock('overload:' . ConfigAggregatorInjector::class);
-        $injectorMock
-            ->shouldReceive('isRegistered')
+        $this->input->method('getArgument')->with('module')->willReturn('MyApp');
+        $this->input->method('getOption')->willReturnMap([
+            ['composer', 'composer.phar'],
+            ['modules-path', './library/modules'],
+        ]);
+
+        $this->injector
+            ->expects(self::once())
+            ->method('isRegistered')
             ->with('MyApp\ConfigProvider')
-            ->andReturn(false)
-            ->once();
+            ->willReturn(false);
 
         $this->package
             ->expects($this->once())
@@ -223,8 +219,8 @@ class DeregisterCommandTest extends TestCase
 
         $method->invoke(
             $this->command,
-            $this->input->reveal(),
-            $this->output->reveal()
+            $this->input,
+            $this->output
         );
     }
 }
diff --git a/test/Module/RegisterCommandTest.php b/test/Module/RegisterCommandTest.php
index 4ffdd00..a5ea1e9 100644
--- a/test/Module/RegisterCommandTest.php
+++ b/test/Module/RegisterCommandTest.php
@@ -9,19 +9,13 @@ use Mezzio\Tooling\Composer\ComposerPackageInterface;
 use Mezzio\Tooling\Composer\ComposerProcessFactoryInterface;
 use Mezzio\Tooling\Composer\ComposerProcessInterface;
 use Mezzio\Tooling\Composer\ComposerProcessResultInterface;
-use Mezzio\Tooling\ConfigInjector\ConfigAggregatorInjector;
 use Mezzio\Tooling\ConfigInjector\InjectorInterface;
 use Mezzio\Tooling\Module\RegisterCommand;
 use Mezzio\Tooling\Module\RuntimeException;
-use Mockery;
-use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
 use org\bovigo\vfs\vfsStream;
 use org\bovigo\vfs\vfsStreamDirectory;
 use PHPUnit\Framework\MockObject\MockObject;
 use PHPUnit\Framework\TestCase;
-use Prophecy\Argument;
-use Prophecy\PhpUnit\ProphecyTrait;
-use Prophecy\Prophecy\ObjectProphecy;
 use ReflectionMethod;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\ConsoleOutputInterface;
@@ -30,31 +24,31 @@ use function mkdir;
 use function preg_replace;
 use function sprintf;
 
+/** @covers \Mezzio\Tooling\Module\RegisterCommand */
 class RegisterCommandTest extends TestCase
 {
     use CommonOptionsAndAttributesTrait;
-    use MockeryPHPUnitIntegration;
-    use ProphecyTrait;
 
     private vfsStreamDirectory $dir;
 
-    /** @var ObjectProphecy<InputInterface> */
-    private $input;
+    /** @var InputInterface&MockObject */
+    private InputInterface $input;
 
-    /** @var ObjectProphecy<ConsoleOutputInterface> */
-    private $output;
+    /** @var ConsoleOutputInterface&MockObject */
+    private ConsoleOutputInterface $output;
 
-    /** @var RegisterCommand */
-    private $command;
+    private RegisterCommand $command;
 
-    /** @var string */
-    private $expectedModuleArgumentDescription;
+    private string $expectedModuleArgumentDescription;
 
     /** @var ComposerPackageInterface&MockObject */
-    private $package;
+    private ComposerPackageInterface $package;
 
     /** @var ComposerProcessFactoryInterface&MockObject */
-    private $processFactory;
+    private ComposerProcessFactoryInterface $processFactory;
+
+    /** @var InjectorInterface&MockObject */
+    private InjectorInterface $injector;
 
     protected function setUp(): void
     {
@@ -63,16 +57,18 @@ class RegisterCommandTest extends TestCase
         $this->dir            = vfsStream::setup('project');
         $this->package        = $this->createMock(ComposerPackageInterface::class);
         $this->processFactory = $this->createMock(ComposerProcessFactoryInterface::class);
+        $this->injector       = $this->createMock(InjectorInterface::class);
 
         $packageFactory = $this->createMock(ComposerPackageFactoryInterface::class);
         $packageFactory->method('loadPackage')->with($this->dir->url())->willReturn($this->package);
 
-        $this->input                             = $this->prophesize(InputInterface::class);
-        $this->output                            = $this->prophesize(ConsoleOutputInterface::class);
+        $this->input                             = $this->createMock(InputInterface::class);
+        $this->output                            = $this->createMock(ConsoleOutputInterface::class);
         $this->command                           = new RegisterCommand(
             $this->dir->url(),
             $packageFactory,
-            $this->processFactory
+            $this->processFactory,
+            $this->injector
         );
         $this->expectedModuleArgumentDescription = RegisterCommand::HELP_ARG_MODULE;
     }
@@ -119,11 +115,7 @@ class RegisterCommandTest extends TestCase
         // phpcs:enable
     }
 
-    /**
-     * @runInSeparateProcess
-     * @preserveGlobalState disabled
-     * @dataProvider injectedEnabled
-     */
+    /** @dataProvider injectedEnabled */
     public function testCommandEmitsExpectedMessagesWhenItInjectsConfigurationAndEnablesModule(
         bool $injected,
         bool $enabled,
@@ -156,25 +148,29 @@ class RegisterCommandTest extends TestCase
             );
         mkdir($pathToCreate, 0777, true);
 
-        $this->input->getArgument('module')->willReturn($module);
-        $this->input->getOption('composer')->willReturn($composer);
-        $this->input->getOption('modules-path')->willReturn($modulesPath);
-        $this->input->getOption('exact-path')->willReturn($exactPath);
+        $this->input->method('getArgument')->with('module')->willReturn($module);
+        $this->input->method('getOption')->willReturnMap([
+            ['composer', $composer],
+            ['modules-path', $modulesPath],
+            ['exact-path', $exactPath],
+        ]);
 
-        $injectorMock = Mockery::mock('overload:' . ConfigAggregatorInjector::class);
-        $injectorMock
-            ->shouldReceive('isRegistered')
+        $this->injector
+            ->expects(self::once())
+            ->method('isRegistered')
             ->with($configProvider)
-            ->andReturn(! $injected)
-            ->once();
+            ->willReturn(! $injected);
+
         if ($injected) {
-            $injectorMock
-                ->shouldReceive('inject')
-                ->with($configProvider, InjectorInterface::TYPE_CONFIG_PROVIDER)
-                ->once();
+            $this->injector
+                ->expects(self::once())
+                ->method('inject')
+                ->with($configProvider, InjectorInterface::TYPE_CONFIG_PROVIDER);
         } else {
-            $injectorMock
-                ->shouldNotReceive('inject');
+            $this->injector
+                ->expects(self::never())
+                ->method('inject')
+                ->with($configProvider, InjectorInterface::TYPE_CONFIG_PROVIDER);
         }
 
         $this->package
@@ -214,10 +210,9 @@ class RegisterCommandTest extends TestCase
                 ->willReturn($process);
 
             $this->output
-                ->writeln(Argument::containingString(
-                    'Registered config provider and autoloading rules for module ' . $module
-                ))
-                ->shouldBeCalled();
+                ->expects(self::atLeastOnce())
+                ->method('writeln')
+                ->with(self::stringContains('Registered config provider and autoloading rules for module ' . $module));
         }
 
         if ($enabled === false) {
@@ -226,38 +221,34 @@ class RegisterCommandTest extends TestCase
                 ->method('createProcess');
 
             $this->output
-                ->writeln(Argument::containingString(
-                    'Registered config provider for module ' . $module
-                ))
-                ->shouldBeCalled();
+                ->expects(self::atLeastOnce())
+                ->method('writeln')
+                ->with(self::stringContains('Registered config provider for module ' . $module));
         }
 
         $method = $this->reflectExecuteMethod();
 
         self::assertSame(0, $method->invoke(
             $this->command,
-            $this->input->reveal(),
-            $this->output->reveal()
+            $this->input,
+            $this->output
         ));
     }
 
-    /**
-     * @runInSeparateProcess
-     * @preserveGlobalState disabled
-     */
     public function testAllowsRuntimeExceptionsThrownFromEnableToBubbleUp(): void
     {
-        $this->input->getArgument('module')->willReturn('MyApp');
-        $this->input->getOption('composer')->willReturn('composer.phar');
-        $this->input->getOption('modules-path')->willReturn('./library/modules');
-        $this->input->getOption('exact-path')->willReturn(null);
-
-        $injectorMock = Mockery::mock('overload:' . ConfigAggregatorInjector::class);
-        $injectorMock
-            ->shouldReceive('isRegistered')
+        $this->input->method('getArgument')->with('module')->willReturn('MyApp');
+        $this->input->method('getOption')->willReturnMap([
+            ['composer', 'composer.phar'],
+            ['modules-path', './library/modules'],
+            ['exact-path', null],
+        ]);
+
+        $this->injector
+            ->expects(self::once())
+            ->method('isRegistered')
             ->with('MyApp\ConfigProvider')
-            ->andReturn(true)
-            ->once();
+            ->willReturn(true);
 
         $this->processFactory->expects($this->never())->method('createProcess');
 
@@ -268,8 +259,8 @@ class RegisterCommandTest extends TestCase
 
         $method->invoke(
             $this->command,
-            $this->input->reveal(),
-            $this->output->reveal()
+            $this->input,
+            $this->output
         );
     }
 }

Ocramius avatar Nov 25 '22 13:11 Ocramius

@weierophinney as a warning for future development (I know this code was written in around 2017, if not earlier): if something needs mockery to workaround final limitations, there's probably a design issue :D

Let's please never use Mockery again.

Ocramius avatar Nov 25 '22 13:11 Ocramius

Extracted work done so far to #37

Ocramius avatar Nov 25 '22 13:11 Ocramius

I remember relief at getting Mockery to work here, which should have been the clue needed to guide me to a refactor... Live and learn...

weierophinney avatar Nov 25 '22 14:11 weierophinney