-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathLowercaseFilterTest.php
77 lines (62 loc) · 2 KB
/
LowercaseFilterTest.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
<?php
namespace App\Tests\InputFilter;
use App\InputFilter\LowercaseFilter;
use App\InputFilter\UnexpectedValueException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* @internal
*/
class LowercaseFilterTest extends TestCase {
#[DataProvider('getExamples')]
public function testInputFiltering(string $input, string $output): void {
// given
$data = ['key' => $input];
$outputData = ['key' => $output];
$trim = new LowercaseFilter();
// when
$result = $trim->applyTo($data, 'key');
// then
$this->assertEquals($outputData, $result);
}
public static function getExamples(): array {
return [
['', ''],
['abc', 'abc'],
['AbC', 'abc'],
['This Is A Test', 'this is a test'],
['TeSt123', 'test123'],
['[email protected]', '[email protected]'],
['[email protected]', '[email protected]'],
['[email protected]', '[email protected]'],
['[email protected]', '[email protected]'],
];
}
public function testDoesNothingWhenKeyIsMissing(): void {
// given
$data = ['otherkey' => 'something'];
$lowercase = new LowercaseFilter();
// when
$result = $lowercase->applyTo($data, 'key');
// then
$this->assertEquals($data, $result);
}
public function testDoesNothingWhenValueIsNull(): void {
// given
$data = ['key' => null];
$trim = new LowercaseFilter();
// when
$result = $trim->applyTo($data, 'key');
// then
$this->assertEquals($data, $result);
}
public function testThrowsWhenValueIsNotStringable(): void {
// given
$data = ['key' => new \stdClass()];
$trim = new LowercaseFilter();
// then
$this->expectException(UnexpectedValueException::class);
// when
$trim->applyTo($data, 'key');
}
}