Completed
Pull Request — master (#691)
by Dave
03:01
created

MockeryPHPUnitIntegration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assertPostConditions() 0 7 1
A addMockeryExpectationsToAssertionCount() 0 8 2
A closeMockery() 0 4 1
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