| 148 |
lars |
1 |
<?php
|
|
|
2 |
namespace Hamcrest\Text;
|
|
|
3 |
|
|
|
4 |
class StringEndsWithTest extends \Hamcrest\AbstractMatcherTest
|
|
|
5 |
{
|
|
|
6 |
|
|
|
7 |
const EXCERPT = 'EXCERPT';
|
|
|
8 |
|
|
|
9 |
private $_stringEndsWith;
|
|
|
10 |
|
|
|
11 |
protected function setUp()
|
|
|
12 |
{
|
|
|
13 |
$this->_stringEndsWith = \Hamcrest\Text\StringEndsWith::endsWith(self::EXCERPT);
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
protected function createMatcher()
|
|
|
17 |
{
|
|
|
18 |
return $this->_stringEndsWith;
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
public function testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring()
|
|
|
22 |
{
|
|
|
23 |
$this->assertFalse(
|
|
|
24 |
$this->_stringEndsWith->matches(self::EXCERPT . 'END'),
|
|
|
25 |
'should be false if excerpt at beginning'
|
|
|
26 |
);
|
|
|
27 |
$this->assertTrue(
|
|
|
28 |
$this->_stringEndsWith->matches('START' . self::EXCERPT),
|
|
|
29 |
'should be true if excerpt at end'
|
|
|
30 |
);
|
|
|
31 |
$this->assertFalse(
|
|
|
32 |
$this->_stringEndsWith->matches('START' . self::EXCERPT . 'END'),
|
|
|
33 |
'should be false if excerpt in middle'
|
|
|
34 |
);
|
|
|
35 |
$this->assertTrue(
|
|
|
36 |
$this->_stringEndsWith->matches(self::EXCERPT . self::EXCERPT),
|
|
|
37 |
'should be true if excerpt is at end and repeated'
|
|
|
38 |
);
|
|
|
39 |
|
|
|
40 |
$this->assertFalse(
|
|
|
41 |
$this->_stringEndsWith->matches('Something else'),
|
|
|
42 |
'should be false if excerpt is not in string'
|
|
|
43 |
);
|
|
|
44 |
$this->assertFalse(
|
|
|
45 |
$this->_stringEndsWith->matches(substr(self::EXCERPT, 0, strlen(self::EXCERPT) - 2)),
|
|
|
46 |
'should be false if part of excerpt is at end of string'
|
|
|
47 |
);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public function testEvaluatesToTrueIfArgumentIsEqualToSubstring()
|
|
|
51 |
{
|
|
|
52 |
$this->assertTrue(
|
|
|
53 |
$this->_stringEndsWith->matches(self::EXCERPT),
|
|
|
54 |
'should be true if excerpt is entire string'
|
|
|
55 |
);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public function testHasAReadableDescription()
|
|
|
59 |
{
|
|
|
60 |
$this->assertDescription('a string ending with "EXCERPT"', $this->_stringEndsWith);
|
|
|
61 |
}
|
|
|
62 |
}
|