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

Fix: Provide all kinds of string values from StringProvider::arbitrary() #338

Merged
merged 2 commits into from
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ For examples, see [`Ergebnis\Test\Util\Test\Unit\DataProvider\NullProviderTest`]

#### `DataProvider\StringProvider`

* `arbitrary()` provides non-empty `string`s without leading and trailing whitespade
* `arbitrary()` provides arbitrary `string`s
* `blank()` provides `string`s consisting of whitespace characters only
* `empty()` provides an empty `string`
* `untrimmed()` provides `string`s with leading and trailing whitespace
Expand Down
4 changes: 1 addition & 3 deletions src/DataProvider/StringProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ final class StringProvider
*/
public static function arbitrary(): \Generator
{
yield from self::provideDataForValuesWhereNot(self::values(), static function (string $value): bool {
return '' === \trim($value);
});
yield from self::provideDataForValues(self::values());
}

/**
Expand Down
11 changes: 8 additions & 3 deletions test/Unit/DataProvider/StringProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ final class StringProviderTest extends AbstractProviderTestCase
/**
* @dataProvider \Ergebnis\Test\Util\DataProvider\StringProvider::arbitrary()
*
* @param string $value
* @param mixed $value
*/
public function testArbitraryProvidesString(string $value): void
public function testArbitraryProvidesString($value): void
{
self::assertNotSame('', \trim($value));
self::assertIsString($value);
}

public function testArbitraryReturnsGeneratorThatProvidesStringsThatAreNeitherEmptyNorBlank(): void
Expand All @@ -42,6 +42,11 @@ public function testArbitraryReturnsGeneratorThatProvidesStringsThatAreNeitherEm
'string-arbitrary-word' => Util\DataProvider\Specification\Closure::create(static function (string $value): bool {
return '' !== $value && '' !== \trim($value);
}),
'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"),
'string-empty' => Util\DataProvider\Specification\Identical::create(''),
'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}$/'),
Expand Down