-
Notifications
You must be signed in to change notification settings - Fork 21
/
SerializerTest.php
93 lines (74 loc) · 2.43 KB
/
SerializerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
declare(strict_types=1);
// SPDX-FileCopyrightText: 2015-2023 Artur Weigandt https://wlabs.de/kontakt
//
// SPDX-License-Identifier: GPL-3.0-or-later
namespace Art4\JsonApiClient\Tests\Functional;
use Art4\JsonApiClient\Input\RequestStringInput;
use Art4\JsonApiClient\Input\ResponseStringInput;
use Art4\JsonApiClient\Manager\ErrorAbortManager;
use Art4\JsonApiClient\Serializer\ArraySerializer;
use Art4\JsonApiClient\Tests\Fixtures\HelperTrait;
use Art4\JsonApiClient\V1\Factory;
use Exception;
use PHPUnit\Framework\TestCase;
class SerializerTest extends TestCase
{
use HelperTrait;
/**
* Provide JSON API data
*
* @return array<array<string|bool>>
*/
public static function jsonapiDataProvider(): array
{
$path = str_replace('/', \DIRECTORY_SEPARATOR, __DIR__ . '/../files/');
$files = [];
$requestFiles = [
'14_create_resource_without_id.json',
'15_create_resource_without_id.json',
];
$filenames = glob($path . '*.json');
if ($filenames === false) {
throw new Exception('Error while getting all json files.');
}
foreach ($filenames as $file) {
$filename = str_replace($path, '', $file);
// Ignore files with errors
if (in_array($filename, [
'16_type_and_id_as_integer.json',
])) {
continue;
}
$files[] = [
$filename,
in_array($filename, $requestFiles),
];
}
return $files;
}
/**
* @dataProvider jsonapiDataProvider
*/
public function testParseJsonapiDataWithErrorAbortManager(string $filename, bool $isRequest): void
{
$manager = new ErrorAbortManager(new Factory());
$string = $this->getJsonString($filename);
if ($isRequest) {
$input = new RequestStringInput($string);
} else {
$input = new ResponseStringInput($string);
}
$document = $manager->parse($input);
$expected = json_decode($string, true);
// TODO #90: Add support for unknown properties
unset($expected['jsonapi']['ext']);
unset($expected['jsonapi']['profile']);
// Test full array
$this->assertEquals(
$expected,
(new ArraySerializer(['recursive' => true]))->serialize($document),
$filename
);
}
}