~tcuthbert/wordpress/openstack-objectstorage

« back to all changes in this revision

Viewing changes to vendor/phpunit/phpunit/src/Framework/Constraint/ExceptionMessage.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
 *
 
13
 *
 
14
 * @package    PHPUnit
 
15
 * @subpackage Framework_Constraint
 
16
 * @author     Sebastian Bergmann <sebastian@phpunit.de>
 
17
 * @copyright  Sebastian Bergmann <sebastian@phpunit.de>
 
18
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 
19
 * @link       http://www.phpunit.de/
 
20
 * @since      Class available since Release 3.6.6
 
21
 */
 
22
class PHPUnit_Framework_Constraint_ExceptionMessage extends PHPUnit_Framework_Constraint
 
23
{
 
24
    /**
 
25
     * @var integer
 
26
     */
 
27
    protected $expectedMessage;
 
28
 
 
29
    /**
 
30
     * @param string $expected
 
31
     */
 
32
    public function __construct($expected)
 
33
    {
 
34
        parent::__construct();
 
35
        $this->expectedMessage = $expected;
 
36
    }
 
37
 
 
38
    /**
 
39
     * Evaluates the constraint for parameter $other. Returns true if the
 
40
     * constraint is met, false otherwise.
 
41
     *
 
42
     * @param  Exception $other
 
43
     * @return boolean
 
44
     */
 
45
    protected function matches($other)
 
46
    {
 
47
        return strpos($other->getMessage(), $this->expectedMessage) !== false;
 
48
    }
 
49
 
 
50
    /**
 
51
     * Returns the description of the failure
 
52
     *
 
53
     * The beginning of failure messages is "Failed asserting that" in most
 
54
     * cases. This method should return the second part of that sentence.
 
55
     *
 
56
     * @param  mixed  $other Evaluated value or object.
 
57
     * @return string
 
58
     */
 
59
    protected function failureDescription($other)
 
60
    {
 
61
        return sprintf(
 
62
            "exception message '%s' contains '%s'",
 
63
            $other->getMessage(),
 
64
            $this->expectedMessage
 
65
        );
 
66
    }
 
67
 
 
68
    /**
 
69
     * @return string
 
70
     */
 
71
    public function toString()
 
72
    {
 
73
        return 'exception message contains ';
 
74
    }
 
75
}