1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Tests\Unit\Core\Utils; |
6
|
|
|
|
7
|
|
|
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Utils\StringUtils; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
final class StringUtilsTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
public function testDoesStartWith(): void |
13
|
|
|
{ |
14
|
|
|
$this->assertTrue(StringUtils::startsWith('Foo', 'FooBar')); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function testDoesStartWith2(): void |
18
|
|
|
{ |
19
|
|
|
$this->assertTrue(StringUtils::startsWith('Foo', 'FooBarFoo')); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testDoesNotStartWith(): void |
23
|
|
|
{ |
24
|
|
|
$this->assertFalse(StringUtils::startsWith('oo', 'FooBar')); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testRemoveFromStart(): void |
28
|
|
|
{ |
29
|
|
|
$this->assertEquals('Bar', StringUtils::removeFromStart('Foo', 'FooBar')); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testRemoveFromStartExceptionWhenInvalidStart(): void |
33
|
|
|
{ |
34
|
|
|
$this->expectException(\InvalidArgumentException::class); |
35
|
|
|
StringUtils::removeFromStart('Bar', 'FooBar'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testDoesEndWith1(): void |
39
|
|
|
{ |
40
|
|
|
$this->assertTrue(StringUtils::endsWith('e', 'abcde')); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testDoesEndWith2(): void |
44
|
|
|
{ |
45
|
|
|
$this->assertTrue(StringUtils::endsWith('de', 'abcde')); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testDoesNotEndWith1(): void |
49
|
|
|
{ |
50
|
|
|
$this->assertFalse(StringUtils::endsWith('d', 'abcde')); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testIsEmpty(): void |
54
|
|
|
{ |
55
|
|
|
$this->assertTrue(StringUtils::isEmptyLine('')); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testIsEmptyWithWhiteSpaces(): void |
59
|
|
|
{ |
60
|
|
|
$this->assertTrue(StringUtils::isEmptyLine(' ')); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testIsNotEmpty(): void |
64
|
|
|
{ |
65
|
|
|
$this->assertFalse(StringUtils::isEmptyLine(' a ')); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|