@@ -19,40 +19,35 @@ public function testGet() {
19
19
20
20
$ this ->post ($ this ->getSampleDataset (1 ));
21
21
22
- $ responseSchema = $ this ->spec ->paths ->{'/api/1/metastore/schemas/{schema_id}/items ' }
23
- ->get ->responses ->{"200 " }->content ->{"application/json " }->schema ;
24
22
$ response = $ this ->httpClient ->request ('GET ' , $ this ->endpoint );
25
23
$ responseBody = json_decode ($ response ->getBody ());
26
24
$ this ->assertEquals (2 , count ($ responseBody ));
27
25
$ this ->assertTrue (is_object ($ responseBody [1 ]));
28
- $ this ->assertJsonIsValid ($ responseSchema , $ responseBody );
26
+ // Have to use this path because the endpoint as added is not in the spec.
27
+ // @todo Simplify dataset vs {schema_id} items in the spec.
28
+ $ this ->validator ->validate ($ response , "api/1/metastore/schemas/{schema_id}/items " , 'get ' );
29
29
30
30
$ datasetId = 'abc-123 ' ;
31
31
$ response = $ this ->httpClient ->get ("$ this ->endpoint / $ datasetId " , [
32
32
RequestOptions::HTTP_ERRORS => FALSE ,
33
33
]);
34
34
$ this ->assertEquals (404 , $ response ->getStatusCode ());
35
35
36
- $ responseBody = json_decode ($ response ->getBody ());
37
- $ responseSchema = $ this ->spec ->components ->responses ->{"404IdNotFound " };
38
- $ this ->assertJsonIsValid ($ responseSchema , $ responseBody );
36
+ $ this ->validator ->validate ($ response , "$ this ->endpoint / $ datasetId " , 'get ' );
39
37
}
40
38
41
39
public function testPost () {
42
40
$ dataset = $ this ->getSampleDataset ();
43
41
$ response = $ this ->post ($ dataset );
44
42
$ this ->assertEquals (201 , $ response ->getStatusCode ());
45
43
46
- $ responseBody = json_decode ($ response ->getBody ());
47
- $ responseSchema = $ this ->spec ->components ->responses ->{"201MetadataCreated " }->content ->{"application/json " }->schema ;
48
-
49
- $ this ->assertJsonIsValid ($ responseSchema , $ responseBody );
44
+ $ this ->validator ->validate ($ response , $ this ->endpoint , 'post ' );
50
45
$ this ->assertDatasetGet ($ dataset );
51
46
52
47
// Now try a duplicate.
53
48
$ response = $ this ->post ($ dataset , FALSE );
54
49
$ this ->assertEquals (409 , $ response ->getStatusCode ());
55
- // @todo Fuly validate response once documented.
50
+ $ this -> validator -> validate ( $ response, $ this -> endpoint , ' post ' );
56
51
}
57
52
58
53
public function testPatch () {
@@ -68,9 +63,7 @@ public function testPatch() {
68
63
69
64
$ this ->assertEquals (200 , $ response ->getStatusCode ());
70
65
71
- $ responseBody = json_decode ($ response ->getBody ());
72
- $ responseSchema = $ this ->spec ->components ->responses ->{"201MetadataCreated " }->content ->{"application/json " }->schema ;
73
- $ this ->assertJsonIsValid ($ responseSchema , $ responseBody );
66
+ $ this ->validator ->validate ($ response , "$ this ->endpoint / $ datasetId " , 'patch ' );
74
67
75
68
$ dataset ->title = $ newTitle ->title ;
76
69
$ this ->assertDatasetGet ($ dataset );
@@ -86,10 +79,8 @@ public function testPatch() {
86
79
]);
87
80
88
81
$ this ->assertEquals (412 , $ response ->getStatusCode ());
82
+ $ this ->validator ->validate ($ response , "$ this ->endpoint / $ datasetId " , 'patch ' );
89
83
90
- $ responseBody = json_decode ($ response ->getBody ());
91
- $ responseSchema = $ this ->spec ->components ->responses ->{"412MetadataObjectNotFound " };
92
- $ this ->assertJsonIsValid ($ responseSchema , $ responseBody );
93
84
}
94
85
95
86
public function testPut () {
@@ -105,9 +96,7 @@ public function testPut() {
105
96
RequestOptions::AUTH => $ this ->auth ,
106
97
]);
107
98
$ this ->assertEquals (200 , $ response ->getStatusCode ());
108
- $ responseBody = json_decode ($ response ->getBody ());
109
- $ responseSchema = $ this ->spec ->components ->responses ->{"201MetadataCreated " }->content ->{"application/json " }->schema ;
110
- $ this ->assertJsonIsValid ($ responseSchema , $ responseBody );
99
+ $ this ->validator ->validate ($ response , "$ this ->endpoint / $ datasetId " , 'put ' );
111
100
$ this ->assertDatasetGet ($ newDataset );
112
101
113
102
// Now try with mismatched identifiers.
@@ -118,15 +107,15 @@ public function testPut() {
118
107
RequestOptions::HTTP_ERRORS => FALSE ,
119
108
]);
120
109
$ this ->assertEquals (409 , $ response ->getStatusCode ());
110
+ $ this ->validator ->validate ($ response , "$ this ->endpoint / $ datasetId " , 'put ' );
121
111
}
122
112
123
113
private function assertDatasetGet ($ dataset ) {
124
114
$ id = $ dataset ->identifier ;
125
- $ responseSchema = $ this ->spec ->components ->schemas ->dataset ;
126
115
$ response = $ this ->httpClient ->get ("$ this ->endpoint / $ id " );
127
116
$ responseBody = json_decode ($ response ->getBody ());
128
117
$ this ->assertEquals (200 , $ response ->getStatusCode ());
129
- $ this ->assertJsonIsValid ( $ responseSchema , $ responseBody );
118
+ $ this ->validator -> validate ( $ response , " $ this -> endpoint / $ id " , ' get ' );
130
119
$ this ->assertEquals ($ dataset , $ responseBody );
131
120
}
132
121
0 commit comments