test(aot): add Symfony framework compatibility tests

- Add SplObjectStorage promise pool test with clone options
- Add __serialize/__unserialize parent state destructuring test
- Add null coalesce assignment in comparison condition test
- Add match(true) condition with assignment and negation test
pull/15/head
韩天峰 2 months ago
parent 748eb37e99
commit 19d74e459d
  1. 72
      tests/aot/symfony/httpclient-splobjectstorage-promise-pool.phpt
  2. 78
      tests/aot/symfony/mime-serialize-parent-state-destructuring.phpt
  3. 29
      tests/aot/symfony/string-coalesce-assign-comparison-precedence.phpt
  4. 24
      tests/aot/symfony/yaml-match-condition-assignment.phpt

@ -0,0 +1,72 @@
--TEST--
Symfony HttpClient style SplObjectStorage promise pool with clone options
--ENV--
USE_ZEND_ALLOC=0
--FILE--
<?php
class SymfonyHttpClientPoolCase
{
private ?SplObjectStorage $promisePool;
private bool $autoUpgradeHttpVersion = true;
private array $options = [];
public function __construct()
{
$this->promisePool = class_exists(SplObjectStorage::class) ? new SplObjectStorage() : null;
}
public function withOptions(array $options): static
{
$clone = clone $this;
if (array_key_exists('auto_upgrade_http_version', $options)) {
$clone->autoUpgradeHttpVersion = $options['auto_upgrade_http_version'];
unset($options['auto_upgrade_http_version']);
}
$clone->options = $options;
return $clone;
}
public function remember(object $response, object $request, object $promise): void
{
$this->promisePool?->attach($response, [$request, $promise]);
}
public function resolve(object $response): string
{
if (!$this->promisePool?->contains($response)) {
return 'missing';
}
[$request, $promise] = $this->promisePool[$response];
return $request->name . ':' . $promise->name;
}
public function describe(): string
{
return ($this->autoUpgradeHttpVersion ? 'auto' : 'manual') . ':' . implode(',', array_keys($this->options));
}
}
function main(): void
{
$client = new SymfonyHttpClientPoolCase();
$response = (object) ['name' => 'response'];
$request = (object) ['name' => 'request'];
$promise = (object) ['name' => 'promise'];
$client->remember($response, $request, $promise);
var_dump($client->resolve($response));
var_dump($client->resolve((object) ['name' => 'other']));
$clone = $client->withOptions(['auto_upgrade_http_version' => false, 'timeout' => 3]);
var_dump($client->describe());
var_dump($clone->describe());
}
?>
--EXPECT--
string(15) "request:promise"
string(7) "missing"
string(5) "auto:"
string(14) "manual:timeout"

@ -0,0 +1,78 @@
--TEST--
Symfony Mime style __serialize/__unserialize with parent state and array destructuring
--XFAIL--
Known AOT bug: parent::__unserialize() does not restore parent private state in this pattern.
--FILE--
<?php
class SymfonyMimeParentMessage
{
private array $headers = [];
public function header(string $name, string $value): void
{
$this->headers[$name] = $value;
}
public function getHeader(string $name): ?string
{
return $this->headers[$name] ?? null;
}
public function __serialize(): array
{
return [$this->headers];
}
public function __unserialize(array $data): void
{
[$this->headers] = $data;
}
}
class SymfonyMimeEmailCase extends SymfonyMimeParentMessage
{
private ?string $text = null;
private ?string $textCharset = null;
private ?string $html = null;
private ?string $htmlCharset = null;
private array $attachments = [];
public function configure(): void
{
$this->text = 'text body';
$this->textCharset = 'utf-8';
$this->html = '<b>html</b>';
$this->htmlCharset = 'utf-8';
$this->attachments = ['a.txt', 'b.txt'];
$this->header('Subject', 'demo');
}
public function __serialize(): array
{
return [$this->text, $this->textCharset, $this->html, $this->htmlCharset, $this->attachments, parent::__serialize()];
}
public function __unserialize(array $data): void
{
[$this->text, $this->textCharset, $this->html, $this->htmlCharset, $this->attachments, $parentData] = $data;
parent::__unserialize($parentData);
}
public function summary(): string
{
return $this->text . '|' . $this->html . '|' . $this->getHeader('Subject') . '|' . count($this->attachments);
}
}
function main(): void
{
$email = new SymfonyMimeEmailCase();
$email->configure();
$restored = unserialize(serialize($email));
var_dump($restored->summary());
}
?>
--EXPECT--
string(28) "text body|<b>html</b>|demo|2"

@ -0,0 +1,29 @@
--TEST--
Symfony String style coalesce assignment in comparison condition
--FILE--
<?php
function symfony_string_split_limit(?int $limit = null): int
{
if (1 > $limit ??= PHP_INT_MAX) {
throw new InvalidArgumentException('Split limit must be a positive integer.');
}
return $limit;
}
function main(): void
{
var_dump(symfony_string_split_limit());
var_dump(symfony_string_split_limit(2));
try {
symfony_string_split_limit(0);
} catch (InvalidArgumentException $e) {
echo $e->getMessage(), "\n";
}
}
?>
--EXPECT--
int(9223372036854775807)
int(2)
Split limit must be a positive integer.

@ -0,0 +1,24 @@
--TEST--
Symfony Yaml style match(true) condition with assignment and negation
--FILE--
<?php
function symfony_yaml_datetime_format(DateTimeInterface $value): string
{
return $value->format(match (true) {
!$length = strlen(rtrim($value->format('u'), '0')) => 'c',
$length < 4 => 'Y-m-d\TH:i:s.vP',
default => 'Y-m-d\TH:i:s.uP',
});
}
function main(): void
{
var_dump(symfony_yaml_datetime_format(new DateTimeImmutable('2024-01-02T03:04:05+00:00')));
var_dump(symfony_yaml_datetime_format(new DateTimeImmutable('2024-01-02T03:04:05.120000+00:00')));
var_dump(symfony_yaml_datetime_format(new DateTimeImmutable('2024-01-02T03:04:05.123456+00:00')));
}
?>
--EXPECT--
string(25) "2024-01-02T03:04:05+00:00"
string(29) "2024-01-02T03:04:05.120+00:00"
string(32) "2024-01-02T03:04:05.123456+00:00"
Loading…
Cancel
Save