Skip to content

Commit 17ae6d4

Browse files
committed
Updated docs for 1.4.x
1 parent 9848be0 commit 17ae6d4

File tree

3 files changed

+102
-77
lines changed

3 files changed

+102
-77
lines changed

CHANGELOG.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 1.4
4+
5+
* Added **_Fluent Interface_** support, this allows you to add `it`'s and `should`'s chained to a `specify` or `describe`.
6+
* `Specify.php` trait now only has the public API methods.
7+
* If an `it` or `should` only receives text now that test is marked as incomplete.
8+
* `shouldNot` and `its` were added as aliases.
9+
* Added `.phpunit.result.cache` file to `.gitignore`
10+
* Updated `README.md`
11+
312
## 1.0
413

514
* BREAKING: PHPUnit 6 support
@@ -15,32 +24,34 @@
1524
3. If relied on property cloning, add `@specify` annotation for all properties which needs to be cloned for specify blocks
1625
4. If you used `throws` parameter, consider using [AssertThrows](https://github.com/Codeception/AssertThrows) package.
1726

18-
#### 0.4.3
27+
## 0.4.3
1928

2029
* Show example index on failure by @zszucs *2015-11-27*
2130

2231

23-
#### 0.4.2
32+
## 0.4.2
2433

2534
* Testing exception messages by @chrismichaels84 https://github.com/Codeception/Specify#exceptions
2635

27-
#### 0.4.0
36+
## 0.4.0
2837

2938
* Fixes cloning properties in examples. Issue #6 *2014-10-15*
3039
* Added global and local specify configs, for disabling cloning properties and changing cloning methods *2014-10-15*
3140

3241

33-
#### 0.3.6 03/22/2014
34-
42+
## 0.3.6
43+
#### 03/22/2014
3544
* Cloning unclonnable items
3645

3746

38-
#### 0.3.5 03/22/2014
47+
## 0.3.5
48+
#### 03/22/2014
3949

4050
* Updated to DeepCopy 1.1.0
4151

4252

43-
#### 0.3.4 02/23/2014
53+
## 0.3.4
54+
#### 02/23/2014
4455

4556
* Added DeepCopy library to save/restore objects between specs
4657
* Robo file for releases

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013 Codeception PHP Testing Framework
3+
Copyright (c) 2013-2020 Codeception PHP Testing Framework
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.md

Lines changed: 83 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
Specify
22
=======
33

4-
BDD style code blocks for PHPUnit / Codeception
4+
BDD style code blocks for [PHPUnit][1] or [Codeception][2]
55

6-
[![Latest Stable Version](https://poser.pugx.org/codeception/specify/v/stable)](https://packagist.org/packages/codeception/specify)[![Total Downloads](https://poser.pugx.org/codeception/specify/downloads)](https://packagist.org/packages/codeception/specify)[![Latest Unstable Version](https://poser.pugx.org/codeception/specify/v/unstable)](https://packagist.org/packages/codeception/specify)[![License](https://poser.pugx.org/codeception/specify/license)](https://packagist.org/packages/codeception/specify)
6+
[![Latest Stable Version](https://poser.pugx.org/codeception/specify/v/stable)](https://packagist.org/packages/codeception/specify)
7+
[![Total Downloads](https://poser.pugx.org/codeception/specify/downloads)](https://packagist.org/packages/codeception/specify)
8+
[![Latest Unstable Version](https://poser.pugx.org/codeception/specify/v/unstable)](https://packagist.org/packages/codeception/specify)
9+
[![License](https://poser.pugx.org/codeception/specify/license)](https://packagist.org/packages/codeception/specify)
710

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/).
11+
Specify allows you to write your tests in more readable BDD style, the same way you might have experienced with [Jasmine][3].
912
Inspired by MiniTest of Ruby now you combine BDD and classical TDD style in one test.
1013

11-
### Basic Example
14+
## Installation
15+
16+
*Requires PHP >= 7.1*
17+
18+
* Install with Composer:
19+
20+
```
21+
composer require codeception/specify --dev
22+
```
23+
24+
* Include `Codeception\Specify` trait in your tests.
25+
26+
27+
## Usage
1228

1329
Specify `$this->specify` method to add isolated test blocks for your PHPUnit tests!
1430

@@ -17,75 +33,65 @@ public function testValidation()
1733
{
1834
$this->assertInstanceOf('Model', $this->user);
1935

20-
$this->specify("username is required", function() {
36+
$this->specify('username is required', function() {
2137
$this->user->username = null;
22-
$this->assertFalse($this->user->validate(['username']));
38+
$this->assertFalse($this->user->validate(['username']));
2339
});
2440

25-
$this->specify("username is too long", function() {
41+
$this->specify('username is too long', function() {
2642
$this->user->username = 'toolooooongnaaaaaaameeee';
27-
$this->assertFalse($this->user->validate(['username']));
28-
});
29-
30-
$this->specify("username is ok", function() {
31-
$this->user->username = 'davert';
32-
$this->assertTrue($this->user->validate(['username']));
43+
$this->assertFalse($this->user->validate(['username']));
3344
});
3445
}
3546
```
3647

3748
### BDD Example
3849

39-
Specify supports `describe-it` BDD syntax inside PHPUnit
50+
Specify supports `describe-it` and `describe-should` BDD syntax inside PHPUnit
4051

4152
```php
4253
public function testValidation()
4354
{
44-
$this->describe("user", function() {
45-
$this->it("should have a name", function() {
55+
$this->describe('user', function () {
56+
$this->it('should have a name', function() {
4657
$this->user->username = null;
47-
$this->assertFalse($this->user->validate(['username']));
58+
$this->assertFalse($this->user->validate(['username']));
4859
});
60+
});
4961

50-
$this->it("should not have long name", function() {
51-
$this->user->username = 'toolooooongnaaaaaaameeee';
52-
$this->assertFalse($this->user->validate(['username']));
53-
});
54-
55-
// use `$this->>should` as shortcut
56-
$this->should("be ok with valid name", function() {
62+
// you can use chained methods for better readability:
63+
$this->describe('user')
64+
->should('be ok with valid name', function() {
5765
$this->user->username = 'davert';
58-
$this->assertTrue($this->user->validate(['username']));
59-
});
60-
66+
$this->assertTrue($this->user->validate(['username']));
67+
})
68+
->shouldNot('have long name', function() {
69+
$this->user->username = 'toolooooongnaaaaaaameeee';
70+
$this->assertFalse($this->user->validate(['username']));
71+
})
6172
// empty codeblocks are marked as Incomplete tests
62-
$this->it("should be ok with valid name");
63-
});
73+
->it('should be ok with valid name')
74+
;
6475
}
6576
```
6677

6778

6879
### Specify + Verify Example
6980

70-
Use [Codeception/Verify](https://github.com/Codeception/Verify) for simpler assertions:
81+
Use [Codeception/Verify][4] for simpler assertions:
7182

7283
```php
7384
public function testValidation()
7485
{
75-
$this->specify("username is required", function() {
76-
$this->user->username = null;
77-
expect_not($this->user->validate(['username']));
78-
});
79-
80-
$this->specify("username is too long", function() {
86+
$this->specify('username is too long', function() {
8187
$this->user->username = 'toolooooongnaaaaaaameeee';
82-
expect_not($this->user->validate(['username']));
88+
expect_not($this->user->validate(['username']));
89+
});
90+
91+
$this->specify('username is ok', function() {
92+
$this->user->username = 'davert';
93+
expect_that($this->user->validate(['username']));
8394
});
84-
85-
$this->specify("username is ok", function() {
86-
$this->user->username = 'davert';
87-
expect_that($this->user->validate(['username']));
88-
});
8995
}
9096
```
9197

@@ -98,26 +104,27 @@ This is very similar to BDD syntax as in RSpec or Mocha but works inside PHPUnit
98104

99105
```php
100106
<?php
107+
101108
class UserTest extends PHPUnit\Framework\TestCase
102109
{
103110
use Codeception\Specify;
104-
111+
105112
/** @specify */
106113
protected $user; // is cloned inside specify blocks
107-
108-
public function setUp()
114+
115+
public function setUp(): void
109116
{
110117
$this->user = new User;
111118
}
112119

113120
public function testValidation()
114121
{
115122
$this->user->name = 'davert';
116-
$this->specify("i can change my name", function() {
123+
$this->specify('i can change my name', function() {
117124
$this->user->name = 'jon';
118125
$this->assertEquals('jon', $this->user->name);
119-
});
120-
// user name is "davert" again
126+
});
127+
// user name is 'davert' again
121128
$this->assertEquals('davert', $this->user->name);
122129
}
123130
}
@@ -130,7 +137,7 @@ Failure in `specify` block won't get your test stopped.
130137

131138
```php
132139
<?php
133-
$this->specify("failing but test goes on", function() {
140+
$this->specify('failing but test goes on', function() {
134141
$this->fail('bye');
135142
});
136143
$this->assertTrue(true);
@@ -186,7 +193,7 @@ $this->specify('this should not fail', function () {
186193

187194
```php
188195
<?php
189-
$this->specify("should calculate square numbers", function($number, $square) {
196+
$this->specify('should calculate square numbers', function($number, $square) {
190197
$this->assertEquals($square, $number*$number);
191198
}, ['examples' => [
192199
[2,4],
@@ -198,7 +205,7 @@ You can also use DataProvider functions in `examples` param.
198205

199206
```php
200207
<?php
201-
$this->specify("should calculate square numbers", function($number, $square) {
208+
$this->specify('should calculate square numbers', function($number, $square) {
202209
$this->assertEquals($square, $number*$number);
203210
}, ['examples' => $this->provider()]);
204211
```
@@ -243,26 +250,25 @@ $this->cleanSpecify(); // removes before/after callbacks
243250

244251
Available methods:
245252

246-
* `$this->specify(name, callable fn = null, params = [])` - starts a specify code block. If `fn` is null, marks test as incomplete.
247-
* `$this->describe(name, callable fn = null)` - starts a describe code block. Same as `specify` but expects to receive more nested into `fn`.
248-
* `$this->it(name, callable fn = null)` - starts a code block. Alias to `specify`.
249-
* `$this->should(name, callable fn = null)` - starts a code block. Same as `specify` but prepends word "should" into description.
253+
```php
254+
// Starts a specify code block:
255+
$this->specify(string $thing, callable $code = null, $examples = [])
250256

257+
// Starts a describe code block. Same as 'specify' but expects chained 'it' or 'should' methods.
258+
$this->describe(string $feature, callable $code = null)
251259

252-
## Installation
260+
// Starts a code block. If 'code' is null, marks test as incomplete.
261+
$this->it(string $spec, callable $code = null, $examples = [])
262+
$this->its(string $spec, callable $code = null, $examples = [])
253263

254-
*Requires PHP >= 7.*
255-
256-
* Install with Composer:
257-
258-
```
259-
composer require codeception/specify --dev
264+
// Starts a code block. Same as 'it' but prepends 'should' or 'should not' into description.
265+
$this->should(string $behavior, callable $code = null, $examples = [])
266+
$this->shouldNot(string $behavior, callable $code = null, $examples = [])
260267
```
261268

262-
* Include `Codeception\Specify` trait into `PHPUnit\Framework\TestCase`.
263-
* Add `/** @specify **/` docblock for all properties you want to make isolated inside tests.
269+
## Printer Options
264270

265-
* For PHPUnit add `Codeception\Specify\ResultPrinter` printer into `phpunit.xml`
271+
For PHPUnit, add `Codeception\Specify\ResultPrinter` printer into `phpunit.xml`
266272

267273
```xml
268274
<phpunit colors="true" printerClass="Codeception\Specify\ResultPrinter">
@@ -271,8 +277,16 @@ composer require codeception/specify --dev
271277

272278
## Recommended
273279

274-
* Use [Codeception/AssertThrows](https://github.com/Codeception/AssertThrows) for exception assertions
275-
* Use [Codeception/DomainAssert](https://github.com/Codeception/DomainAssert) for verbose domain logic assertions
276-
* Сombine this with [Codeception/Verify](https://github.com/Codeception/Verify) library, to get BDD style assertions.
280+
* Use [Codeception/AssertThrows][5] for exception assertions
281+
* Use [Codeception/DomainAssert][6] for verbose domain logic assertions
282+
* Combine this with [Codeception/Verify][4] library, to get BDD style assertions.
283+
284+
License: [MIT.][7]
277285

278-
License: MIT
286+
[1]: https://phpunit.de/
287+
[2]: http://codeception.com/
288+
[3]: https://jasmine.github.io/
289+
[4]: https://github.com/Codeception/Verify
290+
[5]: https://github.com/Codeception/AssertThrows
291+
[6]: https://github.com/Codeception/DomainAssert
292+
[7]: /LICENSE

0 commit comments

Comments
 (0)