Completed
Push — master ( de5feb...63987b )
by Dave
03:08
created

MockeryPHPUnitIntegration::closeMockery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Adapter\Phpunit;
22
23
use Mockery;
24
25
/**
26
 * Integrates Mockery into PHPUnit. Ensures Mockery expectations are verified
27
 * for each test and are included by the assertion counter.
28
 */
29
trait MockeryPHPUnitIntegration
30
{
31
    /**
32
     * Performs assertions shared by all tests of a test case. This method is
33
     * called before execution of a test ends and before the tearDown method.
34
     */
35 415
    protected function assertPostConditions()
36
    {
37 415
        $this->addMockeryExpectationsToAssertionCount();
38 415
        $this->closeMockery();
39
40 415
        parent::assertPostConditions();
41 415
    }
42
43 415
    protected function addMockeryExpectationsToAssertionCount()
44
    {
45 415
        $container = Mockery::getContainer();
46 415
        if ($container != null) {
47 415
            $count = $container->mockery_getExpectationCount();
48 415
            $this->addToAssertionCount($count);
0 ignored issues
show
Bug introduced by
It seems like addToAssertionCount() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
49
        }
50 415
    }
51
52 415
    protected function closeMockery()
53
    {
54 415
        Mockery::close();
55 415
    }
56
}
57