@@ 253-269 (lines=17) @@ | ||
250 | * @return Assert |
|
251 | * @throws AssertionFailedException |
|
252 | */ |
|
253 | public function greaterThan($value2, $message = null, $propertyPath = null) |
|
254 | { |
|
255 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
256 | { |
|
257 | return $this; |
|
258 | } |
|
259 | if ( ! ( $this->value > $value2 ) ) |
|
260 | { |
|
261 | $message = sprintf( |
|
262 | $message ?: 'Value "%s" does not greater then expected value "%s".', |
|
263 | $this->stringify($this->value), |
|
264 | $this->stringify($value2) |
|
265 | ); |
|
266 | throw $this->createException($message, self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
267 | } |
|
268 | return $this; |
|
269 | } |
|
270 | ||
271 | /** |
|
272 | * |
|
@@ 279-295 (lines=17) @@ | ||
276 | * @return Assert |
|
277 | * @throws AssertionFailedException |
|
278 | */ |
|
279 | public function greaterThanOrEq($value2, $message = null, $propertyPath = null) |
|
280 | { |
|
281 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
282 | { |
|
283 | return $this; |
|
284 | } |
|
285 | if ( ! ( $this->value >= $value2 ) ) |
|
286 | { |
|
287 | $message = sprintf( |
|
288 | $message ?: 'Value "%s" does not greater than or equal to expected value "%s".', |
|
289 | $this->stringify($this->value), |
|
290 | $this->stringify($value2) |
|
291 | ); |
|
292 | throw $this->createException($message, self::INVALID_EQ, $propertyPath, ['expected' => $value2]); |
|
293 | } |
|
294 | return $this; |
|
295 | } |
|
296 | ||
297 | /** |
|
298 | * |
|
@@ 305-321 (lines=17) @@ | ||
302 | * @return Assert |
|
303 | * @throws AssertionFailedException |
|
304 | */ |
|
305 | public function lessThan($value2, $message = null, $propertyPath = null) |
|
306 | { |
|
307 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
308 | { |
|
309 | return $this; |
|
310 | } |
|
311 | if ( ! ( $this->value < $value2 ) ) |
|
312 | { |
|
313 | $message = sprintf( |
|
314 | $message ?: 'Value "%s" does not less then expected value "%s".', |
|
315 | $this->stringify($this->value), |
|
316 | $this->stringify($value2) |
|
317 | ); |
|
318 | throw $this->createException($message, self::INVALID_LESS_THAN, $propertyPath, ['expected' => $value2]); |
|
319 | } |
|
320 | return $this; |
|
321 | } |
|
322 | ||
323 | /** |
|
324 | * |
|
@@ 331-347 (lines=17) @@ | ||
328 | * @return Assert |
|
329 | * @throws AssertionFailedException |
|
330 | */ |
|
331 | public function lessThanOrEq($value2, $message = null, $propertyPath = null) |
|
332 | { |
|
333 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
334 | { |
|
335 | return $this; |
|
336 | } |
|
337 | if ( ! ( $this->value <= $value2 ) ) |
|
338 | { |
|
339 | $message = sprintf( |
|
340 | $message ?: 'Value "%s" does not less than or equal to expected value "%s".', |
|
341 | $this->stringify($this->value), |
|
342 | $this->stringify($value2) |
|
343 | ); |
|
344 | throw $this->createException($message, self::INVALID_LESS_THAN_OR_EQ, $propertyPath, ['expected' => $value2]); |
|
345 | } |
|
346 | return $this; |
|
347 | } |
|
348 | ||
349 | /** |
|
350 | * Assert that two values are the same (using ===). |
|
@@ 1416-1433 (lines=18) @@ | ||
1413 | * @return Assert |
|
1414 | * @throws AssertionFailedException |
|
1415 | */ |
|
1416 | public function ascii($message = null, $propertyPath = null) |
|
1417 | { |
|
1418 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1419 | { |
|
1420 | return $this; |
|
1421 | } |
|
1422 | $this->string($message, $propertyPath); |
|
1423 | if ( ! preg_match('/^[ -~]+$/', $this->value) ) |
|
1424 | { |
|
1425 | $message = $message |
|
1426 | ?: sprintf( |
|
1427 | 'Value "%s" was expected to be a valid ASCII string', |
|
1428 | $this->stringify($this->value) |
|
1429 | ); |
|
1430 | throw $this->createException($message, self::INVALID_ASCII, $propertyPath); |
|
1431 | } |
|
1432 | return $this; |
|
1433 | } |
|
1434 | ||
1435 | /** |
|
1436 | * Assert that key exists in an array/array-accessible object using isset() |
|
@@ 1737-1753 (lines=17) @@ | ||
1734 | * @return Assert |
|
1735 | * @throws AssertionFailedException |
|
1736 | */ |
|
1737 | public function directory($message = null, $propertyPath = null) |
|
1738 | { |
|
1739 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1740 | { |
|
1741 | return $this; |
|
1742 | } |
|
1743 | $this->string($message, $propertyPath); |
|
1744 | if ( !is_dir($this->value) ) |
|
1745 | { |
|
1746 | $message = sprintf( |
|
1747 | $message ?: 'Path "%s" was expected to be a directory.', |
|
1748 | $this->stringify($this->value) |
|
1749 | ); |
|
1750 | throw $this->createException($message, self::INVALID_DIRECTORY, $propertyPath); |
|
1751 | } |
|
1752 | return $this; |
|
1753 | } |
|
1754 | ||
1755 | /** |
|
1756 | * Assert that the value is something readable |
|
@@ 1763-1779 (lines=17) @@ | ||
1760 | * @return Assert |
|
1761 | * @throws AssertionFailedException |
|
1762 | */ |
|
1763 | public function readable($message = null, $propertyPath = null) |
|
1764 | { |
|
1765 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1766 | { |
|
1767 | return $this; |
|
1768 | } |
|
1769 | $this->string($message, $propertyPath); |
|
1770 | if ( !is_readable($this->value) ) |
|
1771 | { |
|
1772 | $message = sprintf( |
|
1773 | $message ?: 'Path "%s" was expected to be readable.', |
|
1774 | $this->stringify($this->value) |
|
1775 | ); |
|
1776 | throw $this->createException($message, self::INVALID_READABLE, $propertyPath); |
|
1777 | } |
|
1778 | return $this; |
|
1779 | } |
|
1780 | ||
1781 | /** |
|
1782 | * Assert that the value is something writeable |
|
@@ 1789-1805 (lines=17) @@ | ||
1786 | * @return Assert |
|
1787 | * @throws AssertionFailedException |
|
1788 | */ |
|
1789 | public function writeable($message = null, $propertyPath = null) |
|
1790 | { |
|
1791 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1792 | { |
|
1793 | return $this; |
|
1794 | } |
|
1795 | $this->string($message, $propertyPath); |
|
1796 | if ( !is_writeable($this->value) ) |
|
1797 | { |
|
1798 | $message = sprintf( |
|
1799 | $message ?: 'Path "%s" was expected to be writeable.', |
|
1800 | $this->stringify($this->value) |
|
1801 | ); |
|
1802 | throw $this->createException($message, self::INVALID_WRITEABLE, $propertyPath); |
|
1803 | } |
|
1804 | return $this; |
|
1805 | } |
|
1806 | ||
1807 | /** |
|
1808 | * Assert that value is an email adress (using |
|
@@ 1945-1965 (lines=21) @@ | ||
1942 | * @return Assert |
|
1943 | * @throws AssertionFailedException |
|
1944 | */ |
|
1945 | public function alnum($message = null, $propertyPath = null) |
|
1946 | { |
|
1947 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
1948 | { |
|
1949 | return $this; |
|
1950 | } |
|
1951 | try |
|
1952 | { |
|
1953 | $this->regex('(^([a-zA-Z]{1}[a-zA-Z0-9]*)$)', $message, $propertyPath); |
|
1954 | } |
|
1955 | catch (AssertionFailedException $e) |
|
1956 | { |
|
1957 | $message = sprintf( |
|
1958 | $message |
|
1959 | ?: 'Value "%s" is not alphanumeric, starting with letters and containing only letters and numbers.', |
|
1960 | $this->stringify($this->value) |
|
1961 | ); |
|
1962 | throw $this->createException($message, self::INVALID_ALNUM, $propertyPath); |
|
1963 | } |
|
1964 | return $this; |
|
1965 | } |
|
1966 | ||
1967 | /** |
|
1968 | * Assert that the value is boolean True. |
|
@@ 2269-2285 (lines=17) @@ | ||
2266 | * @returns Assert |
|
2267 | * @throws |
|
2268 | */ |
|
2269 | public function methodExists($object, $message = null, $propertyPath = null) |
|
2270 | { |
|
2271 | if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) ) |
|
2272 | { |
|
2273 | return $this; |
|
2274 | } |
|
2275 | (new Assert($object))->setExceptionClass($this->exceptionClass)->isObject($message, $propertyPath); |
|
2276 | if ( !method_exists($object, $this->value) ) |
|
2277 | { |
|
2278 | $message = sprintf( |
|
2279 | $message ?: 'Expected "%s" does not a exist in provided object.', |
|
2280 | $this->stringify($this->value) |
|
2281 | ); |
|
2282 | throw $this->createException($message, self::INVALID_METHOD, $propertyPath); |
|
2283 | } |
|
2284 | return $this; |
|
2285 | } |
|
2286 | ||
2287 | /** |
|
2288 | * Determines that the provided value is an object. |