= 8.1 */ final class EnumNodeBuilderTest extends TestCase { private RootNodeBuilder $builder; protected function setUp(): void { parent::setUp(); $this->builder = new RootNodeBuilder(new EnumNodeBuilder()); } public function test_invalid_type_fails_assertion(): void { $this->expectException(AssertionError::class); $this->builder->build(Shell::root(new FakeType(), [])); } public function test_invalid_value_throws_exception(): void { $type = new EnumType(PureEnum::class); $this->expectException(InvalidEnumValue::class); $this->expectExceptionCode(1633093113); $this->expectExceptionMessage("Invalid value 'foo', it must be one of 'FOO', 'BAR'."); $this->builder->build(Shell::root($type, 'foo')); } public function test_invalid_string_value_throws_exception(): void { $type = new EnumType(BackedStringEnum::class); $this->expectException(InvalidEnumValue::class); $this->expectExceptionCode(1633093113); $this->expectExceptionMessage("Invalid value object(stdClass), it must be one of 'foo', 'bar'."); $this->builder->build(Shell::root($type, new stdClass())); } public function test_boolean_instead_of_integer_value_throws_exception(): void { $type = new EnumType(BackedIntegerEnum::class); $this->expectException(InvalidEnumValue::class); $this->expectExceptionCode(1633093113); $this->expectExceptionMessage('Invalid value false, it must be one of 42, 1337.'); $this->builder->build(Shell::root($type, false)); } public function test_invalid_integer_value_throws_exception(): void { $type = new EnumType(BackedIntegerEnum::class); $this->expectException(InvalidEnumValue::class); $this->expectExceptionCode(1633093113); $this->expectExceptionMessage('Invalid value object(stdClass), it must be one of 42, 1337.'); $this->builder->build(Shell::root($type, new stdClass())); } }