-
-
Notifications
You must be signed in to change notification settings - Fork 12
Update dependency psalm/plugin-mockery to v1 #36
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
base: 2.13.x
Are you sure you want to change the base?
Conversation
|
I tried writing a patch to get rid of mockery and failed. The internal components of 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
);
}
}
|
|
@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 Let's please never use Mockery again. |
|
Extracted work done so far to #37 |
|
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... |
1c49b68 to
300a300
Compare
271d972 to
03b34a1
Compare
d4b0cc9 to
452fb66
Compare
a34a180 to
e2d7c48
Compare
34b4d21 to
e26dea3
Compare
ed63df6 to
171373c
Compare
171373c to
9557c9b
Compare
e3648e7 to
231e346
Compare
231e346 to
bc1a30f
Compare
bc1a30f to
16de25f
Compare
16de25f to
4d8b867
Compare
7dc32be to
7cc8ce9
Compare
98f0835 to
3c8d48d
Compare
90411c2 to
1d9911d
Compare
00bf290 to
98f4c12
Compare
98f4c12 to
631d19e
Compare
8756b9c to
e37a415
Compare
8ec5acd to
d9055bc
Compare
d9055bc to
c380128
Compare
24cf877 to
ba15a1b
Compare
45195b0 to
fb33b96
Compare
fb33b96 to
d9f5a2e
Compare
d9f5a2e to
48241ee
Compare
| datasource | package | from | to | | ---------- | -------------------- | ------ | ----- | | packagist | psalm/plugin-mockery | 0.11.0 | 1.2.1 | Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
48241ee to
45a1511
Compare
This PR contains the following updates:
^0.11.0->^1.0.0Release Notes
psalm/psalm-plugin-mockery (psalm/plugin-mockery)
v1.2.1: Psalm v7 supportCompare Source
This release adds Psalm v7 support.
Full Changelog: psalm/psalm-plugin-mockery@1.2.0...1.2.1
v1.2.0: Psalm v6 supportCompare Source
This release adds support for Psalm v6.
v1.1.0Compare Source
What's Changed
Full Changelog: psalm/psalm-plugin-mockery@1.0.0...1.1.0
v1.0.0Compare Source
What's Changed
Full Changelog: psalm/psalm-plugin-mockery@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.
Read more information about the use of Renovate Bot within Laminas.