Skip to content

Commit 63b0368

Browse files
authored
Merge pull request #460 from kbsali/fix-php-8.6-tests
Fix tests for 8.6
2 parents 00d823f + f67a8fc commit 63b0368

15 files changed

Lines changed: 384 additions & 70 deletions

File tree

src/Redmine/Serializer/XmlSerializer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,18 @@ private function deserialize(string $encoded): void
7777
$this->deserialized = new SimpleXMLElement($encoded);
7878
} catch (Throwable $e) {
7979
$errors = [];
80+
$code = $e->getCode();
8081

8182
foreach (libxml_get_errors() as $error) {
8283
$errors[] = $error->message;
84+
$code = max($code, $error->level);
8385
}
8486

8587
libxml_clear_errors();
8688

8789
throw new SerializerException(
8890
'Catched errors: "' . implode('", "', $errors) . '" while decoding XML: ' . $encoded,
89-
$e->getCode(),
91+
$code,
9092
$e,
9193
);
9294
} finally {

tests/Unit/Api/AbstractApi/GetTest.php

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testGetWithHttpClient(): void
4949
* @dataProvider getJsonDecodingFromGetMethodData
5050
*/
5151
#[DataProvider('getJsonDecodingFromGetMethodData')]
52-
public function testJsonDecodingFromGetMethod(string $response, ?bool $decode, $expected): void
52+
public function testJsonDecodingFromGetMethod(string $response, ?bool $shouldDecode, $expected): void
5353
{
5454
$client = $this->createStub(Client::class);
5555
$client->method('getLastResponseBody')->willReturn($response);
@@ -63,8 +63,8 @@ public function testJsonDecodingFromGetMethod(string $response, ?bool $decode, $
6363
}
6464

6565
// Perform the tests
66-
if (is_bool($decode)) {
67-
$this->assertSame($expected, $method->invoke($api, 'path', $decode));
66+
if (is_bool($shouldDecode)) {
67+
$this->assertSame($expected, $method->invoke($api, 'path', $shouldDecode));
6868
} else {
6969
$this->assertSame($expected, $method->invoke($api, 'path'));
7070
}
@@ -73,12 +73,37 @@ public function testJsonDecodingFromGetMethod(string $response, ?bool $decode, $
7373
public static function getJsonDecodingFromGetMethodData(): array
7474
{
7575
return [
76-
'test decode by default' => ['{"foo_bar": 12345}', null, ['foo_bar' => 12345]],
77-
'test decode by default, JSON decode: false' => ['{"foo_bar": 12345}', false, '{"foo_bar": 12345}'],
78-
'test decode by default, JSON decode: true' => ['{"foo_bar": 12345}', true, ['foo_bar' => 12345]],
79-
'Empty body, JSON decode: false' => ['', false, false],
80-
'Empty body, JSON decode: true' => ['', true, false],
81-
'test invalid JSON' => ['{"foo_bar":', true, 'Error decoding body as JSON: Syntax error'],
76+
'test decode by default' => [
77+
'{"foo_bar": 12345}',
78+
null,
79+
['foo_bar' => 12345],
80+
],
81+
'test decode by default, JSON decode: false' => [
82+
'{"foo_bar": 12345}',
83+
false,
84+
'{"foo_bar": 12345}',
85+
],
86+
'test decode by default, JSON decode: true' => [
87+
'{"foo_bar": 12345}',
88+
true,
89+
['foo_bar' => 12345],
90+
],
91+
'Empty body, JSON decode: false' => [
92+
'',
93+
false,
94+
false,
95+
],
96+
'Empty body, JSON decode: true' => [
97+
'',
98+
true,
99+
false,
100+
],
101+
'test invalid JSON' => [
102+
'{"foo_bar":',
103+
true,
104+
/** @phpstan-ignore smaller.alwaysTrue(Remove this line after release of PHP 8.6) */
105+
(PHP_VERSION_ID < 80600) ? 'Error decoding body as JSON: Syntax error' : 'Error decoding body as JSON: Syntax error near location 1:12',
106+
],
82107
];
83108
}
84109

tests/Unit/Api/Attachment/ShowTest.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,32 @@ public function testShowReturnsCorrectResponse($id, string $expectedPath, string
4040
public static function getShowData(): array
4141
{
4242
return [
43-
'array response with integer id' => [5, '/attachments/5.json', '["API Response"]', ['API Response']],
44-
'array response with string id' => ['5', '/attachments/5.json', '["API Response"]', ['API Response']],
45-
'string response' => [5, '/attachments/5.json', 'string', 'Error decoding body as JSON: Syntax error'],
46-
'false response' => [5, '/attachments/5.json', '', false],
43+
'array response with integer id' => [
44+
5,
45+
'/attachments/5.json',
46+
'["API Response"]',
47+
['API Response'],
48+
],
49+
'array response with string id' =>
50+
[
51+
'5',
52+
'/attachments/5.json',
53+
'["API Response"]',
54+
['API Response'],
55+
],
56+
'string response' => [
57+
5,
58+
'/attachments/5.json',
59+
'string',
60+
/** @phpstan-ignore smaller.alwaysTrue(Remove this line after release of PHP 8.6) */
61+
(PHP_VERSION_ID < 80600) ? 'Error decoding body as JSON: Syntax error' : 'Error decoding body as JSON: Syntax error near location 1:1',
62+
],
63+
'false response' => [
64+
5,
65+
'/attachments/5.json',
66+
'',
67+
false,
68+
],
4769
];
4870
}
4971
}

tests/Unit/Api/Group/ShowTest.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,42 @@ public function testShowReturnsCorrectResponse($groupId, array $params, string $
4040
public static function getShowData(): array
4141
{
4242
return [
43-
'array response with integer id' => [5, [], '/groups/5.json', '["API Response"]', ['API Response']],
44-
'array response with string id' => ['5', [], '/groups/5.json', '["API Response"]', ['API Response']],
45-
'array response with parameters' => [5, ['include' => ['parameter1', 'parameter2'], 'not-used'], '/groups/5.json?include%5B%5D=parameter1&include%5B%5D=parameter2&0=not-used', '["API Response"]', ['API Response']],
46-
'string response' => [5, [], '/groups/5.json', 'string', 'Error decoding body as JSON: Syntax error'],
47-
'false response' => [5, [], '/groups/5.json', '', false],
43+
'array response with integer id' => [
44+
5,
45+
[],
46+
'/groups/5.json',
47+
'["API Response"]',
48+
['API Response'],
49+
],
50+
'array response with string id' => [
51+
'5',
52+
[],
53+
'/groups/5.json',
54+
'["API Response"]',
55+
['API Response'],
56+
],
57+
'array response with parameters' => [
58+
5,
59+
['include' => ['parameter1', 'parameter2'], 'not-used'],
60+
'/groups/5.json?include%5B%5D=parameter1&include%5B%5D=parameter2&0=not-used',
61+
'["API Response"]',
62+
['API Response'],
63+
],
64+
'string response' => [
65+
5,
66+
[],
67+
'/groups/5.json',
68+
'string',
69+
/** @phpstan-ignore smaller.alwaysTrue(Remove this line after release of PHP 8.6) */
70+
(PHP_VERSION_ID < 80600) ? 'Error decoding body as JSON: Syntax error' : 'Error decoding body as JSON: Syntax error near location 1:1',
71+
],
72+
'false response' => [
73+
5,
74+
[],
75+
'/groups/5.json',
76+
'',
77+
false,
78+
],
4879
];
4980
}
5081
}

tests/Unit/Api/Issue/ShowTest.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,42 @@ public function testShowReturnsCorrectResponse($issueId, array $params, string $
4040
public static function getShowData(): array
4141
{
4242
return [
43-
'array response with integer id' => [5, [], '/issues/5.json', '["API Response"]', ['API Response']],
44-
'array response with string id' => ['5', [], '/issues/5.json', '["API Response"]', ['API Response']],
45-
'array response with parameters' => [5, ['include' => ['parameter1', 'parameter2'], 'not-used'], '/issues/5.json?include=parameter1%2Cparameter2&0=not-used', '["API Response"]', ['API Response']],
46-
'string response' => [5, [], '/issues/5.json', 'string', 'Error decoding body as JSON: Syntax error'],
47-
'false response' => [5, [], '/issues/5.json', '', false],
43+
'array response with integer id' => [
44+
5,
45+
[],
46+
'/issues/5.json',
47+
'["API Response"]',
48+
['API Response'],
49+
],
50+
'array response with string id' => [
51+
'5',
52+
[],
53+
'/issues/5.json',
54+
'["API Response"]',
55+
['API Response'],
56+
],
57+
'array response with parameters' => [
58+
5,
59+
['include' => ['parameter1', 'parameter2'], 'not-used'],
60+
'/issues/5.json?include=parameter1%2Cparameter2&0=not-used',
61+
'["API Response"]',
62+
['API Response'],
63+
],
64+
'string response' => [
65+
5,
66+
[],
67+
'/issues/5.json',
68+
'string',
69+
/** @phpstan-ignore smaller.alwaysTrue(Remove this line after release of PHP 8.6) */
70+
(PHP_VERSION_ID < 80600) ? 'Error decoding body as JSON: Syntax error' : 'Error decoding body as JSON: Syntax error near location 1:1',
71+
],
72+
'false response' => [
73+
5,
74+
[],
75+
'/issues/5.json',
76+
'',
77+
false,
78+
],
4879
];
4980
}
5081
}

tests/Unit/Api/IssueCategory/ShowTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,31 @@ public function testShowReturnsCorrectResponse($id, string $expectedPath, string
4040
public static function getShowData(): array
4141
{
4242
return [
43-
'array response with integer id' => [5, '/issue_categories/5.json', '["API Response"]', ['API Response']],
44-
'array response with string id' => ['5', '/issue_categories/5.json', '["API Response"]', ['API Response']],
45-
'string response' => [5, '/issue_categories/5.json', 'string', 'Error decoding body as JSON: Syntax error'],
46-
'false response' => [5, '/issue_categories/5.json', '', false],
43+
'array response with integer id' => [
44+
5,
45+
'/issue_categories/5.json',
46+
'["API Response"]',
47+
['API Response'],
48+
],
49+
'array response with string id' => [
50+
'5',
51+
'/issue_categories/5.json',
52+
'["API Response"]',
53+
['API Response'],
54+
],
55+
'string response' => [
56+
5,
57+
'/issue_categories/5.json',
58+
'string',
59+
/** @phpstan-ignore smaller.alwaysTrue(Remove this line after release of PHP 8.6) */
60+
(PHP_VERSION_ID < 80600) ? 'Error decoding body as JSON: Syntax error' : 'Error decoding body as JSON: Syntax error near location 1:1',
61+
],
62+
'false response' => [
63+
5,
64+
'/issue_categories/5.json',
65+
'',
66+
false,
67+
],
4768
];
4869
}
4970
}

tests/Unit/Api/IssueRelation/ShowTest.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,36 @@ public function testShowReturnsCorrectResponse($id, string $expectedPath, string
4040
public static function getShowData(): array
4141
{
4242
return [
43-
'array response with integer id' => [5, '/relations/5.json', '{"relation":{"child":[5,2,3]}}', ['child' => [5, 2, 3]]],
44-
'array response with string id' => ['5', '/relations/5.json', '{"relation":{"child":[5,2,3]}}', ['child' => [5, 2, 3]]],
45-
'array response on object without relation key error' => [5, '/relations/5.json', '{}', []],
46-
'array response on string error' => [5, '/relations/5.json', 'string', []],
47-
'array response on empty error' => [5, '/relations/5.json', '', []],
43+
'array response with integer id' => [
44+
5,
45+
'/relations/5.json',
46+
'{"relation":{"child":[5,2,3]}}',
47+
['child' => [5, 2, 3]],
48+
],
49+
'array response with string id' => [
50+
'5',
51+
'/relations/5.json',
52+
'{"relation":{"child":[5,2,3]}}',
53+
['child' => [5, 2, 3]],
54+
],
55+
'array response on object without relation key error' => [
56+
5,
57+
'/relations/5.json',
58+
'{}',
59+
[],
60+
],
61+
'array response on string error' => [
62+
5,
63+
'/relations/5.json',
64+
'string',
65+
[],
66+
],
67+
'array response on empty error' => [
68+
5,
69+
'/relations/5.json',
70+
'',
71+
[],
72+
],
4873
];
4974
}
5075
}

tests/Unit/Api/Project/ShowTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public static function getShowData(): array
8888
[],
8989
'/projects/5.json?include=trackers%2Cissue_categories%2Cattachments%2Crelations',
9090
'string',
91-
'Error decoding body as JSON: Syntax error',
91+
/** @phpstan-ignore smaller.alwaysTrue(Remove this line after release of PHP 8.6) */
92+
(PHP_VERSION_ID < 80600) ? 'Error decoding body as JSON: Syntax error' : 'Error decoding body as JSON: Syntax error near location 1:1',
9293
],
9394
'false response' => [
9495
5,

tests/Unit/Api/Role/ShowTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,31 @@ public function testShowReturnsCorrectResponse($id, string $expectedPath, string
4040
public static function getShowData(): array
4141
{
4242
return [
43-
'array response with integer id' => [5, '/roles/5.json', '["API Response"]', ['API Response']],
44-
'array response with string id' => ['5', '/roles/5.json', '["API Response"]', ['API Response']],
45-
'string response' => [5, '/roles/5.json', 'string', 'Error decoding body as JSON: Syntax error'],
46-
'false response' => [5, '/roles/5.json', '', false],
43+
'array response with integer id' => [
44+
5,
45+
'/roles/5.json',
46+
'["API Response"]',
47+
['API Response'],
48+
],
49+
'array response with string id' => [
50+
'5',
51+
'/roles/5.json',
52+
'["API Response"]',
53+
['API Response'],
54+
],
55+
'string response' => [
56+
5,
57+
'/roles/5.json',
58+
'string',
59+
/** @phpstan-ignore smaller.alwaysTrue(Remove this line after release of PHP 8.6) */
60+
(PHP_VERSION_ID < 80600) ? 'Error decoding body as JSON: Syntax error' : 'Error decoding body as JSON: Syntax error near location 1:1',
61+
],
62+
'false response' => [
63+
5,
64+
'/roles/5.json',
65+
'',
66+
false,
67+
],
4768
];
4869
}
4970
}

tests/Unit/Api/TimeEntry/ShowTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,31 @@ public function testShowReturnsCorrectResponse($id, string $expectedPath, string
4040
public static function getShowData(): array
4141
{
4242
return [
43-
'array response with integer id' => [5, '/time_entries/5.json', '["API Response"]', ['API Response']],
44-
'array response with string id' => ['5', '/time_entries/5.json', '["API Response"]', ['API Response']],
45-
'string response' => [5, '/time_entries/5.json', 'string', 'Error decoding body as JSON: Syntax error'],
46-
'false response' => [5, '/time_entries/5.json', '', false],
43+
'array response with integer id' => [
44+
5,
45+
'/time_entries/5.json',
46+
'["API Response"]',
47+
['API Response'],
48+
],
49+
'array response with string id' => [
50+
'5',
51+
'/time_entries/5.json',
52+
'["API Response"]',
53+
['API Response'],
54+
],
55+
'string response' => [
56+
5,
57+
'/time_entries/5.json',
58+
'string',
59+
/** @phpstan-ignore smaller.alwaysTrue(Remove this line after release of PHP 8.6) */
60+
(PHP_VERSION_ID < 80600) ? 'Error decoding body as JSON: Syntax error' : 'Error decoding body as JSON: Syntax error near location 1:1',
61+
],
62+
'false response' => [
63+
5,
64+
'/time_entries/5.json',
65+
'',
66+
false,
67+
],
4768
];
4869
}
4970
}

0 commit comments

Comments
 (0)