@@ -8,9 +8,10 @@ BDD style code blocks for PHPUnit / Codeception
8
8
Specify allows you to write your tests in more readable BDD style, the same way you might have experienced with [ Jasmine] ( https://jasmine.github.io/ ) .
9
9
Inspired by MiniTest of Ruby now you combine BDD and classical TDD style in one test.
10
10
11
- ### BDD Example
11
+ ### Basic Example
12
12
13
- Specify supports ` describe-it ` BDD syntax inside PHPUnit
13
+ Traditionally Specify used ` $this->specify ` function for all descriptions.
14
+ That works too!
14
15
15
16
``` php
16
17
<?php
@@ -28,35 +29,29 @@ class UserTest extends PHPUnit\Framework\TestCase {
28
29
29
30
public function testValidation()
30
31
{
31
- $this->describe("user", function() {
32
- $this->it("should have a name", function() {
33
- $this->user->username = null;
34
- $this->assertFalse($this->user->validate(['username']));
35
- });
36
-
37
- $this->it("should not have long name", function() {
38
- $this->user->username = 'toolooooongnaaaaaaameeee';
39
- $this->assertFalse($this->user->validate(['username']));
40
- });
41
-
42
- // use `$this->>should` as shortcut
43
- $this->should("be ok with valid name", function() {
44
- $this->user->username = 'davert';
45
- $this->assertTrue($this->user->validate(['username']));
46
- });
47
-
48
- // empty codeblocks are marked as Incomplete tests
49
- $this->it("should be ok with valid name");
50
- });
32
+ $this->assertInstanceOf('Model', $this->user);
33
+
34
+ $this->specify("username is required", function() {
35
+ $this->user->username = null;
36
+ $this->assertFalse($this->user->validate(['username']));
37
+ });
51
38
39
+ $this->specify("username is too long", function() {
40
+ $this->user->username = 'toolooooongnaaaaaaameeee',
41
+ $this->assertFalse($this->user->validate(['username']));
42
+ });
43
+
44
+ $this->specify("username is ok", function() {
45
+ $this->user->username = 'davert',
46
+ $this->assertTrue($this->user->validate(['username']));
47
+ });
52
48
}
53
49
}
54
50
```
55
51
56
- ### Basic Example
52
+ ### BDD Example
57
53
58
- Traditionally Specify used ` $this->specify ` function for all descriptions.
59
- That works too!
54
+ Specify supports ` describe-it ` BDD syntax inside PHPUnit
60
55
61
56
``` php
62
57
<?php
@@ -74,29 +69,35 @@ class UserTest extends PHPUnit\Framework\TestCase {
74
69
75
70
public function testValidation()
76
71
{
77
- $this->assertInstanceOf('Model', $this->user);
78
-
79
- $this->specify("username is required", function() {
80
- $this->user->username = null;
81
- $this->assertFalse($this->user->validate(['username']));
82
- });
83
-
84
- $this->specify("username is too long", function() {
85
- $this->user->username = 'toolooooongnaaaaaaameeee',
86
- $this->assertFalse($this->user->validate(['username']));
87
- });
72
+ $this->describe("user", function() {
73
+ $this->it("should have a name", function() {
74
+ $this->user->username = null;
75
+ $this->assertFalse($this->user->validate(['username']));
76
+ });
77
+
78
+ $this->it("should not have long name", function() {
79
+ $this->user->username = 'toolooooongnaaaaaaameeee';
80
+ $this->assertFalse($this->user->validate(['username']));
81
+ });
82
+
83
+ // use `$this->>should` as shortcut
84
+ $this->should("be ok with valid name", function() {
85
+ $this->user->username = 'davert';
86
+ $this->assertTrue($this->user->validate(['username']));
87
+ });
88
+
89
+ // empty codeblocks are marked as Incomplete tests
90
+ $this->it("should be ok with valid name");
91
+ });
88
92
89
- $this->specify("username is ok", function() {
90
- $this->user->username = 'davert',
91
- $this->assertTrue($this->user->validate(['username']));
92
- });
93
93
}
94
94
}
95
95
```
96
96
97
+
97
98
### Specify + Verify Example
98
99
99
- Use [ Codeception/Verify] (https://github.com/Codeception/Verify for simpler assertions:
100
+ Use [ Codeception/Verify] ( https://github.com/Codeception/Verify ) for simpler assertions:
100
101
101
102
``` php
102
103
<?php
0 commit comments