72% of 368OPs |
81% of 54Lines |
51% of 53Branches |
41% of 49Paths |
| # | |
|---|---|
| 1 |
<?php |
| 2 |
|
| 3 |
namespace mageekguy\atoum; |
| 4 |
|
| 5 |
use |
| 6 |
mageekguy\atoum, |
| 7 |
mageekguy\atoum\asserter, |
| 8 |
mageekguy\atoum\exceptions, |
| 9 |
mageekguy\atoum\tools\variable |
| 10 |
; |
| 11 |
|
| 12 |
abstract class asserter implements asserter\definition |
| 13 |
{
|
| 14 |
protected $locale = null; |
| 15 |
protected $analyzer = null; |
| 16 |
protected $generator = null; |
| 17 |
protected $test = null; |
| 18 |
|
| 19 |
public function __construct(asserter\generator $generator = null, variable\analyzer $analyzer = null, locale $locale = null)100% |
| 20 |
{
|
| 21 |
$this |
| 22 |
->setGenerator($generator) |
| 23 |
->setAnalyzer($analyzer) |
| 24 |
->setLocale($locale) |
| 25 |
; |
| 26 |
} |
| 27 |
|
| 28 |
public function __get($asserter)100% |
| 29 |
{
|
| 30 |
return $this->generator->{$asserter};
|
| 31 |
} |
| 32 |
|
| 33 |
public function __call($method, $arguments)36% |
| 34 |
{
|
| 35 |
switch ($method) |
| 36 |
{
|
| 37 |
case 'foreach': |
| 38 |
if (isset($arguments[0]) === false || (is_array($arguments[0]) === false && $arguments[0] instanceof \traversable === false)) |
| 39 |
{
|
| 40 |
throw new exceptions\logic\invalidArgument('First argument of ' . get_class($this) . '::' . $method . '() must be an array or a \traversable instance');
|
| 41 |
} |
| 42 |
else if (isset($arguments[1]) === false || $arguments[1] instanceof \closure === false) |
| 43 |
{
|
| 44 |
throw new exceptions\logic\invalidArgument('Second argument of ' . get_class($this) . '::' . $method . '() must be a closure');
|
| 45 |
} |
| 46 |
|
| 47 |
foreach ($arguments[0] as $key => $value) |
| 48 |
{
|
| 49 |
call_user_func_array($arguments[1], array($this, $value, $key)); |
| 50 |
} |
| 51 |
|
| 52 |
return $this; |
| 53 |
|
| 54 |
default: |
| 55 |
return $this->generator->__call($method, $arguments); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
public function reset()100% |
| 60 |
{
|
| 61 |
return $this; |
| 62 |
} |
| 63 |
|
| 64 |
public function setLocale(locale $locale = null)100% |
| 65 |
{
|
| 66 |
$this->locale = $locale ?: new locale(); |
| 67 |
|
| 68 |
return $this; |
| 69 |
} |
| 70 |
|
| 71 |
public function getLocale()100% |
| 72 |
{
|
| 73 |
return $this->locale; |
| 74 |
} |
| 75 |
|
| 76 |
public function setGenerator(asserter\generator $generator = null)100% |
| 77 |
{
|
| 78 |
$this->generator = $generator ?: new asserter\generator(); |
| 79 |
|
| 80 |
return $this; |
| 81 |
} |
| 82 |
|
| 83 |
public function getGenerator()100% |
| 84 |
{
|
| 85 |
return $this->generator; |
| 86 |
} |
| 87 |
|
| 88 |
public function setAnalyzer(variable\analyzer $analyzer = null)100% |
| 89 |
{
|
| 90 |
$this->analyzer = $analyzer ?: new variable\analyzer(); |
| 91 | |
| 92 |
return $this; |
| 93 |
} |
| 94 |
|
| 95 |
public function getAnalyzer()100% |
| 96 |
{
|
| 97 |
return $this->analyzer; |
| 98 |
} |
| 99 |
|
| 100 |
public function getTest()100% |
| 101 |
{
|
| 102 |
return $this->test; |
| 103 |
} |
| 104 |
|
| 105 |
public function setWithTest(test $test)100% |
| 106 |
{
|
| 107 |
$this->test = $test; |
| 108 |
|
| 109 |
return $this; |
| 110 |
} |
| 111 |
|
| 112 |
public function setWith($mixed)100% |
| 113 |
{
|
| 114 |
return $this->reset(); |
| 115 |
} |
| 116 |
|
| 117 |
public function setWithArguments(array $arguments)100% |
| 118 |
{
|
| 119 |
if (sizeof($arguments) > 0) |
| 120 |
{
|
| 121 |
call_user_func_array(array($this, 'setWith'), $arguments); |
| 122 |
} |
| 123 |
|
| 124 |
return $this; |
| 125 |
} |
| 126 |
|
| 127 |
protected function pass()100% |
| 128 |
{
|
| 129 |
if ($this->test !== null) |
| 130 |
{
|
| 131 |
$this->test->getScore()->addPass(); |
| 132 |
} |
| 133 |
|
| 134 |
return $this; |
| 135 |
} |
| 136 |
|
| 137 |
protected function fail($reason)75% |
| 138 |
{
|
| 139 |
if (is_string($reason) === false) |
| 140 |
{
|
| 141 |
throw new exceptions\logic\invalidArgument('Fail message must be a string');
|
| 142 |
} |
| 143 |
|
| 144 |
throw new asserter\exception($this, $reason); |
| 145 |
} |
| 146 |
|
| 147 |
protected function getTypeOf($mixed)100% |
| 148 |
{
|
| 149 |
return $this->analyzer->getTypeOf($mixed); |
| 150 |
} |
| 151 |
|
| 152 |
protected function _($string) |
| 153 |
{
|
| 154 |
return call_user_func_array(array($this->locale, '_'), func_get_args()); |
| 155 |
} |
| 156 |
|
| 157 |
protected function __($singular, $plural, $quantity)100% |
| 158 |
{
|
| 159 |
return call_user_func_array(array($this->locale, '__'), func_get_args()); |
| 160 |
} |
| 161 |
} |