@@ -19,30 +19,36 @@ With [BDD][3] assertions influenced by [Chai][4], [Jasmine][5], and [RSpec][6] y
1919composer require codeception/verify --dev
2020```
2121
22+ > :arrow_up : ** Upgrade from 1.x by following [ the upgrade guide.] [ 9 ] **
23+
24+
2225## Usage
2326
2427Use 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
3035verify($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
4854verify($user->isAdmin())->true();
@@ -51,68 +57,71 @@ verify($user->invitedBy)->null();
5157verify($user->getPosts())->notNull();
5258
5359// empty
54- verify($user->getComments())->isEmpty ();
60+ verify($user->getComments())->empty ();
5561verify($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
0 commit comments