test(aot): add Symfony framework compatibility tests

- Add test for AssetMapper style match statement with nullsafe side effect and throw arm
- Add test for Finder style lazy iterator using yield from callable property invocation
- Add test for HttpFoundation style static reflection cache with coalesce assignment operator
- Include proper skip conditions for unsupported features
- Verify correct behavior of Symfony-style PHP constructs in AOT compilation
pull/15/head
韩天峰 2 months ago
parent ec4a12f122
commit 748eb37e99
  1. 62
      tests/aot/symfony/assetmapper-match-statement-side-effects.phpt
  2. 36
      tests/aot/symfony/finder-lazy-iterator-yield-from-callable.phpt
  3. 36
      tests/aot/symfony/httpfoundation-reflection-cache-coalesce-assign.phpt

@ -0,0 +1,62 @@
--TEST--
Symfony AssetMapper style match statement with nullsafe side effect and throw arm
--FILE--
<?php
interface SymfonyMissingImportLogger
{
public function warning(string $message): void;
}
class SymfonyMissingImportMemoryLogger implements SymfonyMissingImportLogger
{
public array $messages = [];
public function warning(string $message): void
{
$this->messages[] = $message;
}
}
class SymfonyMissingImportHandler
{
public const IGNORE = 'ignore';
public const WARN = 'warn';
public const STRICT = 'strict';
public function __construct(
private string $mode,
private ?SymfonyMissingImportLogger $logger = null,
) {
}
public function handle(string $message): void
{
match ($this->mode) {
self::IGNORE => null,
self::WARN => $this->logger?->warning($message),
self::STRICT => throw new RuntimeException($message),
};
}
}
function main(): void
{
$logger = new SymfonyMissingImportMemoryLogger();
(new SymfonyMissingImportHandler(SymfonyMissingImportHandler::IGNORE))->handle('ignored');
(new SymfonyMissingImportHandler(SymfonyMissingImportHandler::WARN, $logger))->handle('missing.js');
var_dump($logger->messages);
try {
(new SymfonyMissingImportHandler(SymfonyMissingImportHandler::STRICT))->handle('strict.js');
} catch (RuntimeException $e) {
echo $e->getMessage(), "\n";
}
}
?>
--EXPECT--
array(1) {
[0]=>
string(10) "missing.js"
}
strict.js

@ -0,0 +1,36 @@
--TEST--
Symfony Finder style lazy iterator: yield from callable property invocation
--SKIPIF--
<?php exit('skip Expr_YieldFrom is not supported yet'); ?>
--FILE--
<?php
class SymfonyLazyIteratorCase implements IteratorAggregate
{
private Closure $iteratorFactory;
public function __construct(callable $iteratorFactory)
{
$this->iteratorFactory = $iteratorFactory(...);
}
public function getIterator(): Traversable
{
yield from ($this->iteratorFactory)();
}
}
function main(): void
{
$iterator = new SymfonyLazyIteratorCase(static function (): Traversable {
yield 'first' => 'alpha';
yield 'second' => 'beta';
});
foreach ($iterator as $key => $value) {
echo $key, '=', $value, "\n";
}
}
?>
--EXPECT--
first=alpha
second=beta

@ -0,0 +1,36 @@
--TEST--
Symfony HttpFoundation style static reflection cache with coalesce assignment
--FILE--
<?php
class SymfonyReflectionCacheResponse
{
private string $statusText = 'initial';
public function getStatusText(): string
{
return $this->statusText;
}
public static function setProperty(self $response, string $name, mixed $value): void
{
static $cache;
$property = $cache[$name] ??= new ReflectionProperty(self::class, $name);
$property->setValue($response, $value);
}
}
function main(): void
{
$response = new SymfonyReflectionCacheResponse();
SymfonyReflectionCacheResponse::setProperty($response, 'statusText', 'created');
var_dump($response->getStatusText());
SymfonyReflectionCacheResponse::setProperty($response, 'statusText', 'accepted');
var_dump($response->getStatusText());
}
?>
--EXPECT--
string(7) "created"
string(8) "accepted"
Loading…
Cancel
Save