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
|
<?php
namespace Hamcrest\Text;
use PHPUnit\Framework\Attributes\Before;
class StringEndsWithTest extends \Hamcrest\AbstractMatcherTestCase
{
const EXCERPT = 'EXCERPT';
private $_stringEndsWith;
#[Before]
protected function setUpTest()
{
$this->_stringEndsWith = \Hamcrest\Text\StringEndsWith::endsWith(self::EXCERPT);
}
protected function createMatcher()
{
return $this->_stringEndsWith;
}
public function testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring()
{
$this->assertFalse(
$this->_stringEndsWith->matches(self::EXCERPT . 'END'),
'should be false if excerpt at beginning'
);
$this->assertTrue(
$this->_stringEndsWith->matches('START' . self::EXCERPT),
'should be true if excerpt at end'
);
$this->assertFalse(
$this->_stringEndsWith->matches('START' . self::EXCERPT . 'END'),
'should be false if excerpt in middle'
);
$this->assertTrue(
$this->_stringEndsWith->matches(self::EXCERPT . self::EXCERPT),
'should be true if excerpt is at end and repeated'
);
$this->assertFalse(
$this->_stringEndsWith->matches('Something else'),
'should be false if excerpt is not in string'
);
$this->assertFalse(
$this->_stringEndsWith->matches(substr(self::EXCERPT, 0, strlen(self::EXCERPT) - 2)),
'should be false if part of excerpt is at end of string'
);
}
public function testEvaluatesToTrueIfArgumentIsEqualToSubstring()
{
$this->assertTrue(
$this->_stringEndsWith->matches(self::EXCERPT),
'should be true if excerpt is entire string'
);
}
public function testHasAReadableDescription()
{
$this->assertDescription('a string ending with "EXCERPT"', $this->_stringEndsWith);
}
}
|