1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dgame\Expectation; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class ScalarExpectations |
7
|
|
|
* @package Dgame\Expectation |
8
|
|
|
*/ |
9
|
|
|
class ScalarExpectations |
10
|
|
|
{ |
11
|
|
|
use ConditionTrait; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* ScalarExpectations constructor. |
15
|
|
|
* |
16
|
|
|
* @param $value |
17
|
|
|
*/ |
18
|
20 |
|
public function __construct($value) |
19
|
|
|
{ |
20
|
20 |
|
if ($this->isScalar($value)) { |
21
|
20 |
|
$this->value = $this->prepare($value); |
22
|
|
|
} |
23
|
20 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param $value |
27
|
|
|
* |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
20 |
|
private function isScalar($value): bool |
31
|
|
|
{ |
32
|
20 |
|
return $this->approveIf(is_scalar($value))->isApproved(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param $value |
37
|
|
|
* |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
15 |
|
protected function prepare($value) |
41
|
|
|
{ |
42
|
15 |
|
return $value; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return ScalarExpectations |
47
|
|
|
*/ |
48
|
|
|
final public function isEmpty(): self |
49
|
|
|
{ |
50
|
|
|
return $this->approveIf(empty($this->value)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return ScalarExpectations |
55
|
|
|
*/ |
56
|
|
|
final public function isNotEmpty(): self |
57
|
|
|
{ |
58
|
|
|
return $this->approveIf(!empty($this->value)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param $value |
63
|
|
|
* |
64
|
|
|
* @return ScalarExpectations |
65
|
|
|
*/ |
66
|
|
|
final public function isEqual($value): self |
67
|
|
|
{ |
68
|
|
|
return $this->approveIf($this->value == $value); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param $value |
73
|
|
|
* |
74
|
|
|
* @return ScalarExpectations |
75
|
|
|
*/ |
76
|
|
|
final public function isNotEqual($value): self |
77
|
|
|
{ |
78
|
|
|
return $this->approveIf($this->value != $value); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param $value |
83
|
|
|
* |
84
|
|
|
* @return ScalarExpectations |
85
|
|
|
*/ |
86
|
|
|
final public function isIdenticalTo($value): self |
87
|
|
|
{ |
88
|
|
|
return $this->approveIf($this->value === $value); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param $value |
93
|
|
|
* |
94
|
|
|
* @return ScalarExpectations |
95
|
|
|
*/ |
96
|
|
|
final public function isNotIdenticalTo($value): self |
97
|
|
|
{ |
98
|
|
|
return $this->approveIf($this->value !== $value); |
99
|
|
|
} |
100
|
|
|
} |