Skip to content

Commit

Permalink
add typing test
Browse files Browse the repository at this point in the history
  • Loading branch information
wol-soft committed Sep 19, 2024
1 parent f9b2716 commit c6ce299
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/Basic/PropertyNamesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
33 changes: 31 additions & 2 deletions tests/Objects/ConstPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ public function testProvidedConstPropertiesIsValidWithDifferentImplicitNull(
bool $implicitNull,
string $reqPropertyValue,
string $optPropertyValue
): void
{
): void {
$className = $this->generateClassFromFile(
'RequiredAndOptionalConstProperties.json',
new GeneratorConfiguration(),
Expand All @@ -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
Expand Down

0 comments on commit c6ce299

Please sign in to comment.