Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #339 from ergebnis/feature/trimmed
Browse files Browse the repository at this point in the history
Enhancement: Implement DataProvider\StringProvider::trimmed()
  • Loading branch information
ergebnis-bot authored Oct 4, 2020
2 parents b1a37c0 + 6deab44 commit c80a390
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
3 changes: 2 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
</file>
<file src="src/DataProvider/StringProvider.php">
<MixedArgumentTypeCoercion occurrences="2"/>
<MoreSpecificReturnType occurrences="4">
<MoreSpecificReturnType occurrences="5">
<code>\Generator&lt;string, array{0: string}&gt;</code>
<code>\Generator&lt;string, array{0: string}&gt;</code>
<code>\Generator&lt;string, array{0: string}&gt;</code>
<code>\Generator&lt;string, array{0: string}&gt;</code>
Expand Down
11 changes: 11 additions & 0 deletions src/DataProvider/StringProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ public static function empty(): \Generator
});
}

/**
* @return \Generator<string, array{0: string}>
*/
public static function trimmed(): \Generator
{
yield from self::provideDataForValuesWhere(self::values(), static function (string $value): bool {
return \trim($value) === $value
&& '' !== \trim($value);
});
}

/**
* @return \Generator<string, array{0: string}>
*/
Expand Down
26 changes: 26 additions & 0 deletions test/Unit/DataProvider/StringProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit c80a390

Please sign in to comment.