cache = new FakeCache(); $this->mapper = (new MapperBuilder())->withCache($this->cache); } public function test_will_warmup_type_parser_cache_for_object_with_properties(): void { $this->mapper->warmup(ObjectToWarmupWithProperties::class); $this->mapper->warmup(ObjectToWarmupWithProperties::class, SomeObjectJ::class); self::assertSame(10, $this->cache->countEntries()); self::assertSame(10, $this->cache->timeSetWasCalled()); } public function test_will_warmup_type_parser_cache_for_object_with_constructor(): void { // @PHP8.1 first-class callable syntax $mapper = $this->mapper->registerConstructor( [ObjectToWarmupWithConstructors::class, 'constructorA'], [ObjectToWarmupWithConstructors::class, 'constructorB'], ); $mapper->warmup(ObjectToWarmupWithConstructors::class); $mapper->warmup(ObjectToWarmupWithConstructors::class, SomeObjectC::class); self::assertSame(7, $this->cache->countEntries()); self::assertSame(7, $this->cache->timeSetWasCalled()); } public function test_will_warmup_type_parser_cache_for_interface(): void { $mapper = $this->mapper ->infer( SomeInterface::class, /** @return class-string */ fn (string $foo, SomeObjectI $objectI) => $foo === 'foo' ? ObjectToWarmupWithProperties::class : ObjectToWarmupWithConstructors::class ); $mapper->warmup(SomeInterface::class); $mapper->warmup(SomeInterface::class, SomeObjectJ::class); self::assertSame(13, $this->cache->countEntries()); self::assertSame(13, $this->cache->timeSetWasCalled()); } public function test_warmup_invalid_signature_throws_exception(): void { $this->expectException(InvalidSignatureToWarmup::class); $this->expectExceptionCode(1653330261); $this->expectExceptionMessage('Cannot warm up invalid signature `SomeInvalidClass`: Cannot parse unknown symbol `SomeInvalidClass`.'); $this->mapper->warmup('SomeInvalidClass'); } } interface SomeInterface { } final class ObjectToWarmupWithProperties implements SomeInterface { public string $string; public SomeObjectA $objectA; /** @var array */ public array $arrayOfStrings; /** @var array */ public array $arrayOfObjects; /** @var list */ public array $listOfObjects; /** @var iterable */ public iterable $iterableOfObjects; /** @var array{foo: string, object: SomeObjectE} */ public array $shapedArrayContainingObject; /** @var string|SomeObjectF */ public $unionContainingObject; // @PHP8.0 Native union /** @var SomeObjectG&DateTimeInterface */ public object $intersectionOfObjects; public static function someUnnecessaryMethod(string $string, SomeObjectH $object): SomeObjectI { return new SomeObjectI(); } } final class ObjectToWarmupWithConstructors implements SomeInterface { public static function constructorA(string $string, SomeObjectA $objectA): self { return new self(); } public static function constructorB(string $string, SomeObjectB $objectb): self { return new self(); } } class SomeObjectA { } class SomeObjectB { } class SomeObjectC { } class SomeObjectD { } class SomeObjectE { } class SomeObjectF { } class SomeObjectG { } class SomeObjectH { } class SomeObjectI { } class SomeObjectJ { }