/
example.php
60 lines (41 loc) · 1.48 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
use \FUnit\fu;
require __DIR__ . '/FUnit.php';
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("this is a test", function() {
fu::ok(1, "the integer '1' is okay");
fu::ok(0, "the integer '0' is not okay"); // this will fail!
});
fu::test("another test", function() {
fu::equal(true, 1, "the integer '1' is truthy");
fu::not_strict_equal(true, 1, "the integer '1' is NOT true");
// access a fixture
$foobar = fu::fixture('foobar');
fu::equal($foobar['foo'], 'bar', "the fixture 'foobar' should have a key 'foo' equal to 'baz'");
$fooarr = array('blam'=>'blaz');
fu::has('blam', $fooarr, "\$fooarr has a key named 'blam'");
$fooobj = new \StdClass;
$fooobj->blam = 'blaz';
fu::has('blam', $fooobj, "\$fooobj has a property named 'blam'");
});
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');
});
fu::run();
// this should output an empty array, because our fixtures will be gone
var_dump(fu::$fixtures);