Skip to content

Commit

Permalink
Add return types to test suite (#748)
Browse files Browse the repository at this point in the history
* refactor: Add return types in the test suite

* docs: Add changelog entry
  • Loading branch information
DannyvdSluijs committed Aug 30, 2024
1 parent cddbef1 commit 23c8551
Show file tree
Hide file tree
Showing 63 changed files with 237 additions and 273 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add return types in the test suite ([#748](https://github.com/jsonrainbow/json-schema/pull/748))

### Fixed
- Correct misconfigured mocks in JsonSchema\Tests\Uri\UriRetrieverTest ([#741](https://github.com/jsonrainbow/json-schema/pull/741))
- Fix pugx badges in README ([#742](https://github.com/jsonrainbow/json-schema/pull/742))
Expand Down
4 changes: 2 additions & 2 deletions tests/ConstraintErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

class ConstraintErrorTest extends TestCase
{
public function testGetValidMessage()
public function testGetValidMessage(): void
{
$e = ConstraintError::ALL_OF();
$this->assertEquals('Failed to match all schemas', $e->getMessage());
}

public function testGetInvalidMessage()
public function testGetInvalidMessage(): void
{
$e = ConstraintError::MISSING_ERROR();

Expand Down
4 changes: 2 additions & 2 deletions tests/Constraints/AdditionalPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AdditionalPropertiesTest extends BaseTestCase
{
protected $validateSchema = true;

public function getInvalidTests()
public function getInvalidTests(): array
{
return [
[
Expand Down Expand Up @@ -114,7 +114,7 @@ public function getInvalidTests()
];
}

public function getValidTests()
public function getValidTests(): array
{
return [
[
Expand Down
4 changes: 2 additions & 2 deletions tests/Constraints/ArraysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ArraysTest extends BaseTestCase
{
protected $validateSchema = true;

public function getInvalidTests()
public function getInvalidTests(): array
{
return [
[
Expand Down Expand Up @@ -120,7 +120,7 @@ public function getInvalidTests()
];
}

public function getValidTests()
public function getValidTests(): array
{
return [
[
Expand Down
28 changes: 8 additions & 20 deletions tests/Constraints/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class BaseTestCase extends VeryBaseTestCase
/**
* @dataProvider getInvalidTests
*/
public function testInvalidCases($input, $schema, $checkMode = Constraint::CHECK_MODE_NORMAL, $errors = [])
public function testInvalidCases($input, $schema, $checkMode = Constraint::CHECK_MODE_NORMAL, $errors = []): void
{
$checkMode = $checkMode === null ? Constraint::CHECK_MODE_NORMAL : $checkMode;
if ($this->validateSchema) {
Expand Down Expand Up @@ -55,7 +55,7 @@ public function testInvalidCases($input, $schema, $checkMode = Constraint::CHECK
/**
* @dataProvider getInvalidForAssocTests
*/
public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST, $errors = [])
public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST, $errors = []): void
{
$checkMode = $checkMode === null ? Constraint::CHECK_MODE_TYPE_CAST : $checkMode;
if ($this->validateSchema) {
Expand Down Expand Up @@ -87,7 +87,7 @@ public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constra
/**
* @dataProvider getValidTests
*/
public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_MODE_NORMAL)
public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_MODE_NORMAL): void
{
if ($this->validateSchema) {
$checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA;
Expand All @@ -109,7 +109,7 @@ public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_M
/**
* @dataProvider getValidForAssocTests
*/
public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST)
public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST): void
{
if ($this->validateSchema) {
$checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA;
Expand All @@ -133,28 +133,16 @@ public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constrain
$this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true));
}

/**
* @return array[]
*/
abstract public function getValidTests();
abstract public function getValidTests(): array;

/**
* @return array[]
*/
public function getValidForAssocTests()
public function getValidForAssocTests(): array
{
return $this->getValidTests();
}

/**
* @return array[]
*/
abstract public function getInvalidTests();
abstract public function getInvalidTests(): array;

/**
* @return array[]
*/
public function getInvalidForAssocTests()
public function getInvalidForAssocTests(): array
{
return $this->getInvalidTests();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Constraints/BasicTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BasicTypesTest extends BaseTestCase
protected $schemaSpec = 'http://json-schema.org/draft-03/schema#';
protected $validateSchema = true;

public function getInvalidTests()
public function getInvalidTests(): array
{
return [
[
Expand Down Expand Up @@ -104,7 +104,7 @@ public function getInvalidTests()
];
}

public function getValidTests()
public function getValidTests(): array
{
return [
[
Expand Down
8 changes: 4 additions & 4 deletions tests/Constraints/CoerciveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function setUp(): void
$this->factory->setConfig(Constraint::CHECK_MODE_TYPE_CAST | Constraint::CHECK_MODE_COERCE_TYPES);
}

public function dataCoerceCases()
public function dataCoerceCases(): array
{
// check type conversions
$types = [
Expand Down Expand Up @@ -190,7 +190,7 @@ public function dataCoerceCases()
}

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

Expand Down Expand Up @@ -232,12 +232,12 @@ public function testCoerceCases($schema, $data, $startType, $endType, $endValue,
}

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

public function testCoerceAPI()
public function testCoerceAPI(): void
{
$input = json_decode('{"propertyOne": "10"}');
$schema = json_decode('{"properties":{"propertyOne":{"type":"number"}}}');
Expand Down
4 changes: 2 additions & 2 deletions tests/Constraints/ConstTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ConstTest extends BaseTestCase
protected $schemaSpec = 'http://json-schema.org/draft-06/schema#';
protected $validateSchema = true;

public function getInvalidTests()
public function getInvalidTests(): array
{
return [
[
Expand Down Expand Up @@ -68,7 +68,7 @@ public function getInvalidTests()
];
}

public function getValidTests()
public function getValidTests(): array
{
return [
[
Expand Down
12 changes: 6 additions & 6 deletions tests/Constraints/DefaultPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class DefaultPropertiesTest extends VeryBaseTestCase
{
public function getValidTests()
public function getValidTests(): array
{
return [
/*
Expand Down Expand Up @@ -170,7 +170,7 @@ public function getValidTests()
/**
* @dataProvider getValidTests
*/
public function testValidCases($input, $schema, $expectOutput = null, $checkMode = 0)
public function testValidCases($input, $schema, $expectOutput = null, $checkMode = 0): void
{
if (is_string($input)) {
$inputDecoded = json_decode($input);
Expand All @@ -197,7 +197,7 @@ public function testValidCases($input, $schema, $expectOutput = null, $checkMode
/**
* @dataProvider getValidTests
*/
public function testValidCasesUsingAssoc($input, $schema, $expectOutput = null, $checkMode = 0)
public function testValidCasesUsingAssoc($input, $schema, $expectOutput = null, $checkMode = 0): void
{
$input = json_decode($input, true);

Expand All @@ -208,14 +208,14 @@ public function testValidCasesUsingAssoc($input, $schema, $expectOutput = null,
/**
* @dataProvider getValidTests
*/
public function testValidCasesUsingAssocWithoutTypeCast($input, $schema, $expectOutput = null, $checkMode = 0)
public function testValidCasesUsingAssocWithoutTypeCast($input, $schema, $expectOutput = null, $checkMode = 0): void
{
$input = json_decode($input, true);

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

public function testNoModificationViaReferences()
public function testNoModificationViaReferences(): void
{
$input = json_decode('{}');
$schema = json_decode('{"properties":{"propertyOne":{"default":"valueOne"}}}');
Expand All @@ -229,7 +229,7 @@ public function testNoModificationViaReferences()
$this->assertEquals('valueOne', $schema->properties->propertyOne->default);
}

public function testLeaveBasicTypesAlone()
public function testLeaveBasicTypesAlone(): void
{
$input = json_decode('"ThisIsAString"');
$schema = json_decode('{"properties": {"propertyOne": {"default": "valueOne"}}}');
Expand Down
4 changes: 2 additions & 2 deletions tests/Constraints/DependenciesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DependenciesTest extends BaseTestCase
protected $schemaSpec = 'http://json-schema.org/draft-03/schema#';
protected $validateSchema = true;

public function getInvalidTests()
public function getInvalidTests(): array
{
return [
[
Expand Down Expand Up @@ -80,7 +80,7 @@ public function getInvalidTests()
];
}

public function getValidTests()
public function getValidTests(): array
{
return [
[
Expand Down
4 changes: 2 additions & 2 deletions tests/Constraints/DisallowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DisallowTest extends BaseTestCase
protected $schemaSpec = 'http://json-schema.org/draft-03/schema#';
protected $validateSchema = false;

public function getInvalidTests()
public function getInvalidTests(): array
{
return [
[
Expand Down Expand Up @@ -107,7 +107,7 @@ public function getInvalidTests()
];
}

public function getValidTests()
public function getValidTests(): array
{
return [
[
Expand Down
4 changes: 2 additions & 2 deletions tests/Constraints/DivisibleByTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DivisibleByTest extends BaseTestCase
{
protected $validateSchema = true;

public function getInvalidTests()
public function getInvalidTests(): array
{
return [
[
Expand Down Expand Up @@ -55,7 +55,7 @@ public function getInvalidTests()
];
}

public function getValidTests()
public function getValidTests(): array
{
return [
[
Expand Down
4 changes: 2 additions & 2 deletions tests/Constraints/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class EnumTest extends BaseTestCase
protected $schemaSpec = 'http://json-schema.org/draft-03/schema#';
protected $validateSchema = true;

public function getInvalidTests()
public function getInvalidTests(): array
{
return [
[
Expand Down Expand Up @@ -94,7 +94,7 @@ public function getInvalidTests()
];
}

public function getValidTests()
public function getValidTests(): array
{
return [
[
Expand Down
4 changes: 2 additions & 2 deletions tests/Constraints/ExtendsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ExtendsTest extends BaseTestCase
protected $schemaSpec = 'http://json-schema.org/draft-03/schema#';
protected $validateSchema = true;

public function getInvalidTests()
public function getInvalidTests(): array
{
return [
[
Expand Down Expand Up @@ -93,7 +93,7 @@ public function getInvalidTests()
];
}

public function getValidTests()
public function getValidTests(): array
{
return [
[
Expand Down
Loading

0 comments on commit 23c8551

Please sign in to comment.