-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexample_standalone.php
84 lines (61 loc) · 2.31 KB
/
example_standalone.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
use \FUnit as fu;
require_once __DIR__ . '/src/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('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');
});
fu::test('Checking iterables with all_ok', function () {
$ints = array(1, 2, 3, 4, 5);
fu::all_ok($ints, 'is_int', "\$ints are all integers");
$ints = array(1, 2, 3, "four", 5);
fu::all_ok($ints, 'is_int', "\$ints are all integers");
$evens = array('a' => 2, 'b' => 42, 'c' => 68, 'd' => 800);
$evens_ao = new ArrayObject($evens);
fu::all_ok($evens_ao, function ($val) {
return ($val % 2) === 0;
}, "\$evens_ao are all even");
});
$exit = fu::run();
exit($exit);