This repository has been archived on 2020-06-07. You can view files and clone it, but cannot push or open issues or pull requests.
php-armadillo/tests/includes/assert.php
2019-06-08 18:04:30 +08:00

41 lines
922 B
PHP

<?php
/**
* Batch assert for one or more cases with the given comparator.
*
* Print message if test fail.
*
* @param string $test
* @param callable $comp
* @param array $cases
* @return bool
*/
function batch_assert_ex($test, $comp, ...$cases) {
foreach ($cases as $case) {
[$expected, $got] = $case;
if ($comp($expected, $got)) {
continue;
}
echo "Test for $test failed.\n";
$expected = var_export($expected, true);
$got = var_export($got, true);
echo "Expected:\n$expected\n";
echo "Got:\n$got\n";
return false;
}
return true;
}
/**
* Batch assert with default comparator.
*
* @param string $test
* @param array $cases
* @return bool
*/
function batch_assert($test, ...$cases) {
return batch_assert_ex($test, function ($expected, $got) {
return $expected == $got;
}, ...$cases);
}