suite() public static méthode

initialize a new test suite. adds a suite to \FUnit::$suites and sets \FUnit::$current_suite_name to the new suite's name
public static suite ( string $name = self::DEFAULT_SUITE_NAME )
$name string default is FUnit::DEFAULT_SUITE_NAME
Exemple #1
0
<?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();
Exemple #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();
Exemple #3
0
<?php

use FUnit as fu;
use FUnit\TestSuite;
require_once __DIR__ . '/../src/FUnit.php';
fu::suite('Assertion test suite');
fu::test('FUnit::assert_ok tests', function () {
    fu::strict_equal(true, fu::assert_ok(1)['result'], "1 is truthy");
    fu::strict_equal(false, fu::assert_ok(0)['result'], "0 is falsy");
    fu::strict_equal(false, fu::assert_ok("")['result'], "empty string is falsy");
    fu::strict_equal(false, fu::assert_ok(array())['result'], "empty array is falsy");
    fu::strict_equal(false, fu::assert_ok(null)['result'], "null is falsy");
    fu::strict_equal(false, fu::assert_ok(false)['result'], "false is falsy");
    fu::strict_equal(true, fu::assert_ok(true)['result'], "true is truthy");
    fu::strict_equal(true, fu::assert_ok('false')['result'], "'false' is truthy");
    fu::strict_equal(true, fu::assert_ok(new stdClass())['result'], "stdClass is truthy");
});
fu::test('FUnit::assert_not_ok tests', function () {
    fu::strict_equal(false, fu::assert_not_ok(1)['result'], "1 is truthy");
    fu::strict_equal(true, fu::assert_not_ok(0)['result'], "0 is falsy");
    fu::strict_equal(true, fu::assert_not_ok("")['result'], "empty string is falsy");
    fu::strict_equal(true, fu::assert_not_ok(array())['result'], "empty array is falsy");
    fu::strict_equal(true, fu::assert_not_ok(null)['result'], "null is falsy");
    fu::strict_equal(true, fu::assert_not_ok(false)['result'], "false is falsy");
    fu::strict_equal(false, fu::assert_not_ok(true)['result'], "true is truthy");
    fu::strict_equal(false, fu::assert_not_ok('false')['result'], "'false' is truthy");
    fu::strict_equal(false, fu::assert_not_ok(new stdClass())['result'], "stdClass is truthy");
});
fu::test('FUnit::assert_all_ok tests', function () {
    $all_ints = array(1, 2, 3, 4, 5);
    $not_all_ints = array(1, 2, "3", 4, 5);