diff --git a/tests/aot/symfony/array-reduce-directive-string.phpt b/tests/aot/symfony/array-reduce-directive-string.phpt new file mode 100644 index 00000000..02e19d25 --- /dev/null +++ b/tests/aot/symfony/array-reduce-directive-string.phpt @@ -0,0 +1,29 @@ +--TEST-- +Symfony pattern: array_reduce builds directive string from keyed arrays +--FILE-- + ('' !== $result ? $result.'; ' : '').sprintf('%s %s', $name, implode(' ', $directives[$name])), + '' + ); + } +} + +function main(): void +{ + $handler = new SymfonyLikeContentSecurityPolicyHandler(); + + var_dump($handler->compileDirectives([ + 'default-src' => ["'self'"], + 'script-src' => ["'self'", 'cdn.example.test'], + ])); +} +?> +--EXPECT-- +string(54) "default-src 'self'; script-src 'self' cdn.example.test" diff --git a/tests/aot/symfony/array-uintersect-spaceship.phpt b/tests/aot/symfony/array-uintersect-spaceship.phpt new file mode 100644 index 00000000..edd7a65e --- /dev/null +++ b/tests/aot/symfony/array-uintersect-spaceship.phpt @@ -0,0 +1,39 @@ +--TEST-- +Symfony pattern: array_uintersect with spaceship comparator for nested arrays +--FILE-- + $a <=> $b); + } +} + +function main(): void +{ + $pass = new SymfonyLikeListenerPass(); + + var_dump(array_values($pass->intersectListeners( + [ + ['event' => 'request', 'method' => 'onRequest'], + ['event' => 'response', 'method' => 'onResponse'], + ], + [ + ['event' => 'response', 'method' => 'onResponse'], + ['event' => 'terminate', 'method' => 'onTerminate'], + ] + ))); +} +?> +--EXPECT-- +array(1) { + [0]=> + array(2) { + ["event"]=> + string(8) "response" + ["method"]=> + string(10) "onResponse" + } +} diff --git a/tests/aot/symfony/current-find-with-static-filter.phpt b/tests/aot/symfony/current-find-with-static-filter.phpt new file mode 100644 index 00000000..1561fa95 --- /dev/null +++ b/tests/aot/symfony/current-find-with-static-filter.phpt @@ -0,0 +1,50 @@ +--TEST-- +Symfony pattern: current() over filtered find result with static arrow callback +--FILE-- +profiles, $filter)), 0, $limit); + } +} + +class SymfonyLikeProfilerController +{ + public function __construct(private SymfonyLikeProfiler $profiler) + { + } + + public function latest(string $profileType): ?array + { + if ($latest = current($this->profiler->find(null, null, 1, null, null, null, null, static fn ($profile) => $profileType === $profile['virtual_type']))) { + return $latest; + } + + return null; + } +} + +function main(): void +{ + $controller = new SymfonyLikeProfilerController(new SymfonyLikeProfiler([ + ['token' => 'a', 'virtual_type' => 'command'], + ['token' => 'b', 'virtual_type' => 'request'], + ])); + + var_dump($controller->latest('request')); +} +?> +--EXPECT-- +array(2) { + ["token"]=> + string(1) "b" + ["virtual_type"]=> + string(7) "request" +} diff --git a/tests/aot/symfony/object-class-in-arrow-map.phpt b/tests/aot/symfony/object-class-in-arrow-map.phpt new file mode 100644 index 00000000..1d28a3e1 --- /dev/null +++ b/tests/aot/symfony/object-class-in-arrow-map.phpt @@ -0,0 +1,59 @@ +--TEST-- +Symfony pattern: object runtime class in arrow function array_map +--FILE-- +authenticator; + } +} + +class SymfonyLikePasswordAuthenticator +{ +} + +class SymfonyLikeTokenAuthenticator +{ +} + +class SymfonyLikeDebugFirewallCommand +{ + public function listAuthenticatorClasses(array $authenticators): array + { + return array_map( + static fn ($authenticator) => [($authenticator instanceof SymfonyLikeTraceableAuthenticator ? $authenticator->getAuthenticator() : $authenticator)::class], + $authenticators + ); + } +} + +function main(): void +{ + $command = new SymfonyLikeDebugFirewallCommand(); + + var_dump($command->listAuthenticatorClasses([ + new SymfonyLikeTraceableAuthenticator(new SymfonyLikePasswordAuthenticator()), + new SymfonyLikeTokenAuthenticator(), + ])); +} +?> +--EXPECT-- +array(2) { + [0]=> + array(1) { + [0]=> + string(32) "SymfonyLikePasswordAuthenticator" + } + [1]=> + array(1) { + [0]=> + string(29) "SymfonyLikeTokenAuthenticator" + } +}