describeArguments(); $argumentsB = $objectBuilder->describeArguments(); self::assertSame($argumentsA, $argumentsB); } public function test_build_object_with_constructor_returns_correct_object(): void { $object = new class ('foo', 'bar') { public string $valueA; public string $valueB; public string $valueC; public function __construct( string $valueA, string $valueB, string $valueC = 'Some parameter default value' ) { $this->valueA = $valueA; $this->valueB = $valueB; $this->valueC = $valueC; } }; $class = FakeClassDefinition::fromReflection(new ReflectionClass($object)); $objectBuilder = new NativeConstructorObjectBuilder($class); $result = $objectBuilder->build([ 'valueA' => 'valueA', 'valueB' => 'valueB', 'valueC' => 'valueC', ]); self::assertSame('valueA', $result->valueA); // @phpstan-ignore-line self::assertSame('valueB', $result->valueB); // @phpstan-ignore-line self::assertSame('valueC', $result->valueC); // @phpstan-ignore-line } public function test_exception_thrown_by_constructor_is_caught_and_wrapped(): void { $class = FakeClassDefinition::fromReflection(new ReflectionClass(SomeClassWithConstructorThatThrowsException::class)); $objectBuilder = new NativeConstructorObjectBuilder($class); $this->expectException(UserlandError::class); $objectBuilder->build([]); } } final class SomeClassWithConstructorThatThrowsException { public function __construct() { throw new RuntimeException('some exception', 1337); } }