Skip to content

Commit ebf833c

Browse files
author
Gustavo Nieves
authored
Merge pull request #45 from Codeception/feat/full_phpunit_api
Support for full PHPUnit API. (42 new verifiers!)
2 parents ce6140c + a39c0dc commit ebf833c

11 files changed

Lines changed: 680 additions & 92 deletions

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ php:
44
- 7.1
55
- 7.2
66
- 7.3
7+
- 7.4
78

89
cache:
910
directories:

CHANGELOG.md

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

3+
## 1.5
4+
5+
* Support for full PHPUnit API `(42 new verifiers!)`
6+
* Updated `supported_verifiers.md` documentation.
7+
38
## 1.4
49

510
* Improved code quality and maintainability.

docs/supported_verifiers.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,29 @@
33
### Array
44
```
55
contains
6+
containsEquals
67
containsOnly
78
containsOnlyInstancesOf
89
count
910
hasKey
1011
hasNotKey
1112
notContains
13+
notContainsEquals
1214
notContainsOnly
1315
notCount
16+
notSameSize
17+
sameSize
1418
```
1519

20+
### Directory
21+
```
22+
directoryDoesNotExist
23+
directoryExists
24+
directoryIsNotReadable
25+
directoryIsNotWritable
26+
directoryIsReadable
27+
directoryIsWritable
28+
```
1629
### File
1730
```
1831
setIsFileExpectation
@@ -22,6 +35,16 @@ exists
2235
notExists
2336
equalsJsonFile
2437
equalsXmlFile
38+
fileEqualsCanonicalizing
39+
fileEqualsIgnoringCase
40+
fileIsNotReadable
41+
fileIsNotWritable
42+
fileIsReadable
43+
fileIsWritable
44+
fileNotEqualsCanonicalizing
45+
fileNotEqualsIgnoringCase
46+
jsonFileNotEqualsJsonFile
47+
jsonStringNotEqualsJsonFile
2548
```
2649

2750
### Mixed
@@ -31,19 +54,25 @@ equalsCanonicalizing
3154
equalsIgnoringCase
3255
equalsWithDelta
3356
false
57+
finite
3458
greaterThan
3559
greaterOrEquals
60+
infinite
3661
isInstanceOf
3762
array
3863
bool
3964
callable
65+
isClosedResource
4066
float
4167
int
68+
isIterable
4269
notArray
4370
notBool
4471
notCallable
72+
isNotClosedResource
4573
notFloat
4674
notInt
75+
isNotIterable
4776
notNumeric
4877
notObject
4978
notResource
@@ -56,26 +85,37 @@ scalar
5685
string
5786
lessThan
5887
lessOrEquals
88+
nan
5989
notEmpty
6090
notEqualsCanonicalizing
6191
notEqualsIgnoringCase
6292
notEqualsWithDelta
93+
notFalse
6394
isNotInstanceOf
6495
notNull
6596
notSame
97+
notTrue
6698
null
6799
same
100+
that
68101
true
69102
```
70103

71104
### String
72105
```
73106
hasStaticAttribute
74107
notHasStaticAttribute
108+
json
109+
jsonStringNotEqualsJsonString
110+
notRegExp
75111
equalsJsonString
76112
regExp
77113
stringContainsString
78114
stringContainsStringIgnoringCase
115+
stringEqualsFileCanonicalizing
116+
stringEqualsFileIgnoringCase
117+
stringNotEqualsFileCanonicalizing
118+
stringNotEqualsFileIgnoringCase
79119
notEndsWith
80120
endsWith
81121
equalsFile
@@ -90,11 +130,17 @@ startsWith
90130
notEqualsFile
91131
```
92132

93-
### Object/String
133+
### Union
134+
##### Object/String
94135
```
95136
hasAttribute
96137
notHasAttribute
97138
```
139+
##### File/Directory
140+
```
141+
isNotReadable
142+
isNotWritable
143+
```
98144

99145
### Throwable
100146
```
@@ -105,4 +151,7 @@ doesNotThrow
105151
### Xml
106152
```
107153
equalsXmlString
154+
xmlFileNotEqualsXmlFile
155+
xmlStringNotEqualsXmlFile
156+
xmlStringNotEqualsXmlString
108157
```

src/Codeception/Verify/Verifiers/VerifyArrayTrait.php

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
trait VerifyArrayTrait
1111
{
1212
/**
13-
* Asserts that a haystack contains a needle.
13+
* Verifies that a haystack contains a needle.
1414
*
1515
* @param $needle
1616
*/
@@ -23,13 +23,22 @@ public function contains($needle)
2323
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
2424
}
2525

26+
public function containsEquals($needle)
27+
{
28+
if(is_iterable($this->actual)) {
29+
TestCase::assertContainsEquals($needle, $this->actual, $this->message);
30+
return;
31+
}
32+
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
33+
}
34+
2635
/**
27-
* Asserts that a haystack contains only values of a given type.
36+
* Verifies that a haystack contains only values of a given type.
2837
*
2938
* @param string $type
3039
* @param bool|null $isNativeType
3140
*/
32-
public function containsOnly($type, $isNativeType = null)
41+
public function containsOnly(string $type, $isNativeType = null)
3342
{
3443
if(is_iterable($this->actual)) {
3544
TestCase::assertContainsOnly($type, $this->actual, $isNativeType, $this->message);
@@ -39,11 +48,11 @@ public function containsOnly($type, $isNativeType = null)
3948
}
4049

4150
/**
42-
* Asserts that a haystack contains only instances of a given class name.
51+
* Verifies that a haystack contains only instances of a given class name.
4352
*
4453
* @param string $className
4554
*/
46-
public function containsOnlyInstancesOf($className)
55+
public function containsOnlyInstancesOf(string $className)
4756
{
4857
if(is_iterable($this->actual)) {
4958
TestCase::assertContainsOnlyInstancesOf($className, $this->actual, $this->message);
@@ -53,11 +62,11 @@ public function containsOnlyInstancesOf($className)
5362
}
5463

5564
/**
56-
* Asserts the number of elements of an array, Countable or Traversable.
65+
* Verifies the number of elements of an array, Countable or Traversable.
5766
*
5867
* @param int $expectedCount
5968
*/
60-
public function count($expectedCount)
69+
public function count(int $expectedCount)
6170
{
6271
if(is_iterable($this->actual) || $this->actual instanceof Countable) {
6372
TestCase::assertCount($expectedCount, $this->actual, $this->message);
@@ -67,7 +76,7 @@ public function count($expectedCount)
6776
}
6877

6978
/**
70-
* Asserts that an array has a specified key.
79+
* Verifies that an array has a specified key.
7180
*
7281
* @param int|string $key
7382
*/
@@ -81,7 +90,7 @@ public function hasKey($key)
8190
}
8291

8392
/**
84-
* Asserts that an array does not have a specified key.
93+
* Verifies that an array does not have a specified key.
8594
*
8695
* @param int|string $key
8796
*/
@@ -94,9 +103,8 @@ public function hasNotKey($key)
94103
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
95104
}
96105

97-
98106
/**
99-
* Asserts that a haystack does not contain a needle.
107+
* Verifies that a haystack does not contain a needle.
100108
*
101109
* @param $needle
102110
*/
@@ -109,13 +117,22 @@ public function notContains($needle)
109117
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
110118
}
111119

120+
public function notContainsEquals($needle)
121+
{
122+
if (is_iterable($this->actual)) {
123+
TestCase::assertNotContainsEquals($needle, $this->actual, $this->message);
124+
return;
125+
}
126+
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
127+
}
128+
112129
/**
113-
* Asserts that a haystack does not contain only values of a given type.
130+
* Verifies that a haystack does not contain only values of a given type.
114131
*
115132
* @param string $type
116133
* @param bool|null $isNativeType
117134
*/
118-
public function notContainsOnly($type, $isNativeType = null)
135+
public function notContainsOnly(string $type, $isNativeType = null)
119136
{
120137
if(is_iterable($this->actual)) {
121138
TestCase::assertNotContainsOnly($type, $this->actual, $isNativeType, $this->message);
@@ -125,11 +142,11 @@ public function notContainsOnly($type, $isNativeType = null)
125142
}
126143

127144
/**
128-
* Asserts the number of elements of an array, Countable or Traversable.
145+
* Verifies the number of elements of an array, Countable or Traversable.
129146
*
130147
* @param int $expectedCount
131148
*/
132-
public function notCount($expectedCount)
149+
public function notCount(int $expectedCount)
133150
{
134151
if(is_iterable($this->actual) || $this->actual instanceof Countable) {
135152
TestCase::assertNotCount($expectedCount, $this->actual, $this->message);
@@ -138,4 +155,31 @@ public function notCount($expectedCount)
138155
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
139156
}
140157

158+
/**
159+
* Verifies that the size of two arrays (or `Countable` or `Traversable` objects) is not the same.
160+
*
161+
* @param Countable|iterable $expected
162+
*/
163+
public function notSameSize($expected)
164+
{
165+
if(is_iterable($this->actual) || $this->actual instanceof Countable) {
166+
TestCase::assertNotSameSize($expected, $this->actual, $this->message);
167+
return;
168+
}
169+
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
170+
}
171+
172+
/**
173+
* Verifies that the size of two arrays (or `Countable` or `Traversable` objects) is the same.
174+
*
175+
* @param Countable|iterable $expected
176+
*/
177+
public function sameSize($expected)
178+
{
179+
if(is_iterable($this->actual) || $this->actual instanceof Countable) {
180+
TestCase::assertSameSize($expected, $this->actual, $this->message);
181+
return;
182+
}
183+
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
184+
}
141185
}

0 commit comments

Comments
 (0)