@@ 637-645 (lines=9) @@ | ||
634 | * |
|
635 | * @throws InvalidArgumentException |
|
636 | */ |
|
637 | public static function null($value, $message = '') |
|
638 | { |
|
639 | if (null !== $value) { |
|
640 | static::reportInvalidArgument(\sprintf( |
|
641 | $message ?: 'Expected null. Got: %s', |
|
642 | static::valueToString($value) |
|
643 | )); |
|
644 | } |
|
645 | } |
|
646 | ||
647 | /** |
|
648 | * @psalm-pure |
|
@@ 674-682 (lines=9) @@ | ||
671 | * |
|
672 | * @throws InvalidArgumentException |
|
673 | */ |
|
674 | public static function true($value, $message = '') |
|
675 | { |
|
676 | if (true !== $value) { |
|
677 | static::reportInvalidArgument(\sprintf( |
|
678 | $message ?: 'Expected a value to be true. Got: %s', |
|
679 | static::valueToString($value) |
|
680 | )); |
|
681 | } |
|
682 | } |
|
683 | ||
684 | /** |
|
685 | * @psalm-pure |
|
@@ 693-701 (lines=9) @@ | ||
690 | * |
|
691 | * @throws InvalidArgumentException |
|
692 | */ |
|
693 | public static function false($value, $message = '') |
|
694 | { |
|
695 | if (false !== $value) { |
|
696 | static::reportInvalidArgument(\sprintf( |
|
697 | $message ?: 'Expected a value to be false. Got: %s', |
|
698 | static::valueToString($value) |
|
699 | )); |
|
700 | } |
|
701 | } |
|
702 | ||
703 | /** |
|
704 | * @psalm-pure |
|
@@ 1379-1388 (lines=10) @@ | ||
1376 | * |
|
1377 | * @throws InvalidArgumentException |
|
1378 | */ |
|
1379 | public static function length($value, $length, $message = '') |
|
1380 | { |
|
1381 | if ($length !== static::strlen($value)) { |
|
1382 | static::reportInvalidArgument(\sprintf( |
|
1383 | $message ?: 'Expected a value to contain %2$s characters. Got: %s', |
|
1384 | static::valueToString($value), |
|
1385 | $length |
|
1386 | )); |
|
1387 | } |
|
1388 | } |
|
1389 | ||
1390 | /** |
|
1391 | * Inclusive min. |
|
@@ 1401-1410 (lines=10) @@ | ||
1398 | * |
|
1399 | * @throws InvalidArgumentException |
|
1400 | */ |
|
1401 | public static function minLength($value, $min, $message = '') |
|
1402 | { |
|
1403 | if (static::strlen($value) < $min) { |
|
1404 | static::reportInvalidArgument(\sprintf( |
|
1405 | $message ?: 'Expected a value to contain at least %2$s characters. Got: %s', |
|
1406 | static::valueToString($value), |
|
1407 | $min |
|
1408 | )); |
|
1409 | } |
|
1410 | } |
|
1411 | ||
1412 | /** |
|
1413 | * Inclusive max. |
|
@@ 1423-1432 (lines=10) @@ | ||
1420 | * |
|
1421 | * @throws InvalidArgumentException |
|
1422 | */ |
|
1423 | public static function maxLength($value, $max, $message = '') |
|
1424 | { |
|
1425 | if (static::strlen($value) > $max) { |
|
1426 | static::reportInvalidArgument(\sprintf( |
|
1427 | $message ?: 'Expected a value to contain at most %2$s characters. Got: %s', |
|
1428 | static::valueToString($value), |
|
1429 | $max |
|
1430 | )); |
|
1431 | } |
|
1432 | } |
|
1433 | ||
1434 | /** |
|
1435 | * Inclusive , so Assert::lengthBetween('asd', 3, 5); passes the assertion. |