<?php require __DIR__ . '/../vendor/autoload.php'; use FUnit as fu; use Knlv\Slim\Middleware\Callback; date_default_timezone_set('Europe/Athens'); fu::test('Test middleware throws exception on invlalid callable', function () { try { new Callback('test'); } catch (Exception $e) { fu::ok($e instanceof InvalidArgumentException, 'Throws if no callback is given'); } }); fu::test('Test middleware set callback', function () { $callback = function () { }; $middleware = new Callback($callback); $reflection = new ReflectionObject($middleware); $propertyReflection = $reflection->getProperty('callback'); $propertyReflection->setAccessible(true); fu::equal($callback, $propertyReflection->getValue($middleware), 'Callback is set'); }); fu::test('Test middleware call uses callback', function () { $middleware = new Callback(function ($m) use(&$middleware) { fu::pass('Callable is called'); fu::equal($middleware, $m, 'Passes itself as callable argument'); }); $middleware->call(); });
fu::strict_equal('Fixture Suite', $ts->getName()); }); fu::test("Check suite run state", function () { $ts = fu::fixture('ts'); fu::strict_equal(false, $ts->run); $ts->run(); fu::strict_equal(true, $ts->run); }); fu::test("Check suite exit code 1", function () { $ts = fu::fixture('ts'); fu::strict_equal(0, $ts->getExitCode()); $ts->addTest('known to fail for suite', function () use($ts) { // this forces the result of this assertion to be recorded in // the `$ts` TestSuite instance fu::fail($ts, 'this always fails'); }); $ts->run(); fu::strict_equal(1, $ts->getExitCode()); }); fu::test("Check suite exit code 0", function () { $ts = fu::fixture('ts'); fu::strict_equal(0, $ts->getExitCode()); $ts->addTest('known to fail for suite', function () use($ts) { // this forces the result of this assertion to be recorded in // the `$ts` TestSuite instance fu::pass($ts, 'this always fails'); }); $ts->run(); fu::strict_equal(0, $ts->getExitCode()); }); fu::run();