StringContainsTest.php
2.6 KB
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
<?php
namespace Hamcrest\Text;
class StringContainsTest extends \Hamcrest\AbstractMatcherTest
{
const EXCERPT = 'EXCERPT';
private $_stringContains;
protected function setUp()
{
$this->_stringContains = \Hamcrest\Text\StringContains::containsString(self::EXCERPT);
}
protected function createMatcher()
{
return $this->_stringContains;
}
public function testEvaluatesToTrueIfArgumentContainsSubstring()
{
$this->assertTrue(
$this->_stringContains->matches(self::EXCERPT . 'END'),
'should be true if excerpt at beginning'
);
$this->assertTrue(
$this->_stringContains->matches('START' . self::EXCERPT),
'should be true if excerpt at end'
);
$this->assertTrue(
$this->_stringContains->matches('START' . self::EXCERPT . 'END'),
'should be true if excerpt in middle'
);
$this->assertTrue(
$this->_stringContains->matches(self::EXCERPT . self::EXCERPT),
'should be true if excerpt is repeated'
);
$this->assertFalse(
$this->_stringContains->matches('Something else'),
'should not be true if excerpt is not in string'
);
$this->assertFalse(
$this->_stringContains->matches(substr(self::EXCERPT, 1)),
'should not be true if part of excerpt is in string'
);
}
public function testEvaluatesToTrueIfArgumentIsEqualToSubstring()
{
$this->assertTrue(
$this->_stringContains->matches(self::EXCERPT),
'should be true if excerpt is entire string'
);
}
public function testEvaluatesToFalseIfArgumentContainsSubstringIgnoringCase()
{
$this->assertFalse(
$this->_stringContains->matches(strtolower(self::EXCERPT)),
'should be false if excerpt is entire string ignoring case'
);
$this->assertFalse(
$this->_stringContains->matches('START' . strtolower(self::EXCERPT) . 'END'),
'should be false if excerpt is contained in string ignoring case'
);
}
public function testIgnoringCaseReturnsCorrectMatcher()
{
$this->assertTrue(
$this->_stringContains->ignoringCase()->matches('EXceRpT'),
'should be true if excerpt is entire string ignoring case'
);
}
public function testHasAReadableDescription()
{
$this->assertDescription(
'a string containing "'
. self::EXCERPT . '"',
$this->_stringContains
);
}
}