mageekguy\atoum\asserters\constant: lines coverage

86% of 222

OPs

88% of 33

Lines

61% of 23

Branches

79% of 14

Paths
Method OPs OPs % Lines Line % Branches Branches % Paths Path %
mageekguy\atoum\asserters\constant::__construct() 20 100% 3 100% 1 0% 1 100%
mageekguy\atoum\asserters\constant::__toString() 11 0% 1 0% 1 0% 1 0%
mageekguy\atoum\asserters\constant::__call() 41 56% 6 50% 6 17% 2 50%
mageekguy\atoum\asserters\constant::setDiff() 16 100% 2 100% 1 100% 1 100%
mageekguy\atoum\asserters\constant::getDiff() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\asserters\constant::wasSet() 8 100% 1 100% 1 100% 1 100%
mageekguy\atoum\asserters\constant::setWith() 20 100% 4 100% 1 100% 1 100%
mageekguy\atoum\asserters\constant::reset() 18 100% 3 100% 1 100% 1 100%
mageekguy\atoum\asserters\constant::getValue() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\asserters\constant::isEqualTo() 56 100% 7 100% 5 80% 2 50%
mageekguy\atoum\asserters\constant::valueIsSet() 20 95% 4 100% 4 75% 2 100%
#
1
<?php
2

                    
3
namespace mageekguy\atoum\asserters;
4

                    
5
use
6
	mageekguy\atoum,
7
	mageekguy\atoum\tools,
8
	mageekguy\atoum\asserter,
9
	mageekguy\atoum\exceptions
10
;
11

                    
12
class constant extends atoum\asserter
13
{
14
	protected $diff = null;
15
	protected $isSet = false;
16
	protected $value = null;
17

                    
18
	public function __construct(asserter\generator $generator = null, tools\variable\analyzer $analyzer = null, atoum\locale $locale = null)100%
19
	{
20
		parent::__construct($generator, $analyzer, $locale);
21

                    
22
		$this->setDiff();
23
	}
24

                    
25
	public function __toString()0%
26
	{
27
		return $this->getTypeOf($this->value);
28
	}
29

                    
30
	public function __call($method, $arguments)50%
31
	{
32
		switch (strtolower($method))
33
		{
34
			case 'equalto':
35
				return call_user_func_array(array($this, 'isEqualTo'), $arguments);
36

                    
37
			default:
38
				return parent::__call($method, $arguments);
39
		}
40
	}
41

                    
42
	public function setDiff(tools\diffs\variable $diff = null)100%
43
	{
44
		$this->diff = $diff ?: new tools\diffs\variable();
45

                    
46
		return $this;
47
	}
48

                    
49
	public function getDiff()100%
50
	{
51
		return $this->diff;
52
	}
53

                    
54
	public function wasSet()100%
55
	{
56
		return ($this->isSet === true);
57
	}
58

                    
59
	public function setWith($value)100%
60
	{
61
		parent::setWith($value);
62

                    
63
		$this->value = $value;
64
		$this->isSet = true;
65

                    
66
		return $this;
67
	}
68

                    
69
	public function reset()100%
70
	{
71
		$this->value = null;
72
		$this->isSet = false;
73

                    
74
		return parent::reset();
75
	}
76

                    
77
	public function getValue()100%
78
	{
79
		return $this->value;
80
	}
81

                    
82
	public function isEqualTo($value, $failMessage = null)100%
83
	{
84
		if ($this->valueIsSet()->value === $value)
85
		{
86
			$this->pass();
87
		}
88
		else
89
		{
90
			$this->fail($failMessage ?: $this->_('%s is not equal to %s', $this, $this->getTypeOf($value)) . PHP_EOL . $this->diff->setExpected($this->value)->setActual($value));
91
		}
92

                    
93
		return $this;
94
	}
95

                    
96
	protected function valueIsSet($message = 'Value is undefined')100%
97
	{
98
		if ($this->isSet === false)
99
		{
100
			throw new exceptions\logic($message);
101
		}
102

                    
103
		return $this;
104
	}
105
}