Skip to content

Commit

Permalink
Merge pull request #56 from gsteel/qa/plugin-manager-types
Browse files Browse the repository at this point in the history
Improve type inference for plugin manager
  • Loading branch information
Ocramius committed Jun 13, 2022
2 parents 61381ca + b02dceb commit a6e8bc7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"require": {
"php": "^7.4 || ~8.0.0 || ~8.1.0",
"laminas/laminas-filter": "^2.13",
"laminas/laminas-servicemanager": "^3.3.1",
"laminas/laminas-servicemanager": "^3.12.0",
"laminas/laminas-stdlib": "^3.0",
"laminas/laminas-validator": "^2.15"
},
Expand Down
32 changes: 16 additions & 16 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/InputFilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
*
* @link ServiceManager
*
* @method InputFilterInterface|InputInterface get(string $name, ?array $options = null)
* @psalm-import-type ServiceManagerConfiguration from ServiceManager
* @template InstanceType of InputFilterInterface|InputInterface
* @extends AbstractPluginManager<InstanceType>
* @method InputFilterInterface|InputInterface get(string $name, ?array $options = null)
*/
class InputFilterPluginManager extends AbstractPluginManager
{
Expand Down Expand Up @@ -141,7 +143,7 @@ public function populateFactoryPluginManagers(Factory $factory)
/**
* {@inheritDoc} (v3)
*
* @psalm-assert InputFilterInterface|InputInterface $instance
* @psalm-assert InstanceType $instance
*/
public function validate($instance)
{
Expand Down
20 changes: 8 additions & 12 deletions test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ public function testCreateInputWithInvalidDataTypeThrowsInvalidArgumentException

public function testCreateInputWithTypeAsAnUnknownPluginAndNotExistsAsClassNameThrowException(): void
{
$type = 'foo';
/** @var InputFilterPluginManager&MockObject $pluginManager */
$pluginManager = $this->getMockBuilder(InputFilterPluginManager::class)
->disableOriginalConstructor()
->getMock();
$type = 'foo';
$pluginManager = $this->createMock(InputFilterPluginManager::class);
$pluginManager->expects($this->atLeastOnce())
->method('has')
->with($type)
->willReturn(false);

/** @psalm-suppress MixedArgumentTypeCoercion */
$factory = new Factory($pluginManager);

$this->expectException(RuntimeException::class);
Expand All @@ -69,20 +67,18 @@ public function testCreateInputWithTypeAsAnUnknownPluginAndNotExistsAsClassNameT

public function testGetInputFilterManagerSettedByItsSetter(): void
{
$pluginManager = $this->getMockBuilder(InputFilterPluginManager::class)
->disableOriginalConstructor()
->getMock();
$pluginManager = $this->createMock(InputFilterPluginManager::class);
$factory = new Factory();
/** @psalm-suppress MixedArgumentTypeCoercion */
$factory->setInputFilterManager($pluginManager);
$this->assertSame($pluginManager, $factory->getInputFilterManager());
}

public function testGetInputFilterManagerWhenYouConstructFactoryWithIt(): void
{
$pluginManager = $this->getMockBuilder(InputFilterPluginManager::class)
->disableOriginalConstructor()
->getMock();
$factory = new Factory($pluginManager);
$pluginManager = $this->createMock(InputFilterPluginManager::class);
/** @psalm-suppress MixedArgumentTypeCoercion */
$factory = new Factory($pluginManager);
$this->assertSame($pluginManager, $factory->getInputFilterManager());
}

Expand Down
2 changes: 2 additions & 0 deletions test/InputFilterPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function testRegisteringInvalidElementRaisesException(): void
$this->expectExceptionMessage(
'must implement Laminas\InputFilter\InputFilterInterface or Laminas\InputFilter\InputInterface'
);
/** @psalm-suppress InvalidArgument */
$this->manager->setService('test', $this);
}

Expand Down Expand Up @@ -165,6 +166,7 @@ public function serviceProvider(): array

/**
* @dataProvider serviceProvider
* @param InputInterface|InputFilterInterface $service
*/
public function testGet(string $serviceName, object $service): void
{
Expand Down

0 comments on commit a6e8bc7

Please sign in to comment.