Skip to content

Commit

Permalink
Enhancement: Add array return type declarations to data providers
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz authored and sebastianbergmann committed Sep 8, 2018
1 parent 3784e19 commit cca308e
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 44 deletions.
22 changes: 8 additions & 14 deletions tests/unit/Framework/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@

class AssertTest extends TestCase
{
/**
* @return array<string, string[]>
*/
public static function validInvalidJsonDataprovider()
public static function validInvalidJsonDataprovider(): array
{
return [
'error syntax in expected JSON' => ['{"Mascott"::}', '{"Mascott" : "Tux"}'],
Expand Down Expand Up @@ -229,10 +226,7 @@ public function testAssertArraySubsetRaisesExceptionForInvalidArguments($partial
$this->assertArraySubset($partial, $subject);
}

/**
* @return array
*/
public function assertArraySubsetInvalidArgumentProvider()
public function assertArraySubsetInvalidArgumentProvider(): array
{
return [
[false, []],
Expand Down Expand Up @@ -502,7 +496,7 @@ public function testAssertArrayNotContainsOnlyStdClass(): void
$this->assertNotContainsOnly('StdClass', [new \stdClass]);
}

public function equalProvider()
public function equalProvider(): array
{
// same |= equal
return \array_merge($this->equalValues(), $this->sameValues());
Expand All @@ -513,12 +507,12 @@ public function notEqualProvider()
return $this->notEqualValues();
}

public function sameProvider()
public function sameProvider(): array
{
return $this->sameValues();
}

public function notSameProvider()
public function notSameProvider(): array
{
// not equal |= not same
// equal, ¬same |= not same
Expand Down Expand Up @@ -2512,7 +2506,7 @@ public function testAssertStringNotMatchesFormatFile(): void
$this->assertStringNotMatchesFormatFile(TEST_FILES_PATH . 'expectedFileFormat.txt', "FOO\n");
}

protected function sameValues()
protected function sameValues(): array
{
$object = new \SampleClass(4, 8, 15);
$file = TEST_FILES_PATH . 'foo.xml';
Expand Down Expand Up @@ -2541,7 +2535,7 @@ protected function sameValues()
];
}

protected function notEqualValues()
protected function notEqualValues(): array
{
// cyclic dependencies
$book1 = new \Book;
Expand Down Expand Up @@ -2682,7 +2676,7 @@ protected function notEqualValues()
];
}

protected function equalValues()
protected function equalValues(): array
{
// cyclic dependencies
$book1 = new \Book;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Framework/Constraint/ArraySubsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class ArraySubsetTest extends ConstraintTestCase
{
public static function evaluateDataProvider()
public static function evaluateDataProvider(): array
{
return [
'loose array subset and array other' => [
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Framework/Constraint/IsEqualTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testConstraintIsEqual2($expected, $actual, $message): void
$this->fail();
}

public function isEqualProvider()
public function isEqualProvider(): array
{
$a = new \stdClass;
$a->foo = 'bar';
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Framework/Constraint/IsJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class IsJsonTest extends ConstraintTestCase
{
public static function evaluateDataprovider()
public static function evaluateDataprovider(): array
{
return [
'valid JSON' => [true, '{}'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class JsonMatchesErrorMessageProviderTest extends TestCase
{
public static function determineJsonErrorDataprovider()
public static function determineJsonErrorDataprovider(): array
{
return [
'JSON_ERROR_NONE' => [
Expand Down Expand Up @@ -45,7 +45,7 @@ public static function determineJsonErrorDataprovider()
];
}

public static function translateTypeToPrefixDataprovider()
public static function translateTypeToPrefixDataprovider(): array
{
return [
'expected' => ['Expected value JSON decode error - ', 'expected'],
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Framework/Constraint/JsonMatchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class JsonMatchesTest extends ConstraintTestCase
{
public static function evaluateDataprovider()
public static function evaluateDataprovider(): array
{
return [
'valid JSON' => [true, \json_encode(['Mascott' => 'Tux']), \json_encode(['Mascott' => 'Tux'])],
Expand All @@ -35,7 +35,7 @@ public static function evaluateDataprovider()
];
}

public static function evaluateThrowsExpectationFailedExceptionWhenJsonIsValidButDoesNotMatchDataprovider()
public static function evaluateThrowsExpectationFailedExceptionWhenJsonIsValidButDoesNotMatchDataprovider(): array
{
return [
'error UTF-8' => [\json_encode('\xB1\x31'), \json_encode(['Mascott' => 'Tux'])],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Framework/MockObject/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function testGetMockForAbstractClassAbstractClassDoesNotExist(): void
$this->generator->getMockForAbstractClass('Tux');
}

public function getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider()
public function getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider(): array
{
return [
'className not a string' => [[], ''],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Framework/MockObject/MockObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ public function testStringableClassCanBeMocked(): void
$this->assertSame('foo', (string) $mock);
}

public function traversableProvider()
public function traversableProvider(): array
{
return [
['Traversable'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Framework/TestResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testAddErrorOfTypeIncompleteTest(): void
$this->assertAttributeContainsOnly(TestFailure::class, 'notImplemented', $result);
}

public function canSkipCoverageProvider()
public function canSkipCoverageProvider(): array
{
return [
['CoverageClassTest', true],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Runner/TestSuiteSorterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function testCanHandleSuiteWithEmptyTestCase(): void
$this->assertSame('No tests found in class "EmptyTestCaseTest".', $suite->tests()[0]->tests()[0]->getMessage());
}

public function suiteSorterOptionPermutationsProvider()
public function suiteSorterOptionPermutationsProvider(): array
{
$orderValues = [TestSuiteSorter::ORDER_DEFAULT, TestSuiteSorter::ORDER_REVERSED, TestSuiteSorter::ORDER_RANDOMIZED];
$resolveValues = [false, true];
Expand Down
15 changes: 3 additions & 12 deletions tests/unit/Util/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public function testCanonicalize($actual, $expected, $expectError): void
}
}

/**
* @return array
*/
public function canonicalizeProvider()
public function canonicalizeProvider(): array
{
return [
['{"name":"John","age":"35"}', '{"age":"35","name":"John"}', false],
Expand All @@ -53,10 +50,7 @@ public function testPrettify($actual, $expected): void
$this->assertEquals($expected, Json::prettify($actual));
}

/**
* @return array
*/
public function prettifyProvider()
public function prettifyProvider(): array
{
return [
['{"name":"John","age": "5"}', "{\n \"name\": \"John\",\n \"age\": \"5\"\n}"],
Expand All @@ -74,10 +68,7 @@ public function testPrettifyException($json): void
Json::prettify($json);
}

/**
* @return array
*/
public function prettifyExceptionProvider()
public function prettifyExceptionProvider(): array
{
return [
['"name":"John","age": "5"}'],
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Util/RegularExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class RegularExpressionTest extends TestCase
{
public function validRegexpProvider()
public function validRegexpProvider(): array
{
return [
['#valid regexp#', 'valid regexp', 1],
Expand All @@ -23,7 +23,7 @@ public function validRegexpProvider()
];
}

public function invalidRegexpProvider()
public function invalidRegexpProvider(): array
{
return [
['valid regexp', 'valid regexp'],
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/Util/TestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testGetRequirements($test, $result): void
);
}

public function requirementsProvider()
public function requirementsProvider(): array
{
return [
['testOne', []],
Expand Down Expand Up @@ -351,7 +351,7 @@ public function testGetRequirementsWithVersionConstraints($test, array $result):
}
}

public function requirementsWithVersionConstraintsProvider()
public function requirementsWithVersionConstraintsProvider(): array
{
return [
[
Expand Down Expand Up @@ -467,7 +467,7 @@ public function testGetRequirementsWithInvalidVersionConstraintsThrowsException(
Test::getRequirements(\RequirementsTest::class, $test);
}

public function requirementsWithInvalidVersionConstraintsThrowsExceptionProvider()
public function requirementsWithInvalidVersionConstraintsThrowsExceptionProvider(): array
{
return [
['testVersionConstraintInvalidPhpConstraint'],
Expand Down Expand Up @@ -512,7 +512,7 @@ public function testGetMissingRequirements($test, $result): void
);
}

public function missingRequirementsProvider()
public function missingRequirementsProvider(): array
{
return [
['testOne', []],
Expand Down Expand Up @@ -913,7 +913,7 @@ public function testNamespacedFunctionCanBeCoveredOrUsed(): void
);
}

public function getLinesToBeCoveredProvider()
public function getLinesToBeCoveredProvider(): array
{
return [
[
Expand Down

0 comments on commit cca308e

Please sign in to comment.