|
8 | 8 | use Laminas\Filter\ImmutableFilterChain; |
9 | 9 | use Laminas\Filter\StringPrefix; |
10 | 10 | use Laminas\Filter\StringToLower; |
| 11 | +use Laminas\Filter\StringTrim; |
11 | 12 | use Laminas\ServiceManager\ServiceManager; |
12 | 13 | use PHPUnit\Framework\TestCase; |
13 | 14 |
|
14 | 15 | use function implode; |
15 | 16 | use function str_replace; |
16 | 17 | use function str_split; |
| 18 | +use function strrev; |
17 | 19 |
|
18 | | -/** @psalm-import-type InstanceType from ImmutableFilterChain */ |
| 20 | +/** |
| 21 | + * @psalm-import-type InstanceType from ImmutableFilterChain |
| 22 | + * @psalm-import-type ServiceManagerConfiguration from ServiceManager |
| 23 | + */ |
19 | 24 | final class ImmutableFilterChainTest extends TestCase |
20 | 25 | { |
21 | 26 | private FilterPluginManager $plugins; |
22 | 27 |
|
23 | 28 | protected function setUp(): void |
24 | 29 | { |
25 | | - $this->plugins = new FilterPluginManager(new ServiceManager()); |
| 30 | + $this->plugins = self::pluginManagerWithConfig(); |
| 31 | + } |
| 32 | + |
| 33 | + /** @param ServiceManagerConfiguration $config */ |
| 34 | + private static function pluginManagerWithConfig(array $config = []): FilterPluginManager |
| 35 | + { |
| 36 | + return new FilterPluginManager(new ServiceManager(), $config); |
26 | 37 | } |
27 | 38 |
|
28 | 39 | public function testThatFiltersWillBeRetrievedFromThePluginManager(): void |
@@ -145,4 +156,22 @@ public function testSpecificationWithFilterInstancesInCallbacks(): void |
145 | 156 |
|
146 | 157 | self::assertSame('Foofoo', $chain->filter('Foo')); |
147 | 158 | } |
| 159 | + |
| 160 | + public function testServiceManagerServicesCanBeUsedInChains(): void |
| 161 | + { |
| 162 | + $plugins = self::pluginManagerWithConfig([ |
| 163 | + 'services' => [ |
| 164 | + 'custom' => static fn (string $value): string => strrev($value), |
| 165 | + ], |
| 166 | + ]); |
| 167 | + |
| 168 | + $chain = ImmutableFilterChain::fromArray([ |
| 169 | + 'filters' => [ |
| 170 | + ['name' => StringTrim::class], |
| 171 | + ['name' => 'custom'], |
| 172 | + ], |
| 173 | + ], $plugins); |
| 174 | + |
| 175 | + self::assertSame('oof', $chain->filter(' foo ')); |
| 176 | + } |
148 | 177 | } |
0 commit comments