diff --git a/tests/aot/symfony/callable-variable-first-class.phpt b/tests/aot/symfony/callable-variable-first-class.phpt new file mode 100644 index 00000000..a6c65594 --- /dev/null +++ b/tests/aot/symfony/callable-variable-first-class.phpt @@ -0,0 +1,37 @@ +--TEST-- +Symfony pattern: callable variable converted to first-class callable +--FILE-- +formatter = null !== $formatter ? $formatter(...) : $this->format(...); + } + + public function log(string $level, string $message): string + { + return ($this->formatter)($level, $message); + } + + private function format(string $level, string $message): string + { + return strtoupper($level).': '.$message; + } +} + +function main(): void +{ + $default = new SymfonyLikeLogger(); + $custom = new SymfonyLikeLogger(static fn (string $level, string $message): string => $level.'|'.strrev($message)); + + var_dump($default->log('info', 'boot')); + var_dump($custom->log('debug', 'boot')); +} +?> +--EXPECT-- +string(10) "INFO: boot" +string(10) "debug|toob" diff --git a/tests/aot/symfony/dynamic-instanceof-filter.phpt b/tests/aot/symfony/dynamic-instanceof-filter.phpt new file mode 100644 index 00000000..272e4a7b --- /dev/null +++ b/tests/aot/symfony/dynamic-instanceof-filter.phpt @@ -0,0 +1,48 @@ +--TEST-- +Symfony pattern: array_filter with dynamic instanceof class name +--XFAIL-- +Known AOT bug: objects filtered by dynamic instanceof can lose their precise class type before closure property reads. +--FILE-- +attributes, static fn ($attr) => $attr instanceof $className)); + } +} + +function main(): void +{ + $event = new SymfonyLikeControllerEvent([ + new SymfonyLikeOtherAttribute(), + new SymfonyLikeControllerAttribute('template'), + new SymfonyLikeControllerAttribute('cache'), + ]); + + var_dump(array_map(static fn ($attribute) => $attribute->name, $event->getAttributes(SymfonyLikeControllerAttribute::class))); +} +?> +--EXPECT-- +array(2) { + [0]=> + string(8) "template" + [1]=> + string(5) "cache" +} diff --git a/tests/aot/symfony/error-handler-ternary-throw.phpt b/tests/aot/symfony/error-handler-ternary-throw.phpt new file mode 100644 index 00000000..09230fe7 --- /dev/null +++ b/tests/aot/symfony/error-handler-ternary-throw.phpt @@ -0,0 +1,47 @@ +--TEST-- +Symfony pattern: error handler arrow function throws conditional exception +--ENV-- +USE_ZEND_ALLOC=0 +--FILE-- +signalingException = new RuntimeException('SIGNAL'); + } + + public function run(string $message): void + { + set_error_handler(fn ($type, $errorMessage) => throw str_contains($errorMessage, $this->signalingException->getMessage()) ? $this->signalingException : new ErrorException($errorMessage)); + + try { + trigger_error($message, E_USER_WARNING); + } finally { + restore_error_handler(); + } + } +} + +function main(): void +{ + $dumper = new SymfonyLikeCompiledUrlMatcherDumper(); + + foreach (['SIGNAL: stop', 'plain failure'] as $message) { + try { + $dumper->run($message); + } catch (Throwable $e) { + var_dump($e::class); + var_dump($e->getMessage()); + } + } +} +?> +--EXPECT-- +string(16) "RuntimeException" +string(6) "SIGNAL" +string(14) "ErrorException" +string(13) "plain failure" diff --git a/tests/aot/symfony/uksort-priority-fallback.phpt b/tests/aot/symfony/uksort-priority-fallback.phpt new file mode 100644 index 00000000..284cbe19 --- /dev/null +++ b/tests/aot/symfony/uksort-priority-fallback.phpt @@ -0,0 +1,51 @@ +--TEST-- +Symfony pattern: uksort with priority fallback comparator +--XFAIL-- +Known AOT bug: uksort with captured arrays in a static arrow comparator can crash during shutdown. +--FILE-- +routes[$name] = $path; + $this->priorities[$name] = $priority; + } + + public function all(): array + { + $priorities = $this->priorities; + $keysOrder = array_flip(array_keys($this->routes)); + + uksort($this->routes, static fn ($n1, $n2) => (($priorities[$n2] ?? 0) <=> ($priorities[$n1] ?? 0)) ?: ($keysOrder[$n1] <=> $keysOrder[$n2])); + + return $this->routes; + } +} + +function main(): void +{ + $collection = new SymfonyLikeRouteCollection(); + $collection->add('fallback', '/fallback'); + $collection->add('admin', '/admin', 20); + $collection->add('api', '/api', 20); + $collection->add('home', '/', 10); + + var_dump(array_keys($collection->all())); +} +?> +--EXPECT-- +array(4) { + [0]=> + string(5) "admin" + [1]=> + string(3) "api" + [2]=> + string(4) "home" + [3]=> + string(8) "fallback" +}