diff --git a/tests/aot/symfony/httpclient-splobjectstorage-promise-pool.phpt b/tests/aot/symfony/httpclient-splobjectstorage-promise-pool.phpt new file mode 100644 index 00000000..8f92c69a --- /dev/null +++ b/tests/aot/symfony/httpclient-splobjectstorage-promise-pool.phpt @@ -0,0 +1,72 @@ +--TEST-- +Symfony HttpClient style SplObjectStorage promise pool with clone options +--ENV-- +USE_ZEND_ALLOC=0 +--FILE-- +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" diff --git a/tests/aot/symfony/mime-serialize-parent-state-destructuring.phpt b/tests/aot/symfony/mime-serialize-parent-state-destructuring.phpt new file mode 100644 index 00000000..760cde99 --- /dev/null +++ b/tests/aot/symfony/mime-serialize-parent-state-destructuring.phpt @@ -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-- +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 = 'html'; + $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|html|demo|2" diff --git a/tests/aot/symfony/string-coalesce-assign-comparison-precedence.phpt b/tests/aot/symfony/string-coalesce-assign-comparison-precedence.phpt new file mode 100644 index 00000000..a9edcd7d --- /dev/null +++ b/tests/aot/symfony/string-coalesce-assign-comparison-precedence.phpt @@ -0,0 +1,29 @@ +--TEST-- +Symfony String style coalesce assignment in comparison condition +--FILE-- + $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. diff --git a/tests/aot/symfony/yaml-match-condition-assignment.phpt b/tests/aot/symfony/yaml-match-condition-assignment.phpt new file mode 100644 index 00000000..227dda47 --- /dev/null +++ b/tests/aot/symfony/yaml-match-condition-assignment.phpt @@ -0,0 +1,24 @@ +--TEST-- +Symfony Yaml style match(true) condition with assignment and negation +--FILE-- +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"