| 148 |
lars |
1 |
<?php
|
|
|
2 |
namespace Hamcrest\Text;
|
|
|
3 |
|
|
|
4 |
class StringContainsTest extends \Hamcrest\AbstractMatcherTest
|
|
|
5 |
{
|
|
|
6 |
|
|
|
7 |
const EXCERPT = 'EXCERPT';
|
|
|
8 |
|
|
|
9 |
private $_stringContains;
|
|
|
10 |
|
|
|
11 |
protected function setUp()
|
|
|
12 |
{
|
|
|
13 |
$this->_stringContains = \Hamcrest\Text\StringContains::containsString(self::EXCERPT);
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
protected function createMatcher()
|
|
|
17 |
{
|
|
|
18 |
return $this->_stringContains;
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
public function testEvaluatesToTrueIfArgumentContainsSubstring()
|
|
|
22 |
{
|
|
|
23 |
$this->assertTrue(
|
|
|
24 |
$this->_stringContains->matches(self::EXCERPT . 'END'),
|
|
|
25 |
'should be true if excerpt at beginning'
|
|
|
26 |
);
|
|
|
27 |
$this->assertTrue(
|
|
|
28 |
$this->_stringContains->matches('START' . self::EXCERPT),
|
|
|
29 |
'should be true if excerpt at end'
|
|
|
30 |
);
|
|
|
31 |
$this->assertTrue(
|
|
|
32 |
$this->_stringContains->matches('START' . self::EXCERPT . 'END'),
|
|
|
33 |
'should be true if excerpt in middle'
|
|
|
34 |
);
|
|
|
35 |
$this->assertTrue(
|
|
|
36 |
$this->_stringContains->matches(self::EXCERPT . self::EXCERPT),
|
|
|
37 |
'should be true if excerpt is repeated'
|
|
|
38 |
);
|
|
|
39 |
|
|
|
40 |
$this->assertFalse(
|
|
|
41 |
$this->_stringContains->matches('Something else'),
|
|
|
42 |
'should not be true if excerpt is not in string'
|
|
|
43 |
);
|
|
|
44 |
$this->assertFalse(
|
|
|
45 |
$this->_stringContains->matches(substr(self::EXCERPT, 1)),
|
|
|
46 |
'should not be true if part of excerpt is in string'
|
|
|
47 |
);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public function testEvaluatesToTrueIfArgumentIsEqualToSubstring()
|
|
|
51 |
{
|
|
|
52 |
$this->assertTrue(
|
|
|
53 |
$this->_stringContains->matches(self::EXCERPT),
|
|
|
54 |
'should be true if excerpt is entire string'
|
|
|
55 |
);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public function testEvaluatesToFalseIfArgumentContainsSubstringIgnoringCase()
|
|
|
59 |
{
|
|
|
60 |
$this->assertFalse(
|
|
|
61 |
$this->_stringContains->matches(strtolower(self::EXCERPT)),
|
|
|
62 |
'should be false if excerpt is entire string ignoring case'
|
|
|
63 |
);
|
|
|
64 |
$this->assertFalse(
|
|
|
65 |
$this->_stringContains->matches('START' . strtolower(self::EXCERPT) . 'END'),
|
|
|
66 |
'should be false if excerpt is contained in string ignoring case'
|
|
|
67 |
);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
public function testIgnoringCaseReturnsCorrectMatcher()
|
|
|
71 |
{
|
|
|
72 |
$this->assertTrue(
|
|
|
73 |
$this->_stringContains->ignoringCase()->matches('EXceRpT'),
|
|
|
74 |
'should be true if excerpt is entire string ignoring case'
|
|
|
75 |
);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
public function testHasAReadableDescription()
|
|
|
79 |
{
|
|
|
80 |
$this->assertDescription(
|
|
|
81 |
'a string containing "'
|
|
|
82 |
. self::EXCERPT . '"',
|
|
|
83 |
$this->_stringContains
|
|
|
84 |
);
|
|
|
85 |
}
|
|
|
86 |
}
|