@@ -50,7 +50,7 @@ protected function setUp(): void
50
50
$ propertyNameCollectionFactory ->create (Dummy::class, ['enable_getter_setter_extraction ' => true , 'schema_type ' => Schema::TYPE_OUTPUT ])->willReturn (new PropertyNameCollection ());
51
51
$ propertyMetadataFactory = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
52
52
53
- $ definitionNameFactory = new DefinitionNameFactory ([ ' jsonapi ' => true , ' jsonhal ' => true , ' jsonld ' => true ] );
53
+ $ definitionNameFactory = new DefinitionNameFactory ();
54
54
55
55
$ baseSchemaFactory = new BaseSchemaFactory (
56
56
resourceMetadataFactory: $ resourceMetadataFactory ->reveal (),
@@ -87,8 +87,8 @@ public function testHasRootDefinitionKeyBuildSchema(): void
87
87
$ rootDefinitionKey = $ resultSchema ->getRootDefinitionKey ();
88
88
89
89
$ this ->assertTrue (isset ($ definitions [$ rootDefinitionKey ]));
90
- $ this ->assertTrue (isset ($ definitions [$ rootDefinitionKey ]['properties ' ]));
91
- $ properties = $ resultSchema ['definitions ' ][$ rootDefinitionKey ]['properties ' ];
90
+ $ this ->assertTrue (isset ($ definitions [$ rootDefinitionKey ]['allOf ' ][ 0 ][ ' properties ' ]));
91
+ $ properties = $ resultSchema ['definitions ' ][$ rootDefinitionKey ]['allOf ' ][ 0 ][ ' properties ' ];
92
92
$ this ->assertArrayHasKey ('_links ' , $ properties );
93
93
$ this ->assertEquals (
94
94
[
@@ -109,29 +109,26 @@ public function testHasRootDefinitionKeyBuildSchema(): void
109
109
);
110
110
}
111
111
112
- public function testSchemaTypeBuildSchema (): void
112
+ public function testCollection (): void
113
113
{
114
114
$ resultSchema = $ this ->schemaFactory ->buildSchema (Dummy::class, 'jsonhal ' , Schema::TYPE_OUTPUT , new GetCollection ());
115
- $ definitionName = 'Dummy.jsonhal ' ;
116
-
117
115
$ this ->assertNull ($ resultSchema ->getRootDefinitionKey ());
118
- $ this ->assertTrue (isset ($ resultSchema ['properties ' ]));
119
- $ this ->assertArrayHasKey ('_embedded ' , $ resultSchema ['properties ' ]);
120
- $ this ->assertArrayHasKey ('totalItems ' , $ resultSchema ['properties ' ]);
121
- $ this ->assertArrayHasKey ('itemsPerPage ' , $ resultSchema ['properties ' ]);
122
- $ this ->assertArrayHasKey ('_links ' , $ resultSchema ['properties ' ]);
123
- $ properties = $ resultSchema ['definitions ' ][$ definitionName ]['properties ' ];
124
- $ this ->assertArrayHasKey ('_links ' , $ properties );
125
116
126
- $ resultSchema = $ this ->schemaFactory ->buildSchema (Dummy::class, 'jsonhal ' , Schema::TYPE_OUTPUT , null , null , null , true );
117
+ $ this ->assertTrue (isset ($ resultSchema ['definitions ' ]['Dummy.jsonhal ' ]));
118
+ $ this ->assertTrue (isset ($ resultSchema ['definitions ' ]['HalCollectionBaseSchema ' ]));
119
+ $ this ->assertTrue (isset ($ resultSchema ['definitions ' ]['Dummy.jsonhal ' ]));
127
120
128
- $ this ->assertNull ($ resultSchema ->getRootDefinitionKey ());
129
- $ this ->assertTrue (isset ($ resultSchema ['properties ' ]));
130
- $ this ->assertArrayHasKey ('_embedded ' , $ resultSchema ['properties ' ]);
131
- $ this ->assertArrayHasKey ('totalItems ' , $ resultSchema ['properties ' ]);
132
- $ this ->assertArrayHasKey ('itemsPerPage ' , $ resultSchema ['properties ' ]);
133
- $ this ->assertArrayHasKey ('_links ' , $ resultSchema ['properties ' ]);
134
- $ properties = $ resultSchema ['definitions ' ][$ definitionName ]['properties ' ];
135
- $ this ->assertArrayHasKey ('_links ' , $ properties );
121
+ foreach ($ resultSchema ['allOf ' ] as $ schema ) {
122
+ if (isset ($ schema ['$ref ' ])) {
123
+ $ this ->assertEquals ($ schema ['$ref ' ], '#/definitions/HalCollectionBaseSchema ' );
124
+ continue ;
125
+ }
126
+
127
+ $ this ->assertArrayHasKey ('_embedded ' , $ schema ['properties ' ]);
128
+ $ this ->assertEquals ('#/definitions/Dummy.jsonhal ' , $ schema ['properties ' ]['_embedded ' ]['additionalProperties ' ]['items ' ]['$ref ' ]);
129
+ }
130
+
131
+ $ forceCollectionSchema = $ this ->schemaFactory ->buildSchema (Dummy::class, 'jsonhal ' , Schema::TYPE_OUTPUT , null , null , null , true );
132
+ $ this ->assertEquals ($ forceCollectionSchema , $ resultSchema );
136
133
}
137
134
}
0 commit comments