Skip to content

Commit

Permalink
Fix "Regression" in [email protected]
Browse files Browse the repository at this point in the history
Input Filter 2.40 changes the FilterChain callable from a legacy callable array to first class callable syntax:

https://github.com/laminas/laminas-filter/pull/190/files#r1912528133

The test case here is wrong to test the implementation detail of the callable, instead it should test behaviour of the expected chain item.

Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Jan 12, 2025
1 parent 6798630 commit 681ba24
Show file tree
Hide file tree
Showing 2 changed files with 28 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.

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 681ba24

Please sign in to comment.