diff --git a/tests/Basic/PropertyNamesTest.php b/tests/Basic/PropertyNamesTest.php index 5c71515..42dd90f 100644 --- a/tests/Basic/PropertyNamesTest.php +++ b/tests/Basic/PropertyNamesTest.php @@ -237,7 +237,8 @@ public function invalidCombinedPropertyNamesDataProvider(): array public function testInvalidConstPropertyNamesThrowsAnException(): void { $this->expectException(SchemaException::class); + $this->expectExceptionMessageMatches('/Invalid const property name in file/'); - $this->generateClassFromFileTemplate('PropertyNames.json', ['{"const": null}']); + $this->generateClassFromFileTemplate('PropertyNames.json', ['{"const": false}'], escape: false); } } diff --git a/tests/Objects/ConstPropertyTest.php b/tests/Objects/ConstPropertyTest.php index 8fc1579..4ed8664 100644 --- a/tests/Objects/ConstPropertyTest.php +++ b/tests/Objects/ConstPropertyTest.php @@ -236,8 +236,7 @@ public function testProvidedConstPropertiesIsValidWithDifferentImplicitNull( bool $implicitNull, string $reqPropertyValue, string $optPropertyValue - ): void - { + ): void { $className = $this->generateClassFromFile( 'RequiredAndOptionalConstProperties.json', new GeneratorConfiguration(), @@ -249,6 +248,36 @@ public function testProvidedConstPropertiesIsValidWithDifferentImplicitNull( $this->assertSame($reqPropertyValue, $object->getRequiredProperty()); $this->assertSame($optPropertyValue, $object->getOptionalProperty()); + + // typing for required const + $this->assertSame('string', $this->getPropertyTypeAnnotation($object, 'requiredProperty')); + + $this->assertSame('string', $this->getReturnTypeAnnotation($object, 'getRequiredProperty')); + $returnType = $this->getReturnType($object, 'getRequiredProperty'); + $this->assertSame('string', $returnType->getName()); + $this->assertFalse($returnType->allowsNull()); + + $this->assertSame('string', $this->getParameterTypeAnnotation($className, 'setRequiredProperty'), + ); + $setAgeParamType = $this->getParameterType($className, 'setRequiredProperty'); + $this->assertSame('string', $setAgeParamType->getName()); + $this->assertFalse($returnType->allowsNull()); + + // typing for optional const + $this->assertSame('string|null', $this->getPropertyTypeAnnotation($object, 'optionalProperty')); + + $this->assertSame('string|null', $this->getReturnTypeAnnotation($object, 'getOptionalProperty')); + $returnType = $this->getReturnType($object, 'getOptionalProperty'); + $this->assertSame('string', $returnType->getName()); + $this->assertTrue($returnType->allowsNull()); + + $this->assertSame( + $implicitNull ? 'string|null' : 'string', + $this->getParameterTypeAnnotation($className, 'setOptionalProperty'), + ); + $setAgeParamType = $this->getParameterType($className, 'setOptionalProperty'); + $this->assertSame('string', $setAgeParamType->getName()); + $this->assertSame($implicitNull, $setAgeParamType->allowsNull()); } public function requiredAndOptionalPropertiesDataProvider(): array