1
1
<?php
2
+
3
+ /**
4
+ * @see https://github.com/open-code-modeling/json-schema-to-php for the canonical source repository
5
+ * @copyright https://github.com/open-code-modeling/json-schema-to-php/blob/master/COPYRIGHT.md
6
+ * @license https://github.com/open-code-modeling/json-schema-to-php/blob/master/LICENSE.md MIT License
7
+ */
8
+
2
9
declare (strict_types=1 );
3
10
4
11
namespace OpenCodeModelingTest \JsonSchemaToPhp \Type ;
5
12
13
+ use OpenCodeModeling \JsonSchemaToPhp \Type \IntegerType ;
14
+ use OpenCodeModeling \JsonSchemaToPhp \Type \NumberType ;
6
15
use OpenCodeModeling \JsonSchemaToPhp \Type \ObjectType ;
16
+ use OpenCodeModeling \JsonSchemaToPhp \Type \StringType ;
7
17
use OpenCodeModeling \JsonSchemaToPhp \Type \Type ;
8
18
use PHPUnit \Framework \TestCase ;
9
19
@@ -27,4 +37,58 @@ public function it_supports_shorthand_definition(): void
27
37
$ this ->assertEquals ('Person ' , $ type ->name ());
28
38
$ this ->assertEquals ('Person ' , $ type ->title ());
29
39
}
40
+
41
+ /**
42
+ * @test
43
+ */
44
+ public function it_supports_string_enums_without_type (): void
45
+ {
46
+ $ typeSet = Type::fromShorthand (['contentLanguage ' => 'enum|de-DE|en-US ' ], 'Content ' );
47
+
48
+ $ this ->assertCount (1 , $ typeSet );
49
+
50
+ /** @var ObjectType $type */
51
+ $ type = $ typeSet ->first ();
52
+
53
+ $ this ->assertInstanceOf (ObjectType::class, $ type );
54
+ $ this ->assertArrayHasKey ('contentLanguage ' , $ type ->properties ());
55
+
56
+ $ contentLanguage = $ type ->properties ()['contentLanguage ' ];
57
+ /** @var StringType $contentLanguageType */
58
+ $ contentLanguageType = $ contentLanguage ->first ();
59
+ $ this ->assertInstanceOf (StringType::class, $ contentLanguageType );
60
+ $ this ->assertSame (['de-DE ' , 'en-US ' ], $ contentLanguageType ->enum ());
61
+ }
62
+
63
+ /**
64
+ * @test
65
+ */
66
+ public function it_supports_int_enums_without_type (): void
67
+ {
68
+ $ typeSet = Type::fromDefinition (['enum ' => [10 , 20 ]], 'Content ' );
69
+
70
+ $ this ->assertCount (1 , $ typeSet );
71
+
72
+ /** @var IntegerType $type */
73
+ $ type = $ typeSet ->first ();
74
+
75
+ $ this ->assertInstanceOf (IntegerType::class, $ type );
76
+ $ this ->assertSame ([10 , 20 ], $ type ->enum ());
77
+ }
78
+
79
+ /**
80
+ * @test
81
+ */
82
+ public function it_supports_float_enums_without_type (): void
83
+ {
84
+ $ typeSet = Type::fromDefinition (['enum ' => [10.10 , 20.20 ]], 'Content ' );
85
+
86
+ $ this ->assertCount (1 , $ typeSet );
87
+
88
+ /** @var NumberType $type */
89
+ $ type = $ typeSet ->first ();
90
+
91
+ $ this ->assertInstanceOf (NumberType::class, $ type );
92
+ $ this ->assertSame ([10.10 , 20.20 ], $ type ->enum ());
93
+ }
30
94
}
0 commit comments