This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
StringProviderTest.php
142 lines (122 loc) · 4.52 KB
/
StringProviderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
declare(strict_types=1);
/**
* Copyright (c) 2017-2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/test-util
*/
namespace Ergebnis\Test\Util\Test\Unit\DataProvider;
use Ergebnis\Test\Util\DataProvider\StringProvider;
/**
* @internal
*
* @covers \Ergebnis\Test\Util\DataProvider\StringProvider
*/
final class StringProviderTest extends AbstractProviderTestCase
{
/**
* @dataProvider \Ergebnis\Test\Util\DataProvider\StringProvider::arbitrary()
*
* @param string $value
*/
public function testArbitraryProvidesString(string $value): void
{
self::assertNotSame('', \trim($value));
}
public function testArbitraryReturnsGeneratorThatProvidesStringsThatAreNeitherEmptyNorBlank(): void
{
$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::assertProvidesDataForValuesPassingTests($tests, $provider);
}
/**
* @dataProvider \Ergebnis\Test\Util\DataProvider\StringProvider::blank()
*
* @param string $value
*/
public function testBlankProvidesBlankString(string $value): void
{
self::assertSame('', \trim($value));
self::assertNotSame('', $value);
}
public function testBlankReturnsGeneratorThatProvidesStringsThatAreNeitherEmptyNorBlank(): void
{
$values = [
'string-blank-carriage-return' => "\r",
'string-blank-line-feed' => "\n",
'string-blank-space' => ' ',
'string-blank-tab' => "\t",
];
$provider = StringProvider::blank();
self::assertProvidesDataForValues($values, $provider);
}
/**
* @dataProvider \Ergebnis\Test\Util\DataProvider\StringProvider::empty()
*
* @param string $value
*/
public function testEmptyProvidesEmptyString(string $value): void
{
self::assertSame('', $value);
}
public function testEmptyReturnsGeneratorThatProvidesAnEmptyString(): void
{
$values = [
'string-empty' => '',
];
$provider = StringProvider::empty();
self::assertProvidesDataForValues($values, $provider);
}
/**
* @dataProvider \Ergebnis\Test\Util\DataProvider\StringProvider::untrimmed()
*
* @param string $value
*/
public function testUntrimmedProvidesUntrimmedString(string $value): void
{
self::assertNotSame(\trim($value), $value);
self::assertNotSame('', $value);
self::assertNotSame('', \trim($value));
}
public function testUntrimmedReturnsGeneratorThatProvidesUntrimmedStrings(): void
{
$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::assertProvidesDataForValuesPassingTests($tests, $provider);
}
}