-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_context.php
91 lines (73 loc) · 2.76 KB
/
test_context.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
85
86
87
88
89
90
91
<?php namespace Matura\Tests;
use Matura\Exceptions\Exception;
use Matura\Test\User;
use Matura\Test\Group;
describe('Context', function ($ctx) {
before(function ($ctx) {
$ctx->before_scalar = 5;
$ctx->empty_array = array();
$ctx->false = false;
$ctx->user = new User('bob');
$ctx->func = function ($value) {
return $value;
};
});
before_all(function ($ctx) {
$ctx->once_before_scalar = 10;
$ctx->group = new Group('admins');
});
it('should return null for an undefined value', function ($ctx) {
expect($ctx->never_set)->to->be(null);
});
it('should allow and preserve setting empty arrays', function ($ctx) {
expect($ctx->empty_array)->to->be(array());
});
it('should allow and preserve setting false', function ($ctx) {
expect($ctx->false)->to->be(false);
});
it('should have a user', function ($ctx) {
expect($ctx->user)->to->be->a('\Matura\Test\User');
expect($ctx->user->name)->to->eql('bob');
});
it('should have a group', function ($ctx) {
expect($ctx->group)->to->be->a('\Matura\Test\Group');
expect($ctx->group->name)->to->eql('admins');
});
it('should have a scalar from the before hook', function ($ctx) {
expect($ctx->before_scalar)->to->be(5);
});
it('should have a scalar from the once before hook', function ($ctx) {
expect($ctx->once_before_scalar)->to->be(10);
});
it('should invoke methods', function ($ctx) {
expect($ctx->func(5))->to->eql(5);
});
describe('Nested, Undefined Values', function ($ctx) {
it('should return null for an undefined value when nested deeper', function ($ctx) {
expect($ctx->another_never_set)->to->be(null);
});
});
describe('Sibling-Of `Isolation` Block', function ($ctx) {
before_all(function ($ctx) {
$ctx->once_before_scalar = 15;
});
before(function ($ctx) {
$ctx->before_scalar = 10;
$ctx->group = new Group('staff');
});
it("should have the clobbered value of `once_before_scalar`", function ($ctx) {
expect($ctx->once_before_scalar)->to->be(15);
});
it("should have the clobbered value of `group`", function ($ctx) {
expect($ctx->group->name)->to->be('staff');
});
});
describe('Isolation', function ($ctx) {
it("should have the parent `once_before_scalar` and not a sibling's", function ($ctx) {
expect($ctx->once_before_scalar)->to->be(10);
});
it("should have the parent `before_scalar` and not a sibling's", function ($ctx) {
expect($ctx->before_scalar)->to->be(5);
});
});
});