diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 91842a82..a5395785 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -11,7 +11,7 @@ on: # yamllint disable-line rule:truthy env: ERGEBNIS_BOT_NAME: "ergebnis-bot" MIN_COVERED_MSI: 93 - MIN_MSI: 91 + MIN_MSI: 92 PHP_EXTENSIONS: "mbstring" jobs: diff --git a/Makefile b/Makefile index 5b1b4b1e..3d2bbe1a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ MIN_COVERED_MSI:=93 -MIN_MSI:=91 +MIN_MSI:=92 .PHONY: it it: coding-standards static-code-analysis tests ## Runs the coding-standards, static-code-analysis, and tests targets diff --git a/README.md b/README.md index c6e929a8..1d3dd833 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,7 @@ For examples, see [`Ergebnis\Test\Util\Test\Unit\DataProvider\NullProviderTest`] * `arbitrary()` provides arbitrary `string`s * `blank()` provides `string`s consisting of whitespace characters only * `empty()` provides an empty `string` +* `trimmed()` provides non-empty `strings` without leading and trailing whitespace * `untrimmed()` provides `string`s with leading and trailing whitespace For examples, see [`Ergebnis\Test\Util\Test\Unit\DataProvider\StringProviderTest`](test/Unit/DataProvider/StringProviderTest.php). diff --git a/psalm-baseline.xml b/psalm-baseline.xml index b0e83ef5..de541f71 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -28,7 +28,8 @@ - + + \Generator<string, array{0: string}> \Generator<string, array{0: string}> \Generator<string, array{0: string}> \Generator<string, array{0: string}> diff --git a/src/DataProvider/StringProvider.php b/src/DataProvider/StringProvider.php index c16009af..d16d96d8 100644 --- a/src/DataProvider/StringProvider.php +++ b/src/DataProvider/StringProvider.php @@ -48,6 +48,17 @@ public static function empty(): \Generator }); } + /** + * @return \Generator + */ + public static function trimmed(): \Generator + { + yield from self::provideDataForValuesWhere(self::values(), static function (string $value): bool { + return \trim($value) === $value + && '' !== \trim($value); + }); + } + /** * @return \Generator */ diff --git a/test/Unit/DataProvider/StringProviderTest.php b/test/Unit/DataProvider/StringProviderTest.php index 3977ac0d..fb5a9abb 100644 --- a/test/Unit/DataProvider/StringProviderTest.php +++ b/test/Unit/DataProvider/StringProviderTest.php @@ -116,6 +116,32 @@ public function testUntrimmedProvidesUntrimmedString(string $value): void self::assertNotSame('', \trim($value)); } + /** + * @dataProvider \Ergebnis\Test\Util\DataProvider\StringProvider::trimmed() + * + * @param mixed $value + */ + public function testTrimmedProvidesString($value): void + { + self::assertIsString($value); + } + + public function testTrimmedReturnsGeneratorThatProvidesStringsThatAreTrimmed(): void + { + $specifications = [ + 'string-arbitrary-sentence' => Util\DataProvider\Specification\Closure::create(static function (string $value): bool { + return '' !== $value && '' !== \trim($value); + }), + 'string-arbitrary-word' => Util\DataProvider\Specification\Closure::create(static function (string $value): bool { + return '' !== $value && '' !== \trim($value); + }), + ]; + + $provider = StringProvider::trimmed(); + + self::assertProvidesDataSetsForValuesSatisfyingSpecifications($specifications, $provider); + } + public function testUntrimmedReturnsGeneratorThatProvidesUntrimmedStrings(): void { $specifications = [