MockeryPHPUnitIntegration   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
ccs 15
cts 15
cp 1
rs 10
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 410
    protected function assertPostConditions()
36
    {
37 410
        $this->addMockeryExpectationsToAssertionCount();
38 410
        $this->closeMockery();
39
40 410
        parent::assertPostConditions();
41 410
    }
42
43 410
    protected function addMockeryExpectationsToAssertionCount()
44
    {
45 410
        $container = Mockery::getContainer();
46 410
        if ($container != null) {
47 410
            $count = $container->mockery_getExpectationCount();
48 410
            $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 410
        }
50 410
    }
51
52 410
    protected function closeMockery()
53
    {
54 410
        Mockery::close();
55 410
    }
56
}
57