Skip to content

Commit b817e85

Browse files
committed
refactor: Add function types to test suite
1 parent 23c8551 commit b817e85

16 files changed

+55
-67
lines changed

tests/Constraints/AdditionalPropertiesTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* file that was distributed with this source code.
88
*/
99

10+
1011
namespace JsonSchema\Tests\Constraints;
1112

1213
use JsonSchema\Validator;

tests/Constraints/BaseTestCase.php

Lines changed: 4 additions & 4 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 = []): void
29+
public function testInvalidCases(string $input, string $schema, ?int $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 = []): void
58+
public function testInvalidCasesUsingAssoc(string $input, string $schema, ?int $checkMode = Constraint::CHECK_MODE_TYPE_CAST, array $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): void
90+
public function testValidCases(string $input, string $schema, int $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): void
112+
public function testValidCasesUsingAssoc(string $input, string $schema, int $checkMode = Constraint::CHECK_MODE_TYPE_CAST): void
113113
{
114114
if ($this->validateSchema) {
115115
$checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA;

tests/Constraints/CoerciveTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,11 @@ public function dataCoerceCases(): array
189189
return $tests;
190190
}
191191

192-
/** @dataProvider dataCoerceCases **/
193-
public function testCoerceCases($schema, $data, $startType, $endType, $endValue, $valid, $extraFlags = 0, $assoc = false): void
192+
/**
193+
* @dataProvider dataCoerceCases
194+
* @param mixed $endValue
195+
*/
196+
public function testCoerceCases(string $schema, string $data, string $startType, string $endType, $endValue, bool $valid, int $extraFlags = 0, bool $assoc = false): void
194197
{
195198
$validator = new Validator($this->factory);
196199

tests/Constraints/DefaultPropertiesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function getValidTests(): array
170170
/**
171171
* @dataProvider getValidTests
172172
*/
173-
public function testValidCases($input, $schema, $expectOutput = null, $checkMode = 0): void
173+
public function testValidCases(string $input, string $schema, ?string $expectOutput = null, int $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): void
200+
public function testValidCasesUsingAssoc(string $input, string $schema, ?string $expectOutput = null, int $checkMode = 0): void
201201
{
202202
$input = json_decode($input, true);
203203

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

tests/Constraints/FactoryTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ protected function setUp(): void
4949

5050
/**
5151
* @dataProvider constraintNameProvider
52-
*
53-
* @param string $constraintName
54-
* @param string $expectedClass
5552
*/
56-
public function testCreateInstanceForConstraintName($constraintName, $expectedClass): void
53+
public function testCreateInstanceForConstraintName(string $constraintName, string $expectedClass): void
5754
{
5855
$constraint = $this->factory->createInstanceFor($constraintName);
5956

@@ -80,10 +77,8 @@ public function constraintNameProvider(): array
8077

8178
/**
8279
* @dataProvider invalidConstraintNameProvider
83-
*
84-
* @param string $constraintName
8580
*/
86-
public function testExceptionWhenCreateInstanceForInvalidConstraintName($constraintName): void
81+
public function testExceptionWhenCreateInstanceForInvalidConstraintName(string $constraintName): void
8782
{
8883
$this->expectException('JsonSchema\Exception\InvalidArgumentException');
8984
$this->factory->createInstanceFor($constraintName);

tests/Constraints/FormatTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testRegex(): void
5757
/**
5858
* @dataProvider getValidFormats
5959
*/
60-
public function testValidFormat($string, $format): void
60+
public function testValidFormat(string $string, string $format): void
6161
{
6262
$validator = new FormatConstraint();
6363
$schema = new \stdClass();
@@ -70,7 +70,7 @@ public function testValidFormat($string, $format): void
7070
/**
7171
* @dataProvider getInvalidFormats
7272
*/
73-
public function testInvalidFormat($string, $format): void
73+
public function testInvalidFormat(string $string, string $format): void
7474
{
7575
$validator = new FormatConstraint();
7676
$schema = new \stdClass();
@@ -83,7 +83,7 @@ public function testInvalidFormat($string, $format): void
8383
/**
8484
* @dataProvider getInvalidFormats
8585
*/
86-
public function testDisabledFormat($string, $format): void
86+
public function testDisabledFormat(string $string, string $format): void
8787
{
8888
$factory = new Factory();
8989
$validator = new FormatConstraint($factory);

tests/Constraints/RequiredPropertyTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ public function testErrorPropertyIsPopulatedForRequiredIfEmptyValueInInput(): vo
102102
$this->assertErrorHasExpectedPropertyValue($error, 'foo');
103103
}
104104

105-
protected function assertErrorHasExpectedPropertyValue($error, $propertyValue): void
105+
/**
106+
* @param mixed $propertyValue
107+
*/
108+
protected function assertErrorHasExpectedPropertyValue(array $error, $propertyValue): void
106109
{
107110
if (!(isset($error[0]) && is_array($error[0]) && isset($error[0]['property']))) {
108111
$this->fail(

tests/Constraints/SchemaValidationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getValidTests(): array
6464
/**
6565
* @dataProvider getInvalidTests
6666
*/
67-
public function testInvalidCases($schema): void
67+
public function testInvalidCases(string $schema): void
6868
{
6969
$input = json_decode('{"propertyOne":"valueOne"}');
7070
$schema = json_decode($schema);
@@ -85,7 +85,7 @@ public function testInvalidCases($schema): void
8585
/**
8686
* @dataProvider getValidTests
8787
*/
88-
public function testValidCases($schema): void
88+
public function testValidCases(string $schema): void
8989
{
9090
$input = json_decode('{"propertyOne":"valueOne"}');
9191
$schema = json_decode($schema);

tests/Constraints/TypeTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ public function provideIndefiniteArticlesForTypes(): array
4343

4444
/**
4545
* @dataProvider provideIndefiniteArticlesForTypes
46+
* @param null $value
4647
*/
47-
public function testIndefiniteArticleForTypeInTypeCheckErrorMessage($type, $wording, $value = null, $label = 'NULL'): void
48+
public function testIndefiniteArticleForTypeInTypeCheckErrorMessage(string $type, string $wording, $value = null, string $label = 'NULL'): void
4849
{
4950
$constraint = new TypeConstraint();
5051
$constraint->check($value, (object) ['type' => $type]);
@@ -66,11 +67,8 @@ public function testLooseTypeChecking(): void
6667

6768
/**
6869
* Helper to assert an error message
69-
*
70-
* @param string $expected
71-
* @param TypeConstraint $actual
7270
*/
73-
private function assertTypeConstraintError($expected, TypeConstraint $actual): void
71+
private function assertTypeConstraintError(string $expected, TypeConstraint $actual): void
7472
{
7573
$actualErrors = $actual->getErrors();
7674

@@ -106,7 +104,7 @@ public function validNameWordingDataProvider(): array
106104
/**
107105
* @dataProvider validNameWordingDataProvider
108106
*/
109-
public function testValidateTypeNameWording($nameWording): void
107+
public function testValidateTypeNameWording(array $nameWording): void
110108
{
111109
$t = new TypeConstraint();
112110
$r = new \ReflectionObject($t);

tests/Constraints/VeryBaseTestCase.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ abstract class VeryBaseTestCase extends TestCase
2323
/** @var object */
2424
private $jsonSchemaDraft04;
2525

26-
/**
27-
* @param object $schema
28-
*/
29-
protected function getUriRetrieverMock($schema): object
26+
protected function getUriRetrieverMock(object $schema): object
3027
{
3128
$relativeTestsRoot = realpath(__DIR__ . '/../../vendor/json-schema/json-schema-test-suite/remotes');
3229

tests/Drafts/BaseDraftTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class BaseDraftTestCase extends BaseTestCase
1212
/** @var string */
1313
protected $relativeTestsRoot = '/../../vendor/json-schema/json-schema-test-suite/tests';
1414

15-
private function setUpTests($isValid): array
15+
private function setUpTests(bool $isValid): array
1616
{
1717
$filePaths = $this->getFilePaths();
1818
$skippedTests = $this->getSkippedTests();

tests/Entity/JsonPointerTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,13 @@ class JsonPointerTest extends TestCase
2121
{
2222
/**
2323
* @dataProvider getTestData
24-
*
25-
* @param string $testValue
26-
* @param string $expectedFileName
27-
* @param array $expectedPropertyPaths
28-
* @param string $expectedPropertyPathAsString
29-
* @param string $expectedToString
3024
*/
3125
public function testJsonPointer(
32-
$testValue,
33-
$expectedFileName,
34-
$expectedPropertyPaths,
35-
$expectedPropertyPathAsString,
36-
$expectedToString
26+
string $testValue,
27+
string $expectedFileName,
28+
array $expectedPropertyPaths,
29+
string $expectedPropertyPathAsString,
30+
string $expectedToString
3731
): void {
3832
$jsonPointer = new JsonPointer($testValue);
3933
$this->assertEquals($expectedFileName, $jsonPointer->getFilename());

tests/Exception/JsonDecodingExceptionTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,49 @@ public function testHierarchy(): void
1515
self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception);
1616
}
1717

18-
public function testDefaultMessage()
18+
public function testDefaultMessage(): void
1919
{
2020
$exception = new JsonDecodingException();
2121
self::assertNotEmpty($exception->getMessage());
2222
}
2323

24-
public function testErrorNoneMessage()
24+
public function testErrorNoneMessage(): void
2525
{
2626
$exception = new JsonDecodingException(JSON_ERROR_NONE);
2727
self::assertNotEmpty($exception->getMessage());
2828
}
2929

30-
public function testErrorDepthMessage()
30+
public function testErrorDepthMessage(): void
3131
{
3232
$exception = new JsonDecodingException(JSON_ERROR_DEPTH);
3333
self::assertNotEmpty($exception->getMessage());
3434
}
3535

36-
public function testErrorStateMismatchMessage()
36+
public function testErrorStateMismatchMessage(): void
3737
{
3838
$exception = new JsonDecodingException(JSON_ERROR_STATE_MISMATCH);
3939
self::assertNotEmpty($exception->getMessage());
4040
}
4141

42-
public function testErrorControlCharacterMessage()
42+
public function testErrorControlCharacterMessage(): void
4343
{
4444
$exception = new JsonDecodingException(JSON_ERROR_CTRL_CHAR);
4545
self::assertNotEmpty($exception->getMessage());
4646
}
4747

48-
public function testErrorUtf8Message()
48+
public function testErrorUtf8Message(): void
4949
{
5050
$exception = new JsonDecodingException(JSON_ERROR_UTF8);
5151
self::assertNotEmpty($exception->getMessage());
5252
}
5353

54-
public function testErrorSyntaxMessage()
54+
public function testErrorSyntaxMessage(): void
5555
{
5656
$exception = new JsonDecodingException(JSON_ERROR_SYNTAX);
5757
self::assertNotEmpty($exception->getMessage());
5858
}
5959

60-
public function testErrorInfiniteOrNotANumberMessage()
60+
public function testErrorInfiniteOrNotANumberMessage(): void
6161
{
6262
if (!defined('JSON_ERROR_INF_OR_NAN')) {
6363
self::markTestSkipped('JSON_ERROR_INF_OR_NAN is not defined until php55.');
@@ -67,7 +67,7 @@ public function testErrorInfiniteOrNotANumberMessage()
6767
self::assertNotEmpty($exception->getMessage());
6868
}
6969

70-
public function testErrorRecursionMessage()
70+
public function testErrorRecursionMessage(): void
7171
{
7272
if (!defined('JSON_ERROR_RECURSION')) {
7373
self::markTestSkipped('JSON_ERROR_RECURSION is not defined until php55.');
@@ -77,7 +77,7 @@ public function testErrorRecursionMessage()
7777
self::assertNotEmpty($exception->getMessage());
7878
}
7979

80-
public function testErrorUnsupportedTypeMessage()
80+
public function testErrorUnsupportedTypeMessage(): void
8181
{
8282
if (!defined('JSON_ERROR_UNSUPPORTED_TYPE')) {
8383
self::markTestSkipped('JSON_ERROR_UNSUPPORTED_TYPE is not defined until php55.');

tests/RefTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function dataRefIgnoresSiblings(): array
6262
}
6363

6464
/** @dataProvider dataRefIgnoresSiblings */
65-
public function testRefIgnoresSiblings($schema, $document, $isValid, $exception = null): void
65+
public function testRefIgnoresSiblings(string $schema, string $document, bool $isValid, ?string $exception = null): void
6666
{
6767
$document = json_decode($document);
6868
$schema = json_decode($schema);

tests/Rfc3339Test.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
class Rfc3339Test extends TestCase
99
{
1010
/**
11-
* @param string $string
12-
* @param \DateTime|null $expected
1311
* @dataProvider provideValidFormats
1412
*/
15-
public function testCreateFromValidString($string, \DateTime $expected): void
13+
public function testCreateFromValidString(string $string, ?\DateTime $expected): void
1614
{
1715
$actual = Rfc3339::createFromString($string);
1816

@@ -21,10 +19,9 @@ public function testCreateFromValidString($string, \DateTime $expected): void
2119
}
2220

2321
/**
24-
* @param string $string
2522
* @dataProvider provideInvalidFormats
2623
*/
27-
public function testCreateFromInvalidString($string): void
24+
public function testCreateFromInvalidString(string $string): void
2825
{
2926
$this->assertNull(Rfc3339::createFromString($string), sprintf('String "%s" should not be converted to DateTime', $string));
3027
}

0 commit comments

Comments
 (0)