PHPUnitConstraint::match()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 3
1
<?php
2
/**
3
 * Mockery
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://github.com/padraic/mockery/blob/master/LICENSE
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to [email protected] so we can send you a copy immediately.
14
 *
15
 * @category   Mockery
16
 * @package    Mockery
17
 * @copyright  Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
18
 * @license    http://github.com/padraic/mockery/blob/master/LICENSE New BSD License
19
 */
20
21
namespace Mockery\Matcher;
22
23
class PHPUnitConstraint extends MatcherAbstract
24
{
25
    protected $constraint;
26
    protected $rethrow;
27
28
    /**
29
     * @param \PHPUnit_Framework_Constraint $constraint
30
     * @param bool $rethrow
31
     */
32 3
    public function __construct(\PHPUnit_Framework_Constraint $constraint, $rethrow = false)
33
    {
34 3
        $this->constraint = $constraint;
35 3
        $this->rethrow = $rethrow;
36 3
    }
37
38
    /**
39
     * @param mixed $actual
40
     * @return bool
41
     */
42 2
    public function match(&$actual)
43
    {
44
        try {
45 2
            $this->constraint->evaluate($actual);
46 1
            return true;
47 2
        } catch (\PHPUnit_Framework_AssertionFailedError $e) {
48 2
            if ($this->rethrow) {
49 1
                throw $e;
50
            }
51 1
            return false;
52
        }
53
    }
54
55
    /**
56
     *
57
     */
58 1
    public function __toString()
59
    {
60 1
        return '<Constraint>';
61
    }
62
}
63