11<?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+
29declare (strict_types=1 );
310
411namespace OpenCodeModelingTest \JsonSchemaToPhp \Type ;
512
13+ use OpenCodeModeling \JsonSchemaToPhp \Type \IntegerType ;
14+ use OpenCodeModeling \JsonSchemaToPhp \Type \NumberType ;
615use OpenCodeModeling \JsonSchemaToPhp \Type \ObjectType ;
16+ use OpenCodeModeling \JsonSchemaToPhp \Type \StringType ;
717use OpenCodeModeling \JsonSchemaToPhp \Type \Type ;
818use PHPUnit \Framework \TestCase ;
919
@@ -27,4 +37,58 @@ public function it_supports_shorthand_definition(): void
2737 $ this ->assertEquals ('Person ' , $ type ->name ());
2838 $ this ->assertEquals ('Person ' , $ type ->title ());
2939 }
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+ }
3094}
0 commit comments