<?php use FUnit as fu; require_once __DIR__ . '/../src/FUnit.php'; fu::test('test output when FUnit::set_disable_reporting(true)', function () use($report_disabled) { $report_disabled = shell_exec("php " . __DIR__ . "/output_scripts/set_disable_reporting_true.php"); fu::strict_equal(0, strlen($report_disabled), "no report output"); }); fu::test('test output when FUnit::set_disable_reporting(false)', function () use($report_disabled) { $report_disabled = shell_exec("php " . __DIR__ . "/output_scripts/set_disable_reporting_false.php"); fu::strict_equal(0, strlen($report_disabled), "Report output received"); }); fu::run();
<?php use FUnit as fu; fu::setup(function () { // set a fixture to use in tests fu::fixture('foobar', array('foo' => 'bar')); }); fu::teardown(function () { // this resets the fu::$fixtures array. May not provide clean shutdown fu::reset_fixtures(); }); fu::test("test for PHP 5.3 or above", function () { fu::strict_equal(true, version_compare(PHP_VERSION, '5.3.0') >= 0, "current PHP is >= 5.3.0"); }); fu::run();
<?php use FUnit as fu; require_once __DIR__ . '/../src/FUnit.php'; fu::suite('Fixture test suite'); fu::test('Test adding fixtures', function () { fu::fixture('a', array(1, 2, 3)); $a = fu::fixture('a'); fu::strict_equal(array(1, 2, 3), $a); }); fu::test('Test resetting fixtures', function () { fu::fixture('a', array(1, 2, 3)); $a = fu::fixture('a'); fu::reset_fixtures(); fu::ok(is_null(fu::fixture('a'))); }); fu::run();
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();
fu::strict_equal(false, fu::assert_has('bingo', $obj)['result'], "\$obj does not have property 'bingo'"); }); fu::test('FUnit::assert_not_has tests', function () { $arr = array("foo" => true, "bar" => null, "baz" => "bingo"); $obj = new stdClass(); $obj->foo = true; $obj->bar = null; $obj->baz = "bingo"; fu::strict_equal(false, fu::assert_not_has('foo', $arr)['result'], "\$arr has key 'foo'"); fu::strict_equal(false, fu::assert_not_has('bar', $arr)['result'], "\$arr has key 'bar'"); fu::strict_equal(false, fu::assert_not_has('baz', $arr)['result'], "\$arr has key 'baz'"); fu::strict_equal(true, fu::assert_not_has('bingo', $arr)['result'], "\$arr does not have key 'bingo'"); fu::strict_equal(false, fu::assert_not_has('foo', $obj)['result'], "\$obj has property 'foo'"); fu::strict_equal(false, fu::assert_not_has('bar', $obj)['result'], "\$obj has property 'bar'"); fu::strict_equal(false, fu::assert_not_has('baz', $obj)['result'], "\$obj has property 'baz'"); fu::strict_equal(true, fu::assert_not_has('bingo', $obj)['result'], "\$obj does not have property 'bingo'"); }); fu::test('FUnit::assert_fail tests', function () { fu::strict_equal(false, fu::assert_fail()['result'], "forced fail"); }); fu::test('FUnit::assert_expect_fail tests', function () { fu::strict_equal(false, fu::assert_expect_fail()['result'], "forced expected fail"); }); fu::test('FUnit::assert_pass tests', function () { fu::strict_equal(true, fu::assert_pass()['result'], "forced pass"); }); fu::test('Ensure not including msg param has no side effects', function () { fu::strict_equal(true, fu::assert_equal(1, 1, 'poop')['result']); fu::strict_equal(true, fu::assert_equal(1, 1)['result']); }); fu::run();