Skip to content

Commit 46b1ce7

Browse files
committed
Optimize readme, rename InvalidArgumentException to avoid confusion with Builtin InvalidArgumentException
1 parent 93f377b commit 46b1ce7

23 files changed

+105
-91
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ The *GeneratorConfiguration* object offers the following methods to configure th
5353

5454
Method | Configuration | Example | Default
5555
--- | --- | --- | ---
56-
``` setNamespacePrefix(string $prefix) ``` | Configures a namespace prefix for all generated classes. The namespaces will be extended with the directory structure of the source directory. | ``` setNamespacePrefix('\MyApp\Model') ``` | Empty string so no namespace prefix will be used
57-
``` setImmutable(bool $immutable) ``` | If set to true the generated model classes will be delivered without setter methods for the object properties. | ``` setImmutable(false) ``` | true
58-
``` setCollectErrors(bool $collectErrors) ``` | By default the complete input is validated and in case of failing validations all error messages will be thrown in a single exception. If set to false the first failing validation will throw an exception. | ``` setCollectErrors(true) ``` | false
59-
``` setPrettyPrint(bool $prettyPrint) ``` | If set to false, the generated model classes won't follow coding gudelines (but the generation is faster). If enabled the package [Symplify/EasyCodingStandard](https://github.com/Symplify/EasyCodingStandard) will be used to clean up the generated code. | ``` setPrettyPrint(false) ``` | true
60-
``` setOutputEnabled(bool $prettyPrint) ``` | Enable or disable output of the generation process to STDOUT | ``` setOutputEnabled(false) ``` | true
61-
``` setErrorRegistryClass(string $exceptionClass) ``` | Define a custom exception implementing the ErrorRegistryExceptionInterface to decouple the generated code from the library (if you want to declare the library as a dev-dependency). The exception will be thrown if a validation fails error collection is **enabled** | ``` setErrorRegistryClass(CustomException::class) ``` | PHPModelGenerator\Exception\ErrorRegistryException::class
62-
``` setExceptionClass(bool $prettyPrint) ``` | Define a custom exception to decouple the generated code from the library (if you want to declare the library as a dev-dependency). The exception will be thrown if a validation fails error collection is **disabled** | ``` setExceptionClass(CustomException::class) ``` | PHPModelGenerator\Exception\InvalidArgumentException::class
56+
``` setNamespacePrefix(string $prefix) ``` <br><br>Example:<br> ``` setNamespacePrefix('\MyApp\Model') ``` | Configures a namespace prefix for all generated classes. The namespaces will be extended with the directory structure of the source directory. | Empty string so no namespace prefix will be used
57+
``` setImmutable(bool $immutable) ``` <br><br>Example:<br> ``` setImmutable(false) ``` | If set to true the generated model classes will be delivered without setter methods for the object properties. | true
58+
``` setCollectErrors(bool $collectErrors) ``` <br><br>Example:<br> ``` setCollectErrors(false) ``` | By default the complete input is validated and in case of failing validations all error messages will be thrown in a single exception. If set to false the first failing validation will throw an exception. | true
59+
``` setPrettyPrint(bool $prettyPrint) ``` <br><br>Example:<br> ``` setPrettyPrint(false) ``` | If set to false, the generated model classes won't follow coding gudelines (but the generation is faster). If enabled the package [Symplify/EasyCodingStandard](https://github.com/Symplify/EasyCodingStandard) will be used to clean up the generated code. | true
60+
``` setOutputEnabled(bool $prettyPrint) ``` <br><br>Example:<br> ``` setOutputEnabled(false) ``` | Enable or disable output of the generation process to STDOUT | true
61+
``` setErrorRegistryClass(string $exceptionClass) ``` <br><br>Example:<br> ``` setErrorRegistryClass(CustomException::class) ``` | Define a custom exception implementing the ErrorRegistryExceptionInterface to decouple the generated code from the library (if you want to declare the library as a dev-dependency). The exception will be thrown if a validation fails error collection is **enabled** | ErrorRegistryException::class
62+
``` setExceptionClass(bool $prettyPrint) ``` <br><br>Example:<br> ``` setExceptionClass(CustomException::class) ``` | Define a custom exception to decouple the generated code from the library (if you want to declare the library as a dev-dependency). The exception will be thrown if a validation fails error collection is **disabled** | ValidationError::class
6363

6464
## How the heck does this work? ##
6565

src/Exception/InvalidArgumentException.php renamed to src/Exception/ValidationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
*
1010
* @package PHPModelGenerator\Exception
1111
*/
12-
class InvalidArgumentException extends PHPModelGeneratorException
12+
class ValidationException extends PHPModelGeneratorException
1313
{
1414
}

src/Model/GeneratorConfiguration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace PHPModelGenerator\Model;
66

77
use PHPModelGenerator\Exception\ErrorRegistryException;
8-
use PHPModelGenerator\Exception\InvalidArgumentException;
8+
use PHPModelGenerator\Exception\ValidationException;
99

1010
/**
1111
* Class GeneratorConfiguration
@@ -27,7 +27,7 @@ class GeneratorConfiguration
2727
/** @var string */
2828
protected $errorRegistryClass = ErrorRegistryException::class;
2929
/** @var string */
30-
protected $exceptionClass = InvalidArgumentException::class;
30+
protected $exceptionClass = ValidationException::class;
3131

3232
/**
3333
* @return string

tests/Basic/AdditionalPropertiesTest.php

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

33
namespace PHPModelGenerator\Tests\Basic;
44

5-
use PHPModelGenerator\Exception\InvalidArgumentException;
5+
use PHPModelGenerator\Exception\ValidationException;
66
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
77

88
/**
@@ -79,7 +79,7 @@ public function definedPropertiesDataProvider():array
7979
*/
8080
public function testAdditionalPropertiesThrowAnExceptionWhenSetToFalse(array $propertyValue): void
8181
{
82-
$this->expectException(InvalidArgumentException::class);
82+
$this->expectException(ValidationException::class);
8383
$this->expectExceptionMessage('Provided JSON contains not allowed additional properties');
8484

8585
$className = $this->generateClassFromFileTemplate('AdditionalProperties.json', ['false']);

tests/Basic/ObjectSizeTest.php

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

33
namespace PHPModelGenerator\Tests\Basic;
44

5-
use PHPModelGenerator\Exception\InvalidArgumentException;
5+
use PHPModelGenerator\Exception\ValidationException;
66
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
77

88
/**
@@ -43,7 +43,7 @@ public function testObjectWithInvalidPropertyAmountThrowsAnException(
4343
array $propertyValue,
4444
string $exceptionMessage
4545
): void {
46-
$this->expectException(InvalidArgumentException::class);
46+
$this->expectException(ValidationException::class);
4747
$this->expectExceptionMessage($exceptionMessage);
4848

4949
$className = $this->generateClassFromFile('ObjectSize.json');

tests/ComposedValue/ComposedAllOfTest.php

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

33
namespace PHPModelGenerator\Tests\ComposedValue;
44

5-
use PHPModelGenerator\Exception\InvalidArgumentException;
5+
use PHPModelGenerator\Exception\ValidationException;
66
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
77
use stdClass;
88

@@ -39,7 +39,7 @@ public function propertyLevelAllOfSchemaFileDataProvider(): array
3939
*/
4040
public function testNotProvidedObjectLevelAllOfNotMatchingAnyOptionThrowsAnException(): void
4141
{
42-
$this->expectException(InvalidArgumentException::class);
42+
$this->expectException(ValidationException::class);
4343
$this->expectExceptionMessageRegExp('/^Invalid value for (.*?) declined by composition constraint$/');
4444

4545
$className = $this->generateClassFromFile('ObjectLevelCompositionRequired.json');
@@ -104,7 +104,7 @@ public function testExtendedPropertyDefinitionWithInvalidValuesThrowsAnException
104104
$propertyValue,
105105
string $exceptionMessage
106106
): void {
107-
$this->expectException(InvalidArgumentException::class);
107+
$this->expectException(ValidationException::class);
108108
$this->expectExceptionMessage($exceptionMessage);
109109

110110
$className = $this->generateClassFromFile('ExtendedPropertyDefinition.json');
@@ -160,7 +160,7 @@ public function referencedPersonDataProvider(): array
160160
* @param $propertyValue
161161
*/
162162
public function testNotMatchingObjectPropertyWithReferencedPersonSchemaThrowsAnException($propertyValue): void {
163-
$this->expectException(InvalidArgumentException::class);
163+
$this->expectException(ValidationException::class);
164164
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
165165

166166
$className = $this->generateClassFromFile('ReferencedObjectSchema.json');
@@ -192,7 +192,7 @@ public function invalidObjectPropertyWithReferencedPersonSchemaDataProvider(): a
192192
*/
193193
public function testNotMatchingObjectPropertyWithReferencedPetSchemaThrowsAnException($propertyValue): void
194194
{
195-
$this->expectException(InvalidArgumentException::class);
195+
$this->expectException(ValidationException::class);
196196
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
197197

198198
$className = $this->generateClassFromFile('ReferencedObjectSchema.json');
@@ -251,7 +251,7 @@ public function validComposedObjectDataProvider(): array
251251
*/
252252
public function testNotMatchingPropertyForComposedAllOfObjectThrowsAnException(array $input): void
253253
{
254-
$this->expectException(InvalidArgumentException::class);
254+
$this->expectException(ValidationException::class);
255255

256256
$className = $this->generateClassFromFile('ObjectLevelComposition.json');
257257

@@ -286,7 +286,7 @@ public function invalidComposedObjectDataProvider()
286286
public function testMatchingPropertyForComposedAllOfObjectWithRequiredPropertiesThrowsAnException(
287287
array $input
288288
): void {
289-
$this->expectException(InvalidArgumentException::class);
289+
$this->expectException(ValidationException::class);
290290

291291
$className = $this->generateClassFromFile('ObjectLevelCompositionRequired.json');
292292

@@ -301,7 +301,7 @@ public function testMatchingPropertyForComposedAllOfObjectWithRequiredProperties
301301
public function testNotMatchingPropertyForComposedAllOfObjectWithRequiredPropertiesThrowsAnException(
302302
array $input
303303
): void {
304-
$this->expectException(InvalidArgumentException::class);
304+
$this->expectException(ValidationException::class);
305305

306306
$className = $this->generateClassFromFile('ObjectLevelCompositionRequired.json');
307307

@@ -343,4 +343,18 @@ public function nestedObjectDataProvider()
343343
['ObjectLevelNestedCompositionNestedObject.json'],
344344
];
345345
}
346+
347+
/*
348+
public function testObjectLevelCompositionConditional()
349+
{
350+
$className = $this->generateClassFromFile('ComposedAllOfConditional.json');
351+
352+
$object = new $className(['name' => 'Hannes', 'cars' => [['ps' => 112]]]);
353+
354+
$this->assertSame('Hannes', $object->getName());
355+
$this->assertIsArray($object->getCars());
356+
$this->assertCount(1, $object->getCars());
357+
$this->assertIsObject($object->getCars()[0]);
358+
$this->assertSame(112, $object->getCars()[0]->getPs());
359+
}*/
346360
}

tests/ComposedValue/ComposedAnyOfTest.php

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

33
namespace PHPModelGenerator\Tests\ComposedValue;
44

5-
use PHPModelGenerator\Exception\InvalidArgumentException;
5+
use PHPModelGenerator\Exception\ValidationException;
66
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
77
use stdClass;
88

@@ -41,7 +41,7 @@ public function propertyLevelAnyOfSchemaFileDataProvider(): array
4141
*/
4242
public function testNotProvidedObjectLevelAnyOfNotMatchingAnyOptionThrowsAnException(): void
4343
{
44-
$this->expectException(InvalidArgumentException::class);
44+
$this->expectException(ValidationException::class);
4545
$this->expectExceptionMessageRegExp('/^Invalid value for (.*?) declined by composition constraint$/');
4646

4747
$className = $this->generateClassFromFile('ObjectLevelCompositionRequired.json');
@@ -106,7 +106,7 @@ public function annotationDataProvider(): array
106106
*/
107107
public function testInvalidProvidedAnyOfTypePropertyThrowsAnException($propertyValue): void
108108
{
109-
$this->expectException(InvalidArgumentException::class);
109+
$this->expectException(ValidationException::class);
110110
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
111111

112112
$className = $this->generateClassFromFile('AnyOfType.json');
@@ -158,7 +158,7 @@ public function testValidProvidedRequiredAnyOfTypePropertyIsValid($propertyValue
158158
*/
159159
public function testInvalidProvidedRequiredAnyOfTypePropertyThrowsAnException($propertyValue): void
160160
{
161-
$this->expectException(InvalidArgumentException::class);
161+
$this->expectException(ValidationException::class);
162162
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
163163

164164
$className = $this->generateClassFromFile('AnyOfTypeRequired.json');
@@ -208,7 +208,7 @@ public function testExtendedPropertyDefinitionWithInvalidValuesThrowsAnException
208208
$propertyValue,
209209
string $exceptionMessage
210210
): void {
211-
$this->expectException(InvalidArgumentException::class);
211+
$this->expectException(ValidationException::class);
212212
$this->expectExceptionMessage($exceptionMessage);
213213

214214
$className = $this->generateClassFromFile('ExtendedPropertyDefinition.json');
@@ -294,7 +294,7 @@ public function testNotMatchingObjectPropertyWithReferencedPersonSchemaThrowsAnE
294294
string $schema,
295295
$propertyValue
296296
): void {
297-
$this->expectException(InvalidArgumentException::class);
297+
$this->expectException(ValidationException::class);
298298
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
299299

300300
$className = $this->generateClassFromFile($schema);
@@ -329,7 +329,7 @@ public function invalidObjectPropertyWithReferencedPersonSchemaDataProvider(): a
329329
*/
330330
public function testNotMatchingObjectPropertyWithReferencedPetSchemaThrowsAnException($propertyValue): void
331331
{
332-
$this->expectException(InvalidArgumentException::class);
332+
$this->expectException(ValidationException::class);
333333
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
334334

335335
$className = $this->generateClassFromFile('ReferencedObjectSchema2.json');
@@ -405,7 +405,7 @@ public function validComposedObjectDataProviderRequired(): array
405405
*/
406406
public function testNotMatchingPropertyForComposedAnyOfObjectThrowsAnException(array $input): void
407407
{
408-
$this->expectException(InvalidArgumentException::class);
408+
$this->expectException(ValidationException::class);
409409

410410
$className = $this->generateClassFromFile('ObjectLevelComposition.json');
411411

@@ -451,7 +451,7 @@ public function testMatchingPropertyForComposedAnyOfObjectWithRequiredProperties
451451
*/
452452
public function testNotMatchingPropertyForComposedAnyOfObjectWithRequiredPropertiesThrowsAnException(array $input): void
453453
{
454-
$this->expectException(InvalidArgumentException::class);
454+
$this->expectException(ValidationException::class);
455455

456456
$className = $this->generateClassFromFile('ObjectLevelCompositionRequired.json');
457457

tests/ComposedValue/ComposedIfTest.php

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

33
namespace PHPModelGenerator\Tests\ComposedValue;
44

5-
use PHPModelGenerator\Exception\InvalidArgumentException;
5+
use PHPModelGenerator\Exception\ValidationException;
66
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
77

88
/**
@@ -55,7 +55,7 @@ public function testInvalidConditionalObjectPropertyThrowsAnException(
5555
?string $country,
5656
?string $postalCode
5757
): void {
58-
$this->expectException(InvalidArgumentException::class);
58+
$this->expectException(ValidationException::class);
5959
$this->expectExceptionMessageRegExp('/postal_code doesn\'t match pattern .*/');
6060

6161
$className = $this->generateClassFromFile('ConditionalObjectProperty.json');

tests/ComposedValue/ComposedNotTest.php

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

33
namespace PHPModelGenerator\Tests\ComposedValue;
44

5-
use PHPModelGenerator\Exception\InvalidArgumentException;
5+
use PHPModelGenerator\Exception\ValidationException;
66
use PHPModelGenerator\Tests\AbstractPHPModelGeneratorTest;
77
use stdClass;
88

@@ -41,7 +41,7 @@ public function testValidProvidedOptionalNotOfTypeStringPropertyIsValid($propert
4141
*/
4242
public function testInvalidProvidedOptionalNotOfTypeStringPropertyThrowsAnException(string $propertyValue): void
4343
{
44-
$this->expectException(InvalidArgumentException::class);
44+
$this->expectException(ValidationException::class);
4545
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
4646

4747
$className = $this->generateClassFromFile('NotOfType.json');
@@ -72,7 +72,7 @@ public function validPropertyTypeDataProvider(): array
7272

7373
public function testNotProvidedOptionalNotNullPropertyThrowsAnException(): void
7474
{
75-
$this->expectException(InvalidArgumentException::class);
75+
$this->expectException(ValidationException::class);
7676
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
7777

7878
$className = $this->generateClassFromFile('NotNull.json');
@@ -82,7 +82,7 @@ public function testNotProvidedOptionalNotNullPropertyThrowsAnException(): void
8282

8383
public function testInvalidProvidedOptionalNotNullPropertyThrowsAnException(): void
8484
{
85-
$this->expectException(InvalidArgumentException::class);
85+
$this->expectException(ValidationException::class);
8686
$this->expectExceptionMessage('Invalid value for property declined by composition constraint');
8787

8888
$className = $this->generateClassFromFile('NotNull.json');
@@ -147,7 +147,7 @@ public function testExtendedPropertyDefinitionWithInvalidValuesThrowsAnException
147147
$propertyValue,
148148
string $exceptionMessage
149149
): void {
150-
$this->expectException(InvalidArgumentException::class);
150+
$this->expectException(ValidationException::class);
151151
$this->expectExceptionMessage($exceptionMessage);
152152

153153
$className = $this->generateClassFromFile('ExtendedPropertyDefinition.json');
@@ -210,7 +210,7 @@ public function objectPropertyWithReferencedSchemaDataProvider(): array
210210

211211
public function testMatchingObjectPropertyWithReferencedSchemaThrowsAnException(): void
212212
{
213-
$this->expectException(InvalidArgumentException::class);
213+
$this->expectException(ValidationException::class);
214214
$this->expectExceptionMessage('Invalid value for person declined by composition constraint');
215215

216216
$className = $this->generateClassFromFile('ReferencedObjectSchema.json');

0 commit comments

Comments
 (0)