92% of 304OPs |
93% of 54Lines |
82% of 51Branches |
65% of 34Paths |
| # | |
|---|---|
| 1 |
<?php |
| 2 |
|
| 3 |
namespace mageekguy\atoum\test\adapter; |
| 4 |
|
| 5 |
use |
| 6 |
mageekguy\atoum\exceptions, |
| 7 |
mageekguy\atoum\test\adapter, |
| 8 |
mageekguy\atoum\test\adapter\call |
| 9 |
; |
| 10 |
|
| 11 |
class call |
| 12 |
{
|
| 13 |
protected $function = null; |
| 14 |
protected $arguments = null; |
| 15 |
protected $decorator = null; |
| 16 |
|
| 17 |
public function __construct($function = null, array $arguments = null, call\decorator $decorator = null)100% |
| 18 |
{
|
| 19 |
if ($function !== null) |
| 20 |
{
|
| 21 |
$this->setFunction($function); |
| 22 |
} |
| 23 |
|
| 24 |
$this->arguments = $arguments; |
| 25 |
|
| 26 |
$this->setDecorator($decorator); |
| 27 |
} |
| 28 |
|
| 29 |
public function __toString()100% |
| 30 |
{
|
| 31 |
return $this->decorator->decorate($this); |
| 32 |
} |
| 33 |
|
| 34 |
public function getFunction()100% |
| 35 |
{
|
| 36 |
return $this->function; |
| 37 |
} |
| 38 |
|
| 39 |
public function setFunction($function)100% |
| 40 |
{
|
| 41 |
$function = (string) $function; |
| 42 |
|
| 43 |
if ($function === '') |
| 44 |
{
|
| 45 |
throw new exceptions\logic\invalidArgument('Function must not be empty');
|
| 46 |
} |
| 47 |
|
| 48 |
$this->function = $function; |
| 49 |
|
| 50 |
return $this; |
| 51 |
} |
| 52 |
|
| 53 |
public function copy(call $call)0% |
| 54 |
{
|
| 55 |
$this->function = $call->function; |
| 56 |
$this->arguments = $call->arguments; |
| 57 |
$this->decorator = $call->decorator; |
| 58 |
|
| 59 |
return $this; |
| 60 |
} |
| 61 |
|
| 62 |
public function getArguments()100% |
| 63 |
{
|
| 64 |
return $this->arguments; |
| 65 |
} |
| 66 |
|
| 67 |
public function setArguments(array $arguments)100% |
| 68 |
{
|
| 69 |
$this->arguments = $arguments; |
| 70 |
|
| 71 |
return $this; |
| 72 |
} |
| 73 |
|
| 74 |
public function unsetArguments()100% |
| 75 |
{
|
| 76 |
$this->arguments = null; |
| 77 |
|
| 78 |
return $this; |
| 79 |
} |
| 80 |
|
| 81 |
public function setDecorator(call\decorator $decorator = null)100% |
| 82 |
{
|
| 83 |
$this->decorator = $decorator ?: new call\decorator(); |
| 84 |
|
| 85 |
return $this; |
| 86 |
} |
| 87 |
|
| 88 |
public function getDecorator()100% |
| 89 |
{
|
| 90 |
return $this->decorator; |
| 91 |
} |
| 92 |
|
| 93 |
public function isEqualTo(call $call)100% |
| 94 |
{
|
| 95 |
switch (true) |
| 96 |
{
|
| 97 |
case $this->function === null || $this->function != $call->function: |
| 98 |
return false; |
| 99 |
|
| 100 |
case $this->arguments === null: |
| 101 |
return true; |
| 102 |
|
| 103 |
case $call->arguments === null: |
| 104 |
return false; |
| 105 |
|
| 106 |
case sizeof($this->arguments) <= 0: |
| 107 |
return $this->arguments == $call->arguments; |
| 108 |
|
| 109 |
case sizeof($this->arguments) <= sizeof($call->arguments): |
| 110 |
$callback = function($a, $b) {
|
| 111 |
return ($a == $b ? 0 : -1); |
| 112 |
}; |
| 113 |
|
| 114 |
return (sizeof($this->arguments) == sizeof(array_uintersect_uassoc($call->arguments, $this->arguments, $callback, $callback))); |
| 115 |
|
| 116 |
default: |
| 117 |
return false; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
public function isIdenticalTo(call $call)100% |
| 122 |
{
|
| 123 |
$isIdentical = $this->isEqualTo($call); |
| 124 |
|
| 125 |
if ($isIdentical === true && $this->arguments !== null && $call->arguments !== null) |
| 126 |
{
|
| 127 |
$callback = function($a, $b) {
|
| 128 |
return ($a === $b ? 0 : -1); |
| 129 |
}; |
| 130 |
|
| 131 |
$isIdentical = ($this->arguments === array_uintersect_uassoc($call->arguments, $this->arguments, $callback, $callback)); |
| 132 |
} |
| 133 |
|
| 134 |
return $isIdentical; |
| 135 |
} |
| 136 |
|
| 137 |
public function isFullyQualified()100% |
| 138 |
{
|
| 139 |
return ($this->function !== null && $this->arguments !== null); |
| 140 |
} |
| 141 |
} |