Skip to content

Commit 6106b36

Browse files
author
Enno Woortmann
committed
coverage
1 parent 9df4dfd commit 6106b36

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/SchemaProcessor/PostProcessor/EnumPostProcessor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public function __construct(
4848
bool $skipNonMappedEnums = false
4949
) {
5050
if (PHP_VERSION_ID < 80100) {
51+
// @codeCoverageIgnoreStart
5152
throw new Exception('Enumerations are only allowed since PHP 8.1');
53+
// @codeCoverageIgnoreEnd
5254
}
5355

5456
(new ModelGenerator())->generateModelDirectory($targetDirectory);
@@ -227,7 +229,9 @@ private function renderEnum(
227229
$fqcn = "$this->namespace\\$name";
228230

229231
if ($generatorConfiguration->isOutputEnabled()) {
232+
// @codeCoverageIgnoreStart
230233
echo "Rendered enum $fqcn\n";
234+
// @codeCoverageIgnoreEnd
231235
}
232236

233237
return $fqcn;

tests/PostProcessor/EnumPostProcessorTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public function testStringOnlyEnum(): void
4545

4646
$this->includeGeneratedEnums(1);
4747

48-
$object = new $className(['property' => 'hans']);
48+
$object = new $className(['property' => 'hans', 'stringProperty' => 'abc']);
4949
$this->assertSame('hans', $object->getProperty()->value);
50+
$this->assertSame('abc', $object->getStringProperty());
5051

5152
$object->setProperty('dieter');
5253
$this->assertSame('dieter', $object->getProperty()->value);
@@ -177,6 +178,26 @@ public function unmappedEnumThrowsAnExceptionDataProvider(): array
177178
];
178179
}
179180

181+
public function testUnmappedEnumIsSkippedWithEnabledSkipOption(): void
182+
{
183+
$this->modifyModelGenerator = static function (ModelGenerator $generator): void {
184+
$generator->addPostProcessor(
185+
new EnumPostProcessor(
186+
join(DIRECTORY_SEPARATOR, [sys_get_temp_dir(), 'PHPModelGeneratorTest', 'Enum']),
187+
'Enum',
188+
true
189+
)
190+
);
191+
};
192+
193+
$className = $this->generateClassFromFileTemplate('EnumProperty.json', ['[0, 1, 2]'], null, false);
194+
195+
$this->includeGeneratedEnums(0);
196+
197+
$object = new $className(['property' => 1]);
198+
$this->assertSame(1, $object->getProperty());
199+
}
200+
180201
/**
181202
* @dataProvider invalidEnumMapThrowsAnExceptionDataProvider
182203
* @requires PHP >= 8.1

tests/Schema/EnumPostProcessorTest/EnumProperty.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"properties": {
44
"property": {
55
"enum": %s
6+
},
7+
"stringProperty": {
8+
"type": "string"
69
}
710
}
811
}

0 commit comments

Comments
 (0)