|
| 1 | +<?php |
| 2 | + |
| 3 | +if (ini_get('zend.assertions') !== '1') { |
| 4 | + throw new LogicException('Tests are expecting `zend.assertions` set to 1 in php.ini.'); |
| 5 | +} |
| 6 | + |
| 7 | +if (ini_get('assert.exception') !== '1') { |
| 8 | + throw new LogicException('Tests are expecting `assert.exception` set to 1 in php.ini.'); |
| 9 | +} |
| 10 | + |
| 11 | +require __DIR__ . '/vendor/autoload.php'; |
| 12 | + |
| 13 | +$status = (function() { |
| 14 | + $total = 0; |
| 15 | + $passed = 0; |
| 16 | + $failed = 0; |
| 17 | + $finished = false; |
| 18 | + |
| 19 | + register_shutdown_function(function () use (&$finished) { |
| 20 | + if (! $finished) { |
| 21 | + echo 'Not all tests were executed.', PHP_EOL; |
| 22 | + return 1; |
| 23 | + } |
| 24 | + return 0; |
| 25 | + }); |
| 26 | + |
| 27 | + $tests = []; |
| 28 | + |
| 29 | + foreach (scandir(__DIR__ . '/tests') as $file) { |
| 30 | + if (substr($file, 0, 10) === 'it_should_') { |
| 31 | + $tests[] = $file; |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + $errors = []; |
| 36 | + |
| 37 | + foreach ($tests as $file) { |
| 38 | + $total++; |
| 39 | + try { |
| 40 | + require __DIR__ . '/tests/' . $file; |
| 41 | + $passed++; |
| 42 | + echo '.'; |
| 43 | + } catch (Throwable $exception) { |
| 44 | + echo 'E'; |
| 45 | + $failed++; |
| 46 | + $errors[$file] = $exception; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + echo " {$total}/{$total} (100%)", PHP_EOL; |
| 51 | + |
| 52 | + if ($failed > 0) { |
| 53 | + echo "There were {$failed} errors: ", PHP_EOL; |
| 54 | + } |
| 55 | + |
| 56 | + foreach (array_keys($errors) as $i => $test) { |
| 57 | + echo PHP_EOL; |
| 58 | + $exception = $errors[$test]; |
| 59 | + echo sprintf("%s) %s", $i + 1, $test), PHP_EOL; |
| 60 | + echo sprintf("`%s` was thrown.", get_class($exception)), PHP_EOL; |
| 61 | + echo sprintf('"%s"', $exception->getMessage()), PHP_EOL; |
| 62 | + echo $exception->getTraceAsString(), PHP_EOL; |
| 63 | + } |
| 64 | + |
| 65 | + echo PHP_EOL; |
| 66 | + |
| 67 | + echo "Tests executed: {$total}", PHP_EOL; |
| 68 | + echo "Passed: {$passed}", PHP_EOL; |
| 69 | + echo "Failed: {$failed}", PHP_EOL; |
| 70 | + |
| 71 | + $finished = true; |
| 72 | + |
| 73 | + return $failed === 0 ? 0 : 1; |
| 74 | +})(); |
| 75 | + |
| 76 | +exit($status); |
0 commit comments