1: <?php
2: namespace Peridot\Leo\Interfaces\Assert;
3:
4: 5: 6: 7: 8: 9:
10: trait TypeAssertTrait
11: {
12: 13: 14: 15: 16: 17: 18:
19: public function typeOf($actual, $expected, $message = "")
20: {
21: $this->assertion->setActual($actual);
22: return $this->assertion->to->be->a($expected, $message);
23: }
24:
25: 26: 27: 28: 29: 30: 31:
32: public function notTypeOf($actual, $expected, $message = "")
33: {
34: $this->assertion->setActual($actual);
35: return $this->assertion->to->not->be->a($expected, $message);
36: }
37:
38: 39: 40: 41: 42: 43:
44: public function isTrue($value, $message = "")
45: {
46: $this->assertion->setActual($value);
47: return $this->assertion->to->be->true($message);
48: }
49:
50: 51: 52: 53: 54: 55:
56: public function isFalse($value, $message = "")
57: {
58: $this->assertion->setActual($value);
59: return $this->assertion->to->be->false($message);
60: }
61:
62: 63: 64: 65: 66: 67:
68: public function isNull($value, $message = "")
69: {
70: $this->assertion->setActual($value);
71: return $this->assertion->to->be->null($message);
72: }
73:
74: 75: 76: 77: 78: 79:
80: public function isNotNull($value, $message = "")
81: {
82: $this->assertion->setActual($value);
83: return $this->assertion->to->not->be->null($message);
84: }
85:
86: 87: 88: 89: 90: 91: 92:
93: public function isCallable($value, $message = "")
94: {
95: $this->assertion->setActual($value);
96: return $this->assertion->to->satisfy('is_callable', $message);
97: }
98:
99: 100: 101: 102: 103: 104: 105:
106: public function isNotCallable($value, $message = "")
107: {
108: $this->assertion->setActual($value);
109: return $this->assertion->to->not->satisfy('is_callable', $message);
110: }
111:
112: 113: 114: 115: 116: 117:
118: public function isObject($value, $message = "")
119: {
120: return $this->typeOf($value, 'object', $message);
121: }
122:
123: 124: 125: 126: 127: 128:
129: public function isNotObject($value, $message = "")
130: {
131: return $this->notTypeOf($value, 'object', $message);
132: }
133:
134: 135: 136: 137: 138: 139:
140: public function isArray($value, $message = "")
141: {
142: return $this->typeOf($value, 'array', $message);
143: }
144:
145: 146: 147: 148: 149: 150:
151: public function isNotArray($value, $message = "")
152: {
153: return $this->notTypeOf($value, 'array', $message);
154: }
155:
156: 157: 158: 159: 160: 161:
162: public function isString($value, $message = "")
163: {
164: return $this->typeOf($value, 'string', $message);
165: }
166:
167: 168: 169: 170: 171: 172:
173: public function isNotString($value, $message = "")
174: {
175: return $this->notTypeOf($value, 'string', $message);
176: }
177:
178: 179: 180: 181: 182: 183: 184:
185: public function isNumeric($value, $message = "")
186: {
187: $this->assertion->setActual($value);
188: return $this->assertion->to->satisfy('is_numeric', $message);
189: }
190:
191: 192: 193: 194: 195: 196: 197:
198: public function isNotNumeric($value, $message = "")
199: {
200: $this->assertion->setActual($value);
201: return $this->assertion->not->to->satisfy('is_numeric', $message);
202: }
203:
204: 205: 206: 207: 208: 209:
210: public function isInteger($value, $message = "")
211: {
212: return $this->typeOf($value, 'integer', $message);
213: }
214:
215: 216: 217: 218: 219: 220:
221: public function isNotInteger($value, $message = "")
222: {
223: return $this->notTypeOf($value, 'integer', $message);
224: }
225:
226: 227: 228: 229: 230: 231:
232: public function isDouble($value, $message = "")
233: {
234: return $this->typeOf($value, 'double', $message);
235: }
236:
237: 238: 239: 240: 241: 242:
243: public function isNotDouble($value, $message = "")
244: {
245: return $this->notTypeOf($value, 'double', $message);
246: }
247:
248: 249: 250: 251: 252: 253:
254: public function isResource($value, $message = "")
255: {
256: return $this->typeOf($value, 'resource', $message);
257: }
258:
259: 260: 261: 262: 263: 264:
265: public function isNotResource($value, $message = "")
266: {
267: return $this->notTypeOf($value, 'resource', $message);
268: }
269:
270: 271: 272: 273: 274: 275:
276: public function isBoolean($value, $message = "")
277: {
278: return $this->typeOf($value, 'boolean', $message);
279: }
280:
281: 282: 283: 284: 285: 286:
287: public function isNotBoolean($value, $message = "")
288: {
289: return $this->notTypeOf($value, 'boolean', $message);
290: }
291: }
292: