Skip to content

Commit ebeb1b7

Browse files
committed
Add parsing tests for atomic extension
1 parent 1eb644a commit ebeb1b7

7 files changed

+63
-24
lines changed

tests/Functional/ParsingTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function testParseSimpleResourceWithDifferentParser(callable $parser): vo
6565
$this->assertFalse($document->has('meta'));
6666
$this->assertFalse($document->has('jsonapi'));
6767
$this->assertFalse($document->has('links'));
68+
$this->assertFalse($document->has('relationships'));
6869
$this->assertFalse($document->has('included'));
6970
$this->assertTrue($document->has('data'));
7071

@@ -76,9 +77,12 @@ public function testParseSimpleResourceWithDifferentParser(callable $parser): vo
7677
$this->assertTrue($resource->has('id'));
7778
$this->assertSame($resource->get('id'), '1');
7879
$this->assertTrue($resource->has('attributes'));
79-
$this->assertInstanceOf(Attributes::class, $resource->get('attributes'));
80-
$this->assertTrue($resource->has('relationships'));
81-
$this->assertInstanceOf(RelationshipCollection::class, $resource->get('relationships'));
80+
81+
$attributes = $resource->get('attributes');
82+
83+
$this->assertInstanceOf(Attributes::class, $attributes);
84+
$this->assertTrue($attributes->has('title'));
85+
$this->assertSame($attributes->get('title'), 'JSON API paints my bikeshed!');
8286
}
8387

8488
public function testParseSimpleResourceIdentifier(): void

tests/Functional/SerializerTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function jsonapiDataProvider(): array
4747
foreach ($filenames as $file) {
4848
$filename = str_replace($path, '', $file);
4949

50-
$files[] = [
50+
$files[$filename] = [
5151
$filename,
5252
in_array($filename, $requestFiles),
5353
];
@@ -71,12 +71,10 @@ public function testParseJsonapiDataWithErrorAbortManager(string $filename, bool
7171

7272
$document = $manager->parse($input);
7373

74-
$expected = json_decode($string, true);
75-
7674
// Test full array
77-
$this->assertEquals(
78-
$expected,
79-
(new ArraySerializer(['recursive' => true]))->serialize($document),
75+
$this->assertJsonStringEqualsJsonString(
76+
$string,
77+
json_encode((new ArraySerializer(['recursive' => true]))->serialize($document), JSON_PRETTY_PRINT),
8078
$filename
8179
);
8280
}

tests/files/01_simple_resource.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"type": "articles",
44
"id": "1",
55
"attributes": {
6-
},
7-
"relationships": {
6+
"title": "JSON API paints my bikeshed!"
87
}
98
}
10-
}
9+
}

tests/files/02_simple_resource_identifier.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"type": "articles",
44
"id": "1"
55
}
6-
}
6+
}
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
2-
"meta": {},
3-
"jsonapi": {
4-
"version": "1.1",
5-
"ext": [
6-
"https://jsonapi.org/ext/atomic"
7-
],
8-
"profile": [
9-
"http://example.com/profiles/flexible-pagination",
10-
"http://example.com/profiles/resource-versioning"
11-
]
12-
}
2+
"meta": {
3+
"note": "BC 1.0: A document MUST contain at least one of the following top-level members: data, errors, meta"
4+
},
5+
"jsonapi": {
6+
"version": "1.1",
7+
"ext": [
8+
"https://jsonapi.org/ext/atomic"
9+
],
10+
"profile": [
11+
"http://example.com/profiles/flexible-pagination",
12+
"http://example.com/profiles/resource-versioning"
13+
]
1314
}
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"atomic:operations": [
3+
{
4+
"op": "add",
5+
"href": "/blogPosts",
6+
"data": {
7+
"type": "articles",
8+
"attributes": {
9+
"title": "JSON API paints my bikeshed!"
10+
}
11+
}
12+
}
13+
],
14+
"meta": {
15+
"note": "BC 1.0: A document MUST contain at least one of the following top-level members: data, errors, meta"
16+
}
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"atomic:results": [
3+
{
4+
"data": {
5+
"links": {
6+
"self": "http://example.com/blogPosts/13"
7+
},
8+
"type": "articles",
9+
"id": "13",
10+
"attributes": {
11+
"title": "JSON API paints my bikeshed!"
12+
}
13+
}
14+
}
15+
],
16+
"meta": {
17+
"note": "BC 1.0: A document MUST contain at least one of the following top-level members: data, errors, meta"
18+
}
19+
}

0 commit comments

Comments
 (0)