Skip to content

Commit 6800622

Browse files
committed
Correct naming
1 parent 5c052bb commit 6800622

21 files changed

+120
-113
lines changed

tests/AbstractPHPModelGeneratorTest.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ abstract class AbstractPHPModelGeneratorTest extends TestCase
2525

2626
private $generatedFiles = [];
2727

28+
/**
29+
* Set up an empty directory for the tests
30+
*/
2831
public static function setUpBeforeClass(): void
2932
{
3033
if (is_dir(sys_get_temp_dir() . '/PHPModelGeneratorTest')) {
@@ -40,6 +43,10 @@ public static function setUpBeforeClass(): void
4043
@mkdir(sys_get_temp_dir() . '/PHPModelGeneratorTest/Models');
4144
}
4245

46+
/**
47+
* Check if the test has failed. In this case move all JSON files and generated classes in a directory for debugging
48+
* Additionally clear the test folder so the next test starts in an empty environment
49+
*/
4350
public function tearDown(): void
4451
{
4552
parent::tearDown();
@@ -96,7 +103,7 @@ private function copyExternalJSON(): void
96103
}
97104

98105
/**
99-
* Generate an object from a given JSON schema file and return the FQCN
106+
* Generate a class from a given JSON schema file and return the FQCN
100107
*
101108
* @param string $file
102109
* @param GeneratorConfiguration|null $generatorConfiguration
@@ -107,16 +114,16 @@ private function copyExternalJSON(): void
107114
* @throws RenderException
108115
* @throws SchemaException
109116
*/
110-
public function generateObjectFromFile(string $file, GeneratorConfiguration $generatorConfiguration = null): string
117+
public function generateClassFromFile(string $file, GeneratorConfiguration $generatorConfiguration = null): string
111118
{
112-
return $this->generateObject(
119+
return $this->generateClass(
113120
file_get_contents(__DIR__ . '/Schema/' . $this->getStaticClassName() . '/' . $file),
114121
$generatorConfiguration
115122
);
116123
}
117124

118125
/**
119-
* Generate an object from a file template and apply all $values via sprintf to the template
126+
* Generate a class from a file template and apply all $values via sprintf to the template
120127
*
121128
* @param string $file
122129
* @param array $values
@@ -129,13 +136,13 @@ public function generateObjectFromFile(string $file, GeneratorConfiguration $gen
129136
* @throws RenderException
130137
* @throws SchemaException
131138
*/
132-
public function generateObjectFromFileTemplate(
139+
public function generateClassFromFileTemplate(
133140
string $file,
134141
array $values,
135142
GeneratorConfiguration $generatorConfiguration = null,
136143
bool $escape = true
137144
): string {
138-
return $this->generateObject(
145+
return $this->generateClass(
139146
call_user_func_array(
140147
'sprintf',
141148
array_merge(
@@ -153,7 +160,7 @@ function ($item) use ($escape) {
153160
}
154161

155162
/**
156-
* Generate an object from a given JSON schema string and return the FQCN
163+
* Generate a class from a given JSON schema string and return the FQCN
157164
*
158165
* @param string $jsonSchema
159166
* @param GeneratorConfiguration $generatorConfiguration
@@ -164,7 +171,7 @@ function ($item) use ($escape) {
164171
* @throws RenderException
165172
* @throws SchemaException
166173
*/
167-
public function generateObject(string $jsonSchema, GeneratorConfiguration $generatorConfiguration = null): string
174+
public function generateClass(string $jsonSchema, GeneratorConfiguration $generatorConfiguration = null): string
168175
{
169176
$generatorConfiguration = $generatorConfiguration ?? new GeneratorConfiguration();
170177
$generatorConfiguration

tests/Basic/AdditionalPropertiesTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AdditionalPropertiesTest extends AbstractPHPModelGeneratorTest
1919
*/
2020
public function testAdditionalPropertiesAreIgnoredByDefault(array $propertyValue): void
2121
{
22-
$className = $this->generateObjectFromFile('AdditionalPropertiesNotDefined.json');
22+
$className = $this->generateClassFromFile('AdditionalPropertiesNotDefined.json');
2323

2424
$object = new $className($propertyValue);
2525
$this->assertSame($propertyValue['name'] ?? null, $object->getName());
@@ -33,7 +33,7 @@ public function testAdditionalPropertiesAreIgnoredByDefault(array $propertyValue
3333
*/
3434
public function testAdditionalPropertiesAreIgnoredWhenSetToTrue(array $propertyValue): void
3535
{
36-
$className = $this->generateObjectFromFileTemplate('AdditionalProperties.json', ['true']);
36+
$className = $this->generateClassFromFileTemplate('AdditionalProperties.json', ['true']);
3737

3838
$object = new $className($propertyValue);
3939
$this->assertSame($propertyValue['name'] ?? null, $object->getName());
@@ -56,7 +56,7 @@ public function additionalPropertiesDataProvider():array
5656
*/
5757
public function testDefinedPropertiesAreAcceptedWhenSetToFalse(array $propertyValue): void
5858
{
59-
$className = $this->generateObjectFromFileTemplate('AdditionalProperties.json', ['false']);
59+
$className = $this->generateClassFromFileTemplate('AdditionalProperties.json', ['false']);
6060

6161
$object = new $className($propertyValue);
6262
$this->assertSame($propertyValue['name'] ?? null, $object->getName());
@@ -82,7 +82,7 @@ public function testAdditionalPropertiesThrowAnExceptionWhenSetToFalse(array $pr
8282
$this->expectException(InvalidArgumentException::class);
8383
$this->expectExceptionMessage('Provided JSON contains not allowed additional properties');
8484

85-
$className = $this->generateObjectFromFileTemplate('AdditionalProperties.json', ['false']);
85+
$className = $this->generateClassFromFileTemplate('AdditionalProperties.json', ['false']);
8686

8787
new $className($propertyValue);
8888
}

tests/Basic/BasicSchemaGenerationTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class BasicSchemaGenerationTest extends AbstractPHPModelGeneratorTest
1616
{
1717
public function testGetterAndSetterAreGenerated(): void
1818
{
19-
$className = $this->generateObjectFromFile('BasicSchema.json');
19+
$className = $this->generateClassFromFile('BasicSchema.json');
2020

2121
$object = new $className([]);
2222

@@ -27,7 +27,7 @@ public function testGetterAndSetterAreGenerated(): void
2727

2828
public function testImmutableGeneratorDoesntGenerateSetter(): void
2929
{
30-
$className = $this->generateObjectFromFile(
30+
$className = $this->generateClassFromFile(
3131
'BasicSchema.json',
3232
(new GeneratorConfiguration())->setImmutable(true)
3333
);
@@ -41,7 +41,7 @@ public function testImmutableGeneratorDoesntGenerateSetter(): void
4141

4242
public function testNamespacePrefix(): void
4343
{
44-
$className = '\\My\\Prefix\\' . $this->generateObjectFromFile(
44+
$className = '\\My\\Prefix\\' . $this->generateClassFromFile(
4545
'BasicSchema.json',
4646
(new GeneratorConfiguration())->setNamespacePrefix('\\My\\Prefix')
4747
);
@@ -91,22 +91,22 @@ public function testInvalidJsonSchemaFileThrowsAnException(): void
9191
$this->expectException(SchemaException::class);
9292
$this->expectExceptionMessageRegExp('/^Invalid JSON-Schema file (.*)\.json$/');
9393

94-
$this->generateObjectFromFile('InvalidJSONSchema.json');
94+
$this->generateClassFromFile('InvalidJSONSchema.json');
9595
}
9696

9797
public function testJsonSchemaWithInvalidPropertyTypeThrowsAnException(): void
9898
{
9999
$this->expectException(SchemaException::class);
100100
$this->expectExceptionMessage('Unsupported property type UnknownType');
101101

102-
$this->generateObjectFromFile('JSONSchemaWithInvalidPropertyType.json');
102+
$this->generateClassFromFile('JSONSchemaWithInvalidPropertyType.json');
103103
}
104104

105105
public function testJsonSchemaWithInvalidPropertyTypeDefinitionThrowsAnException(): void
106106
{
107107
$this->expectException(SchemaException::class);
108108
$this->expectExceptionMessage('Invalid property type');
109109

110-
$this->generateObjectFromFile('JSONSchemaWithInvalidPropertyTypeDefinition.json');
110+
$this->generateClassFromFile('JSONSchemaWithInvalidPropertyTypeDefinition.json');
111111
}
112112
}

tests/Basic/DefaultValueTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DefaultValueTest extends AbstractPHPModelGeneratorTest
2727
*/
2828
public function testDefaultValueForTypedProperty(string $valueType, $defaultValue, $compareValue): void
2929
{
30-
$className = $this->generateObjectFromFileTemplate(
30+
$className = $this->generateClassFromFileTemplate(
3131
'DefaultValueTypedProperty.json',
3232
[$valueType, $defaultValue],
3333
null,
@@ -80,7 +80,7 @@ public function testInvalidDefaultValueForTypedPropertyThrowsAnException(string
8080
$this->expectException(SchemaException::class);
8181
$this->expectExceptionMessage('Invalid type for default value of property property');
8282

83-
$this->generateObjectFromFileTemplate(
83+
$this->generateClassFromFileTemplate(
8484
'DefaultValueTypedProperty.json',
8585
[$valueType, $defaultValue],
8686
null,
@@ -129,7 +129,7 @@ public function invalidDefaultValueForTypedPropertyDataProvider(): array
129129
*/
130130
public function testDefaultValueForUntypedTypedProperty($defaultValue, $compareValue): void
131131
{
132-
$className = $this->generateObjectFromFileTemplate(
132+
$className = $this->generateClassFromFileTemplate(
133133
'DefaultValueUntypedProperty.json',
134134
[$defaultValue],
135135
null,

tests/Basic/ObjectSizeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ObjectSizeTest extends AbstractPHPModelGeneratorTest
1919
*/
2020
public function testObjectWithPropertyAmountInRangeIsValid(array $propertyValue): void
2121
{
22-
$className = $this->generateObjectFromFile('ObjectSize.json');
22+
$className = $this->generateClassFromFile('ObjectSize.json');
2323

2424
$object = new $className($propertyValue);
2525
$this->assertSame($propertyValue, $object->getRawModelDataInput());
@@ -46,7 +46,7 @@ public function testObjectWithInvalidPropertyAmountThrowsAnException(
4646
$this->expectException(InvalidArgumentException::class);
4747
$this->expectExceptionMessage($exceptionMessage);
4848

49-
$className = $this->generateObjectFromFile('ObjectSize.json');
49+
$className = $this->generateClassFromFile('ObjectSize.json');
5050

5151
new $className($propertyValue);
5252
}

tests/ComposedValue/ComposedNotTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ComposedNotTest extends AbstractPHPModelGeneratorTest
1515
{
1616
public function testNotProvidedOptionalNotOfTypeStringPropertyIsValid(): void
1717
{
18-
$className = $this->generateObjectFromFile('NotOfType.json');
18+
$className = $this->generateClassFromFile('NotOfType.json');
1919

2020
$object = new $className([]);
2121
$this->assertNull($object->getProperty());
@@ -28,7 +28,7 @@ public function testNotProvidedOptionalNotOfTypeStringPropertyIsValid(): void
2828
*/
2929
public function testValidProvidedOptionalNotOfTypeStringPropertyIsValid($propertyValue): void
3030
{
31-
$className = $this->generateObjectFromFile('NotOfType.json');
31+
$className = $this->generateClassFromFile('NotOfType.json');
3232

3333
$object = new $className(['property' => $propertyValue]);
3434
$this->assertSame($propertyValue, $object->getProperty());
@@ -44,7 +44,7 @@ public function testInvalidProvidedOptionalNotOfTypeStringPropertyThrowsAnExcept
4444
$this->expectException(InvalidArgumentException::class);
4545
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
4646

47-
$className = $this->generateObjectFromFile('NotOfType.json');
47+
$className = $this->generateClassFromFile('NotOfType.json');
4848

4949
new $className(['property' => $propertyValue]);
5050
}
@@ -75,7 +75,7 @@ public function testNotProvidedOptionalNotNullPropertyThrowsAnException(): void
7575
$this->expectException(InvalidArgumentException::class);
7676
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
7777

78-
$className = $this->generateObjectFromFile('NotNull.json');
78+
$className = $this->generateClassFromFile('NotNull.json');
7979

8080
new $className([]);
8181
}
@@ -85,7 +85,7 @@ public function testInvalidProvidedOptionalNotNullPropertyThrowsAnException(): v
8585
$this->expectException(InvalidArgumentException::class);
8686
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
8787

88-
$className = $this->generateObjectFromFile('NotNull.json');
88+
$className = $this->generateClassFromFile('NotNull.json');
8989

9090
new $className(['property' => null]);
9191
}
@@ -97,7 +97,7 @@ public function testInvalidProvidedOptionalNotNullPropertyThrowsAnException(): v
9797
*/
9898
public function testValidProvidedOptionalNotNullPropertyIsValid($propertyValue): void
9999
{
100-
$className = $this->generateObjectFromFile('NotNull.json');
100+
$className = $this->generateClassFromFile('NotNull.json');
101101

102102
$object = new $className(['property' => $propertyValue]);
103103
$this->assertSame($propertyValue, $object->getProperty());
@@ -122,7 +122,7 @@ public function validNotNullPropertyDataProvider(): array
122122
*/
123123
public function testExtendedPropertyDefinitionWithValidValues($propertyValue): void
124124
{
125-
$className = $this->generateObjectFromFile('ExtendedPropertyDefinition.json');
125+
$className = $this->generateClassFromFile('ExtendedPropertyDefinition.json');
126126

127127
$object = new $className(['property' => $propertyValue]);
128128
$this->assertSame($propertyValue, $object->getProperty());
@@ -150,7 +150,7 @@ public function testExtendedPropertyDefinitionWithInvalidValuesThrowsAnException
150150
$this->expectException(InvalidArgumentException::class);
151151
$this->expectExceptionMessage($exceptionMessage);
152152

153-
$className = $this->generateObjectFromFile('ExtendedPropertyDefinition.json');
153+
$className = $this->generateClassFromFile('ExtendedPropertyDefinition.json');
154154

155155
new $className(['property' => $propertyValue]);
156156
}
@@ -172,7 +172,7 @@ public function invalidExtendedPropertyDataProvider(): array
172172

173173
public function testNotProvidedObjectPropertyWithReferencedSchemaIsValid(): void
174174
{
175-
$className = $this->generateObjectFromFile('ReferencedObjectSchema.json');
175+
$className = $this->generateClassFromFile('ReferencedObjectSchema.json');
176176

177177
$object = new $className([]);
178178
$this->assertNull($object->getPerson());
@@ -185,7 +185,7 @@ public function testNotProvidedObjectPropertyWithReferencedSchemaIsValid(): void
185185
*/
186186
public function testNotMatchingObjectPropertyWithReferencedSchemaIsValid($propertyValue): void
187187
{
188-
$className = $this->generateObjectFromFile('ReferencedObjectSchema.json');
188+
$className = $this->generateClassFromFile('ReferencedObjectSchema.json');
189189

190190
$object = new $className(['person' => $propertyValue]);
191191
$this->assertSame($propertyValue, $object->getPerson());
@@ -213,7 +213,7 @@ public function testMatchingObjectPropertyWithReferencedSchemaThrowsAnException(
213213
$this->expectException(InvalidArgumentException::class);
214214
$this->expectExceptionMessage('Invalid value for person declined by composition constraint');
215215

216-
$className = $this->generateObjectFromFile('ReferencedObjectSchema.json');
216+
$className = $this->generateClassFromFile('ReferencedObjectSchema.json');
217217

218218
new $className(['person' => ['name' => 'Hannes', 'age' => 42]]);
219219
}

0 commit comments

Comments
 (0)