Skip to content

Commit c6ce299

Browse files
committed
add typing test
1 parent f9b2716 commit c6ce299

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

tests/Basic/PropertyNamesTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ public function invalidCombinedPropertyNamesDataProvider(): array
237237
public function testInvalidConstPropertyNamesThrowsAnException(): void
238238
{
239239
$this->expectException(SchemaException::class);
240+
$this->expectExceptionMessageMatches('/Invalid const property name in file/');
240241

241-
$this->generateClassFromFileTemplate('PropertyNames.json', ['{"const": null}']);
242+
$this->generateClassFromFileTemplate('PropertyNames.json', ['{"const": false}'], escape: false);
242243
}
243244
}

tests/Objects/ConstPropertyTest.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ public function testProvidedConstPropertiesIsValidWithDifferentImplicitNull(
236236
bool $implicitNull,
237237
string $reqPropertyValue,
238238
string $optPropertyValue
239-
): void
240-
{
239+
): void {
241240
$className = $this->generateClassFromFile(
242241
'RequiredAndOptionalConstProperties.json',
243242
new GeneratorConfiguration(),
@@ -249,6 +248,36 @@ public function testProvidedConstPropertiesIsValidWithDifferentImplicitNull(
249248

250249
$this->assertSame($reqPropertyValue, $object->getRequiredProperty());
251250
$this->assertSame($optPropertyValue, $object->getOptionalProperty());
251+
252+
// typing for required const
253+
$this->assertSame('string', $this->getPropertyTypeAnnotation($object, 'requiredProperty'));
254+
255+
$this->assertSame('string', $this->getReturnTypeAnnotation($object, 'getRequiredProperty'));
256+
$returnType = $this->getReturnType($object, 'getRequiredProperty');
257+
$this->assertSame('string', $returnType->getName());
258+
$this->assertFalse($returnType->allowsNull());
259+
260+
$this->assertSame('string', $this->getParameterTypeAnnotation($className, 'setRequiredProperty'),
261+
);
262+
$setAgeParamType = $this->getParameterType($className, 'setRequiredProperty');
263+
$this->assertSame('string', $setAgeParamType->getName());
264+
$this->assertFalse($returnType->allowsNull());
265+
266+
// typing for optional const
267+
$this->assertSame('string|null', $this->getPropertyTypeAnnotation($object, 'optionalProperty'));
268+
269+
$this->assertSame('string|null', $this->getReturnTypeAnnotation($object, 'getOptionalProperty'));
270+
$returnType = $this->getReturnType($object, 'getOptionalProperty');
271+
$this->assertSame('string', $returnType->getName());
272+
$this->assertTrue($returnType->allowsNull());
273+
274+
$this->assertSame(
275+
$implicitNull ? 'string|null' : 'string',
276+
$this->getParameterTypeAnnotation($className, 'setOptionalProperty'),
277+
);
278+
$setAgeParamType = $this->getParameterType($className, 'setOptionalProperty');
279+
$this->assertSame('string', $setAgeParamType->getName());
280+
$this->assertSame($implicitNull, $setAgeParamType->allowsNull());
252281
}
253282

254283
public function requiredAndOptionalPropertiesDataProvider(): array

0 commit comments

Comments
 (0)