/
Scalar.php
107 lines (98 loc) · 2.91 KB
/
Scalar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* PHPSpec
*
* LICENSE
*
* This file is subject to the GNU Lesser General Public License Version 3
* that is bundled with this package in the file LICENSE.
* It is also available through the world-wide-web at this URL:
* http://www.gnu.org/licenses/lgpl-3.0.txt
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@phpspec.net so we can send you a copy immediately.
*
* @category PHPSpec
* @package PHPSpec
* @copyright Copyright (c) 2007-2009 Pádraic Brady, Travis Swicegood
* @copyright Copyright (c) 2010-2011 Pádraic Brady, Travis Swicegood,
* Marcello Duarte
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
namespace PHPSpec\Specification;
/**
* @category PHPSpec
* @package PHPSpec
* @copyright Copyright (c) 2007-2009 Pádraic Brady, Travis Swicegood
* @copyright Copyright (c) 2010-2011 Pádraic Brady, Travis Swicegood,
* Marcello Duarte
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
*/
class Scalar extends \PHPSpec\Specification
{
/**
* The scalar value
*
* @var scalar
*/
protected $_scalarValue = null;
/**
* Scalar is constructed with its value
*
* @param $scalarValue
*/
public function __construct($scalarValue = null)
{
if (!is_null($scalarValue)) {
$this->_scalarValue = $scalarValue;
$this->setActualValue($this->_scalarValue);
}
$this->_expectation = new \PHPSpec\Expectation;
}
/**
* Adds DSL method calls to scalar values
*
* @throws \PHPSpec\Exception
* @param string $method
* @param array $args
* @return \PHPSpec\Specification|boolean
*/
public function __call($method, $args)
{
$dslResult = parent::__call($method, $args);
if (!is_null($dslResult)) {
return $dslResult;
}
throw new \PHPSpec\Exception('unknown method called');
}
/**
* Adds DSL properties to scalar values
*
* @throws \PHPSpec\Exception
* @param string $name
* @return \PHPSpec\Specification\Scalar An instance of self
*/
public function __get($name)
{
$dslResult = parent::__get($name);
if (!is_null($dslResult)) {
return $dslResult;
}
throw new \PHPSpec\Exception('unknown property requested');
}
/**
* Gets the scalar value
*
* @throws \PHPSpec\Exception
* @return scalar
*/
public function getScalar()
{
if (is_null($this->_scalarValue)) {
throw new \PHPSpec\Exception(
'a scalar value has not yet been initialised'
);
}
return $this->_scalarValue;
}
}