Skip to content

Commit

Permalink
Merge pull request #118 from gsteel/v2/fix-tests
Browse files Browse the repository at this point in the history
Fix "Regression" in `[email protected]`
  • Loading branch information
gsteel authored Jan 13, 2025
2 parents 6798630 + 05286ca commit bd30348
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 36 deletions.
10 changes: 5 additions & 5 deletions composer.lock

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

33 changes: 33 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@
</PossiblyUnusedReturnValue>
</file>
<file src="src/Factory.php">
<DeprecatedConstant>
<code><![CDATA[FilterChain::DEFAULT_PRIORITY]]></code>
</DeprecatedConstant>
<DeprecatedMethod>
<code><![CDATA[getPluginManager]]></code>
<code><![CDATA[setPluginManager]]></code>
</DeprecatedMethod>
<MixedArgument>
<code><![CDATA[$inputFilterSpecification['count']]]></code>
<code><![CDATA[$inputFilterSpecification['input_filter']]]></code>
Expand Down Expand Up @@ -239,6 +246,9 @@
<DeprecatedInterface>
<code><![CDATA[InputFilterAbstractServiceFactory]]></code>
</DeprecatedInterface>
<DeprecatedMethod>
<code><![CDATA[setPluginManager]]></code>
</DeprecatedMethod>
<MixedArgument>
<code><![CDATA[$config]]></code>
</MixedArgument>
Expand Down Expand Up @@ -279,6 +289,9 @@
<DeprecatedInterface>
<code><![CDATA[null|ConfigInterface|ContainerInterface]]></code>
</DeprecatedInterface>
<DeprecatedMethod>
<code><![CDATA[setPluginManager]]></code>
</DeprecatedMethod>
<MethodSignatureMismatch>
<code><![CDATA[InputFilterPluginManager]]></code>
<code><![CDATA[InputFilterPluginManager]]></code>
Expand Down Expand Up @@ -553,8 +566,18 @@
</PossiblyUnusedMethod>
</file>
<file src="test/FactoryTest.php">
<DeprecatedConstant>
<code><![CDATA[Filter\FilterChain::DEFAULT_PRIORITY]]></code>
<code><![CDATA[Filter\FilterChain::DEFAULT_PRIORITY]]></code>
</DeprecatedConstant>
<DeprecatedMethod>
<code><![CDATA[getFilters]]></code>
<code><![CDATA[getMessageTemplates]]></code>
<code><![CDATA[getPluginManager]]></code>
<code><![CDATA[getPluginManager]]></code>
<code><![CDATA[getPluginManager]]></code>
<code><![CDATA[setPluginManager]]></code>
<code><![CDATA[setPluginManager]]></code>
</DeprecatedMethod>
<PossiblyNullReference>
<code><![CDATA[getPluginManager]]></code>
Expand Down Expand Up @@ -630,6 +653,13 @@
<code><![CDATA[$generator instanceof Generator]]></code>
</TypeDoesNotContainType>
</file>
<file src="test/InputFilterAbstractServiceFactoryTest.php">
<DeprecatedMethod>
<code><![CDATA[getFilters]]></code>
<code><![CDATA[getPluginManager]]></code>
<code><![CDATA[plugin]]></code>
</DeprecatedMethod>
</file>
<file src="test/InputFilterPluginManagerCompatibilityTest.php">
<InvalidReturnType>
<code><![CDATA[getInstanceOf]]></code>
Expand All @@ -641,6 +671,9 @@
</PossiblyUnusedMethod>
</file>
<file src="test/InputFilterPluginManagerTest.php">
<DeprecatedMethod>
<code><![CDATA[getPluginManager]]></code>
</DeprecatedMethod>
<LessSpecificReturnStatement>
<code><![CDATA[[
// Description => [$serviceName, $service, $instanceOf]
Expand Down
54 changes: 23 additions & 31 deletions test/InputFilterAbstractServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
use Laminas\Filter;
use Laminas\Filter\FilterChain;
use Laminas\Filter\FilterPluginManager;
use Laminas\InputFilter\FileInput;
use Laminas\InputFilter\InputFilter;
use Laminas\InputFilter\InputFilterAbstractServiceFactory;
use Laminas\InputFilter\InputFilterInterface;
use Laminas\InputFilter\InputFilterPluginManager;
use Laminas\InputFilter\InputInterface;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Validator;
use Laminas\Validator\ValidatorChain;
use Laminas\Validator\ValidatorInterface;
use Laminas\Validator\ValidatorPluginManager;
Expand All @@ -23,7 +21,10 @@
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\TestCase;

use function assert;
use function call_user_func_array;
use function is_string;
use function strrev;

#[CoversClass(InputFilterAbstractServiceFactory::class)]
class InputFilterAbstractServiceFactoryTest extends TestCase
Expand Down Expand Up @@ -220,7 +221,20 @@ public function testAllowsPassingNonPluginManagerContainerToFactoryWithServiceMa
*/
public function testWillUseCustomFiltersWhenProvided(): void
{
$filter = $this->createMock(Filter\FilterInterface::class);
$filter = new class implements Filter\FilterInterface
{
public function filter(mixed $value): string
{
assert(is_string($value));

return strrev($value);
}

public function __invoke(mixed $value): string
{
return $this->filter($value);
}
};

$filters = new FilterPluginManager($this->services);
$filters->setService('CustomFilter', $filter);
Expand All @@ -234,31 +248,9 @@ public function testWillUseCustomFiltersWhenProvided(): void
'input_filter_specs' => [
'test' => [
[
'name' => 'a-file-element',
'type' => FileInput::class,
'name' => 'value',
'required' => true,
'validators' => [
[
'name' => Validator\File\UploadFile::class,
'options' => [
'breakchainonfailure' => true,
],
],
[
'name' => Validator\File\Size::class,
'options' => [
'breakchainonfailure' => true,
'max' => '6GB',
],
],
[
'name' => Validator\File\Extension::class,
'options' => [
'breakchainonfailure' => true,
'extension' => 'csv,zip',
],
],
],
'validators' => [],
'filters' => [
['name' => 'CustomFilter'],
],
Expand All @@ -273,14 +265,14 @@ public function testWillUseCustomFiltersWhenProvided(): void
$inputFilter = $this->services->get(InputFilterPluginManager::class)->get('test');
self::assertInstanceOf(InputFilterInterface::class, $inputFilter);

$input = $inputFilter->get('a-file-element');
self::assertInstanceOf(FileInput::class, $input);
$input = $inputFilter->get('value');
self::assertInstanceOf(InputInterface::class, $input);

$filters = $input->getFilterChain();
self::assertCount(1, $filters);

$callback = $filters->getFilters()->top();
self::assertIsArray($callback);
self::assertSame($filter, $callback[0]);
self::assertIsCallable($callback);
self::assertSame('oof', $callback('foo'));
}
}

0 comments on commit bd30348

Please sign in to comment.