Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for full PHPUnit API #45

Merged
1 commit merged into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4

cache:
directories:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.5

* Support for full PHPUnit API `(42 new verifiers!)`
* Updated `supported_verifiers.md` documentation.

## 1.4

* Improved code quality and maintainability.
Expand Down
51 changes: 50 additions & 1 deletion docs/supported_verifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,29 @@
### Array
```
contains
containsEquals
containsOnly
containsOnlyInstancesOf
count
hasKey
hasNotKey
notContains
notContainsEquals
notContainsOnly
notCount
notSameSize
sameSize
```

### Directory
```
directoryDoesNotExist
directoryExists
directoryIsNotReadable
directoryIsNotWritable
directoryIsReadable
directoryIsWritable
```
### File
```
setIsFileExpectation
Expand All @@ -22,6 +35,16 @@ exists
notExists
equalsJsonFile
equalsXmlFile
fileEqualsCanonicalizing
fileEqualsIgnoringCase
fileIsNotReadable
fileIsNotWritable
fileIsReadable
fileIsWritable
fileNotEqualsCanonicalizing
fileNotEqualsIgnoringCase
jsonFileNotEqualsJsonFile
jsonStringNotEqualsJsonFile
```

### Mixed
Expand All @@ -31,19 +54,25 @@ equalsCanonicalizing
equalsIgnoringCase
equalsWithDelta
false
finite
greaterThan
greaterOrEquals
infinite
isInstanceOf
array
bool
callable
isClosedResource
float
int
isIterable
notArray
notBool
notCallable
isNotClosedResource
notFloat
notInt
isNotIterable
notNumeric
notObject
notResource
Expand All @@ -56,26 +85,37 @@ scalar
string
lessThan
lessOrEquals
nan
notEmpty
notEqualsCanonicalizing
notEqualsIgnoringCase
notEqualsWithDelta
notFalse
isNotInstanceOf
notNull
notSame
notTrue
null
same
that
true
```

### String
```
hasStaticAttribute
notHasStaticAttribute
json
jsonStringNotEqualsJsonString
notRegExp
equalsJsonString
regExp
stringContainsString
stringContainsStringIgnoringCase
stringEqualsFileCanonicalizing
stringEqualsFileIgnoringCase
stringNotEqualsFileCanonicalizing
stringNotEqualsFileIgnoringCase
notEndsWith
endsWith
equalsFile
Expand All @@ -90,11 +130,17 @@ startsWith
notEqualsFile
```

### Object/String
### Union
##### Object/String
```
hasAttribute
notHasAttribute
```
##### File/Directory
```
isNotReadable
isNotWritable
```

### Throwable
```
Expand All @@ -105,4 +151,7 @@ doesNotThrow
### Xml
```
equalsXmlString
xmlFileNotEqualsXmlFile
xmlStringNotEqualsXmlFile
xmlStringNotEqualsXmlString
```
74 changes: 59 additions & 15 deletions src/Codeception/Verify/Verifiers/VerifyArrayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
trait VerifyArrayTrait
{
/**
* Asserts that a haystack contains a needle.
* Verifies that a haystack contains a needle.
*
* @param $needle
*/
Expand All @@ -23,13 +23,22 @@ public function contains($needle)
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
}

public function containsEquals($needle)
{
if(is_iterable($this->actual)) {
TestCase::assertContainsEquals($needle, $this->actual, $this->message);
return;
}
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
}

/**
* Asserts that a haystack contains only values of a given type.
* Verifies that a haystack contains only values of a given type.
*
* @param string $type
* @param bool|null $isNativeType
*/
public function containsOnly($type, $isNativeType = null)
public function containsOnly(string $type, $isNativeType = null)
{
if(is_iterable($this->actual)) {
TestCase::assertContainsOnly($type, $this->actual, $isNativeType, $this->message);
Expand All @@ -39,11 +48,11 @@ public function containsOnly($type, $isNativeType = null)
}

/**
* Asserts that a haystack contains only instances of a given class name.
* Verifies that a haystack contains only instances of a given class name.
*
* @param string $className
*/
public function containsOnlyInstancesOf($className)
public function containsOnlyInstancesOf(string $className)
{
if(is_iterable($this->actual)) {
TestCase::assertContainsOnlyInstancesOf($className, $this->actual, $this->message);
Expand All @@ -53,11 +62,11 @@ public function containsOnlyInstancesOf($className)
}

/**
* Asserts the number of elements of an array, Countable or Traversable.
* Verifies the number of elements of an array, Countable or Traversable.
*
* @param int $expectedCount
*/
public function count($expectedCount)
public function count(int $expectedCount)
{
if(is_iterable($this->actual) || $this->actual instanceof Countable) {
TestCase::assertCount($expectedCount, $this->actual, $this->message);
Expand All @@ -67,7 +76,7 @@ public function count($expectedCount)
}

/**
* Asserts that an array has a specified key.
* Verifies that an array has a specified key.
*
* @param int|string $key
*/
Expand All @@ -81,7 +90,7 @@ public function hasKey($key)
}

/**
* Asserts that an array does not have a specified key.
* Verifies that an array does not have a specified key.
*
* @param int|string $key
*/
Expand All @@ -94,9 +103,8 @@ public function hasNotKey($key)
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
}


/**
* Asserts that a haystack does not contain a needle.
* Verifies that a haystack does not contain a needle.
*
* @param $needle
*/
Expand All @@ -109,13 +117,22 @@ public function notContains($needle)
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
}

public function notContainsEquals($needle)
{
if (is_iterable($this->actual)) {
TestCase::assertNotContainsEquals($needle, $this->actual, $this->message);
return;
}
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
}

/**
* Asserts that a haystack does not contain only values of a given type.
* Verifies that a haystack does not contain only values of a given type.
*
* @param string $type
* @param bool|null $isNativeType
*/
public function notContainsOnly($type, $isNativeType = null)
public function notContainsOnly(string $type, $isNativeType = null)
{
if(is_iterable($this->actual)) {
TestCase::assertNotContainsOnly($type, $this->actual, $isNativeType, $this->message);
Expand All @@ -125,11 +142,11 @@ public function notContainsOnly($type, $isNativeType = null)
}

/**
* Asserts the number of elements of an array, Countable or Traversable.
* Verifies the number of elements of an array, Countable or Traversable.
*
* @param int $expectedCount
*/
public function notCount($expectedCount)
public function notCount(int $expectedCount)
{
if(is_iterable($this->actual) || $this->actual instanceof Countable) {
TestCase::assertNotCount($expectedCount, $this->actual, $this->message);
Expand All @@ -138,4 +155,31 @@ public function notCount($expectedCount)
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
}

/**
* Verifies that the size of two arrays (or `Countable` or `Traversable` objects) is not the same.
*
* @param Countable|iterable $expected
*/
public function notSameSize($expected)
{
if(is_iterable($this->actual) || $this->actual instanceof Countable) {
TestCase::assertNotSameSize($expected, $this->actual, $this->message);
return;
}
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
}

/**
* Verifies that the size of two arrays (or `Countable` or `Traversable` objects) is the same.
*
* @param Countable|iterable $expected
*/
public function sameSize($expected)
{
if(is_iterable($this->actual) || $this->actual instanceof Countable) {
TestCase::assertSameSize($expected, $this->actual, $this->message);
return;
}
throw new InvalidVerifyException(__FUNCTION__, $this->actual);
}
}
Loading