Skip to content

Commit 7dcafcd

Browse files
committed
refactor: Add return types in the test suite
1 parent cddbef1 commit 7dcafcd

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

+234
-273
lines changed

tests/ConstraintErrorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
class ConstraintErrorTest extends TestCase
1616
{
17-
public function testGetValidMessage()
17+
public function testGetValidMessage(): void
1818
{
1919
$e = ConstraintError::ALL_OF();
2020
$this->assertEquals('Failed to match all schemas', $e->getMessage());
2121
}
2222

23-
public function testGetInvalidMessage()
23+
public function testGetInvalidMessage(): void
2424
{
2525
$e = ConstraintError::MISSING_ERROR();
2626

tests/Constraints/AdditionalPropertiesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AdditionalPropertiesTest extends BaseTestCase
1515
{
1616
protected $validateSchema = true;
1717

18-
public function getInvalidTests()
18+
public function getInvalidTests(): array
1919
{
2020
return [
2121
[
@@ -114,7 +114,7 @@ public function getInvalidTests()
114114
];
115115
}
116116

117-
public function getValidTests()
117+
public function getValidTests(): array
118118
{
119119
return [
120120
[

tests/Constraints/ArraysTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ArraysTest extends BaseTestCase
1313
{
1414
protected $validateSchema = true;
1515

16-
public function getInvalidTests()
16+
public function getInvalidTests(): array
1717
{
1818
return [
1919
[
@@ -120,7 +120,7 @@ public function getInvalidTests()
120120
];
121121
}
122122

123-
public function getValidTests()
123+
public function getValidTests(): array
124124
{
125125
return [
126126
[

tests/Constraints/BaseTestCase.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class BaseTestCase extends VeryBaseTestCase
2626
/**
2727
* @dataProvider getInvalidTests
2828
*/
29-
public function testInvalidCases($input, $schema, $checkMode = Constraint::CHECK_MODE_NORMAL, $errors = [])
29+
public function testInvalidCases($input, $schema, $checkMode = Constraint::CHECK_MODE_NORMAL, $errors = []): void
3030
{
3131
$checkMode = $checkMode === null ? Constraint::CHECK_MODE_NORMAL : $checkMode;
3232
if ($this->validateSchema) {
@@ -55,7 +55,7 @@ public function testInvalidCases($input, $schema, $checkMode = Constraint::CHECK
5555
/**
5656
* @dataProvider getInvalidForAssocTests
5757
*/
58-
public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST, $errors = [])
58+
public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST, $errors = []): void
5959
{
6060
$checkMode = $checkMode === null ? Constraint::CHECK_MODE_TYPE_CAST : $checkMode;
6161
if ($this->validateSchema) {
@@ -87,7 +87,7 @@ public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constra
8787
/**
8888
* @dataProvider getValidTests
8989
*/
90-
public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_MODE_NORMAL)
90+
public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_MODE_NORMAL): void
9191
{
9292
if ($this->validateSchema) {
9393
$checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA;
@@ -109,7 +109,7 @@ public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_M
109109
/**
110110
* @dataProvider getValidForAssocTests
111111
*/
112-
public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST)
112+
public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST): void
113113
{
114114
if ($this->validateSchema) {
115115
$checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA;
@@ -133,28 +133,16 @@ public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constrain
133133
$this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true));
134134
}
135135

136-
/**
137-
* @return array[]
138-
*/
139-
abstract public function getValidTests();
136+
abstract public function getValidTests(): array;
140137

141-
/**
142-
* @return array[]
143-
*/
144-
public function getValidForAssocTests()
138+
public function getValidForAssocTests(): array
145139
{
146140
return $this->getValidTests();
147141
}
148142

149-
/**
150-
* @return array[]
151-
*/
152-
abstract public function getInvalidTests();
143+
abstract public function getInvalidTests(): array;
153144

154-
/**
155-
* @return array[]
156-
*/
157-
public function getInvalidForAssocTests()
145+
public function getInvalidForAssocTests(): array
158146
{
159147
return $this->getInvalidTests();
160148
}

tests/Constraints/BasicTypesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BasicTypesTest extends BaseTestCase
1414
protected $schemaSpec = 'http://json-schema.org/draft-03/schema#';
1515
protected $validateSchema = true;
1616

17-
public function getInvalidTests()
17+
public function getInvalidTests(): array
1818
{
1919
return [
2020
[
@@ -104,7 +104,7 @@ public function getInvalidTests()
104104
];
105105
}
106106

107-
public function getValidTests()
107+
public function getValidTests(): array
108108
{
109109
return [
110110
[

tests/Constraints/CoerciveTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function setUp(): void
2424
$this->factory->setConfig(Constraint::CHECK_MODE_TYPE_CAST | Constraint::CHECK_MODE_COERCE_TYPES);
2525
}
2626

27-
public function dataCoerceCases()
27+
public function dataCoerceCases(): array
2828
{
2929
// check type conversions
3030
$types = [
@@ -190,7 +190,7 @@ public function dataCoerceCases()
190190
}
191191

192192
/** @dataProvider dataCoerceCases **/
193-
public function testCoerceCases($schema, $data, $startType, $endType, $endValue, $valid, $extraFlags = 0, $assoc = false)
193+
public function testCoerceCases($schema, $data, $startType, $endType, $endValue, $valid, $extraFlags = 0, $assoc = false): void
194194
{
195195
$validator = new Validator($this->factory);
196196

@@ -232,12 +232,12 @@ public function testCoerceCases($schema, $data, $startType, $endType, $endValue,
232232
}
233233

234234
/** @dataProvider dataCoerceCases **/
235-
public function testCoerceCasesUsingAssoc($schema, $data, $startType, $endType, $endValue, $valid, $early = false)
235+
public function testCoerceCasesUsingAssoc($schema, $data, $startType, $endType, $endValue, $valid, $early = false): void
236236
{
237237
$this->testCoerceCases($schema, $data, $startType, $endType, $endValue, $valid, $early, true);
238238
}
239239

240-
public function testCoerceAPI()
240+
public function testCoerceAPI(): void
241241
{
242242
$input = json_decode('{"propertyOne": "10"}');
243243
$schema = json_decode('{"properties":{"propertyOne":{"type":"number"}}}');

tests/Constraints/ConstTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ConstTest extends BaseTestCase
1414
protected $schemaSpec = 'http://json-schema.org/draft-06/schema#';
1515
protected $validateSchema = true;
1616

17-
public function getInvalidTests()
17+
public function getInvalidTests(): array
1818
{
1919
return [
2020
[
@@ -68,7 +68,7 @@ public function getInvalidTests()
6868
];
6969
}
7070

71-
public function getValidTests()
71+
public function getValidTests(): array
7272
{
7373
return [
7474
[

tests/Constraints/DefaultPropertiesTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class DefaultPropertiesTest extends VeryBaseTestCase
1818
{
19-
public function getValidTests()
19+
public function getValidTests(): array
2020
{
2121
return [
2222
/*
@@ -170,7 +170,7 @@ public function getValidTests()
170170
/**
171171
* @dataProvider getValidTests
172172
*/
173-
public function testValidCases($input, $schema, $expectOutput = null, $checkMode = 0)
173+
public function testValidCases($input, $schema, $expectOutput = null, $checkMode = 0): void
174174
{
175175
if (is_string($input)) {
176176
$inputDecoded = json_decode($input);
@@ -197,7 +197,7 @@ public function testValidCases($input, $schema, $expectOutput = null, $checkMode
197197
/**
198198
* @dataProvider getValidTests
199199
*/
200-
public function testValidCasesUsingAssoc($input, $schema, $expectOutput = null, $checkMode = 0)
200+
public function testValidCasesUsingAssoc($input, $schema, $expectOutput = null, $checkMode = 0): void
201201
{
202202
$input = json_decode($input, true);
203203

@@ -208,14 +208,14 @@ public function testValidCasesUsingAssoc($input, $schema, $expectOutput = null,
208208
/**
209209
* @dataProvider getValidTests
210210
*/
211-
public function testValidCasesUsingAssocWithoutTypeCast($input, $schema, $expectOutput = null, $checkMode = 0)
211+
public function testValidCasesUsingAssocWithoutTypeCast($input, $schema, $expectOutput = null, $checkMode = 0): void
212212
{
213213
$input = json_decode($input, true);
214214

215215
self::testValidCases($input, $schema, $expectOutput, $checkMode);
216216
}
217217

218-
public function testNoModificationViaReferences()
218+
public function testNoModificationViaReferences(): void
219219
{
220220
$input = json_decode('{}');
221221
$schema = json_decode('{"properties":{"propertyOne":{"default":"valueOne"}}}');
@@ -229,7 +229,7 @@ public function testNoModificationViaReferences()
229229
$this->assertEquals('valueOne', $schema->properties->propertyOne->default);
230230
}
231231

232-
public function testLeaveBasicTypesAlone()
232+
public function testLeaveBasicTypesAlone(): void
233233
{
234234
$input = json_decode('"ThisIsAString"');
235235
$schema = json_decode('{"properties": {"propertyOne": {"default": "valueOne"}}}');

tests/Constraints/DependenciesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DependenciesTest extends BaseTestCase
1414
protected $schemaSpec = 'http://json-schema.org/draft-03/schema#';
1515
protected $validateSchema = true;
1616

17-
public function getInvalidTests()
17+
public function getInvalidTests(): array
1818
{
1919
return [
2020
[
@@ -80,7 +80,7 @@ public function getInvalidTests()
8080
];
8181
}
8282

83-
public function getValidTests()
83+
public function getValidTests(): array
8484
{
8585
return [
8686
[

tests/Constraints/DisallowTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DisallowTest extends BaseTestCase
1919
protected $schemaSpec = 'http://json-schema.org/draft-03/schema#';
2020
protected $validateSchema = false;
2121

22-
public function getInvalidTests()
22+
public function getInvalidTests(): array
2323
{
2424
return [
2525
[
@@ -107,7 +107,7 @@ public function getInvalidTests()
107107
];
108108
}
109109

110-
public function getValidTests()
110+
public function getValidTests(): array
111111
{
112112
return [
113113
[

tests/Constraints/DivisibleByTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class DivisibleByTest extends BaseTestCase
1313
{
1414
protected $validateSchema = true;
1515

16-
public function getInvalidTests()
16+
public function getInvalidTests(): array
1717
{
1818
return [
1919
[
@@ -55,7 +55,7 @@ public function getInvalidTests()
5555
];
5656
}
5757

58-
public function getValidTests()
58+
public function getValidTests(): array
5959
{
6060
return [
6161
[

tests/Constraints/EnumTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class EnumTest extends BaseTestCase
1414
protected $schemaSpec = 'http://json-schema.org/draft-03/schema#';
1515
protected $validateSchema = true;
1616

17-
public function getInvalidTests()
17+
public function getInvalidTests(): array
1818
{
1919
return [
2020
[
@@ -94,7 +94,7 @@ public function getInvalidTests()
9494
];
9595
}
9696

97-
public function getValidTests()
97+
public function getValidTests(): array
9898
{
9999
return [
100100
[

tests/Constraints/ExtendsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ExtendsTest extends BaseTestCase
1414
protected $schemaSpec = 'http://json-schema.org/draft-03/schema#';
1515
protected $validateSchema = true;
1616

17-
public function getInvalidTests()
17+
public function getInvalidTests(): array
1818
{
1919
return [
2020
[
@@ -93,7 +93,7 @@ public function getInvalidTests()
9393
];
9494
}
9595

96-
public function getValidTests()
96+
public function getValidTests(): array
9797
{
9898
return [
9999
[

tests/Constraints/FactoryTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ protected function setUp(): void
5353
* @param string $constraintName
5454
* @param string $expectedClass
5555
*/
56-
public function testCreateInstanceForConstraintName($constraintName, $expectedClass)
56+
public function testCreateInstanceForConstraintName($constraintName, $expectedClass): void
5757
{
5858
$constraint = $this->factory->createInstanceFor($constraintName);
5959

6060
$this->assertInstanceOf($expectedClass, $constraint);
6161
$this->assertInstanceOf('JsonSchema\Constraints\ConstraintInterface', $constraint);
6262
}
6363

64-
public function constraintNameProvider()
64+
public function constraintNameProvider(): array
6565
{
6666
return [
6767
['array', 'JsonSchema\Constraints\CollectionConstraint'],
@@ -83,42 +83,42 @@ public function constraintNameProvider()
8383
*
8484
* @param string $constraintName
8585
*/
86-
public function testExceptionWhenCreateInstanceForInvalidConstraintName($constraintName)
86+
public function testExceptionWhenCreateInstanceForInvalidConstraintName($constraintName): void
8787
{
8888
$this->expectException('JsonSchema\Exception\InvalidArgumentException');
8989
$this->factory->createInstanceFor($constraintName);
9090
}
9191

92-
public function invalidConstraintNameProvider()
92+
public function invalidConstraintNameProvider(): array
9393
{
9494
return [
9595
['invalidConstraintName'],
9696
];
9797
}
9898

99-
public function testSetConstraintClassExistsCondition()
99+
public function testSetConstraintClassExistsCondition(): void
100100
{
101101
$this->expectException(\JsonSchema\Exception\InvalidArgumentException::class);
102102

103103
$this->factory->setConstraintClass('string', 'SomeConstraint');
104104
}
105105

106-
public function testSetConstraintClassImplementsCondition()
106+
public function testSetConstraintClassImplementsCondition(): void
107107
{
108108
$this->expectException(\JsonSchema\Exception\InvalidArgumentException::class);
109109

110110
$this->factory->setConstraintClass('string', 'JsonSchema\Tests\Constraints\MyBadConstraint');
111111
}
112112

113-
public function testSetConstraintClassInstance()
113+
public function testSetConstraintClassInstance(): void
114114
{
115115
$this->factory->setConstraintClass('string', 'JsonSchema\Tests\Constraints\MyStringConstraint');
116116
$constraint = $this->factory->createInstanceFor('string');
117117
$this->assertInstanceOf('JsonSchema\Tests\Constraints\MyStringConstraint', $constraint);
118118
$this->assertInstanceOf('JsonSchema\Constraints\ConstraintInterface', $constraint);
119119
}
120120

121-
public function testCheckMode()
121+
public function testCheckMode(): void
122122
{
123123
$f = new Factory();
124124

0 commit comments

Comments
 (0)