Skip to content

Commit ef2314a

Browse files
author
Enno Woortmann
committed
Removed unreachable exceptions, added test cases for schema exceptions
1 parent eff48d9 commit ef2314a

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

src/PropertyProcessor/ComposedValueProcessorFactory.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public function getProcessor(
3838
Schema $schema
3939
): PropertyProcessorInterface {
4040
$processor = '\\PHPModelGenerator\\PropertyProcessor\\ComposedValue\\' . ucfirst($type) . 'Processor';
41-
if (!class_exists($processor)) {
42-
throw new SchemaException("Unsupported composed value type $type");
43-
}
4441

4542
return new $processor($propertyMetaDataCollection, $schemaProcessor, $schema, $this->rootLevelComposition);
4643
}

src/PropertyProcessor/Property/ObjectProcessor.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ public function process(string $propertyName, JsonSchema $propertySchema): Prope
4343
$this->schema->getSchemaDictionary()
4444
);
4545

46-
if ($schema === null) {
47-
throw new SchemaException(
48-
sprintf(
49-
'Failed to process schema for object property %s in file %s',
50-
$propertyName,
51-
$propertySchema->getFile()
52-
)
53-
);
54-
}
55-
5646
// if the generated schema is located in a different namespace (the schema for the given structure in
5747
// $propertySchema is duplicated) add used classes to the current schema. By importing the class which is
5848
// represented by $schema and by transferring all imports of $schema as well as imports for all properties

tests/ComposedValue/ComposedAllOfTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPModelGenerator\Tests\ComposedValue;
44

5+
use PHPModelGenerator\Exception\SchemaException;
56
use PHPModelGenerator\Exception\ValidationException;
67
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
78
use ReflectionMethod;
@@ -447,6 +448,14 @@ public function nestedObjectDataProvider()
447448
];
448449
}
449450

451+
public function testNoNestedSchemaThrowsAnException(): void
452+
{
453+
$this->expectException(SchemaException::class);
454+
$this->expectExceptionMessage('No nested schema for composed property');
455+
456+
$this->generateClassFromFile('NoNestedSchema.json');
457+
}
458+
450459
/*
451460
public function testObjectLevelCompositionConditional()
452461
{

tests/ComposedValue/ComposedIfTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,12 @@ public function invalidConditionalObjectPropertyDataProvider(): array
9595
]
9696
);
9797
}
98+
99+
public function testIncompleteCompositionThrowsAnException(): void
100+
{
101+
$this->expectException(SchemaException::class);
102+
$this->expectExceptionMessage('Incomplete conditional composition for property');
103+
104+
$this->generateClassFromFile('IncompleteConditional.json');
105+
}
98106
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "object",
3+
"allOf": [
4+
{
5+
"type": "integer",
6+
"minimum": 10
7+
}
8+
]
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"country": {
5+
"enum": [
6+
"USA",
7+
"Canada"
8+
]
9+
}
10+
},
11+
"if": {
12+
"properties": {
13+
"country": {
14+
"const": "USA"
15+
}
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)