@@ 0,0 1,114 @@
+#!/usr/bin/env php
+<?php
+declare(strict_types=1);
+
+namespace Thirdplace;
+
+function assertNull($value, string $message = null)
+{
+ if ($value !== null) {
+ fail(null, $value, $message);
+ }
+}
+
+function assertTrue($value, string $message = null)
+{
+ if ($value !== true) {
+ fail(true, $value, $message);
+ }
+}
+
+function assertFalse($value, string $message = null)
+{
+ if ($value !== false) {
+ fail(false, $value, $message);
+ }
+}
+
+function assertEquals($expected, $actual, string $message = null)
+{
+ if ($expected != $actual) {
+ fail($expected, $actual, $message);
+ }
+}
+
+function assertSame($expected, $actual, string $message = null)
+{
+ if ($expected !== $actual) {
+ fail($expected, $actual, $message);
+ }
+}
+
+function expectException(\Closure $fn, string $expected = \Exception::class, string $message = null)
+{
+ try {
+ $fn();
+ fail($expected, '', $message);
+ } catch (\Exception $e) {
+ if (! $e instanceof $expected) {
+ fail($expected, get_class($e), $message);
+ }
+ }
+}
+
+function fail($expected, $actual, string $message = null)
+{
+ $stackFrame = debug_backtrace()[1];
+ printf("\nFAIL at %s line %s\n", $stackFrame['file'], $stackFrame['line']);
+ if ($message) {
+ printf("Message : %s\n", $message);
+ }
+ printf("Expected: %s\n", toString($expected));
+ printf("Actual: %s\n", toString($actual));
+}
+
+function toString($value)
+{
+ if ($value === null) {
+ return '[null]';
+ }
+ if (is_bool($value)) {
+ return $value ? '[true]' : '[false]';
+ }
+ if (is_string($value) || method_exists($value, '__toString')) {
+ return "'$value'";
+ }
+ return print_r($value, true);
+}
+
+function main($argc, $argv): void
+{
+ set_error_handler(function ($code, $message, $file, $line) {
+ throw new \ErrorException($message, 0, $code, $file, $line);
+ });
+
+ $base = $argv[1] ?? './';
+
+ if (!is_dir($base)) {
+ exit(sprintf("Folder not found: %s\n", $base));
+ }
+
+ $autoloader = "$base/vendor/autoload.php";
+ if (is_file($autoloader)) {
+ require $autoloader;
+ }
+
+ $testsFolder = "$base/tests";
+ if (!is_dir($testsFolder)) {
+ exit(sprintf("Tests folder not found: %s\n", $testsFolder));
+ }
+
+ $tests = glob($testsFolder . '/*.php');
+ if (!$tests) {
+ exit("Tests folder is empty\n");
+ }
+
+ foreach ($tests as $test) {
+ require $test;
+ print '.';
+ }
+
+ print "\n";
+}
+
+main($argc, $argv);
@@ 35,6 35,7 @@
]
},
"bin": [
+ "./bin/tunit"
],
"require": {
"php" : ">=7.4",
@@ 47,5 48,8 @@
},
"require-dev": {
"thirdplace/tunit": "dev-main"
+ },
+ "scripts": {
+ "test": "./bin/tunit"
}
}