94% of 219OPs |
97% of 35Lines |
85% of 20Branches |
94% of 16Paths |
# | |
---|---|
1 |
<?php |
2 |
|
3 |
namespace mageekguy\atoum\asserter; |
4 |
|
5 |
use |
6 |
mageekguy\atoum, |
7 |
mageekguy\atoum\asserter, |
8 |
mageekguy\atoum\exceptions, |
9 |
mageekguy\atoum\test\assertion |
10 |
; |
11 |
|
12 |
class generator |
13 |
{ |
14 |
protected $locale = null; |
15 |
protected $resolver = null; |
16 |
|
17 |
public function __construct(atoum\locale $locale = null, asserter\resolver $resolver = null, assertion\aliaser $aliaser = null)100% |
18 |
{ |
19 |
$this |
20 |
->setLocale($locale) |
21 |
->setResolver($resolver) |
22 |
; |
23 |
} |
24 |
|
25 |
public function __get($property)100% |
26 |
{ |
27 |
return $this->getAsserterInstance($property); |
28 |
} |
29 |
|
30 |
public function __isset($property)0% |
31 |
{ |
32 |
return ($this->getAsserterClass($property) !== null); |
33 |
} |
34 |
|
35 |
public function __call($method, $arguments)100% |
36 |
{ |
37 |
return $this->getAsserterInstance($method, $arguments); |
38 |
} |
39 |
|
40 |
public function setBaseClass($baseClass)100% |
41 |
{ |
42 |
$this->resolver->setBaseClass($baseClass); |
43 |
|
44 |
return $this; |
45 |
} |
46 |
|
47 |
public function getBaseClass()100% |
48 |
{ |
49 |
return $this->resolver->getBaseClass(); |
50 |
} |
51 |
|
52 |
public function addNamespace($namespace)100% |
53 |
{ |
54 |
$this->resolver->addNamespace($namespace); |
55 |
|
56 |
return $this; |
57 |
} |
58 |
|
59 |
public function getNamespaces()100% |
60 |
{ |
61 |
return $this->resolver->getNamespaces(); |
62 |
} |
63 |
|
64 |
public function setLocale(atoum\locale $locale = null)100% |
65 |
{ |
66 |
$this->locale = $locale ?: new atoum\locale(); |
67 |
|
68 |
return $this; |
69 |
} |
70 |
|
71 |
public function getLocale()100% |
72 |
{ |
73 |
return $this->locale; |
74 |
} |
75 |
|
76 |
public function setResolver(asserter\resolver $resolver = null) |
77 |
{ |
78 |
$this->resolver = $resolver ?: new asserter\resolver(); |
79 |
|
80 |
return $this; |
81 |
} |
82 |
|
83 |
public function getResolver()100% |
84 |
{ |
85 |
return $this->resolver; |
86 |
} |
87 |
|
88 |
public function getAsserterClass($asserter)100% |
89 |
{ |
90 |
return $this->resolver->resolve($asserter); |
91 |
} |
92 |
|
93 |
public function getAsserterInstance($asserter, array $arguments = array(), atoum\test $test = null)100% |
94 |
{ |
95 |
if (($asserterClass = $this->getAsserterClass($asserter)) === null) |
96 |
{ |
97 |
throw new exceptions\logic\invalidArgument('Asserter \'' . $asserter . '\' does not exist'); |
98 |
} |
99 |
|
100 |
$asserterInstance = new $asserterClass(); |
101 |
|
102 |
if ($test !== null) |
103 |
{ |
104 |
$asserterInstance->setWithTest($test); |
105 |
} |
106 | |
107 |
return $asserterInstance |
108 |
->setGenerator($this) |
109 |
->setLocale($this->locale) |
110 |
->setWithArguments($arguments) |
111 |
; |
112 |
} |
113 |
} |