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

Commit

Permalink
Enhancement: Implement DataProvider\StringProvider::trimmed()
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Oct 4, 2020
1 parent 928a7ac commit d68f138
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integrate.yaml
Expand Up @@ -10,8 +10,8 @@ on: # yamllint disable-line rule:truthy

env:
ERGEBNIS_BOT_NAME: "ergebnis-bot"
MIN_COVERED_MSI: 93
MIN_MSI: 91
MIN_COVERED_MSI: 94
MIN_MSI: 92
PHP_EXTENSIONS: "mbstring"

jobs:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
@@ -1,5 +1,5 @@
MIN_COVERED_MSI:=93
MIN_MSI:=91
MIN_COVERED_MSI:=94
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
Expand Up @@ -165,6 +165,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
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
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
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 d68f138

Please sign in to comment.