Test::getMocks()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4286
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
namespace Pumpkin\Test;
3
4
use Pumpkin\Database\Table;
5
use Pumpkin\Database\TableBuilder;
6
use Pumpkin\Mock\MockBuilder;
7
use ReflectionMethod;
8
9
/**
10
 * Class Test
11
 * The current test method executed by PHPUnit.
12
 *
13
 * @package Pumpkin
14
 * @author Raphaël Lefebvre <[email protected]>
15
 */
16
class Test
17
{
18
    /**
19
     * @var ReflectionMethod
20
     */
21
    private $reflectedTestMethod;
22
23
    /**
24
     * @var object[]
25
     */
26
    private $mocks;
27
28
    /**
29
     * @var Table[]
30
     */
31
    private $tables;
32
33
    /**
34
     * Constructor.
35
     *
36
     * @param ReflectionMethod $reflectedTestMethod
37
     */
38 24
    public function __construct(ReflectionMethod $reflectedTestMethod)
39
    {
40 24
        $this->setReflectedTestMethod($reflectedTestMethod);
41 24
    }
42
43
    /**
44
     * The reflected method of current test.
45
     *
46
     * @return ReflectionMethod
47
     */
48 24
    public function getReflectedTestMethod()
49
    {
50 24
        return $this->reflectedTestMethod;
51
    }
52
53
    /**
54
     * Returns the list of mock objects associated with the current test.
55
     *
56
     * @param array $constructorArgs
57
     * @return object[]
58
     */
59 3
    public function getMocks(array $constructorArgs = array())
60
    {
61 3
        if ($this->mocks === null) {
62 3
            $mockBuilder = new MockBuilder($this);
63 3
            $this->mocks = $mockBuilder->getMocks($constructorArgs);
64 3
        }
65 3
        return $this->mocks;
66
    }
67
68
    /**
69
     * Returns the list of database tables associated with the current test.
70
     *
71
     * @return Table[]
72
     */
73 3
    public function getTables()
74
    {
75 3
        if ($this->tables === null) {
76 3
            $tableBuilder = new TableBuilder($this);
77 3
            $this->tables = $tableBuilder->getTables();
78 3
        }
79 3
        return $this->tables;
80
    }
81
82
    /**
83
     * @param ReflectionMethod $reflectedTestMethod
84
     */
85 24
    private function setReflectedTestMethod(ReflectionMethod $reflectedTestMethod)
86
    {
87 24
        $this->reflectedTestMethod = $reflectedTestMethod;
88 24
    }
89
}
90