95% of 160OPs |
100% of 31Lines |
84% of 32Branches |
65% of 17Paths |
Method | OPs | OPs % | Lines | Line % | Branches | Branches % | Paths | Path % |
---|---|---|---|---|---|---|---|---|
mageekguy\atoum\mock\controller\linker::__construct() | 8 | 100% | 2 | 100% | 1 | 0% | 1 | 100% |
mageekguy\atoum\mock\controller\linker::link() | 46 | 100% | 12 | 100% | 10 | 80% | 6 | 33% |
mageekguy\atoum\mock\controller\linker::getController() | 17 | 100% | 1 | 100% | 5 | 100% | 2 | 100% |
mageekguy\atoum\mock\controller\linker::getMock() | 17 | 100% | 1 | 100% | 5 | 100% | 2 | 100% |
mageekguy\atoum\mock\controller\linker::unlink() | 29 | 100% | 8 | 100% | 4 | 100% | 2 | 100% |
mageekguy\atoum\mock\controller\linker::reset() | 22 | 64% | 4 | 100% | 6 | 67% | 3 | 33% |
mageekguy\atoum\mock\controller\linker::init() | 21 | 100% | 3 | 100% | 1 | 100% | 1 | 100% |
# | |
---|---|
1 |
<?php |
2 |
|
3 |
namespace mageekguy\atoum\mock\controller; |
4 |
|
5 |
use |
6 |
mageekguy\atoum\mock |
7 |
; |
8 |
|
9 |
class linker |
10 |
{ |
11 |
protected $mocks = null; |
12 |
protected $controllers = null; |
13 |
|
14 |
public function __construct()100% |
15 |
{ |
16 |
$this->init(); |
17 |
} |
18 |
|
19 |
public function link(mock\controller $controller, mock\aggregator $mock)100% |
20 |
{ |
21 |
$currentMock = $this->getMock($controller); |
22 |
|
23 |
if ($currentMock === null || $currentMock !== $this) |
24 |
{ |
25 |
if ($currentMock !== $this) |
26 |
{ |
27 |
$this->unlink($controller); |
28 |
} |
29 |
|
30 |
$this->mocks[$controller] = $mock; |
31 |
$this->controllers[$mock] = $controller; |
32 |
|
33 |
$controller->control($mock); |
34 |
} |
35 |
|
36 |
return $this; |
37 |
} |
38 |
|
39 |
public function getController(mock\aggregator $mock)100% |
40 |
{ |
41 |
return (isset($this->controllers[$mock]) === false ? null : $this->controllers[$mock]); |
42 |
} |
43 |
|
44 |
public function getMock(mock\controller $controller)100% |
45 |
{ |
46 |
return (isset($this->mocks[$controller]) === false ? null : $this->mocks[$controller]); |
47 |
} |
48 |
|
49 |
public function unlink(mock\controller $controller)100% |
50 |
{ |
51 |
$mock = $this->getMock($controller); |
52 |
|
53 |
if ($mock !== null) |
54 |
{ |
55 |
unset($this->controllers[$mock]); |
56 |
unset($this->mocks[$controller]); |
57 |
|
58 |
$controller->reset(); |
59 |
} |
60 |
|
61 |
return $this; |
62 |
} |
63 |
|
64 |
public function reset()100% |
65 |
{ |
66 |
foreach ($this->mocks as $controller) |
67 |
{ |
68 |
$controller->reset(); |
69 |
} |
70 |
|
71 |
return $this->init(); |
72 |
} |
73 |
|
74 |
protected function init()100% |
75 |
{ |
76 |
$this->mocks = new \splObjectStorage(); |
77 |
$this->controllers = new \splObjectStorage(); |
78 |
|
79 |
return $this; |
80 |
} |
81 |
} |