90% of 173OPs |
84% of 31Lines |
59% of 22Branches |
85% of 13Paths |
Method | OPs | OPs % | Lines | Line % | Branches | Branches % | Paths | Path % |
---|---|---|---|---|---|---|---|---|
mageekguy\atoum\asserters\extension::__construct() | 22 | 100% | 3 | 100% | 1 | 0% | 1 | 100% |
mageekguy\atoum\asserters\extension::__toString() | 7 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserters\extension::__get() | 35 | 51% | 6 | 50% | 6 | 17% | 2 | 50% |
mageekguy\atoum\asserters\extension::setWith() | 9 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserters\extension::reset() | 9 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserters\extension::getName() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserters\extension::isLoaded() | 48 | 100% | 7 | 100% | 5 | 60% | 2 | 50% |
mageekguy\atoum\asserters\extension::valueIsSet() | 20 | 95% | 4 | 100% | 4 | 75% | 2 | 100% |
mageekguy\atoum\asserters\extension::pass() | 5 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
mageekguy\atoum\asserters\extension::setPhpExtensionFactory() | 12 | 100% | 4 | 50% | 1 | 100% | 1 | 100% |
# | |
---|---|
1 |
<?php |
2 |
|
3 |
namespace mageekguy\atoum\asserters; |
4 |
|
5 |
use |
6 |
mageekguy\atoum, |
7 |
mageekguy\atoum\test, |
8 |
mageekguy\atoum\asserter, |
9 |
mageekguy\atoum\exceptions |
10 |
; |
11 |
|
12 |
class extension extends atoum\asserter |
13 |
{ |
14 |
protected $name = null; |
15 |
protected $phpExtensionFactory = null; |
16 |
|
17 |
public function __construct(asserter\generator $generator = null, atoum\locale $locale = null, \closure $phpExtensionFactory = null)100% |
18 |
{ |
19 |
parent::__construct($generator, null, $locale); |
20 |
|
21 |
$this->setPhpExtensionFactory($phpExtensionFactory); |
22 |
} |
23 |
|
24 |
public function __toString()100% |
25 |
{ |
26 |
return (string) $this->name; |
27 |
} |
28 |
|
29 |
public function __get($asserter)50% |
30 |
{ |
31 |
switch (strtolower($asserter)) |
32 |
{ |
33 |
case 'isloaded': |
34 |
return $this->{$asserter}(); |
35 |
|
36 |
default: |
37 |
return parent::__get($asserter); |
38 |
} |
39 |
} |
40 |
|
41 |
public function setWith($name)100% |
42 |
{ |
43 |
$this->name = $name; |
44 |
|
45 |
return $this; |
46 |
} |
47 |
|
48 |
public function reset()100% |
49 |
{ |
50 |
$this->name = null; |
51 |
|
52 |
return $this; |
53 |
} |
54 |
|
55 |
public function getName()100% |
56 |
{ |
57 |
return $this->name; |
58 |
} |
59 |
|
60 |
public function isLoaded($failMessage = null)100% |
61 |
{ |
62 |
$extension = call_user_func($this->phpExtensionFactory, $this->valueIsSet()->name); |
63 |
|
64 |
try |
65 |
{ |
66 |
$extension->requireExtension(); |
67 |
|
68 |
$this->pass(); |
69 |
} |
70 |
catch (atoum\php\exception $exception) |
71 |
{ |
72 |
$this->fail($failMessage ?: $this->_('PHP extension \'%s\' is not loaded', $this)); |
73 |
} |
74 |
|
75 |
return $this; |
76 |
} |
77 |
|
78 |
protected function valueIsSet($message = 'Name of PHP extension is undefined')100% |
79 |
{ |
80 |
if ($this->name === null) |
81 |
{ |
82 |
throw new exceptions\logic($message); |
83 |
} |
84 |
|
85 |
return $this; |
86 |
} |
87 |
|
88 |
protected function pass()100% |
89 |
{ |
90 |
return $this; |
91 |
} |
92 |
|
93 |
public function setPhpExtensionFactory(\closure $factory = null)50% |
94 |
{ |
95 |
$this->phpExtensionFactory = $factory ?: function($extensionName) { |
96 |
return new atoum\php\extension($extensionName); |
97 |
}; |
98 |
|
99 |
return $this; |
100 |
} |
101 |
} |