diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml
index cc4bed70..25d2385d 100644
--- a/.github/workflows/integrate.yaml
+++ b/.github/workflows/integrate.yaml
@@ -10,8 +10,8 @@ on: # yamllint disable-line rule:truthy
env:
ERGEBNIS_BOT_NAME: "ergebnis-bot"
- MIN_COVERED_MSI: 90
- MIN_MSI: 88
+ MIN_COVERED_MSI: 94
+ MIN_MSI: 91
PHP_EXTENSIONS: "mbstring"
jobs:
diff --git a/Makefile b/Makefile
index 279d366a..eff3f4e0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-MIN_COVERED_MSI:=90
-MIN_MSI:=88
+MIN_COVERED_MSI:=94
+MIN_MSI:=91
.PHONY: it
it: coding-standards static-code-analysis tests ## Runs the coding-standards, static-code-analysis, and tests targets
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index aaf6a2ba..f50a06d1 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -665,6 +665,11 @@ parameters:
count: 2
path: test/Unit/DataProvider/AbstractProviderTestCase.php
+ -
+ message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\) with array will always evaluate to true\\.$#"
+ count: 1
+ path: test/Unit/DataProvider/AbstractProviderTestCase.php
+
-
message: "#^Method Ergebnis\\\\Test\\\\Util\\\\Test\\\\Unit\\\\Exception\\\\EmptyValuesTest\\:\\:faker\\(\\) is protected, but since the containing class is final, it can be private\\.$#"
count: 1
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 086e4f96..a96875bb 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -54,10 +54,19 @@
class-string
-
+
$value
+
+ $value
+
+
+ assertIsArray
+
+
+ true === $test($value)
+
diff --git a/test/Unit/DataProvider/AbstractProviderTestCase.php b/test/Unit/DataProvider/AbstractProviderTestCase.php
index 93384a62..e8c0c642 100644
--- a/test/Unit/DataProvider/AbstractProviderTestCase.php
+++ b/test/Unit/DataProvider/AbstractProviderTestCase.php
@@ -45,27 +45,46 @@ final protected static function assertProvidesDataForValues(array $values, \Gene
}
/**
- * @param \Closure $test
+ * @param array $tests
* @param \Generator> $provider
*/
- final protected static function assertProvidesDataForValuesWhere(\Closure $test, \Generator $provider): void
+ final protected static function assertProvidesDataForValuesPassingTests(array $tests, \Generator $provider): void
{
$provided = \iterator_to_array($provider);
- self::assertProvidedDataIsNotEmpty($provided);
- self::assertProvidedDataContainsArraysWhereFirstElementPassesTest($test, $provided);
- }
+ self::assertEquals(
+ \array_keys($tests),
+ \array_keys($provided),
+ 'Failed asserting that the provided data has the same keys as the tests.'
+ );
- /**
- * @param \Closure $test
- * @param \Generator> $provider
- */
- final protected static function assertProvidesDataForValuesWhereNot(\Closure $test, \Generator $provider): void
- {
- $provided = \iterator_to_array($provider);
+ $normalizedTests = \array_map(static function ($test): \Closure {
+ if (!$test instanceof \Closure) {
+ return static function ($value) use ($test): bool {
+ return $value === $test;
+ };
+ }
- self::assertProvidedDataIsNotEmpty($provided);
- self::assertProvidedDataContainsArraysWhereFirstElementDoesNotPassTest($test, $provided);
+ return $test;
+ }, $tests);
+
+ $keysWhereValueDoesNotPassTest = \array_filter(\array_keys($provided), static function (string $key) use ($provided, $normalizedTests): bool {
+ $set = $provided[$key];
+
+ self::assertIsArray($set);
+ self::assertCount(1, $set);
+
+ $value = \array_shift($set);
+ $test = $normalizedTests[$key];
+
+ return true !== $test($value);
+ });
+
+ self::assertEquals(
+ [],
+ $keysWhereValueDoesNotPassTest,
+ 'Failed asserting that all values pass the corresponding tests.'
+ );
}
/**
diff --git a/test/Unit/DataProvider/IntProviderTest.php b/test/Unit/DataProvider/IntProviderTest.php
index 07b77959..1ced5f43 100644
--- a/test/Unit/DataProvider/IntProviderTest.php
+++ b/test/Unit/DataProvider/IntProviderTest.php
@@ -34,13 +34,21 @@ public function testArbitraryProvidesInt($value): void
public function testArbitraryReturnsGeneratorThatProvidesIntValues(): void
{
- $test = static function ($value): bool {
- return \is_int($value);
- };
+ $tests = [
+ 'int-less-than-minus-one' => 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;
+ },
+ ];
$provider = IntProvider::arbitrary();
- self::assertProvidesDataForValuesWhere($test, $provider);
+ self::assertProvidesDataForValuesPassingTests($tests, $provider);
}
/**
@@ -55,13 +63,16 @@ public function testLessThanZeroProvidesIntLessThanZero(int $value): void
public function testLessThanZeroReturnsGeneratorThatProvidesIntLessThanZero(): void
{
- $test = static function (int $value): bool {
- return 0 > $value;
- };
+ $tests = [
+ 'int-less-than-minus-one' => static function (int $value): bool {
+ return -1 > $value;
+ },
+ 'int-minus-one' => -1,
+ ];
$provider = IntProvider::lessThanZero();
- self::assertProvidesDataForValuesWhere($test, $provider);
+ self::assertProvidesDataForValuesPassingTests($tests, $provider);
}
/**
@@ -97,13 +108,16 @@ public function testGreaterThanZeroProvidesIntGreaterThanZero(int $value): void
public function testGreaterThanZeroReturnsGeneratorThatProvidesIntGreaterThanZero(): void
{
- $test = static function (int $value): bool {
- return 0 < $value;
- };
+ $tests = [
+ 'int-plus-one' => 1,
+ 'int-greater-than-plus-one' => static function (int $value): bool {
+ return 1 < $value;
+ },
+ ];
$provider = IntProvider::greaterThanZero();
- self::assertProvidesDataForValuesWhere($test, $provider);
+ self::assertProvidesDataForValuesPassingTests($tests, $provider);
}
/**
@@ -118,13 +132,17 @@ public function testLessThanOneProvidesIntLessThanOne(int $value): void
public function testLessThanOneReturnsGeneratorThatProvidesIntLessThanOne(): void
{
- $test = static function (int $value): bool {
- return 1 > $value;
- };
+ $tests = [
+ 'int-less-than-minus-one' => static function (int $value): bool {
+ return -1 > $value;
+ },
+ 'int-minus-one' => -1,
+ 'int-zero' => 0,
+ ];
$provider = IntProvider::lessThanOne();
- self::assertProvidesDataForValuesWhere($test, $provider);
+ self::assertProvidesDataForValuesPassingTests($tests, $provider);
}
public function testOneReturnsGeneratorThatProvidesOne(): void
@@ -150,12 +168,14 @@ public function testGreaterThanOneProvidesIntGreaterThanOne(int $value): void
public function testGreaterThanOneReturnsGeneratorThatProvidesIntGreaterThanOne(): void
{
- $test = static function (int $value): bool {
- return 1 < $value;
- };
+ $tests = [
+ 'int-greater-than-plus-one' => static function (int $value): bool {
+ return 1 < $value;
+ },
+ ];
$provider = IntProvider::greaterThanOne();
- self::assertProvidesDataForValuesWhere($test, $provider);
+ self::assertProvidesDataForValuesPassingTests($tests, $provider);
}
}
diff --git a/test/Unit/DataProvider/StringProviderTest.php b/test/Unit/DataProvider/StringProviderTest.php
index ddfc5f5e..8a31da42 100644
--- a/test/Unit/DataProvider/StringProviderTest.php
+++ b/test/Unit/DataProvider/StringProviderTest.php
@@ -34,13 +34,30 @@ public function testArbitraryProvidesString(string $value): void
public function testArbitraryReturnsGeneratorThatProvidesStringsThatAreNeitherEmptyNorBlank(): void
{
- $test = static function (string $value): bool {
- return '' === \trim($value);
- };
+ $tests = [
+ 'string-arbitrary-sentence' => static function (string $value): bool {
+ return '' !== $value && '' !== \trim($value);
+ },
+ 'string-arbitrary-word' => 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);
+ },
+ ];
$provider = StringProvider::arbitrary();
- self::assertProvidesDataForValuesWhereNot($test, $provider);
+ self::assertProvidesDataForValuesPassingTests($tests, $provider);
}
/**
@@ -103,13 +120,23 @@ public function testUntrimmedProvidesUntrimmedString(string $value): void
public function testUntrimmedReturnsGeneratorThatProvidesUntrimmedStrings(): void
{
- $test = static function (string $value): bool {
- return \trim($value) !== $value
- && '' !== \trim($value);
- };
+ $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);
+ },
+ ];
$provider = StringProvider::untrimmed();
- self::assertProvidesDataForValuesWhere($test, $provider);
+ self::assertProvidesDataForValuesPassingTests($tests, $provider);
}
}