~ballot/wordpress/openstack-objectstorage-bis

« back to all changes in this revision

Viewing changes to vendor/phpunit/phpunit/src/Framework/Constraint/StringEndsWith.php

  • Committer: Jacek Nykis
  • Date: 2015-02-11 15:35:31 UTC
  • Revision ID: jacek.nykis@canonical.com-20150211153531-hmy6zi0ov2qfkl0b
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *
 
15
 * @package    PHPUnit
 
16
 * @subpackage Framework_Constraint
 
17
 * @author     Sebastian Bergmann <sebastian@phpunit.de>
 
18
 * @author     Bernhard Schussek <bschussek@2bepublished.at>
 
19
 * @copyright  Sebastian Bergmann <sebastian@phpunit.de>
 
20
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 
21
 * @link       http://www.phpunit.de/
 
22
 * @since      Class available since Release 3.4.0
 
23
 */
 
24
class PHPUnit_Framework_Constraint_StringEndsWith extends PHPUnit_Framework_Constraint
 
25
{
 
26
    /**
 
27
     * @var string
 
28
     */
 
29
    protected $suffix;
 
30
 
 
31
    /**
 
32
     * @param string $suffix
 
33
     */
 
34
    public function __construct($suffix)
 
35
    {
 
36
        parent::__construct();
 
37
        $this->suffix = $suffix;
 
38
    }
 
39
 
 
40
    /**
 
41
     * Evaluates the constraint for parameter $other. Returns true if the
 
42
     * constraint is met, false otherwise.
 
43
     *
 
44
     * @param  mixed $other Value or object to evaluate.
 
45
     * @return bool
 
46
     */
 
47
    protected function matches($other)
 
48
    {
 
49
        return substr($other, 0 - strlen($this->suffix)) == $this->suffix;
 
50
    }
 
51
 
 
52
    /**
 
53
     * Returns a string representation of the constraint.
 
54
     *
 
55
     * @return string
 
56
     */
 
57
    public function toString()
 
58
    {
 
59
        return 'ends with "' . $this->suffix . '"';
 
60
    }
 
61
}