Skip to content

Commit 252fe61

Browse files
author
Gustavo Nieves
authored
Verify 2.0.0-rc1
Verify 2.0.0 Release Candidate 1
2 parents ebf833c + b880ef3 commit 252fe61

36 files changed

Lines changed: 2902 additions & 1943 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
vendor
22
.idea
33
.phpunit.result.cache
4+
composer.lock
45
composer.phar

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
language: php
22

33
php:
4-
- 7.1
5-
- 7.2
64
- 7.3
75
- 7.4
86

CHANGELOG.md

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

3+
## 2.0
4+
5+
* Support for Chained Verifiers.
6+
* The Verify API is now fully based on the PHPUnit public API.
7+
* Improved IDE autocompletion depending on the type of data you want to verify
8+
* Simplified data validations.
9+
* Improved code quality, performance and maintainability.
10+
* See **BC** details in the UPGRADE.md file.
11+
312
## 1.5
413

514
* Support for full PHPUnit API `(42 new verifiers!)`

README.md

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,36 @@ With [BDD][3] assertions influenced by [Chai][4], [Jasmine][5], and [RSpec][6] y
1919
composer require codeception/verify --dev
2020
```
2121

22+
> :arrow_up: **Upgrade from 1.x by following [the upgrade guide.][9]**
23+
24+
2225
## Usage
2326

2427
Use in any test `verify` function instead of `$this->assert*` methods:
2528

2629
```php
30+
use Codeception\Verify\Verify;
31+
2732
$user = User::find(1);
2833

29-
// equal
34+
// equals
3035
verify($user->getName())->equals('davert');
31-
verify("user have 5 posts", $user->getNumPosts())->equals(5);
32-
verify($user->getNumPosts())->notEquals(3);
36+
37+
verify($user->getNumPosts())
38+
->equals(5, 'user have 5 posts')
39+
->notEquals(3);
3340

3441
// contains
35-
verify('first user is admin', $user->getRoles())->contains('admin');
36-
verify("first user is not banned", $user->getRoles())->notContains('banned');
42+
Verify::Array($user->getRoles())
43+
->contains('admin', 'first user is admin')
44+
->notContains('banned', 'first user is not banned');
3745

38-
// greater / less
39-
$rate = $user->getRate();
40-
verify('first user rate is 7', $rate)->equals(7);
4146

42-
verify($rate)->greaterThan(5);
43-
verify($rate)->lessThan(10);
44-
verify($rate)->lessOrEquals(7);
45-
verify($rate)->greaterOrEquals(5);
47+
// greater / less
48+
verify($user->getRate())
49+
->greaterThan(5)
50+
->lessThan(10)
51+
->equals(7, 'first user rate is 7');
4652

4753
// true / false / null
4854
verify($user->isAdmin())->true();
@@ -51,68 +57,71 @@ verify($user->invitedBy)->null();
5157
verify($user->getPosts())->notNull();
5258

5359
// empty
54-
verify($user->getComments())->isEmpty();
60+
verify($user->getComments())->empty();
5561
verify($user->getRoles())->notEmpty();
5662

5763
// throws
58-
verify($callback)->throws();
59-
verify($callback)->throws(Exception::class);
60-
verify($callback)->throws(Exception::class, 'exception message');
61-
verify($callback)->throws(new Exception());
62-
verify($callback)->throws(new Exception('message'));
64+
Verify::Callable($callback)
65+
->throws()
66+
->throws(Exception::class)
67+
->throws(Exception::class, 'exception message')
68+
->throws(new Exception())
69+
->throws(new Exception('message'));
6370

6471
// does not throw
65-
verify($callback)->doesNotThrow();
66-
verify($callback)->throws(Exception::class);
67-
verify($callback)->doesNotThrow(new Exception());
72+
Verify::Callable($callback)
73+
->doesNotThrow()
74+
->throws(Exception::class)
75+
->doesNotThrow(new Exception());
6876

6977
// and many more !
7078
```
7179

72-
> ##### :page_facing_up: See Verifiers full list [here.][7]
73-
74-
Shorthands for testing truth/fallacy:
75-
76-
```php
77-
verify_that($user->isActivated());
78-
verify_not($user->isBanned());
79-
```
80-
81-
These two functions don't check for strict true/false matching, rather `empty` function is used.
82-
`verify_that` checks that result is not empty value, `verify_not` does the opposite.
80+
> :page_facing_up: **See Verifiers full list [here.][7]**
8381
8482
## Alternative Syntax
8583

86-
If you follow TDD/BDD you'd rather use `expect` instead of `verify`. Which are just an alias functions:
84+
If you follow TDD/BDD you'd rather use `expect` or `verify_that` instead of `verify`. Which are just an alias function:
8785

8886
```php
89-
expect("user have 5 posts", $user->getNumPosts())->equals(5);
90-
expect_that($user->isActive());
91-
expect_not($user->isBanned());
87+
expect($user->getNumPosts())->equals(5, 'user have 5 posts');
88+
89+
verify_that($user->getRate())->equals(7, 'first user rate is 7');
9290
```
9391

9492
## Extending
9593

96-
In order to add more assertions you can override `Codeception\Verify` class:
94+
In order to add more assertions you can extend the abstract class `Verify`:
9795

9896
```php
99-
class MyVerify extends \Codeception\Verify {
97+
use Codeception\Verify\Verify;
98+
use PHPUnit\Framework\Assert;
99+
100+
class MyVerify extends Verify {
101+
102+
//you can type $actual to only receive a specific data type
103+
104+
public function __construct($actual = null)
105+
{
106+
parent::__construct($actual);
107+
}
100108

101-
public function success()
109+
public function success(string $message = '')
102110
{
111+
Assert::assertTrue(true, $message);
103112
}
104113

105114
}
106115
```
107116

108-
Set the class name to `Codeception\Verify::$override` property to `verify` function use it:
117+
And use it!
109118

110119
```php
120+
$myVerify = new MyVerify;
111121

112-
\Codeception\Verify::$override = MyVerify::class;
122+
$myVerify->success('it works!');
113123

114-
// access overridden class
115-
verify('it works')->success();
124+
$myVerify::Mixed('this also')->notEquals('works');
116125
```
117126

118127
## License
@@ -128,3 +137,4 @@ Verify is open-sourced software licensed under the [MIT][8] License.
128137
[6]: http://rspec.info/
129138
[7]: /docs/supported_verifiers.md
130139
[8]: /LICENSE
140+
[9]: /UPGRADE.md

UPGRADE.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
UPGRADE FROM 1.X TO 2.X
2+
=======================
3+
4+
5+
PHP version
6+
------
7+
8+
* Removed support for `PHP 7.1` & `PHP 7.2`.
9+
10+
11+
Verify function
12+
-------
13+
14+
In version `2.x`, `verifiers` can be used as classes. Each verifier class handles a specific type of data.
15+
16+
Thanks to this you can enjoy an autocompletion of your `IDE` much more intelligent than before...
17+
18+
That is why **we remove some global functions** that have a less intuitive behavior.
19+
20+
According to the above:
21+
22+
* `verify` no longer receives a `string $message` as a parameter, now each _**verifier**_ fulfills this function.
23+
* `verify_not` was deleted. Use `verify()->empty` instead.
24+
* `expect_that` and `expect_not` were deleted. Use `expect()->notEmpty` and `expect()->empty` instead.
25+
* `expect_file` and `setIsFileExpectation` were deleted. Use `Verify::File()` instead.
26+
27+
Verifiers
28+
-------
29+
30+
| Verify 1.x | Verify 2.x |
31+
|-------------------------------------------------|-------------------------------------------------|
32+
| `verify()->array` | `verify()->isArray` |
33+
| `verify()->bool` | `verify()->isBool` |
34+
| `verify()->callable` | `verify()->isCallable` |
35+
| `verify()->float` | `verify()->isFloat` |
36+
| `verify()->greaterOrEquals` | `verify()->greaterThanOrEqual` |
37+
| `verify()->int` | `verify()->isInt` |
38+
| `verify()->isEmpty` | `verify()->empty` |
39+
| `verify()->isInstanceOf` | `verify()->instanceOf` |
40+
| `verify()->isNotInstanceOf` | `verify()->notInstanceOf` |
41+
| `verify()->lessOrEquals` | `verify()->lessThanOrEqual` |
42+
| `verify()->notArray` | `verify()->isNotArray` |
43+
| `verify()->notBool` | `verify()->isNotBool` |
44+
| `verify()->notCallable` | `verify()->isNotCallable` |
45+
| `verify()->notFloat` | `verify()->isNotFloat` |
46+
| `verify()->notInt` | `verify()->isNotInt` |
47+
| `verify()->notNumeric` | `verify()->isNotNumeric` |
48+
| `verify()->notObject` | `verify()->isNotObject` |
49+
| `verify()->notResource` | `verify()->isNotResource` |
50+
| `verify()->notScalar` | `verify()->isNotScalar` |
51+
| `verify()->notString` | `verify()->isNotString` |
52+
| `verify()->numeric` | `verify()->isNumeric` |
53+
| `verify()->object` | `verify()->isObject` |
54+
| `verify()->resource` | `verify()->isResource` |
55+
| `verify()->scalar` | `verify()->isScalar` |
56+
| `verify()->string` | `verify()->isString` |
57+
| `verify()->hasAttribute` | `Verify()->baseObjectHasAttribute` |
58+
| `verify()->notHasAttribute` | `Verify()->baseObjectNotHasAttribute` |
59+
| `verify()->throws` | `Verify()->callableThrows` |
60+
| `verify()->doesNotThrow` | `Verify()->callableDoesNotThrow` |
61+
| `verify()->hasStaticAttribute` | `Verify()->classHasStaticAttribute` |
62+
| `verify()->notHasStaticAttribute` | `Verify()->classNotHasStaticAttribute` |
63+
| `verify()->hasAttribute` | `Verify()->classHasAttribute` |
64+
| `verify()->notHasAttribute` | `Verify()->classNotHasAttribute` |
65+
| `verify()->notExists` | `Verify()->fileDoesNotExists` |
66+
| `verify()->regExp` | `Verify()->stringMatchesRegExp` |
67+
| `verify()->notRegExp` | `Verify()->stringDoesNotMatchRegExp` |
68+
| `verify()->notStartsWith` | `Verify()->stringNotStartsWith` |
69+
70+
71+
Extending
72+
-------
73+
74+
* `Codeception\Verify::$override` was removed, extend from abstract `Codeception\Verify\Verify` class instead.

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">= 7.1",
16+
"php": "^7.3",
1717
"ext-dom": "*",
18-
"phpunit/phpunit": ">= 7.0",
19-
"codeception/phpunit-wrapper": "^7.8.0 | ^8.1.2 | ^9.0.2"
18+
"phpunit/phpunit": "^9.3"
2019
},
2120
"autoload": {
22-
"files": ["src/Codeception/function.php"],
23-
"psr-4":{
21+
"files": [
22+
"src/Codeception/bootstrap.php"
23+
],
24+
"psr-4": {
2425
"Codeception\\": "src\\Codeception"
2526
}
2627
}

0 commit comments

Comments
 (0)