Skip to content

Commit 4118460

Browse files
Upgrade test suite to use generators (#834)
This PR will: - Update all data providers to return `Generator` objects. - Remove file headers with a license reference in favour of the `LICENSE.md` at the root - Remove class docbocks which where defining unused attributes - Add `declare(strict_types=1);` to all test files - Replace class strings with their resp. `::class` constant. - More updates bringing test files to PHP 7.2 level using rector
1 parent 0b25270 commit 4118460

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+3108
-3454
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99
### Changed
1010
- Update test case to current (PHP) standards ([#831](https://github.com/jsonrainbow/json-schema/pull/831))
11+
- Upgrade test suite to use generators ([#834](https://github.com/jsonrainbow/json-schema/pull/834))
1112

1213
## [6.4.2] - 2025-06-03
1314
### Fixed

tests/ConstraintErrorTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<?php
22

3-
/*
4-
* This file is part of the JsonSchema package.
5-
*
6-
* For the full copyright and license information, please view the LICENSE
7-
* file that was distributed with this source code.
8-
*/
3+
declare(strict_types=1);
94

105
namespace JsonSchema\Tests;
116

@@ -24,7 +19,7 @@ public function testGetInvalidMessage(): void
2419
{
2520
$e = ConstraintError::MISSING_ERROR();
2621

27-
$this->expectException('\JsonSchema\Exception\InvalidArgumentException');
22+
$this->expectException(\JsonSchema\Exception\InvalidArgumentException::class);
2823
$this->expectExceptionMessage('Missing error message for missingError');
2924

3025
$e->getMessage();

tests/Constraints/AdditionalPropertiesTest.php

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<?php
22

3-
/*
4-
* This file is part of the JsonSchema package.
5-
*
6-
* For the full copyright and license information, please view the LICENSE
7-
* file that was distributed with this source code.
8-
*/
3+
declare(strict_types=1);
94

105
namespace JsonSchema\Tests\Constraints;
116

@@ -15,10 +10,9 @@ class AdditionalPropertiesTest extends BaseTestCase
1510
{
1611
protected $validateSchema = true;
1712

18-
public function getInvalidTests(): array
13+
public function getInvalidTests(): \Generator
1914
{
20-
return [
21-
[
15+
yield [
2216
'{
2317
"prop":"1",
2418
"patternProp":"3",
@@ -49,8 +43,8 @@ public function getInvalidTests(): array
4943
'context' => Validator::ERROR_DOCUMENT_VALIDATION
5044
]
5145
]
52-
],
53-
[
46+
];
47+
yield [
5448
'{
5549
"prop":"1",
5650
"additionalProp":"2"
@@ -62,8 +56,8 @@ public function getInvalidTests(): array
6256
},
6357
"additionalProperties": false
6458
}'
65-
],
66-
[
59+
];
60+
yield [
6761
'{
6862
"prop":"1",
6963
"additionalProp":2
@@ -75,8 +69,8 @@ public function getInvalidTests(): array
7569
},
7670
"additionalProperties": {"type":"string"}
7771
}'
78-
],
79-
[
72+
];
73+
yield [
8074
'{
8175
"prop":"1",
8276
"additionalProp":2
@@ -88,8 +82,8 @@ public function getInvalidTests(): array
8882
},
8983
"additionalProperties": {"type":"string"}
9084
}'
91-
],
92-
[
85+
];
86+
yield [
9387
'{
9488
"prop1": "a",
9589
"prop2": "b"
@@ -100,8 +94,8 @@ public function getInvalidTests(): array
10094
"type": "boolean"
10195
}
10296
}'
103-
],
104-
[
97+
];
98+
yield [
10599
'{
106100
"prop1": "a",
107101
"prop2": "b"
@@ -110,14 +104,12 @@ public function getInvalidTests(): array
110104
"type": "object",
111105
"additionalProperties": false
112106
}'
113-
],
114-
];
107+
];
115108
}
116109

117-
public function getValidTests(): array
110+
public function getValidTests(): \Generator
118111
{
119-
return [
120-
[
112+
yield [
121113
'{
122114
"prop":"1",
123115
"additionalProp":"2"
@@ -128,8 +120,8 @@ public function getValidTests(): array
128120
"prop":{"type":"string"}
129121
}
130122
}'
131-
],
132-
[
123+
];
124+
yield [
133125
'{
134126
"prop":"1",
135127
"additionalProp":"2"
@@ -140,8 +132,8 @@ public function getValidTests(): array
140132
"prop":{"type":"string"}
141133
}
142134
}'
143-
],
144-
[
135+
];
136+
yield [
145137
'{
146138
"prop":"1",
147139
"additionalProp":"2"
@@ -153,8 +145,8 @@ public function getValidTests(): array
153145
},
154146
"additionalProperties": {"type":"string"}
155147
}'
156-
],
157-
[
148+
];
149+
yield [
158150
'{
159151
"prop":"1",
160152
"additionalProp":[]
@@ -166,8 +158,8 @@ public function getValidTests(): array
166158
},
167159
"additionalProperties": true
168160
}'
169-
],
170-
[
161+
];
162+
yield [
171163
'{
172164
"prop1": "a",
173165
"prop2": "b"
@@ -178,8 +170,8 @@ public function getValidTests(): array
178170
"type": "string"
179171
}
180172
}'
181-
],
182-
[
173+
];
174+
yield [
183175
'{
184176
"prop1": "a",
185177
"prop2": "b"
@@ -188,8 +180,8 @@ public function getValidTests(): array
188180
"type": "object",
189181
"additionalProperties": true
190182
}'
191-
],
192-
'additional property casted into int when actually is numeric string (#784)' => [
183+
];
184+
yield 'additional property casted into int when actually is numeric string (#784)' => [
193185
'{
194186
"prop1": {
195187
"123": "a"
@@ -206,7 +198,6 @@ public function getValidTests(): array
206198
}
207199
}
208200
}'
209-
],
210-
];
201+
];
211202
}
212203
}

0 commit comments

Comments
 (0)