teardown() public static method

typically you'd use the passed function to close/clean-up any fixtures you made
See also: FUnit::fixture()
See also: FUnit::reset_fixtures()
public static teardown ( Closure $teardown )
$teardown Closure an anon function
Example #1
0
<?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('Checking for exceptions', function () {
    $callback = function () {
        throw new RuntimeException();
    };
    fu::throws($callback, 'RuntimeException', 'Correct exception');
    $callback = function ($foo) {
        throw new RuntimeException($foo);
    };
    fu::throws($callback, array('bar'), 'LogicException', 'Not the correct exception');
});
fu::test('Forced failure', function () {
    fu::fail('This is a forced fail');
});
fu::test('Expected failure', function () {
    fu::expect_fail('This is a good place to describe a missing test');
});
fu::test('Forced Errors/Exception', function () {
    trigger_error('This was triggered inside a test', E_USER_ERROR);
    trigger_error('This was triggered inside a test', E_USER_NOTICE);
    throw new Exception('This was thrown inside a test');
Example #2
0
<?php

use FUnit as fu;
use FUnit\TestSuite;
require_once __DIR__ . '/../src/FUnit.php';
fu::suite('Test suite tests');
fu::setup(function () {
    fu::fixture('ts', new TestSuite('Fixture Suite'));
});
fu::teardown(function () {
    fu::reset_fixtures();
});
fu::test("Check suite name", function () {
    $ts = fu::fixture('ts');
    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();