Skip to content

Commit d35f10f

Browse files
committed
merged with master, removed PHPUnit 5.x support
2 parents 97022a4 + 8a17273 commit d35f10f

File tree

6 files changed

+59
-24
lines changed

6 files changed

+59
-24
lines changed

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-2015 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: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
Verify
22
======
33

4-
BDD Assertions for PHPUnit and Codeception
4+
BDD Assertions for [PHPUnit][1] and [Codeception][2]
55

66
This is very tiny wrapper for PHPUnit assertions, that are aimed to make tests a bit more readable.
7-
With BDD assertions influenced by Chai, Jasmine, and RSpec your assertions would be a bit closer to natural language.
7+
With [BDD][3] assertions influenced by [Chai][4], [Jasmine][5], and [RSpec][6] your assertions would be a bit closer to natural language.
88

99
[![Build Status](https://travis-ci.org/Codeception/Verify.png?branch=master)](https://travis-ci.org/Codeception/Verify) [![Latest Stable Version](https://poser.pugx.org/codeception/verify/v/stable.png)](https://packagist.org/packages/codeception/verify)
1010

11-
12-
``` php
13-
<?php
11+
```php
1412
$user = User::find(1);
1513

1614
// equal
@@ -33,7 +31,7 @@ verify($rate)->lessOrEquals(8);
3331
verify($rate)->greaterOrEquals(7);
3432
verify($rate)->greaterOrEquals(5);
3533

36-
// true/false/null
34+
// true / false / null
3735
verify($user->isAdmin())->true();
3836
verify($user->isBanned())->false();
3937
verify($user->invitedBy)->null();
@@ -42,42 +40,52 @@ verify($user->getPosts())->notNull();
4240
// empty
4341
verify($user->getComments())->isEmpty();
4442
verify($user->getRoles())->notEmpty();
45-
?>
4643
```
4744

4845
Shorthands for testing truth/fallacy:
4946

50-
``` php
51-
<?php
47+
```php
5248
verify_that($user->isActivated());
5349
verify_not($user->isBanned());
54-
?>
5550
```
5651

57-
This 2 functions doesn't check for strict true/false matching, rather `empty` function is used.
52+
These two functions don't check for strict true/false matching, rather `empty` function is used.
5853
`verify_that` checks that result is not empty value, `verify_not` does the opposite.
5954

6055
## Alternative Syntax
6156

62-
If you follow TDD/BDD you'd rather use `expect` instead of `verify`. Which is just an alias functions:
57+
If you follow TDD/BDD you'd rather use `expect` instead of `verify`. Which are just an alias functions:
6358

64-
``` php
59+
```php
6560
expect("user have 5 posts", $user->getNumPosts())->equals(5);
6661
expect_that($user->isActive());
6762
expect_not($user->isBanned());
6863
```
6964

70-
7165
## Installation
7266

73-
With Composer:
67+
### Installing via Composer
68+
69+
Install composer in a common location or in your project:
7470

71+
```sh
72+
curl -s http://getcomposer.org/installer | php
7573
```
74+
75+
Create the `composer.json` file as follows:
76+
77+
```json
7678
"require-dev": {
7779
"codeception/verify": "^1.0"
7880
}
7981
```
8082

83+
Run the composer installer:
84+
85+
```sh
86+
php composer.phar install
87+
```
88+
8189
## Usage
8290

8391
Use in any test `verify` function instead of `$this->assert*` methods.
@@ -106,5 +114,14 @@ Set the class name to `Codeception\Verify::override` property to `verify` functi
106114
verify('it works')->success();
107115
```
108116

117+
## License
118+
119+
Verify is open-sourced software licensed under the [MIT][7] License. © Codeception PHP Testing Framework
109120

110-
**License: MIT**
121+
[1]: https://phpunit.de/
122+
[2]: http://codeception.com/
123+
[3]: https://en.wikipedia.org/wiki/Behavior-driven_development
124+
[4]: http://chaijs.com/
125+
[5]: http://jasmine.github.io/
126+
[6]: http://rspec.info/
127+
[7]: https://github.com/Codeception/Verify/blob/master/LICENSE

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "codeception/verify",
33
"description": "BDD assertion library for PHPUnit",
4+
"license": "MIT",
45
"authors": [
56
{
67
"name": "Michael Bodnarchuk",

src/Codeception/Verify.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ public function setIsFileExpectation($isFileExpectation)
3333
$this->isFileExpectation = $isFileExpectation;
3434
}
3535

36-
public function equals($expected)
36+
public function equals($expected, $delta = 0)
3737
{
3838
if ( ! $this->isFileExpectation ) {
39-
a::assertEquals($expected, $this->actual, $this->description);
39+
a::assertEquals($expected, $this->actual, $this->description, $delta);
4040
} else {
4141
a::assertFileEquals($expected, $this->actual, $this->description);
4242
}
4343
}
4444

45-
public function notEquals($expected)
45+
public function notEquals($expected, $delta = 0)
4646
{
4747
if ( ! $this->isFileExpectation ) {
48-
a::assertNotEquals($expected, $this->actual, $this->description);
48+
a::assertNotEquals($expected, $this->actual, $this->description, $delta);
4949
} else {
5050
a::assertFileNotEquals($expected, $this->actual, $this->description);
5151
}
@@ -143,7 +143,7 @@ public function notInternalType($type)
143143

144144
public function hasAttribute($attribute)
145145
{
146-
if (is_string($attribute)) {
146+
if (is_string($this->actual)) {
147147
a::assertClassHasAttribute($attribute, $this->actual, $this->description);
148148
} else {
149149
a::assertObjectHasAttribute($attribute, $this->actual, $this->description);
@@ -152,7 +152,7 @@ public function hasAttribute($attribute)
152152

153153
public function notHasAttribute($attribute)
154154
{
155-
if (is_string($attribute)) {
155+
if (is_string($this->actual)) {
156156
a::assertClassNotHasAttribute($attribute, $this->actual, $this->description);
157157
} else {
158158
a::assertObjectNotHasAttribute($attribute, $this->actual, $this->description);

src/Codeception/function.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
if (!class_exists('PHPUnit_Framework_Assert') && class_exists('PHPUnit\Framework\Assert')) {
3+
class_alias('PHPUnit\Framework\Assert', 'PHPUnit_Framework_Assert');
4+
}
5+
26
if (!function_exists('verify')) {
37
/**
48
* @param $description

tests/VerifyTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,22 @@ protected function setUp()
1111
$this->xml = new DomDocument;
1212
$this->xml->loadXML('<foo><bar>Baz</bar><bar>Baz</bar></foo>');
1313
}
14+
1415
public function testEquals()
1516
{
1617
verify(5)->equals(5);
1718
verify("hello")->equals("hello");
1819
verify("user have 5 posts", 5)->equals(5);
19-
verify(3)->notEquals(5);
20+
verify(3.251)->equals(3.25, 0.01);
21+
verify("respects delta", 3.251)->equals(3.25, 0.01);
2022
verify_file(__FILE__)->equals(__FILE__);
23+
}
24+
25+
public function testNotEquals()
26+
{
27+
verify(3)->notEquals(5);
28+
verify(3.252)->notEquals(3.25, 0.001);
29+
verify("respects delta", 3.252, 0.001);
2130
verify_file(__FILE__)->notEquals(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'composer.json');
2231
}
2332

@@ -99,6 +108,10 @@ public function testHasAttribute()
99108
{
100109
expect('Exception')->hasAttribute('message');
101110
expect('Exception')->notHasAttribute('fakeproperty');
111+
112+
$testObject = (object) array('existingAttribute' => true);
113+
expect($testObject)->hasAttribute('existingAttribute');
114+
expect($testObject)->notHasAttribute('fakeproperty');
102115
}
103116

104117
public function testHasStaticAttribute()

0 commit comments

Comments
 (0)