@@ -21,98 +21,102 @@ composer require codeception/verify --dev
2121
2222## Usage
2323
24- Use in any test ` verify ` function instead of ` $this->assert* ` methods:
24+ Use in any test ` Verify ` function instead of ` $this->assert* ` methods:
2525
2626``` php
27+ use Codeception\Verify\Verify;
28+
2729$user = User::find(1);
2830
29- // equal
30- verify($user->getName())->equals('davert');
31- verify("user have 5 posts", $user->getNumPosts())->equals(5);
32- verify($user->getNumPosts())->notEquals(3);
31+ // equals
32+ Verify($user->getName())->equals('davert');
33+
34+ Verify($user->getNumPosts())
35+ ->equals(5, 'user have 5 posts')
36+ ->notEquals(3);
3337
3438// contains
35- verify('first user is admin', $user->getRoles())->contains('admin');
36- verify("first user is not banned", $user->getRoles())->notContains('banned');
39+ Verify::Array($user->getRoles())
40+ ->contains('admin', 'first user is admin')
41+ ->notContains('banned', 'first user is not banned');
3742
38- // greater / less
39- $rate = $user->getRate();
40- verify('first user rate is 7', $rate)->equals(7);
4143
42- verify($rate)->greaterThan(5);
43- verify($rate)->lessThan(10);
44- verify($rate)->lessOrEquals(7);
45- verify($rate)->greaterOrEquals(5);
44+ // greater / less
45+ Verify($user->getRate())
46+ ->greaterThan(5)
47+ ->lessThan(10)
48+ ->equals(7, 'first user rate is 7');
4649
4750// true / false / null
48- verify ($user->isAdmin())->true();
49- verify ($user->isBanned())->false();
50- verify ($user->invitedBy)->null();
51- verify ($user->getPosts())->notNull();
51+ Verify ($user->isAdmin())->true();
52+ Verify ($user->isBanned())->false();
53+ Verify ($user->invitedBy)->null();
54+ Verify ($user->getPosts())->notNull();
5255
5356// empty
54- verify ($user->getComments())->isEmpty ();
55- verify ($user->getRoles())->notEmpty();
57+ Verify ($user->getComments())->empty ();
58+ Verify ($user->getRoles())->notEmpty();
5659
5760// 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'));
61+ Verify::Callable($callback)
62+ ->throws()
63+ ->throws(Exception::class)
64+ ->throws(Exception::class, 'exception message')
65+ ->throws(new Exception())
66+ ->throws(new Exception('message'));
6367
6468// does not throw
65- verify($callback)->doesNotThrow();
66- verify($callback)->throws(Exception::class);
67- verify($callback)->doesNotThrow(new Exception());
69+ Verify::Callable($callback)
70+ ->doesNotThrow()
71+ ->throws(Exception::class)
72+ ->doesNotThrow(new Exception());
6873
6974// and many more !
7075```
7176
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.
77+ > :page_facing_up : ** See Verifiers full list [ here.] [ 7 ] **
8378
8479## Alternative Syntax
8580
86- If you follow TDD/BDD you'd rather use ` expect ` instead of ` verify ` . Which are just an alias functions :
81+ If you follow TDD/BDD you'd rather use ` Expect ` instead of ` Verify ` . Which are just an alias function :
8782
8883``` php
89- expect("user have 5 posts", $user->getNumPosts())->equals(5);
90- expect_that($user->isActive());
91- expect_not($user->isBanned());
84+ Expect($user->getNumPosts())->equals(5, 'user have 5 posts');
9285```
9386
9487## Extending
9588
96- In order to add more assertions you can override ` Codeception\ Verify` class :
89+ In order to add more assertions you can extend the abstract class ` Verify ` :
9790
9891``` php
99- class MyVerify extends \Codeception\Verify {
92+ use Codeception\Verify\Verify;
93+ use PHPUnit\Framework\Assert;
94+
95+ class MyVerify extends Verify {
96+
97+ //you can type $actual to only receive a specific data type
98+
99+ public function __construct($actual = null)
100+ {
101+ parent::__construct($actual);
102+ }
100103
101- public function success()
104+ public function success(string $message = '' )
102105 {
106+ Assert::assertTrue(true, $message);
103107 }
104108
105109}
106110```
107111
108- Set the class name to ` Codeception\Verify::$override ` property to ` verify ` function use it:
112+ And use it!
109113
110114``` php
115+ $myVerify = new MyVerify;
111116
112- \Codeception\Verify::$override = MyVerify::class ;
117+ $myVerify->success('it works!') ;
113118
114- // access overridden class
115- verify('it works')->success();
119+ $myVerify::Mixed('this also')->notEquals('works');
116120```
117121
118122## License
0 commit comments