diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml
index 25d2385d..91842a82 100644
--- a/.github/workflows/integrate.yaml
+++ b/.github/workflows/integrate.yaml
@@ -10,7 +10,7 @@ on: # yamllint disable-line rule:truthy
env:
ERGEBNIS_BOT_NAME: "ergebnis-bot"
- MIN_COVERED_MSI: 94
+ MIN_COVERED_MSI: 93
MIN_MSI: 91
PHP_EXTENSIONS: "mbstring"
diff --git a/Makefile b/Makefile
index eff3f4e0..5b1b4b1e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-MIN_COVERED_MSI:=94
+MIN_COVERED_MSI:=93
MIN_MSI:=91
.PHONY: it
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index f50a06d1..805f150d 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -666,7 +666,7 @@ parameters:
path: test/Unit/DataProvider/AbstractProviderTestCase.php
-
- message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\) with array will always evaluate to true\\.$#"
+ message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\) with array and string will always evaluate to true\\.$#"
count: 1
path: test/Unit/DataProvider/AbstractProviderTestCase.php
@@ -1255,3 +1255,38 @@ parameters:
count: 1
path: test/Unit/HelperTest.php
+ -
+ message: "#^Method Ergebnis\\\\Test\\\\Util\\\\Test\\\\Util\\\\DataProvider\\\\Specification\\\\Closure\\:\\:isSatisfiedBy\\(\\) has parameter \\$value with no typehint specified\\.$#"
+ count: 1
+ path: test/Util/DataProvider/Specification/Closure.php
+
+ -
+ message: "#^Property Ergebnis\\\\Test\\\\Util\\\\Test\\\\Util\\\\DataProvider\\\\Specification\\\\Identical\\:\\:\\$value has no typehint specified\\.$#"
+ count: 1
+ path: test/Util/DataProvider/Specification/Identical.php
+
+ -
+ message: "#^Method Ergebnis\\\\Test\\\\Util\\\\Test\\\\Util\\\\DataProvider\\\\Specification\\\\Identical\\:\\:__construct\\(\\) has parameter \\$value with no typehint specified\\.$#"
+ count: 1
+ path: test/Util/DataProvider/Specification/Identical.php
+
+ -
+ message: "#^Method Ergebnis\\\\Test\\\\Util\\\\Test\\\\Util\\\\DataProvider\\\\Specification\\\\Identical\\:\\:create\\(\\) has parameter \\$value with no typehint specified\\.$#"
+ count: 1
+ path: test/Util/DataProvider/Specification/Identical.php
+
+ -
+ message: "#^Method Ergebnis\\\\Test\\\\Util\\\\Test\\\\Util\\\\DataProvider\\\\Specification\\\\Identical\\:\\:isSatisfiedBy\\(\\) has parameter \\$value with no typehint specified\\.$#"
+ count: 1
+ path: test/Util/DataProvider/Specification/Identical.php
+
+ -
+ message: "#^Method Ergebnis\\\\Test\\\\Util\\\\Test\\\\Util\\\\DataProvider\\\\Specification\\\\Pattern\\:\\:isSatisfiedBy\\(\\) has parameter \\$value with no typehint specified\\.$#"
+ count: 1
+ path: test/Util/DataProvider/Specification/Pattern.php
+
+ -
+ message: "#^Method Ergebnis\\\\Test\\\\Util\\\\Test\\\\Util\\\\DataProvider\\\\Specification\\\\Specification\\:\\:isSatisfiedBy\\(\\) has parameter \\$value with no typehint specified\\.$#"
+ count: 1
+ path: test/Util/DataProvider/Specification/Specification.php
+
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index a96875bb..b0e83ef5 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -55,18 +55,15 @@
-
- $value
-
$value
assertIsArray
-
- true === $test($value)
-
+
+ Util\Test\Util\DataProvider\Specification\Specification
+
@@ -118,4 +115,38 @@
\iterator_to_array
+
+
+ $value
+
+
+ $value
+
+
+ bool
+
+
+ $closure($value)
+
+
+
+
+ $value
+ $value
+ $value
+
+
+ $value
+
+
+
+
+ $value
+
+
+
+
+ $value
+
+
diff --git a/test/Unit/DataProvider/AbstractProviderTestCase.php b/test/Unit/DataProvider/AbstractProviderTestCase.php
index e8c0c642..2eabfdfe 100644
--- a/test/Unit/DataProvider/AbstractProviderTestCase.php
+++ b/test/Unit/DataProvider/AbstractProviderTestCase.php
@@ -27,72 +27,89 @@ abstract class AbstractProviderTestCase extends Framework\TestCase
* @param array $values
* @param \Generator> $provider
*/
- final protected static function assertProvidesDataForValues(array $values, \Generator $provider): void
+ final protected static function assertProvidesDataSetsForValues(array $values, \Generator $provider): void
{
self::assertExpectedValuesAreNotEmpty($values);
- $expected = \iterator_to_array(self::provideDataForValues($values));
+ $expectedDataSets = \iterator_to_array(self::provideDataForValues($values));
+ $actualDataSets = \iterator_to_array($provider);
- $provided = \iterator_to_array($provider);
-
- self::assertProvidedDataIsNotEmpty($provided);
+ self::assertDataSetsAreNotEmpty($actualDataSets);
self::assertEquals(
- $expected,
- $provided,
- 'Failed asserting that a generator yields data for expected values.'
+ $expectedDataSets,
+ $actualDataSets,
+ 'Failed asserting that a generator yields data sets for the expected values.'
);
}
/**
- * @param array $tests
- * @param \Generator> $provider
+ * @param array $specifications
+ * @param \Generator> $provider
*/
- final protected static function assertProvidesDataForValuesPassingTests(array $tests, \Generator $provider): void
+ final protected static function assertProvidesDataSetsForValuesSatisfyingSpecifications(array $specifications, \Generator $provider): void
{
- $provided = \iterator_to_array($provider);
+ self::assertContainsOnly(
+ 'string',
+ \array_keys($specifications),
+ true,
+ 'Failed asserting that the keys of specifications are all strings.'
+ );
+
+ self::assertContainsOnly(
+ Util\Test\Util\DataProvider\Specification\Specification::class,
+ $specifications,
+ false,
+ \sprintf(
+ 'Failed asserting that the values of specifications implement "%s".',
+ Util\Test\Util\DataProvider\Specification\Specification::class
+ )
+ );
+
+ $dataSets = \iterator_to_array($provider);
self::assertEquals(
- \array_keys($tests),
- \array_keys($provided),
- 'Failed asserting that the provided data has the same keys as the tests.'
+ \array_keys($specifications),
+ \array_keys($dataSets),
+ 'Failed asserting that the provided data has the same keys as the specifications.'
);
- $normalizedTests = \array_map(static function ($test): \Closure {
- if (!$test instanceof \Closure) {
- return static function ($value) use ($test): bool {
- return $value === $test;
- };
- }
+ $keysForDataSetsWhereValueDoesNotSatisfySpecification = \array_filter(\array_keys($dataSets), static function (string $key) use ($dataSets, $specifications): bool {
+ /** @var Util\Test\Util\DataProvider\Specification\Specification $specification */
+ $specification = $specifications[$key];
- return $test;
- }, $tests);
+ $dataSet = $dataSets[$key];
- $keysWhereValueDoesNotPassTest = \array_filter(\array_keys($provided), static function (string $key) use ($provided, $normalizedTests): bool {
- $set = $provided[$key];
+ self::assertIsArray($dataSet, \sprintf(
+ 'Failed asserting that the data set provided for key "%s" is an array.',
+ $key
+ ));
- self::assertIsArray($set);
- self::assertCount(1, $set);
+ self::assertCount(1, $dataSet, \sprintf(
+ 'Failed asserting that the data set provided for key "%s" contains only one value.',
+ $key
+ ));
- $value = \array_shift($set);
- $test = $normalizedTests[$key];
+ $value = \array_shift($dataSet);
- return true !== $test($value);
+ return !$specification->isSatisfiedBy($value);
});
- self::assertEquals(
- [],
- $keysWhereValueDoesNotPassTest,
- 'Failed asserting that all values pass the corresponding tests.'
- );
+ self::assertEquals([], $keysForDataSetsWhereValueDoesNotSatisfySpecification, \sprintf(
+ 'Failed asserting that the value for the data sets with the keys "%s" satisfy the corresponding requirements.',
+ \implode(
+ '", "',
+ $keysForDataSetsWhereValueDoesNotSatisfySpecification
+ )
+ ));
}
/**
* @param array $actual
*/
- final protected static function assertProvidedDataIsNotEmpty(array $actual): void
+ final protected static function assertDataSetsAreNotEmpty(array $actual): void
{
- self::assertNotEmpty($actual, 'Failed asserting that provided values are not empty.');
+ self::assertNotEmpty($actual, 'Failed asserting that provided data sets are not empty.');
}
/**
@@ -102,84 +119,4 @@ private static function assertExpectedValuesAreNotEmpty(array $values): void
{
self::assertNotEmpty($values, 'Failed asserting that expected values are not empty.');
}
-
- /**
- * @param \Closure $test
- * @param array $provided
- */
- private static function assertProvidedDataContainsArraysWhereFirstElementPassesTest(\Closure $test, array $provided): void
- {
- self::assertProvidedDataContainsArraysWithOneElement($provided);
-
- $value = \array_map(static function (array $set) {
- return \array_shift($set);
- }, $provided);
-
- $tested = \array_filter($value, static function ($value) use ($test): bool {
- return true === $test($value);
- });
-
- self::assertEquals(
- $value,
- $tested,
- 'Failed asserting that the first value in each array passed the test.'
- );
- }
-
- /**
- * @param \Closure $test
- * @param array $provided
- */
- private static function assertProvidedDataContainsArraysWhereFirstElementDoesNotPassTest(\Closure $test, array $provided): void
- {
- self::assertProvidedDataContainsArraysWithOneElement($provided);
-
- $value = \array_map(static function (array $set) {
- return \array_shift($set);
- }, $provided);
-
- $tested = \array_filter($value, static function ($value) use ($test): bool {
- return false === $test($value);
- });
-
- self::assertEquals(
- $value,
- $tested,
- 'Failed asserting that the first value in each array does not pass the test.'
- );
- }
-
- /**
- * @param array $provided
- */
- private static function assertProvidedDataContainsArraysWithOneElement(array $provided): void
- {
- self::assertProvidedDataContainsArraysOnly($provided);
-
- $setsWhereNumberOfProvidedArgumentsIsNotOne = \array_filter($provided, static function (array $set): bool {
- return 1 !== \count($set);
- });
-
- self::assertEquals(
- [],
- $setsWhereNumberOfProvidedArgumentsIsNotOne,
- 'Failed asserting that each set in the provided data contains only a single value.'
- );
- }
-
- /**
- * @param array $provided
- */
- private static function assertProvidedDataContainsArraysOnly(array $provided): void
- {
- $values = \array_filter($provided, static function ($set): bool {
- return !\is_array($set);
- });
-
- self::assertEquals(
- [],
- $values,
- 'Failed asserting that each value is an array.'
- );
- }
}
diff --git a/test/Unit/DataProvider/BoolProviderTest.php b/test/Unit/DataProvider/BoolProviderTest.php
index 73f88765..7bfaaa42 100644
--- a/test/Unit/DataProvider/BoolProviderTest.php
+++ b/test/Unit/DataProvider/BoolProviderTest.php
@@ -14,6 +14,7 @@
namespace Ergebnis\Test\Util\Test\Unit\DataProvider;
use Ergebnis\Test\Util\DataProvider\BoolProvider;
+use Ergebnis\Test\Util\Test\Util;
/**
* @internal
@@ -34,14 +35,14 @@ public function testArbitraryProvidesBool($value): void
public function testArbitraryReturnsGeneratorThatProvidesBoolValues(): void
{
- $values = [
- 'bool-false' => false,
- 'bool-true' => true,
+ $specifications = [
+ 'bool-false' => Util\DataProvider\Specification\Identical::create(false),
+ 'bool-true' => Util\DataProvider\Specification\Identical::create(true),
];
$provider = BoolProvider::arbitrary();
- self::assertProvidesDataForValues($values, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
/**
@@ -56,13 +57,13 @@ public function testFalseProvidesFalse($value): void
public function testFalseReturnsGeneratorThatProvidesFalse(): void
{
- $values = [
- 'bool-false' => false,
+ $specifications = [
+ 'bool-false' => Util\DataProvider\Specification\Identical::create(false),
];
$provider = BoolProvider::false();
- self::assertProvidesDataForValues($values, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
/**
@@ -77,12 +78,12 @@ public function testTrueProvidesTrue($value): void
public function testTrueReturnsGeneratorThatProvidesTrue(): void
{
- $values = [
- 'bool-true' => true,
+ $specifications = [
+ 'bool-true' => Util\DataProvider\Specification\Identical::create(true),
];
$provider = BoolProvider::true();
- self::assertProvidesDataForValues($values, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
}
diff --git a/test/Unit/DataProvider/IntProviderTest.php b/test/Unit/DataProvider/IntProviderTest.php
index 1ced5f43..10191b78 100644
--- a/test/Unit/DataProvider/IntProviderTest.php
+++ b/test/Unit/DataProvider/IntProviderTest.php
@@ -14,6 +14,7 @@
namespace Ergebnis\Test\Util\Test\Unit\DataProvider;
use Ergebnis\Test\Util\DataProvider\IntProvider;
+use Ergebnis\Test\Util\Test\Util;
/**
* @internal
@@ -34,21 +35,21 @@ public function testArbitraryProvidesInt($value): void
public function testArbitraryReturnsGeneratorThatProvidesIntValues(): void
{
- $tests = [
- 'int-less-than-minus-one' => static function (int $value): bool {
+ $specifications = [
+ 'int-less-than-minus-one' => Util\DataProvider\Specification\Closure::create(static function (int $value): bool {
return -1 > $value;
- },
- 'int-minus-one' => -1,
- 'int-zero' => 0,
- 'int-plus-one' => 1,
- 'int-greater-than-plus-one' => static function (int $value): bool {
- return 1 < $value;
- },
+ }),
+ 'int-minus-one' => Util\DataProvider\Specification\Identical::create(-1),
+ 'int-zero' => Util\DataProvider\Specification\Identical::create(0),
+ 'int-plus-one' => Util\DataProvider\Specification\Identical::create(1),
+ 'int-greater-than-plus-one' => Util\DataProvider\Specification\Closure::create(static function (int $value): bool {
+ return 1 < $value;
+ }),
];
$provider = IntProvider::arbitrary();
- self::assertProvidesDataForValuesPassingTests($tests, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
/**
@@ -63,16 +64,16 @@ public function testLessThanZeroProvidesIntLessThanZero(int $value): void
public function testLessThanZeroReturnsGeneratorThatProvidesIntLessThanZero(): void
{
- $tests = [
- 'int-less-than-minus-one' => static function (int $value): bool {
+ $specifications = [
+ 'int-less-than-minus-one' => Util\DataProvider\Specification\Closure::create(static function (int $value): bool {
return -1 > $value;
- },
- 'int-minus-one' => -1,
+ }),
+ 'int-minus-one' => Util\DataProvider\Specification\Identical::create(-1),
];
$provider = IntProvider::lessThanZero();
- self::assertProvidesDataForValuesPassingTests($tests, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
/**
@@ -87,13 +88,13 @@ public function testZeroProvidesZero(int $value): void
public function testZeroReturnsGeneratorThatProvidesZero(): void
{
- $values = [
- 'int-zero' => 0,
+ $specifications = [
+ 'int-zero' => Util\DataProvider\Specification\Identical::create(0),
];
$provider = IntProvider::zero();
- self::assertProvidesDataForValues($values, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
/**
@@ -108,16 +109,16 @@ public function testGreaterThanZeroProvidesIntGreaterThanZero(int $value): void
public function testGreaterThanZeroReturnsGeneratorThatProvidesIntGreaterThanZero(): void
{
- $tests = [
- 'int-plus-one' => 1,
- 'int-greater-than-plus-one' => static function (int $value): bool {
- return 1 < $value;
- },
+ $specifications = [
+ 'int-plus-one' => Util\DataProvider\Specification\Identical::create(1),
+ 'int-greater-than-plus-one' => Util\DataProvider\Specification\Closure::create(static function (int $value): bool {
+ return 1 < $value;
+ }),
];
$provider = IntProvider::greaterThanZero();
- self::assertProvidesDataForValuesPassingTests($tests, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
/**
@@ -132,28 +133,28 @@ public function testLessThanOneProvidesIntLessThanOne(int $value): void
public function testLessThanOneReturnsGeneratorThatProvidesIntLessThanOne(): void
{
- $tests = [
- 'int-less-than-minus-one' => static function (int $value): bool {
+ $specifications = [
+ 'int-less-than-minus-one' => Util\DataProvider\Specification\Closure::create(static function (int $value): bool {
return -1 > $value;
- },
- 'int-minus-one' => -1,
- 'int-zero' => 0,
+ }),
+ 'int-minus-one' => Util\DataProvider\Specification\Identical::create(-1),
+ 'int-zero' => Util\DataProvider\Specification\Identical::create(0),
];
$provider = IntProvider::lessThanOne();
- self::assertProvidesDataForValuesPassingTests($tests, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
public function testOneReturnsGeneratorThatProvidesOne(): void
{
- $values = [
- 'int-plus-one' => 1,
+ $specifications = [
+ 'int-plus-one' => Util\DataProvider\Specification\Identical::create(1),
];
$provider = IntProvider::one();
- self::assertProvidesDataForValues($values, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
/**
@@ -168,14 +169,14 @@ public function testGreaterThanOneProvidesIntGreaterThanOne(int $value): void
public function testGreaterThanOneReturnsGeneratorThatProvidesIntGreaterThanOne(): void
{
- $tests = [
- 'int-greater-than-plus-one' => static function (int $value): bool {
- return 1 < $value;
- },
+ $specifications = [
+ 'int-greater-than-plus-one' => Util\DataProvider\Specification\Closure::create(static function (int $value): bool {
+ return 1 < $value;
+ }),
];
$provider = IntProvider::greaterThanOne();
- self::assertProvidesDataForValuesPassingTests($tests, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
}
diff --git a/test/Unit/DataProvider/NullProviderTest.php b/test/Unit/DataProvider/NullProviderTest.php
index 4783e965..6a489cf3 100644
--- a/test/Unit/DataProvider/NullProviderTest.php
+++ b/test/Unit/DataProvider/NullProviderTest.php
@@ -14,6 +14,7 @@
namespace Ergebnis\Test\Util\Test\Unit\DataProvider;
use Ergebnis\Test\Util\DataProvider\NullProvider;
+use Ergebnis\Test\Util\Test\Util;
/**
* @internal
@@ -34,12 +35,12 @@ public function testNullProvidesNull($value): void
public function testNullReturnsGeneratorThatProvidesNull(): void
{
- $values = [
- 'null' => null,
+ $specifications = [
+ 'null' => Util\DataProvider\Specification\Identical::create(null),
];
$provider = NullProvider::null();
- self::assertProvidesDataForValues($values, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
}
diff --git a/test/Unit/DataProvider/StringProviderTest.php b/test/Unit/DataProvider/StringProviderTest.php
index 8a31da42..a7ca1fd1 100644
--- a/test/Unit/DataProvider/StringProviderTest.php
+++ b/test/Unit/DataProvider/StringProviderTest.php
@@ -14,6 +14,7 @@
namespace Ergebnis\Test\Util\Test\Unit\DataProvider;
use Ergebnis\Test\Util\DataProvider\StringProvider;
+use Ergebnis\Test\Util\Test\Util;
/**
* @internal
@@ -34,30 +35,22 @@ public function testArbitraryProvidesString(string $value): void
public function testArbitraryReturnsGeneratorThatProvidesStringsThatAreNeitherEmptyNorBlank(): void
{
- $tests = [
- 'string-arbitrary-sentence' => static function (string $value): bool {
+ $specifications = [
+ 'string-arbitrary-sentence' => Util\DataProvider\Specification\Closure::create(static function (string $value): bool {
return '' !== $value && '' !== \trim($value);
- },
- 'string-arbitrary-word' => static function (string $value): bool {
+ }),
+ 'string-arbitrary-word' => Util\DataProvider\Specification\Closure::create(static function (string $value): bool {
return '' !== $value && '' !== \trim($value);
- },
- 'string-untrimmed-carriage-return' => static function (string $value): bool {
- return 1 === \preg_match('/^\r{1,5}\w+\r{1,5}$/', $value);
- },
- 'string-untrimmed-line-feed' => static function (string $value): bool {
- return 1 === \preg_match('/^\n{1,5}\w+\n{1,5}$/', $value);
- },
- 'string-untrimmed-space' => static function (string $value): bool {
- return 1 === \preg_match('/^\s{1,5}\w+\s{1,5}$/', $value);
- },
- 'string-untrimmed-tab' => static function (string $value): bool {
- return 1 === \preg_match('/^\t{1,5}\w+\t{1,5}$/', $value);
- },
+ }),
+ 'string-untrimmed-carriage-return' => Util\DataProvider\Specification\Pattern::create('/^\r{1,5}\w+\r{1,5}$/'),
+ 'string-untrimmed-line-feed' => Util\DataProvider\Specification\Pattern::create('/^\n{1,5}\w+\n{1,5}$/'),
+ 'string-untrimmed-space' => Util\DataProvider\Specification\Pattern::create('/^\s{1,5}\w+\s{1,5}$/'),
+ 'string-untrimmed-tab' => Util\DataProvider\Specification\Pattern::create('/^\t{1,5}\w+\t{1,5}$/'),
];
$provider = StringProvider::arbitrary();
- self::assertProvidesDataForValuesPassingTests($tests, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
/**
@@ -73,16 +66,16 @@ public function testBlankProvidesBlankString(string $value): void
public function testBlankReturnsGeneratorThatProvidesStringsThatAreNeitherEmptyNorBlank(): void
{
- $values = [
- 'string-blank-carriage-return' => "\r",
- 'string-blank-line-feed' => "\n",
- 'string-blank-space' => ' ',
- 'string-blank-tab' => "\t",
+ $specifications = [
+ 'string-blank-carriage-return' => Util\DataProvider\Specification\Identical::create("\r"),
+ 'string-blank-line-feed' => Util\DataProvider\Specification\Identical::create("\n"),
+ 'string-blank-space' => Util\DataProvider\Specification\Identical::create(' '),
+ 'string-blank-tab' => Util\DataProvider\Specification\Identical::create("\t"),
];
$provider = StringProvider::blank();
- self::assertProvidesDataForValues($values, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
/**
@@ -97,13 +90,13 @@ public function testEmptyProvidesEmptyString(string $value): void
public function testEmptyReturnsGeneratorThatProvidesAnEmptyString(): void
{
- $values = [
- 'string-empty' => '',
+ $specifications = [
+ 'string-empty' => Util\DataProvider\Specification\Identical::create(''),
];
$provider = StringProvider::empty();
- self::assertProvidesDataForValues($values, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
/**
@@ -120,23 +113,15 @@ public function testUntrimmedProvidesUntrimmedString(string $value): void
public function testUntrimmedReturnsGeneratorThatProvidesUntrimmedStrings(): void
{
- $tests = [
- 'string-untrimmed-carriage-return' => static function (string $value): bool {
- return 1 === \preg_match('/^\r{1,5}\w+\r{1,5}$/', $value);
- },
- 'string-untrimmed-line-feed' => static function (string $value): bool {
- return 1 === \preg_match('/^\n{1,5}\w+\n{1,5}$/', $value);
- },
- 'string-untrimmed-space' => static function (string $value): bool {
- return 1 === \preg_match('/^\s{1,5}\w+\s{1,5}$/', $value);
- },
- 'string-untrimmed-tab' => static function (string $value): bool {
- return 1 === \preg_match('/^\t{1,5}\w+\t{1,5}$/', $value);
- },
+ $specifications = [
+ 'string-untrimmed-carriage-return' => Util\DataProvider\Specification\Pattern::create('/^\r{1,5}\w+\r{1,5}$/'),
+ 'string-untrimmed-line-feed' => Util\DataProvider\Specification\Pattern::create('/^\n{1,5}\w+\n{1,5}$/'),
+ 'string-untrimmed-space' => Util\DataProvider\Specification\Pattern::create('/^\s{1,5}\w+\s{1,5}$/'),
+ 'string-untrimmed-tab' => Util\DataProvider\Specification\Pattern::create('/^\t{1,5}\w+\t{1,5}$/'),
];
$provider = StringProvider::untrimmed();
- self::assertProvidesDataForValuesPassingTests($tests, $provider);
+ self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider);
}
}
diff --git a/test/Util/DataProvider/Specification/Closure.php b/test/Util/DataProvider/Specification/Closure.php
new file mode 100644
index 00000000..fd2e3901
--- /dev/null
+++ b/test/Util/DataProvider/Specification/Closure.php
@@ -0,0 +1,41 @@
+closure = static function ($value) use ($closure): bool {
+ return true === $closure($value);
+ };
+ }
+
+ public static function create(\Closure $closure): self
+ {
+ return new self($closure);
+ }
+
+ public function isSatisfiedBy($value): bool
+ {
+ $closure = $this->closure;
+
+ return $closure($value);
+ }
+}
diff --git a/test/Util/DataProvider/Specification/Identical.php b/test/Util/DataProvider/Specification/Identical.php
new file mode 100644
index 00000000..88c43ce9
--- /dev/null
+++ b/test/Util/DataProvider/Specification/Identical.php
@@ -0,0 +1,34 @@
+value = $value;
+ }
+
+ public static function create($value): self
+ {
+ return new self($value);
+ }
+
+ public function isSatisfiedBy($value): bool
+ {
+ return $this->value === $value;
+ }
+}
diff --git a/test/Util/DataProvider/Specification/Pattern.php b/test/Util/DataProvider/Specification/Pattern.php
new file mode 100644
index 00000000..9fe9e98f
--- /dev/null
+++ b/test/Util/DataProvider/Specification/Pattern.php
@@ -0,0 +1,41 @@
+pattern = $pattern;
+ }
+
+ public static function create(string $pattern): self
+ {
+ return new self($pattern);
+ }
+
+ public function isSatisfiedBy($value): bool
+ {
+ if (!\is_string($value)) {
+ return false;
+ }
+
+ return 1 === \preg_match($this->pattern, $value);
+ }
+}
diff --git a/test/Util/DataProvider/Specification/Specification.php b/test/Util/DataProvider/Specification/Specification.php
new file mode 100644
index 00000000..33cc3a6b
--- /dev/null
+++ b/test/Util/DataProvider/Specification/Specification.php
@@ -0,0 +1,19 @@
+