-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExample.php
More file actions
80 lines (70 loc) · 1.77 KB
/
Example.php
File metadata and controls
80 lines (70 loc) · 1.77 KB
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
<?php
declare(strict_types=1);
use function Pest\Gwt\scenario;
use function PHPUnit\Framework\assertEquals;
scenario('given and when returning nothing')
->given(function () {})
->when(function () {})
->then(function () {
assertEquals(1, 1);
});
scenario('given and when returning non array values')
->given(function () {
return 5;
})
->when(function (int $number) {
return $number * 10;
})
->then(function (int $answer) {
assertEquals(50, $answer);
});
scenario('given and when returning arrays')
->given(function () {
return [5];
})
->when(function (int $number) {
return [$number * 10];
})
->then(function (int $answer) {
assertEquals(50, $answer);
});
scenario('writing testes without given')
->when(function () {
return [5 * 10];
})
->then(function (int $answer) {
assertEquals(50, $answer);
});
scenario('expecting exception')
->when(function () {
throw new Exception('Woops!');
})
->throws(Exception::class, 'Woops!');
scenario('expecting exception without message')
->when(function () {
throw new Exception('Woops!');
})
->throws(Exception::class);
scenario('not returning an array works')
->given(function () {
return 'this is not an array';
})
->when(function (string $s) {
return $s;
})
->then(function (string $s) {
expect($s)->toBe('this is not an array');
});
scenario('returning an arrayable class works')
->given(function () {
return new class
{
public $a;
};
})
->when(function ($c) {
return $c;
})
->then(function ($c) {
expect((array) $c)->toBe(['a' => null]);
});