1<?php
2/*
3 * This file is part of PHPUnit.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11/**
12 * Constraint that asserts that the string it is evaluated for ends with a given
13 * suffix.
14 */
15class PHPUnit_Framework_Constraint_StringEndsWith extends PHPUnit_Framework_Constraint
16{
17    /**
18     * @var string
19     */
20    protected $suffix;
21
22    /**
23     * @param string $suffix
24     */
25    public function __construct($suffix)
26    {
27        parent::__construct();
28        $this->suffix = $suffix;
29    }
30
31    /**
32     * Evaluates the constraint for parameter $other. Returns true if the
33     * constraint is met, false otherwise.
34     *
35     * @param mixed $other Value or object to evaluate.
36     *
37     * @return bool
38     */
39    protected function matches($other)
40    {
41        return substr($other, 0 - strlen($this->suffix)) == $this->suffix;
42    }
43
44    /**
45     * Returns a string representation of the constraint.
46     *
47     * @return string
48     */
49    public function toString()
50    {
51        return 'ends with "' . $this->suffix . '"';
52    }
53}
54