first commit

This commit is contained in:
2026-01-25 18:18:09 +08:00
commit 509312e604
8136 changed files with 2349298 additions and 0 deletions

View File

@ -0,0 +1,29 @@
name: CI
on: [push, pull_request]
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
php: [8.0, 8.1, 8.2]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Validate composer.json
run: composer validate
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction --no-suggest
- name: Run test suite
run: php vendor/bin/phpunit

5
vendor/codeception/verify/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
vendor
.idea
.phpunit.result.cache
composer.lock
composer.phar

36
vendor/codeception/verify/CHANGELOG.md vendored Normal file
View File

@ -0,0 +1,36 @@
# Changelog
## 2.1
* Added new expect-toBe and expect-notTo BDD Syntax.
* Added full documentation about Expectations.
* Fixed minor bugs.
* Deleted RoboFile and VERSION file.
* **BC:** `expect` function now works with expectations instead of verifiers.
## 2.0
* Support for Chained Verifiers.
* The Verify API is now fully based on the PHPUnit public API.
* Improved IDE autocompletion depending on the type of data you want to verify
* Simplified data validations.
* Improved code quality, performance and maintainability.
* See **BC** details in the UPGRADE.md file.
## 1.5
* Support for full PHPUnit API `(42 new verifiers!)`
* Updated `supported_verifiers.md` documentation.
## 1.4
* Improved code quality and maintainability.
* Used strict types and namespaces.
Created exception `InvalidVerifyException.php` in case verify is used with some invalid data.
* Added documentation for all verifiers.
* Divided the verifiers into traits depending on the type of data they verify.
* Added data validations with php issers functions and instanceof.
* **BC:** `equalXMLStructure` and its corresponding test were removed.
* **BC:** hasntKey verifier renamed to hasNotKey for clarity.
* **BC:** Removed support for PHP 7.0 and its corresponding versions of `PHPUnit` and `phpunit-wrapper`.

20
vendor/codeception/verify/LICENSE vendored Normal file
View File

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013-2020 Codeception PHP Testing Framework
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

153
vendor/codeception/verify/README.md vendored Normal file
View File

@ -0,0 +1,153 @@
Verify
======
BDD Assertions for [PHPUnit][1] or [Codeception][2]
[![Latest Stable Version](https://poser.pugx.org/codeception/verify/v/stable)](https://packagist.org/packages/codeception/verify)
[![Total Downloads](https://poser.pugx.org/codeception/verify/downloads)](https://packagist.org/packages/codeception/verify)
[![Build Status](https://travis-ci.org/Codeception/Verify.png?branch=master)](https://travis-ci.org/Codeception/Verify)
[![License](https://poser.pugx.org/codeception/specify/license)](https://packagist.org/packages/codeception/verify)
[![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
This is very tiny wrapper for PHPUnit assertions, that are aimed to make tests a bit more readable.
With [BDD][3] assertions influenced by [Chai][4], [Jasmine][5], and [RSpec][6] your assertions would be a bit closer to natural language.
⚠️ This is the Verify 2.0 documentation, to see v1.x docs click [here.](https://github.com/Codeception/Verify/tree/1.x)
## Installation
*Requires PHP 7.4 or higher*
```
composer require codeception/verify --dev
```
> :arrow_up: **Upgrade from 1.x by following [the upgrade guide.][10]**
## Usage
Use in any test `verify` function instead of `$this->assert*` methods:
```php
use Codeception\Verify\Verify;
$user = User::find(1);
// equals
verify($user->getName())->equals('davert');
verify($user->getNumPosts())
->equals(5, 'user have 5 posts')
->notEquals(3);
// contains
Verify::Array($user->getRoles())
->contains('admin', 'first user is admin')
->notContains('banned', 'first user is not banned');
// greater / less
verify($user->getRate())
->greaterThan(5)
->lessThan(10)
->equals(7, 'first user rate is 7');
// true / false / null
verify($user->isAdmin())->true();
verify($user->isBanned())->false();
verify($user->invitedBy)->null();
verify($user->getPosts())->notNull();
// empty
verify($user->getComments())->empty();
verify($user->getRoles())->notEmpty();
// throws
Verify::Callable($callback)
->throws()
->throws(Exception::class)
->throws(Exception::class, 'exception message')
->throws(new Exception())
->throws(new Exception('message'));
// does not throw
Verify::Callable($callback)
->doesNotThrow()
->throws(Exception::class)
->doesNotThrow(new Exception());
// and many more !
```
> :page_facing_up: **See Verifiers full list [here.][7]**
## Alternative Syntax
If you follow TDD/BDD you'd rather use `expect` instead of `verify`:
```php
expect($user->getNumPosts())
->notToBeNull()
->toBeInt()
->toEqual(5, 'user have 5 posts');
```
> :page_facing_up: **See Expectations full list [here.][8]**
>
Or `verify_that` which is just an alias function:
```php
verify_that($user->getRate())->equals(7, 'first user rate is 7');
```
## Extending
In order to add more assertions you can extend the abstract class `Verify`:
```php
use Codeception\Verify\Verify;
use PHPUnit\Framework\Assert;
class MyVerify extends Verify {
//you can type $actual to only receive a specific data type
public function __construct($actual = null)
{
parent::__construct($actual);
}
public function success(string $message = '')
{
Assert::assertTrue(true, $message);
}
}
```
And use it!
```php
$myVerify = new MyVerify;
$myVerify->success('it works!');
$myVerify::Mixed('this also')->notEquals('works');
```
## License
Verify is open-sourced software licensed under the [MIT][9] License.
© Codeception PHP Testing Framework
[1]: https://phpunit.de/
[2]: https://codeception.com/
[3]: https://en.wikipedia.org/wiki/Behavior-driven_development
[4]: https://chaijs.com/
[5]: https://jasmine.github.io/
[6]: https://rspec.info/
[7]: ./docs/supported_verifiers.md
[8]: ./docs/supported_expectations.md
[9]: ./LICENSE
[10]: ./UPGRADE.md

74
vendor/codeception/verify/UPGRADE.md vendored Normal file
View File

@ -0,0 +1,74 @@
UPGRADE FROM 1.X TO 2.X
=======================
PHP version
------
* Removed support for `PHP 7.1` & `PHP 7.2`.
Verify function
-------
In version `2.x`, `verifiers` can be used as classes. Each verifier class handles a specific type of data.
Thanks to this you can enjoy an autocompletion of your `IDE` much more intelligent than before...
That is why **we remove some global functions** that have a less intuitive behavior.
According to the above:
* `verify` no longer receives a `string $message` as a parameter, now each _**verifier**_ fulfills this function.
* `verify_not` was deleted. Use `verify()->empty` instead.
* `expect_that` and `expect_not` were deleted. Use `expect()->notEmpty` and `expect()->empty` instead.
* `expect_file` and `setIsFileExpectation` were deleted. Use `Verify::File()` instead.
Verifiers
-------
| Verify 1.x | Verify 2.x |
|-------------------------------------------------|-------------------------------------------------|
| `verify()->array` | `verify()->isArray` |
| `verify()->bool` | `verify()->isBool` |
| `verify()->callable` | `verify()->isCallable` |
| `verify()->float` | `verify()->isFloat` |
| `verify()->greaterOrEquals` | `verify()->greaterThanOrEqual` |
| `verify()->int` | `verify()->isInt` |
| `verify()->isEmpty` | `verify()->empty` |
| `verify()->isInstanceOf` | `verify()->instanceOf` |
| `verify()->isNotInstanceOf` | `verify()->notInstanceOf` |
| `verify()->lessOrEquals` | `verify()->lessThanOrEqual` |
| `verify()->notArray` | `verify()->isNotArray` |
| `verify()->notBool` | `verify()->isNotBool` |
| `verify()->notCallable` | `verify()->isNotCallable` |
| `verify()->notFloat` | `verify()->isNotFloat` |
| `verify()->notInt` | `verify()->isNotInt` |
| `verify()->notNumeric` | `verify()->isNotNumeric` |
| `verify()->notObject` | `verify()->isNotObject` |
| `verify()->notResource` | `verify()->isNotResource` |
| `verify()->notScalar` | `verify()->isNotScalar` |
| `verify()->notString` | `verify()->isNotString` |
| `verify()->numeric` | `verify()->isNumeric` |
| `verify()->object` | `verify()->isObject` |
| `verify()->resource` | `verify()->isResource` |
| `verify()->scalar` | `verify()->isScalar` |
| `verify()->string` | `verify()->isString` |
| `verify()->hasAttribute` | `Verify()->baseObjectHasAttribute` |
| `verify()->notHasAttribute` | `Verify()->baseObjectNotHasAttribute` |
| `verify()->throws` | `Verify()->callableThrows` |
| `verify()->doesNotThrow` | `Verify()->callableDoesNotThrow` |
| `verify()->hasStaticAttribute` | `Verify()->classHasStaticAttribute` |
| `verify()->notHasStaticAttribute` | `Verify()->classNotHasStaticAttribute` |
| `verify()->hasAttribute` | `Verify()->classHasAttribute` |
| `verify()->notHasAttribute` | `Verify()->classNotHasAttribute` |
| `verify()->notExists` | `Verify()->fileDoesNotExists` |
| `verify()->regExp` | `Verify()->stringMatchesRegExp` |
| `verify()->notRegExp` | `Verify()->stringDoesNotMatchRegExp` |
| `verify()->notStartsWith` | `Verify()->stringNotStartsWith` |
Extending
-------
* `Codeception\Verify::$override` was removed, extend from abstract `Codeception\Verify\Verify` class instead.

29
vendor/codeception/verify/composer.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"name": "codeception/verify",
"description": "BDD assertion library for PHPUnit",
"license": "MIT",
"authors": [
{
"name": "Michael Bodnarchuk",
"email": "davert@codeception.com"
},
{
"name": "Gustavo Nieves",
"homepage": "https://medium.com/@ganieves"
}
],
"minimum-stability": "RC",
"require": {
"php": "^7.4 || ^8.0",
"ext-dom": "*",
"phpunit/phpunit": "^9.6.11 || ^10.0 || ^11.0 || ^12.0"
},
"autoload": {
"files": [
"src/Codeception/bootstrap.php"
],
"psr-4": {
"Codeception\\": "src\\Codeception"
}
}
}

View File

@ -0,0 +1,182 @@
## Expectations List
`expect()` supports all the expectations listed here! :rocket:
### Array
```
notToContain
notToContainEqual
notToContainOnly
notToHaveCount
notToHaveKey
notToHaveSameSizeAs
toContain
toContainEqual
toContainOnly
toContainOnlyInstancesOf
toHaveCount
toHaveKey
toHaveSameSizeAs
```
### BaseObject
```
notToHaveProperty
toHaveProperty
```
### Callable
```
notToThrow
toThrow
```
### Class
```
notToHaveAttribute
notToHaveStaticAttribute
toHaveAttribute
toHaveStaticAttribute
```
### Directory
```
notToBeReadable
notToBeWritable
notToExist
toBeReadable
toBeWritable
toExist
toExistAndNotToBeReadable
toExistAndNotToBeWritable
toExistAndToBeReadable
toExistAndToBeWritable
```
### File
```
notToBeReadable
notToBeWritable
notToExist
toBeEqual
toBeEqualCanonicalizing
toBeEqualIgnoringCase
toBeReadable
toBeWritable
toExist
toExistAndNotToBeReadable
toExistAndNotToBeWritable
toExistAndToBeReadable
toExistAndToBeWritable
toNotEqual
toNotEqualCanonicalizing
toNotEqualIgnoringCase
```
### JsonFile
```
notToEqualJsonFile
toEqualJsonFile
```
### JsonString
```
notToEqualJsonFile
notToEqualJsonString
toEqualJsonFile
toEqualJsonString
```
### Mixed
```
notToBe
notToBeArray
notToBeBool
notToBeCallable
notToBeClosedResource
notToBeEmpty
notToBeFalse
notToBeFloat
notToBeInstanceOf
notToBeInt
notToBeIterable
notToBeNull
notToBeNumeric
notToBeObject
notToBeResource
notToBeScalar
notToBeString
notToBeTrue
notToEqual
notToEqualCanonicalizing
notToEqualIgnoringCase
notToEqualWithDelta
toBe
toBeArray
toBeBool
toBeCallable
toBeClosedResource
toBeEmpty
toBeFalse
toBeFinite
toBeFloat
toBeGreaterThan
toBeGreaterThanOrEqualTo
toBeInfinite
toBeInstanceOf
toBeInt
toBeIterable
toBeLessThan
toBeLessThanOrEqualTo
toBeNan
toBeNull
toBeNumeric
toBeObject
toBeResource
toBeScalar
toBeString
toBeTrue
toEqual
toEqualCanonicalizing
toEqualIgnoringCase
toEqualWithDelta
```
### String
```
notToContainString
notToContainStringIgnoringCase
notToEndWith
notToEqualFile
notToEqualFileCanonicalizing
notToEqualFileIgnoringCase
notToMatchFormat
notToMatchFormatFile
notToMatchRegExp
notToStartWith
toBeJson
toContainString
toContainStringIgnoringCase
toEndWith
toEqualFile
toEqualFileCanonicalizing
toEqualFileIgnoringCase
toMatchFormat
toMatchFormatFile
toMatchRegExp
toStartWith
```
### XmlFile
```
notToEqualXmlFile
toEqualXmlFile
```
### XmlString
```
notToEqualXmlFile
notToEqualXmlString
toEqualXmlFile
toEqualXmlString
```

View File

@ -0,0 +1,182 @@
## Verifiers List
`verify()` supports all the verifiers listed here! :rocket:
### Array
```
contains
containsEquals
containsOnly
containsOnlyInstancesOf
count
hasKey
hasNotKey
notContains
notContainsEquals
notContainsOnly
notCount
notSameSize
sameSize
```
### BaseObject
```
hasProperty
notHasProperty
```
### Callable
```
throws
doesNotThrow
```
### Class
```
hasAttribute
hasStaticAttribute
notHasAttribute
notHasStaticAttribute
```
### Directory
```
doesNotExist
exists
existsAndIsNotReadable
existsAndIsNotWritable
existsAndIsReadable
existsAndIsWritable
isNotReadable
isNotWritable
isReadable
isWritable
```
### File
```
doesNotExists
equals
equalsCanonicalizing
equalsIgnoringCase
exists
existsAndIsNotReadable
existsAndIsNotWritable
existsAndIsReadable
existsAndIsWritable
isNotReadable
isNotWritable
isReadable
isWritable
notEquals
notEqualsCanonicalizing
notEqualsIgnoringCase
```
### JsonFile
```
equalsJsonFile
notEqualsJsonFile
```
### JsonString
```
equalsJsonFile
equalsJsonString
notEqualsJsonFile
notEqualsJsonString
```
### Mixed
```
empty
equals
equalsCanonicalizing
equalsIgnoringCase
equalsWithDelta
false
finite
greaterThan
greaterThanOrEqual
infinite
instanceOf
isArray
isBool
isCallable
isClosedResource
isFloat
isInt
isIterable
isNotArray
isNotBool
isNotCallable
isNotClosedResource
isNotFloat
isNotInt
isNotIterable
isNotNumeric
isNotObject
isNotResource
isNotScalar
isNotString
isNumeric
isObject
isResource
isScalar
isString
lessThan
lessThanOrEqual
nan
notEmpty
notEquals
notEqualsCanonicalizing
notEqualsIgnoringCase
notEqualsWithDelta
notFalse
notInstanceOf
notNull
notSame
notTrue
null
same
true
```
### String
```
containsString
containsStringIgnoringCase
doesNotMatchRegExp
endsWith
equalsFile
equalsFileCanonicalizing
equalsFileIgnoringCase
json
matchesFormat
matchesFormatFile
matchesRegExp
notContainsString
notContainsStringIgnoringCase
notEndsWith
notEqualsFile
notEqualsFileCanonicalizing
notEqualsFileIgnoringCase
notMatchesFormat
notMatchesFormatFile
startsNotWith
startsWith
```
### XmlFile
```
equalsXmlFile
notEqualsXmlFile
```
### XmlString
```
equalsXmlFile
equalsXmlString
notEqualsXmlFile
notEqualsXmlString
```

7
vendor/codeception/verify/phpunit.xml vendored Normal file
View File

@ -0,0 +1,7 @@
<phpunit colors="true">
<testsuites>
<testsuite name="Verify">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Codeception\Exception;
use InvalidArgumentException;
use function gettype;
use function sprintf;
final class InvalidVerifyException extends InvalidArgumentException
{
public function __construct($verifyName, $actual)
{
$message = sprintf(
"%s type cannot be used with %s verify.",
gettype($actual),
$verifyName
);
parent::__construct($message);
}
}

View File

@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Asserts;
use Exception;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\ExpectationFailedException;
use Throwable;
trait AssertThrows
{
public function assertThrows($throws = null, $message = false): self
{
if ($throws instanceof Exception) {
$message = $throws->getMessage();
$throws = get_class($throws);
}
try {
call_user_func($this->actual);
} catch (Throwable $throwable) {
if (!$throws) {
return $this; // it throws
}
$actualThrows = get_class($throwable);
$actualMessage = $throwable->getMessage();
Assert::assertSame($throws, $actualThrows, sprintf("exception '%s' was expected, but '%s' was thrown", $throws, $actualThrows));
if ($message) {
Assert::assertSame($message, $actualMessage, sprintf("exception message '%s' was expected, but '%s' was received", $message, $actualMessage));
}
}
if (!isset($throwable)) {
throw new ExpectationFailedException(sprintf("exception '%s' was not thrown as expected", $throws));
}
return $this;
}
public function assertDoesNotThrow($throws = null, $message = false): self
{
if ($throws instanceof Exception) {
$message = $throws->getMessage();
$throws = get_class($throws);
}
try {
call_user_func($this->actual);
} catch (Throwable $exception) {
if (!$throws) {
throw new ExpectationFailedException('exception was not expected to be thrown');
}
$actualThrows = get_class($exception);
$actualMessage = $exception->getMessage();
if ($throws !== $actualThrows) {
return $this;
}
if (!$message) {
throw new ExpectationFailedException(sprintf("exception '%s' was not expected to be thrown", $throws));
}
if ($message === $actualMessage) {
throw new ExpectationFailedException(sprintf("exception '%s' with message '%s' was not expected to be thrown", $throws, $message));
}
}
return $this;
}
}

View File

@ -0,0 +1,112 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify;
use ArrayAccess;
use Codeception\Verify\Expectations\ExpectArray;
use Codeception\Verify\Expectations\ExpectBaseObject;
use Codeception\Verify\Expectations\ExpectCallable;
use Codeception\Verify\Expectations\ExpectClass;
use Codeception\Verify\Expectations\ExpectDirectory;
use Codeception\Verify\Expectations\ExpectFile;
use Codeception\Verify\Expectations\ExpectJsonFile;
use Codeception\Verify\Expectations\ExpectJsonString;
use Codeception\Verify\Expectations\ExpectString;
use Codeception\Verify\Expectations\ExpectXmlFile;
use Codeception\Verify\Expectations\ExpectXmlString;
use Countable;
abstract class Expect
{
/** @var mixed */
protected $actual = null;
/**
* Expect constructor
*
* @param mixed $actual
*/
protected function __construct($actual)
{
$this->actual = $actual;
}
/**
* @param mixed $actual
* @return self
*/
public function __invoke($actual): self
{
return $this($actual);
}
public static function File(string $filename): ExpectFile
{
return new ExpectFile($filename);
}
public static function JsonFile(string $filename): ExpectJsonFile
{
return new ExpectJsonFile($filename);
}
public static function JsonString(string $json): ExpectJsonString
{
return new ExpectJsonString($json);
}
public static function XmlFile(string $filename): ExpectXmlFile
{
return new ExpectXmlFile($filename);
}
public static function XmlString(string $xml): ExpectXmlString
{
return new ExpectXmlString($xml);
}
public static function BaseObject(object $object): ExpectBaseObject
{
return new ExpectBaseObject($object);
}
public static function Class(string $className): ExpectClass
{
return new ExpectClass($className);
}
public static function Directory(string $directory): ExpectDirectory
{
return new ExpectDirectory($directory);
}
/**
* @param array|ArrayAccess|Countable|iterable $array
* @return ExpectArray
*/
public static function Array($array): ExpectArray
{
return new ExpectArray($array);
}
public static function String(string $string): ExpectString
{
return new ExpectString($string);
}
public static function Callable(callable $callable): ExpectCallable
{
return new ExpectCallable($callable);
}
/**
* @param mixed $actual
* @return ExpectCallable
*/
public static function Mixed($actual): ExpectCallable
{
return new ExpectCallable($actual);
}
}

View File

@ -0,0 +1,454 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Verify\Expect;
class ExpectAny extends ExpectMixed
{
public function arrayToContain($needle, string $message = ''): self
{
Expect::Array($this->actual)->toContain($needle, $message);
return $this;
}
public function arrayToContainEqual($needle, string $message = ''): self
{
Expect::Array($this->actual)->toContainEqual($needle, $message);
return $this;
}
public function arrayToContainOnly(string $type, ?bool $isNativeType = null, string $message = ''): self
{
Expect::Array($this->actual)->toContainOnly($type, $isNativeType, $message);
return $this;
}
public function arrayToContainOnlyInstancesOf(string $className, string $message = ''): self
{
Expect::Array($this->actual)->toContainOnlyInstancesOf($className, $message);
return $this;
}
public function arrayToHaveCount(int $expectedCount, string $message = ''): self
{
Expect::Array($this->actual)->toHaveCount($expectedCount, $message);
return $this;
}
public function arrayToHaveKey($key, string $message = ''): self
{
Expect::Array($this->actual)->toHaveKey($key, $message);
return $this;
}
public function arrayNotToHaveKey($key, string $message = ''): self
{
Expect::Array($this->actual)->notToHaveKey($key, $message);
return $this;
}
public function arrayNotToContain($needle, string $message = ''): self
{
Expect::Array($this->actual)->notToContain($needle, $message);
return $this;
}
public function arrayNotToContainEqual($needle, string $message = ''): self
{
Expect::Array($this->actual)->notToContainEqual($needle, $message);
return $this;
}
public function arrayNotToContainOnly(string $type, ?bool $isNativeType = null, string $message = ''): self
{
Expect::Array($this->actual)->notToContainOnly($type, $isNativeType, $message);
return $this;
}
public function arrayNotToHaveCount(int $expectedCount, string $message = ''): self
{
Expect::Array($this->actual)->notToHaveCount($expectedCount, $message);
return $this;
}
public function arrayNotToHaveSameSizeAs($expected, string $message = ''): self
{
Expect::Array($this->actual)->notToHaveSameSizeAs($expected, $message);
return $this;
}
public function arrayToHaveSameSizeAs($expected, string $message = ''): self
{
Expect::Array($this->actual)->toHaveSameSizeAs($expected, $message);
return $this;
}
public function baseObjectToHaveAttribute(string $attributeName, string $message = ''): self
{
Expect::BaseObject($this->actual)->toHaveAttribute($attributeName, $message);
return $this;
}
public function baseObjectNotToHaveAttribute(string $attributeName, string $message = ''): self
{
Expect::BaseObject($this->actual)->notToHaveAttribute($attributeName, $message);
return $this;
}
public function baseObjectToHaveProperty(string $propertyName, string $message = ''): self
{
Expect::BaseObject($this->actual)->toHaveProperty($propertyName, $message);
return $this;
}
public function baseObjectNotToHaveProperty(string $propertyName, string $message = ''): self
{
Expect::BaseObject($this->actual)->notToHaveProperty($propertyName, $message);
return $this;
}
public function callableToThrow($throws = null, string $message = ''): self
{
Expect::Callable($this->actual)->toThrow($throws, $message);
return $this;
}
public function callableNotToThrow($throws = null, string $message = ''): self
{
Expect::Callable($this->actual)->notToThrow($throws, $message);
return $this;
}
public function classToHaveAttribute(string $attributeName, string $message = ''): self
{
Expect::Class($this->actual)->toHaveAttribute($attributeName, $message);
return $this;
}
public function classToHaveStaticAttribute(string $attributeName, string $message = ''): self
{
Expect::Class($this->actual)->toHaveStaticAttribute($attributeName, $message);
return $this;
}
public function classNotToHaveAttribute(string $attributeName, string $message = ''): self
{
Expect::Class($this->actual)->notToHaveAttribute($attributeName, $message);
return $this;
}
public function classNotToHaveStaticAttribute(string $attributeName, string $message = ''): self
{
Expect::Class($this->actual)->notToHaveStaticAttribute($attributeName, $message);
return $this;
}
public function directoryNotToExist(string $message = ''): self
{
Expect::Directory($this->actual)->notToExist($message);
return $this;
}
public function directoryToExist(string $message = ''): self
{
Expect::Directory($this->actual)->toExist($message);
return $this;
}
public function directoryNotToBeReadable(string $message = ''): self
{
Expect::Directory($this->actual)->notToBeReadable($message);
return $this;
}
public function directoryNotToBeWritable(string $message = ''): self
{
Expect::Directory($this->actual)->notToBeWritable($message);
return $this;
}
public function directoryToBeReadable(string $message = ''): self
{
Expect::Directory($this->actual)->toBeReadable($message);
return $this;
}
public function directoryToBeWritable(string $message = ''): self
{
Expect::Directory($this->actual)->toBeWritable($message);
return $this;
}
public function fileNotToExist(string $message = ''): self
{
Expect::File($this->actual)->notToExist($message);
return $this;
}
public function fileToBeEqual(string $expected, string $message = ''): self
{
Expect::File($this->actual)->toBeEqual($expected, $message);
return $this;
}
public function fileToBeEqualCanonicalizing(string $expected, string $message = ''): self
{
Expect::File($this->actual)->toBeEqualCanonicalizing($expected, $message);
return $this;
}
public function fileToBeEqualIgnoringCase(string $expected, string $message = ''): self
{
Expect::File($this->actual)->toBeEqualIgnoringCase($expected, $message);
return $this;
}
public function fileToExist(string $message = ''): self
{
Expect::File($this->actual)->toExist($message);
return $this;
}
public function fileNotToBeReadable(string $message = ''): self
{
Expect::File($this->actual)->notToBeReadable($message);
return $this;
}
public function fileNotToBeWritable(string $message = ''): self
{
Expect::File($this->actual)->notToBeWritable($message);
return $this;
}
public function fileToBeReadable(string $message = ''): self
{
Expect::File($this->actual)->toBeReadable($message);
return $this;
}
public function fileToBeWritable(string $message = ''): self
{
Expect::File($this->actual)->toBeWritable($message);
return $this;
}
public function fileToNotEqual(string $expected, string $message = ''): self
{
Expect::File($this->actual)->toNotEqual($expected, $message);
return $this;
}
public function fileToNotEqualCanonicalizing(string $expected, string $message = ''): self
{
Expect::File($this->actual)->toNotEqualCanonicalizing($expected, $message);
return $this;
}
public function fileToNotEqualIgnoringCase(string $expected, string $message = ''): self
{
Expect::File($this->actual)->toNotEqualIgnoringCase($expected, $message);
return $this;
}
public function jsonFileToEqualJsonFile(string $expectedFile, string $message = ''): self
{
Expect::JsonFile($this->actual)->toEqualJsonFile($expectedFile, $message);
return $this;
}
public function jsonFileNotToEqualJsonFile(string $expectedFile, string $message = ''): self
{
Expect::JsonFile($this->actual)->notToEqualJsonFile($expectedFile, $message);
return $this;
}
public function jsonStringToEqualJsonFile(string $expectedFile, string $message = ''): self
{
Expect::JsonString($this->actual)->toEqualJsonFile($expectedFile, $message);
return $this;
}
public function jsonStringToEqualJsonString(string $expectedJson, string $message = ''): self
{
Expect::JsonString($this->actual)->toEqualJsonString($expectedJson, $message);
return $this;
}
public function jsonStringNotToEqualJsonFile(string $expectedFile, string $message = ''): self
{
Expect::JsonString($this->actual)->notToEqualJsonFile($expectedFile, $message);
return $this;
}
public function jsonStringNotToEqualJsonString(string $expectedJson, string $message = ''): self
{
Expect::JsonString($this->actual)->notToEqualJsonString($expectedJson, $message);
return $this;
}
public function stringToContainString(string $needle, string $message = ''): self
{
Expect::String($this->actual)->toContainString($needle, $message);
return $this;
}
public function stringToContainStringIgnoringCase($needle, string $message = ''): self
{
Expect::String($this->actual)->toContainStringIgnoringCase($needle, $message);
return $this;
}
public function stringNotToMatchRegExp(string $pattern, string $message = ''): self
{
Expect::String($this->actual)->notToMatchRegExp($pattern, $message);
return $this;
}
public function stringToEndWith(string $suffix, string $message = ''): self
{
Expect::String($this->actual)->toEndWith($suffix, $message);
return $this;
}
public function stringToEqualFile(string $expectedFile, string $message = ''): self
{
Expect::String($this->actual)->toEqualFile($expectedFile, $message);
return $this;
}
public function stringToEqualFileCanonicalizing(string $expectedFile, string $message = ''): self
{
Expect::String($this->actual)->toEqualFileCanonicalizing($expectedFile, $message);
return $this;
}
public function stringToEqualFileIgnoringCase(string $expectedFile, string $message = ''): self
{
Expect::String($this->actual)->toEqualFileIgnoringCase($expectedFile, $message);
return $this;
}
public function stringToBeJson(string $message = ''): self
{
Expect::String($this->actual)->toBeJson($message);
return $this;
}
public function stringToMatchFormat(string $format, string $message = ''): self
{
Expect::String($this->actual)->toMatchFormat($format, $message);
return $this;
}
public function stringToMatchFormatFile(string $formatFile, string $message = ''): self
{
Expect::String($this->actual)->toMatchFormatFile($formatFile, $message);
return $this;
}
public function stringToMatchRegExp(string $pattern, string $message = ''): self
{
Expect::String($this->actual)->toMatchRegExp($pattern, $message);
return $this;
}
public function stringNotToContainString(string $needle, string $message = ''): self
{
Expect::String($this->actual)->notToContainString($needle, $message);
return $this;
}
public function stringNotToContainStringIgnoringCase(string $needle, string $message = ''): self
{
Expect::String($this->actual)->notToContainStringIgnoringCase($needle, $message);
return $this;
}
public function stringNotToEndWith(string $suffix, string $message = ''): self
{
Expect::String($this->actual)->notToEndWith($suffix, $message);
return $this;
}
public function stringNotToEqualFile(string $expectedFile, string $message = ''): self
{
Expect::String($this->actual)->notToEqualFile($expectedFile, $message);
return $this;
}
public function stringNotToEqualFileCanonicalizing(string $expectedFile, string $message = ''): self
{
Expect::String($this->actual)->notToEqualFileCanonicalizing($expectedFile, $message);
return $this;
}
public function stringNotToEqualFileIgnoringCase(string $expectedFile, string $message = ''): self
{
Expect::String($this->actual)->notToEqualFileIgnoringCase($expectedFile, $message);
return $this;
}
public function stringNotToMatchFormat($format, string $message = ''): self
{
Expect::String($this->actual)->notToMatchFormat($format, $message);
return $this;
}
public function stringNotToMatchFormatFile(string $formatFile, string $message = ''): self
{
Expect::String($this->actual)->notToMatchFormatFile($formatFile, $message);
return $this;
}
public function stringNotToStartWith(string $prefix, string $message = ''): self
{
Expect::String($this->actual)->notToStartWith($prefix, $message);
return $this;
}
public function stringToStartWith(string $prefix, string $message = ''): self
{
Expect::String($this->actual)->toStartWith($prefix, $message);
return $this;
}
public function xmlFileToEqualXmlFile(string $expectedFile, string $message = ''): self
{
Expect::XmlFile($this->actual)->toEqualXmlFile($expectedFile, $message);
return $this;
}
public function xmlFileNotToEqualXmlFile(string $expectedFile, string $message = ''): self
{
Expect::XmlFile($this->actual)->notToEqualXmlFile($expectedFile, $message);
return $this;
}
public function xmlStringToEqualXmlFile(string $expectedFile, string $message = ''): self
{
Expect::XmlString($this->actual)->toEqualXmlFile($expectedFile, $message);
return $this;
}
public function xmlStringToEqualXmlString($expectedXml, string $message = ''): self
{
Expect::XmlString($this->actual)->toEqualXmlString($expectedXml, $message);
return $this;
}
public function xmlStringNotToEqualXmlFile(string $expectedFile, string $message = ''): self
{
Expect::XmlString($this->actual)->notToEqualXmlFile($expectedFile, $message);
return $this;
}
public function xmlStringNotToEqualXmlString($expectedXml, string $message = ''): self
{
Expect::XmlString($this->actual)->notToEqualXmlString($expectedXml, $message);
return $this;
}
}

View File

@ -0,0 +1,194 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use ArrayAccess;
use Codeception\Exception\InvalidVerifyException;
use Codeception\Verify\Expect;
use Countable;
use PHPUnit\Framework\Assert;
use function basename;
use function is_array;
use function is_iterable;
class ExpectArray extends Expect
{
/**
* ExpectArray constructor
*
* @param array|ArrayAccess|Countable|iterable $actual
*/
public function __construct($actual)
{
if (
is_array($actual) ||
$actual instanceof ArrayAccess ||
$actual instanceof Countable ||
is_iterable($actual)
) {
parent::__construct($actual);
return;
}
throw new InvalidVerifyException(basename(self::class), $actual);
}
/**
* Expect that a haystack does not contain a needle.
*
* @param $needle
* @param string $message
* @return self
*/
public function notToContain($needle, string $message = ''): self
{
Assert::assertNotContains($needle, $this->actual, $message);
return $this;
}
public function notToContainEqual($needle, string $message = ''): self
{
Assert::assertNotContainsEquals($needle, $this->actual, $message);
return $this;
}
/**
* Expect that a haystack does not contain only values of a given type.
*
* @param string $type
* @param bool|null $isNativeType
* @param string $message
* @return self
*/
public function notToContainOnly(string $type, ?bool $isNativeType = null, string $message = ''): self
{
Assert::assertNotContainsOnly($type, $this->actual, $isNativeType, $message);
return $this;
}
/**
* Expect the number of elements of an array, Countable or Traversable.
*
* @param int $expectedCount
* @param string $message
* @return self
*/
public function notToHaveCount(int $expectedCount, string $message = ''): self
{
Assert::assertNotCount($expectedCount, $this->actual, $message);
return $this;
}
/**
* Expect that an array does not have a specified key.
*
* @param int|string $key
* @param string $message
* @return self
*/
public function notToHaveKey($key, string $message = ''): self
{
Assert::assertArrayNotHasKey($key, $this->actual, $message);
return $this;
}
/**
* Expect that the size of two arrays (or `Countable` or `Traversable` objects) is not the same.
*
* @param Countable|iterable $expected
* @param string $message
* @return self
*/
public function notToHaveSameSizeAs($expected, string $message = ''): self
{
Assert::assertNotSameSize($expected, $this->actual, $message);
return $this;
}
/**
* Expect that a haystack contains a needle.
*
* @param $needle
* @param string $message
* @return self
*/
public function toContain($needle, string $message = ''): self
{
Assert::assertContains($needle, $this->actual, $message);
return $this;
}
public function toContainEqual($needle, string $message = ''): self
{
Assert::assertContainsEquals($needle, $this->actual, $message);
return $this;
}
/**
* Expect that a haystack contains only values of a given type.
*
* @param string $type
* @param bool|null $isNativeType
* @param string $message
* @return self
*/
public function toContainOnly(string $type, ?bool $isNativeType = null, string $message = ''): self
{
Assert::assertContainsOnly($type, $this->actual, $isNativeType, $message);
return $this;
}
/**
* Expect that a haystack contains only instances of a given class name.
*
* @param string $className
* @param string $message
* @return self
*/
public function toContainOnlyInstancesOf(string $className, string $message = ''): self
{
Assert::assertContainsOnlyInstancesOf($className, $this->actual, $message);
return $this;
}
/**
* Expect the number of elements of an array, Countable or Traversable.
*
* @param int $expectedCount
* @param string $message
* @return self
*/
public function toHaveCount(int $expectedCount, string $message = ''): self
{
Assert::assertCount($expectedCount, $this->actual, $message);
return $this;
}
/**
* Expect that an array has a specified key.
*
* @param int|string $key
* @param string $message
* @return self
*/
public function toHaveKey($key, string $message = ''): self
{
Assert::assertArrayHasKey($key, $this->actual, $message);
return $this;
}
/**
* Expect that the size of two arrays (or `Countable` or `Traversable` objects) is the same.
*
* @param Countable|iterable $expected
* @param string $message
* @return self
*/
public function toHaveSameSizeAs($expected, string $message = ''): self
{
Assert::assertSameSize($expected, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Verify\Expect;
use PHPUnit\Framework\Assert;
class ExpectBaseObject extends Expect
{
use ExpectDataTrait;
/**
* ExpectBaseObject constructor
*
* @param object $object
*/
public function __construct(object $object)
{
parent::__construct($object);
}
/**
* Expect that an object does not have a specified attribute.
*
* @deprecated Deprecated in favour of notToHaveProperty
*
* @param string $attributeName
* @param string $message
* @return self
*/
public function notToHaveAttribute(string $attributeName, string $message = ''): self
{
Assert::assertObjectNotHasProperty($attributeName, $this->actual, $message);
return $this;
}
/**
* Expect that an object has a specified attribute.
*
* @deprecated Deprecated in favour of toHaveProperty
*
* @param string $attributeName
* @param string $message
* @return self
*/
public function toHaveAttribute(string $attributeName, string $message = ''): self
{
Assert::assertObjectHasProperty($attributeName, $this->actual, $message);
return $this;
}
/**
* Expect that an object does not have a specified property.
*
* @param string $propertyName
* @param string $message
* @return self
*/
public function notToHaveProperty(string $propertyName, string $message = ''): self
{
Assert::assertObjectNotHasProperty($propertyName, $this->actual, $message);
return $this;
}
/**
* Expect that an object has a specified property.
*
* @param string $propertyName
* @param string $message
* @return self
*/
public function toHaveProperty(string $propertyName, string $message = ''): self
{
Assert::assertObjectHasProperty($propertyName, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Verify\Asserts\AssertThrows;
use Codeception\Verify\Expect;
use Exception;
use Throwable;
class ExpectCallable extends Expect
{
use AssertThrows;
public function __construct(callable $callable)
{
parent::__construct($callable);
}
/**
* @param Exception|string|null $throws
* @param string|false $message
* @return $this
*/
public function notToThrow($throws = null, $message = false): self
{
return $this->assertDoesNotThrow($throws, $message);
}
/**
* @param Exception|string|null $throws
* @param string|false $message
* @return ExpectCallable
* @throws Throwable
*/
public function toThrow($throws = null, $message = false): self
{
return $this->assertThrows($throws, $message);
}
}

View File

@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Verify\Expect;
use Codeception\Verify\Verifiers\VerifyDataTrait;
use PHPUnit\Framework\Assert;
class ExpectClass extends Expect
{
use VerifyDataTrait;
/**
* ExpectClass constructor
*
* @param string $className
*/
public function __construct(string $className)
{
parent::__construct($className);
}
/**
* Expect that a class does not have a specified attribute.
*
* @param string $attributeName
* @param string $message
* @return self
*/
public function notToHaveAttribute(string $attributeName, string $message = ''): self
{
Assert::assertClassNotHasAttribute($attributeName, $this->actual, $message);
return $this;
}
/**
* Expect that a class does not have a specified static attribute.
*
* @param string $attributeName
* @param string $message
* @return self
*/
public function notToHaveStaticAttribute(string $attributeName, string $message = ''): self
{
Assert::assertClassNotHasStaticAttribute($attributeName, $this->actual, $message);
return $this;
}
/**
* Expect that a class has a specified attribute.
*
* @param string $attributeName
* @param string $message
* @return self
*/
public function toHaveAttribute(string $attributeName, string $message = ''): self
{
Assert::assertClassHasAttribute($attributeName, $this->actual, $message);
return $this;
}
/**
* Expect that a class has a specified static attribute.
*
* @param string $attributeName
* @param string $message
* @return self
*/
public function toHaveStaticAttribute(string $attributeName, string $message = ''): self
{
Assert::assertClassHasStaticAttribute($attributeName, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use PHPUnit\Framework\Assert;
trait ExpectDataTrait
{
/**
* Expect that a file/dir is not readable.
*
* @param string $message
* @return self
*/
public function notToBeReadable(string $message = ''): self
{
Assert::assertIsNotReadable($this->actual, $message);
return $this;
}
/**
* Expect that a file/dir is not writable.
*
* @param string $message
* @return self
*/
public function notToBeWritable(string $message = ''): self
{
Assert::assertIsNotWritable($this->actual, $message);
return $this;
}
/**
* Expect that a file/dir is readable.
*
* @param string $message
* @return self
*/
public function toBeReadable(string $message = ''): self
{
Assert::assertIsReadable($this->actual, $message);
return $this;
}
/**
* Expect that a file/dir is writable.
*
* @param string $message
* @return self
*/
public function toBeWritable(string $message = ''): self
{
Assert::assertIsWritable($this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Verify\Expect;
use PHPUnit\Framework\Assert;
class ExpectDirectory extends Expect
{
use ExpectDataTrait;
/**
* ExpectDirectory constructor
*
* @param string $directory
*/
public function __construct(string $directory)
{
parent::__construct($directory);
}
/**
* Expect that a directory does not exist.
*
* @param string $message
* @return self
*/
public function notToExist(string $message = ''): self
{
Assert::assertDirectoryDoesNotExist($this->actual, $message);
return $this;
}
/**
* Expect that a directory exists.
*
* @param string $message
* @return self
*/
public function toExist(string $message = ''): self
{
Assert::assertDirectoryExists($this->actual, $message);
return $this;
}
/**
* Expect that a directory exists and is not readable.
*
* @param string $message
* @return self
*/
public function toExistAndNotToBeReadable(string $message = ''): self
{
Assert::assertDirectoryIsNotReadable($this->actual, $message);
return $this;
}
/**
* Expect that a directory exists and is not writable.
*
* @param string $message
* @return self
*/
public function toExistAndNotToBeWritable(string $message = ''): self
{
Assert::assertDirectoryIsNotWritable($this->actual, $message);
return $this;
}
/**
* Expect that a directory exists and is readable.
*
* @param string $message
* @return self
*/
public function toExistAndToBeReadable(string $message = ''): self
{
Assert::assertDirectoryIsReadable($this->actual, $message);
return $this;
}
/**
* Expect that a directory exists and is writable.
*
* @param string $message
* @return self
*/
public function toExistAndToBeWritable(string $message = ''): self
{
Assert::assertDirectoryIsWritable($this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,168 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Verify\Expect;
use PHPUnit\Framework\Assert;
class ExpectFile extends Expect
{
use ExpectDataTrait;
public function __construct(string $actual)
{
parent::__construct($actual);
}
/**
* Expect that a file does not exist.
*
* @param string $message
* @return self
*/
public function notToExist(string $message = ''): self
{
Assert::assertFileDoesNotExist($this->actual, $message);
return $this;
}
/**
* Expect that the contents of one file is equal to the contents of another file.
*
* @param string $expected
* @param string $message
* @return self
*/
public function toBeEqual(string $expected, string $message = ''): self
{
Assert::assertFileEquals($expected, $this->actual, $message);
return $this;
}
/**
* Expect that the contents of one file is equal to the contents of another file (canonicalizing).
*
* @param string $expected
* @param string $message
* @return self
*/
public function toBeEqualCanonicalizing(string $expected, string $message = ''): self
{
Assert::assertFileEqualsCanonicalizing($expected, $this->actual, $message);
return $this;
}
/**
* Expect that the contents of one file is equal to the contents of another file (ignoring case).
*
* @param string $expected
* @param string $message
* @return self
*/
public function toBeEqualIgnoringCase(string $expected, string $message = ''): self
{
Assert::assertFileEqualsIgnoringCase($expected, $this->actual, $message);
return $this;
}
/**
* Expect that a file exists.
*
* @param string $message
* @return self
*/
public function toExist(string $message = ''): self
{
Assert::assertFileExists($this->actual, $message);
return $this;
}
/**
* Expect that a file exists and is not readable.
*
* @param string $message
* @return self
*/
public function toExistAndNotToBeReadable(string $message = ''): self
{
Assert::assertFileIsNotReadable($this->actual, $message);
return $this;
}
/**
* Expect that a file exists and is not writable.
*
* @param string $message
* @return self
*/
public function toExistAndNotToBeWritable(string $message = ''): self
{
Assert::assertFileIsNotWritable($this->actual, $message);
return $this;
}
/**
* Expect that a file exists and is readable.
*
* @param string $message
* @return self
*/
public function toExistAndToBeReadable(string $message = ''): self
{
Assert::assertFileIsReadable($this->actual, $message);
return $this;
}
/**
* Expect that a file exists and is writable.
*
* @param string $message
* @return self
*/
public function toExistAndToBeWritable(string $message = ''): self
{
Assert::assertFileIsWritable($this->actual, $message);
return $this;
}
/**
* Expect that the contents of one file is not equal to the contents of another file.
*
* @param $expected
* @param string $message
* @return self
*/
public function toNotEqual(string $expected, string $message = ''): self
{
Assert::assertFileNotEquals($expected, $this->actual, $message);
return $this;
}
/**
* Expect that the contents of one file is not equal to the contents of another file (canonicalizing).
*
* @param $expected
* @param string $message
* @return self
*/
public function toNotEqualCanonicalizing(string $expected, string $message = ''): self
{
Assert::assertFileNotEqualsCanonicalizing($expected, $this->actual, $message);
return $this;
}
/**
* Expect that the contents of one file is not equal to the contents of another file (ignoring case).
*
* @param $expected
* @param string $message
* @return self
*/
public function toNotEqualIgnoringCase(string $expected, string $message = ''): self
{
Assert::assertFileNotEqualsIgnoringCase($expected, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Verify\Expect;
use PHPUnit\Framework\Assert;
class ExpectJsonFile extends Expect
{
public function __construct(string $actualFile)
{
parent::__construct($actualFile);
}
/**
* Expect that two JSON files are not equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notToEqualJsonFile(string $expectedFile, string $message = ''): self
{
Assert::assertJsonFileNotEqualsJsonFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that two JSON files are equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function toEqualJsonFile(string $expectedFile, string $message = ''): self
{
Assert::assertJsonFileEqualsJsonFile($expectedFile, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Verify\Expect;
use PHPUnit\Framework\Assert;
class ExpectJsonString extends Expect
{
public function __construct(string $actualJson)
{
parent::__construct($actualJson);
}
/**
* Expect that the generated JSON encoded object and the content of the given file are not equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notToEqualJsonFile(string $expectedFile, string $message = ''): self
{
Assert::assertJsonStringNotEqualsJsonFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that two given JSON encoded objects or arrays are not equal.
*
* @param string $expectedJson
* @param string $message
* @return self
*/
public function notToEqualJsonString(string $expectedJson, string $message = ''): self
{
Assert::assertJsonStringNotEqualsJsonString($expectedJson, $this->actual, $message);
return $this;
}
/**
* Expect that the generated JSON encoded object and the content of the given file are equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function toEqualJsonFile(string $expectedFile, string $message = ''): self
{
Assert::assertJsonStringEqualsJsonFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that two given JSON encoded objects or arrays are equal.
*
* @param string $expectedJson
* @param string $message
* @return self
*/
public function toEqualJsonString(string $expectedJson, string $message = ''): self
{
Assert::assertJsonStringEqualsJsonString($expectedJson, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,651 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Verify\Expect;
use PHPUnit\Framework\Assert;
class ExpectMixed extends Expect
{
/**
* ExpectMixed constructor.
*
* @param mixed $actual
*/
public function __construct($actual)
{
parent::__construct($actual);
}
/**
* Expect that two variables do not have the same type and value.
*
* @param $expected
* @param string $message
* @return self
*/
public function notToBe($expected, string $message = ''): self
{
Assert::assertNotSame($expected, $this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type array.
*
* @param string $message
* @return self
*/
public function notToBeArray(string $message = ''): self
{
Assert::assertIsNotArray($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type bool.
*
* @param string $message
* @return self
*/
public function notToBeBool(string $message = ''): self
{
Assert::assertIsNotBool($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type callable.
*
* @param string $message
* @return self
*/
public function notToBeCallable(string $message = ''): self
{
Assert::assertIsNotCallable($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type resource.
*
* @param string $message
* @return self
*/
public function notToBeClosedResource(string $message = ''): self
{
Assert::assertIsNotClosedResource($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not empty.
*
* @param string $message
* @return self
*/
public function notToBeEmpty(string $message = ''): self
{
Assert::assertNotEmpty($this->actual, $message);
return $this;
}
/**
* Expect that a condition is not false.
*
* @param string $message
* @return self
*/
public function notToBeFalse(string $message = ''): self
{
Assert::assertNotFalse($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type float.
*
* @param string $message
* @return self
*/
public function notToBeFloat(string $message = ''): self
{
Assert::assertIsNotFloat($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of a given type.
*
* @param string $expected
* @param string $message
* @return self
*/
public function notToBeInstanceOf(string $expected, string $message = ''): self
{
Assert::assertNotInstanceOf($expected, $this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type int.
*
* @param string $message
* @return self
*/
public function notToBeInt(string $message = ''): self
{
Assert::assertIsNotInt($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type iterable.
*
* @param string $message
* @return self
*/
public function notToBeIterable(string $message = ''): self
{
Assert::assertIsNotIterable($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not null.
*
* @param string $message
* @return self
*/
public function notToBeNull(string $message = ''): self
{
Assert::assertNotNull($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type numeric.
*
* @param string $message
* @return self
*/
public function notToBeNumeric(string $message = ''): self
{
Assert::assertIsNotNumeric($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type object.
*
* @param string $message
* @return self
*/
public function notToBeObject(string $message = ''): self
{
Assert::assertIsNotObject($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type resource.
*
* @param string $message
* @return self
*/
public function notToBeResource(string $message = ''): self
{
Assert::assertIsNotResource($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type scalar.
*
* @param string $message
* @return self
*/
public function notToBeScalar(string $message = ''): self
{
Assert::assertIsNotScalar($this->actual, $message);
return $this;
}
/**
* Expect that a variable is not of type string.
*
* @param string $message
* @return self
*/
public function notToBeString(string $message = ''): self
{
Assert::assertIsNotString($this->actual, $message);
return $this;
}
/**
* Expect that a condition is not true.
*
* @param string $message
* @return self
*/
public function notToBeTrue(string $message = ''): self
{
Assert::assertNotTrue($this->actual, $message);
return $this;
}
/**
* Expect that two variables are not equal.
*
* @param $expected
* @param string $message
* @return self
*/
public function notToEqual($expected, string $message = ''): self
{
Assert::assertNotEquals($expected, $this->actual, $message);
return $this;
}
/**
* Expect that two variables are not equal (canonicalizing).
*
* @param $expected
* @param string $message
* @return self
*/
public function notToEqualCanonicalizing($expected, string $message = ''): self
{
Assert::assertNotEqualsCanonicalizing($expected, $this->actual, $message);
return $this;
}
/**
* Expect that two variables are not equal (ignoring case).
*
* @param $expected
* @param string $message
* @return self
*/
public function notToEqualIgnoringCase($expected, string $message = ''): self
{
Assert::assertNotEqualsIgnoringCase($expected, $this->actual, $message);
return $this;
}
/**
* Expect that two variables are not equal (with delta).
*
* @param $expected
* @param float $delta
* @param string $message
* @return self
*/
public function notToEqualWithDelta($expected, float $delta, string $message = ''): self
{
Assert::assertNotEqualsWithDelta($expected, $this->actual, $delta, $message);
return $this;
}
/**
* Expect that two variables have the same type and value.
*
* @param $expected
* @param string $message
* @return self
*/
public function toBe($expected, string $message = ''): self
{
Assert::assertSame($expected, $this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type array.
*
* @param string $message
* @return self
*/
public function toBeArray(string $message = ''): self
{
Assert::assertIsArray($this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type bool.
*
* @param string $message
* @return self
*/
public function toBeBool(string $message = ''): self
{
Assert::assertIsBool($this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type callable.
*
* @param string $message
* @return self
*/
public function toBeCallable(string $message = ''): self
{
Assert::assertIsCallable($this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type resource and is closed.
*
* @param string $message
* @return self
*/
public function toBeClosedResource(string $message = ''): self
{
Assert::assertIsClosedResource($this->actual, $message);
return $this;
}
/**
* Expect that a variable is empty.
*
* @param string $message
* @return self
*/
public function toBeEmpty(string $message = ''): self
{
Assert::assertEmpty($this->actual, $message);
return $this;
}
/**
* Expect that a condition is false.
*
* @param string $message
* @return self
*/
public function toBeFalse(string $message = ''): self
{
Assert::assertFalse($this->actual, $message);
return $this;
}
/**
* Expect that a variable is finite.
*
* @param string $message
* @return self
*/
public function toBeFinite(string $message = ''): self
{
Assert::assertFinite($this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type float.
*
* @param string $message
* @return self
*/
public function toBeFloat(string $message = ''): self
{
Assert::assertIsFloat($this->actual, $message);
return $this;
}
/**
* Expect that a value is greater than another value.
*
* @param $expected
* @param string $message
* @return self
*/
public function toBeGreaterThan($expected, string $message = ''): self
{
Assert::assertGreaterThan($expected, $this->actual, $message);
return $this;
}
/**
* Expect that a value is greater than or equal to another value.
*
* @param $expected
* @param string $message
* @return self
*/
public function toBeGreaterThanOrEqualTo($expected, string $message = ''): self
{
Assert::assertGreaterThanOrEqual($expected, $this->actual, $message);
return $this;
}
/**
* Expect that a variable is infinite.
*
* @param string $message
* @return self
*/
public function toBeInfinite(string $message = ''): self
{
Assert::assertInfinite($this->actual, $message);
return $this;
}
/**
* Expect that a variable is of a given type.
*
* @param string $expected
* @param string $message
* @return self
*/
public function toBeInstanceOf(string $expected, string $message = ''): self
{
Assert::assertInstanceOf($expected, $this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type int.
*
* @param string $message
* @return self
*/
public function toBeInt(string $message = ''): self
{
Assert::assertIsInt($this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type iterable.
*
* @param string $message
* @return self
*/
public function toBeIterable(string $message = ''): self
{
Assert::assertIsIterable($this->actual, $message);
return $this;
}
/**
* Expect that a value is smaller than another value.
*
* @param $expected
* @param string $message
* @return self
*/
public function toBeLessThan($expected, string $message = ''): self
{
Assert::assertLessThan($expected, $this->actual, $message);
return $this;
}
/**
* Expect that a value is smaller than or equal to another value.
*
* @param $expected
* @param string $message
* @return self
*/
public function toBeLessThanOrEqualTo($expected, string $message = ''): self
{
Assert::assertLessThanOrEqual($expected, $this->actual, $message);
return $this;
}
/**
* Expect that a variable is nan.
*
* @param string $message
* @return self
*/
public function toBeNan(string $message = ''): self
{
Assert::assertNan($this->actual, $message);
return $this;
}
/**
* Expect that a variable is null.
*
* @param string $message
* @return self
*/
public function toBeNull(string $message = ''): self
{
Assert::assertNull($this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type numeric.
*
* @param string $message
* @return self
*/
public function toBeNumeric(string $message = ''): self
{
Assert::assertIsNumeric($this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type object.
*
* @param string $message
* @return self
*/
public function toBeObject(string $message = ''): self
{
Assert::assertIsObject($this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type resource.
*
* @param string $message
* @return self
*/
public function toBeResource(string $message = ''): self
{
Assert::assertIsResource($this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type scalar.
*
* @param string $message
* @return self
*/
public function toBeScalar(string $message = ''): self
{
Assert::assertIsScalar($this->actual, $message);
return $this;
}
/**
* Expect that a variable is of type string.
*
* @param string $message
* @return self
*/
public function toBeString(string $message = ''): self
{
Assert::assertIsString($this->actual, $message);
return $this;
}
/**
* Expect that a condition is true.
*
* @param string $message
* @return self
*/
public function toBeTrue(string $message = ''): self
{
Assert::assertTrue($this->actual, $message);
return $this;
}
/**
* Expect that two variables are equal.
*
* @param $expected
* @param string $message
* @return self
*/
public function toEqual($expected, string $message = ''): self
{
Assert::assertEquals($expected, $this->actual, $message);
return $this;
}
/**
* Expect that two variables are equal (canonicalizing).
*
* @param $expected
* @param string $message
* @return self
*/
public function toEqualCanonicalizing($expected, string $message = ''): self
{
Assert::assertEqualsCanonicalizing($expected, $this->actual, $message);
return $this;
}
/**
* Expect that two variables are equal (ignoring case).
*
* @param $expected
* @param string $message
* @return self
*/
public function toEqualIgnoringCase($expected, string $message = ''): self
{
Assert::assertEqualsIgnoringCase($expected, $this->actual, $message);
return $this;
}
/**
* Expect that two variables are equal (with delta).
*
* @param $expected
* @param float $delta
* @param string $message
* @return self
*/
public function toEqualWithDelta($expected, float $delta, string $message = ''): self
{
Assert::assertEqualsWithDelta($expected, $this->actual, $delta, $message);
return $this;
}
}

View File

@ -0,0 +1,260 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Verify\Expect;
use PHPUnit\Framework\Assert;
class ExpectString extends Expect
{
public function __construct(string $string)
{
parent::__construct($string);
}
public function notToContainString(string $needle, string $message = ''): self
{
Assert::assertStringNotContainsString($needle, $this->actual, $message);
return $this;
}
public function notToContainStringIgnoringCase(string $needle, string $message = ''): self
{
Assert::assertStringNotContainsStringIgnoringCase($needle, $this->actual, $message);
return $this;
}
/**
* Expect that a string ends not with a given suffix.
*
* @param string $suffix
* @param string $message
* @return self
*/
public function notToEndWith(string $suffix, string $message = ''): self
{
Assert::assertStringEndsNotWith($suffix, $this->actual, $message);
return $this;
}
/**
* Expect that the contents of a string is not equal to the contents of a file.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notToEqualFile(string $expectedFile, string $message = ''): self
{
Assert::assertStringNotEqualsFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that the contents of a string is not equal to the contents of a file (canonicalizing).
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notToEqualFileCanonicalizing(string $expectedFile, string $message = ''): self
{
Assert::assertStringNotEqualsFileCanonicalizing($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that the contents of a string is not equal to the contents of a file (ignoring case).
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notToEqualFileIgnoringCase(string $expectedFile, string $message = ''): self
{
Assert::assertStringNotEqualsFileIgnoringCase($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that a string does not match a given format string.
*
* @param $format
* @param string $message
* @return self
*/
public function notToMatchFormat(string $format, string $message = ''): self
{
Assert::assertStringNotMatchesFormat($format, $this->actual, $message);
return $this;
}
/**
* Expect that a string does not match a given format string.
*
* @param string $formatFile
* @param string $message
* @return self
*/
public function notToMatchFormatFile(string $formatFile, string $message = ''): self
{
Assert::assertStringNotMatchesFormatFile($formatFile, $this->actual, $message);
return $this;
}
/**
* Expect that a string does not match a given regular expression.
*
* @param string $pattern
* @param string $message
* @return self
*/
public function notToMatchRegExp(string $pattern, string $message = ''): self
{
Assert::assertDoesNotMatchRegularExpression($pattern, $this->actual, $message);
return $this;
}
/**
* Expect that a string starts not with a given prefix.
*
* @param string $prefix
* @param string $message
* @return self
*/
public function notToStartWith(string $prefix, string $message = ''): self
{
Assert::assertStringStartsNotWith($prefix, $this->actual, $message);
return $this;
}
/**
* Expect that a string is a valid JSON string.
*
* @param string $message
* @return self
*/
public function toBeJson(string $message = ''): self
{
Assert::assertJson($this->actual, $message);
return $this;
}
public function toContainString(string $needle, string $message = ''): self
{
Assert::assertStringContainsString($needle, $this->actual, $message);
return $this;
}
public function toContainStringIgnoringCase(string $needle, string $message = ''): self
{
Assert::assertStringContainsStringIgnoringCase($needle, $this->actual, $message);
return $this;
}
/**
* Expect that a string ends with a given suffix.
*
* @param string $suffix
* @param string $message
* @return self
*/
public function toEndWith(string $suffix, string $message = ''): self
{
Assert::assertStringEndsWith($suffix, $this->actual, $message);
return $this;
}
/**
* Expect that the contents of a string is equal to the contents of a file.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function toEqualFile(string $expectedFile, string $message = ''): self
{
Assert::assertStringEqualsFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that the contents of a string is equal to the contents of a file (canonicalizing).
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function toEqualFileCanonicalizing(string $expectedFile, string $message = ''): self
{
Assert::assertStringEqualsFileCanonicalizing($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that the contents of a string is equal to the contents of a file (ignoring case).
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function toEqualFileIgnoringCase(string $expectedFile, string $message = ''): self
{
Assert::assertStringEqualsFileIgnoringCase($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that a string matches a given format string.
*
* @param string $format
* @param string $message
* @return self
*/
public function toMatchFormat(string $format, string $message = ''): self
{
Assert::assertStringMatchesFormat($format, $this->actual, $message);
return $this;
}
/**
* Expect that a string matches a given format file.
*
* @param string $formatFile
* @param string $message
* @return self
*/
public function toMatchFormatFile(string $formatFile, string $message = ''): self
{
Assert::assertStringMatchesFormatFile($formatFile, $this->actual, $message);
return $this;
}
/**
* Expect that a string matches a given regular expression.
*
* @param string $pattern
* @param string $message
* @return self
*/
public function toMatchRegExp(string $pattern, string $message = ''): self
{
Assert::assertMatchesRegularExpression($pattern, $this->actual, $message);
return $this;
}
/**
* Expect that a string starts with a given prefix.
*
* @param string $prefix
* @param string $message
* @return self
*/
public function toStartWith(string $prefix, string $message = ''): self
{
Assert::assertStringStartsWith($prefix, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Verify\Expect;
use PHPUnit\Framework\Assert;
class ExpectXmlFile extends Expect
{
public function __construct(string $actualFile)
{
parent::__construct($actualFile);
}
/**
* Expect that two XML files are not equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notToEqualXmlFile(string $expectedFile, string $message = ''): self
{
Assert::assertXmlFileNotEqualsXmlFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that two XML files are equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function toEqualXmlFile(string $expectedFile, string $message = ''): self
{
Assert::assertXmlFileEqualsXmlFile($expectedFile, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Expectations;
use Codeception\Exception\InvalidVerifyException;
use Codeception\Verify\Expect;
use DOMDocument;
use PHPUnit\Framework\Assert;
use function basename;
use function is_string;
class ExpectXmlString extends Expect
{
/**
* ExpectXmlString constructor
*
* @param DOMDocument|string $actualXml
*/
public function __construct($actualXml)
{
if (is_string($actualXml) || $actualXml instanceof DOMDocument) {
parent::__construct($actualXml);
return;
}
throw new InvalidVerifyException(basename(self::class), $actualXml);
}
/**
* Expect that two XML documents are not equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notToEqualXmlFile(string $expectedFile, string $message = ''): self
{
Assert::assertXmlStringNotEqualsXmlFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that two XML documents are not equal.
*
* @param DOMDocument|string $expectedXml
* @param string $message
* @return self
*/
public function notToEqualXmlString($expectedXml, string $message = ''): self
{
Assert::assertXmlStringNotEqualsXmlString($expectedXml, $this->actual, $message);
return $this;
}
/**
* Expect that two XML documents are equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function toEqualXmlFile(string $expectedFile, string $message = ''): self
{
Assert::assertXmlStringEqualsXmlFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Expect that two XML documents are equal.
*
* @param DOMDocument|string $expectedXml
* @param string $message
* @return self
*/
public function toEqualXmlString($expectedXml, string $message = ''): self
{
Assert::assertXmlStringEqualsXmlString($expectedXml, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,454 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use Codeception\Verify\Verify;
class VerifyAny extends VerifyMixed
{
public function arrayContains($needle, string $message = ''): self
{
Verify::Array($this->actual)->contains($needle, $message);
return $this;
}
public function arrayContainsEquals($needle, string $message = ''): self
{
Verify::Array($this->actual)->containsEquals($needle, $message);
return $this;
}
public function arrayContainsOnly(string $type, ?bool $isNativeType = null, string $message = ''): self
{
Verify::Array($this->actual)->containsOnly($type, $isNativeType, $message);
return $this;
}
public function arrayContainsOnlyInstancesOf(string $className, string $message = ''): self
{
Verify::Array($this->actual)->containsOnlyInstancesOf($className, $message);
return $this;
}
public function arrayCount(int $expectedCount, string $message = ''): self
{
Verify::Array($this->actual)->count($expectedCount, $message);
return $this;
}
public function arrayHasKey($key, string $message = ''): self
{
Verify::Array($this->actual)->hasKey($key, $message);
return $this;
}
public function arrayHasNotKey($key, string $message = ''): self
{
Verify::Array($this->actual)->hasNotKey($key, $message);
return $this;
}
public function arrayNotContains($needle, string $message = ''): self
{
Verify::Array($this->actual)->notContains($needle, $message);
return $this;
}
public function arrayNotContainsEquals($needle, string $message = ''): self
{
Verify::Array($this->actual)->notContainsEquals($needle, $message);
return $this;
}
public function arrayNotContainsOnly(string $type, ?bool $isNativeType = null, string $message = ''): self
{
Verify::Array($this->actual)->notContainsOnly($type, $isNativeType, $message);
return $this;
}
public function arrayNotCount(int $expectedCount, string $message = ''): self
{
Verify::Array($this->actual)->notCount($expectedCount, $message);
return $this;
}
public function arrayNotSameSize($expected, string $message = ''): self
{
Verify::Array($this->actual)->notSameSize($expected, $message);
return $this;
}
public function arraySameSize($expected, string $message = ''): self
{
Verify::Array($this->actual)->sameSize($expected, $message);
return $this;
}
public function baseObjectHasAttribute(string $attributeName, string $message = ''): self
{
Verify::BaseObject($this->actual)->hasAttribute($attributeName, $message);
return $this;
}
public function baseObjectNotHasAttribute(string $attributeName, string $message = ''): self
{
Verify::BaseObject($this->actual)->notHasAttribute($attributeName, $message);
return $this;
}
public function baseObjectHasProperty(string $propertyName, string $message = ''): self
{
Verify::BaseObject($this->actual)->hasProperty($propertyName, $message);
return $this;
}
public function baseObjectNotHasProperty(string $propertyName, string $message = ''): self
{
Verify::BaseObject($this->actual)->notHasProperty($propertyName, $message);
return $this;
}
public function callableThrows($throws = null, string $message = ''): self
{
Verify::Callable($this->actual)->throws($throws, $message);
return $this;
}
public function callableDoesNotThrow($throws = null, string $message = ''): self
{
Verify::Callable($this->actual)->doesNotThrow($throws, $message);
return $this;
}
public function classHasAttribute(string $attributeName, string $message = ''): self
{
Verify::Class($this->actual)->hasAttribute($attributeName, $message);
return $this;
}
public function classHasStaticAttribute(string $attributeName, string $message = ''): self
{
Verify::Class($this->actual)->hasStaticAttribute($attributeName, $message);
return $this;
}
public function classNotHasAttribute(string $attributeName, string $message = ''): self
{
Verify::Class($this->actual)->notHasAttribute($attributeName, $message);
return $this;
}
public function classNotHasStaticAttribute(string $attributeName, string $message = ''): self
{
Verify::Class($this->actual)->notHasStaticAttribute($attributeName, $message);
return $this;
}
public function directoryDoesNotExist(string $message = ''): self
{
Verify::Directory($this->actual)->doesNotExist($message);
return $this;
}
public function directoryExists(string $message = ''): self
{
Verify::Directory($this->actual)->exists($message);
return $this;
}
public function directoryIsNotReadable(string $message = ''): self
{
Verify::Directory($this->actual)->isNotReadable($message);
return $this;
}
public function directoryIsNotWritable(string $message = ''): self
{
Verify::Directory($this->actual)->isNotWritable($message);
return $this;
}
public function directoryIsReadable(string $message = ''): self
{
Verify::Directory($this->actual)->isReadable($message);
return $this;
}
public function directoryIsWritable(string $message = ''): self
{
Verify::Directory($this->actual)->isWritable($message);
return $this;
}
public function fileDoesNotExists(string $message = ''): self
{
Verify::File($this->actual)->doesNotExists($message);
return $this;
}
public function fileEquals(string $expected, string $message = ''): self
{
Verify::File($this->actual)->equals($expected, $message);
return $this;
}
public function fileEqualsCanonicalizing(string $expected, string $message = ''): self
{
Verify::File($this->actual)->equalsCanonicalizing($expected, $message);
return $this;
}
public function fileEqualsIgnoringCase(string $expected, string $message = ''): self
{
Verify::File($this->actual)->equalsIgnoringCase($expected, $message);
return $this;
}
public function fileExists(string $message = ''): self
{
Verify::File($this->actual)->exists($message);
return $this;
}
public function fileIsNotReadable(string $message = ''): self
{
Verify::File($this->actual)->isNotReadable($message);
return $this;
}
public function fileIsNotWritable(string $message = ''): self
{
Verify::File($this->actual)->isNotWritable($message);
return $this;
}
public function fileIsReadable(string $message = ''): self
{
Verify::File($this->actual)->isReadable($message);
return $this;
}
public function fileIsWritable(string $message = ''): self
{
Verify::File($this->actual)->isWritable($message);
return $this;
}
public function fileNotEquals(string $expected, string $message = ''): self
{
Verify::File($this->actual)->notEquals($expected, $message);
return $this;
}
public function fileNotEqualsCanonicalizing(string $expected, string $message = ''): self
{
Verify::File($this->actual)->notEqualsCanonicalizing($expected, $message);
return $this;
}
public function fileNotEqualsIgnoringCase(string $expected, string $message = ''): self
{
Verify::File($this->actual)->notEqualsIgnoringCase($expected, $message);
return $this;
}
public function jsonFileEqualsJsonFile(string $expectedFile, string $message = ''): self
{
Verify::JsonFile($this->actual)->equalsJsonFile($expectedFile, $message);
return $this;
}
public function jsonFileNotEqualsJsonFile(string $expectedFile, string $message = ''): self
{
Verify::JsonFile($this->actual)->notEqualsJsonFile($expectedFile, $message);
return $this;
}
public function jsonStringEqualsJsonFile(string $expectedFile, string $message = ''): self
{
Verify::JsonString($this->actual)->equalsJsonFile($expectedFile, $message);
return $this;
}
public function jsonStringEqualsJsonString(string $expectedJson, string $message = ''): self
{
Verify::JsonString($this->actual)->equalsJsonString($expectedJson, $message);
return $this;
}
public function jsonStringNotEqualsJsonFile(string $expectedFile, string $message = ''): self
{
Verify::JsonString($this->actual)->notEqualsJsonFile($expectedFile, $message);
return $this;
}
public function jsonStringNotEqualsJsonString(string $expectedJson, string $message = ''): self
{
Verify::JsonString($this->actual)->notEqualsJsonString($expectedJson, $message);
return $this;
}
public function stringContainsString(string $needle, string $message = ''): self
{
Verify::String($this->actual)->containsString($needle, $message);
return $this;
}
public function stringContainsStringIgnoringCase($needle, string $message = ''): self
{
Verify::String($this->actual)->containsStringIgnoringCase($needle, $message);
return $this;
}
public function stringDoesNotMatchRegExp(string $pattern, string $message = ''): self
{
Verify::String($this->actual)->doesNotMatchRegExp($pattern, $message);
return $this;
}
public function stringEndsWith(string $suffix, string $message = ''): self
{
Verify::String($this->actual)->endsWith($suffix, $message);
return $this;
}
public function stringEqualsFile(string $expectedFile, string $message = ''): self
{
Verify::String($this->actual)->equalsFile($expectedFile, $message);
return $this;
}
public function stringEqualsFileCanonicalizing(string $expectedFile, string $message = ''): self
{
Verify::String($this->actual)->equalsFileCanonicalizing($expectedFile, $message);
return $this;
}
public function stringEqualsFileIgnoringCase(string $expectedFile, string $message = ''): self
{
Verify::String($this->actual)->equalsFileIgnoringCase($expectedFile, $message);
return $this;
}
public function stringJson(string $message = ''): self
{
Verify::String($this->actual)->json($message);
return $this;
}
public function stringMatchesFormat(string $format, string $message = ''): self
{
Verify::String($this->actual)->matchesFormat($format, $message);
return $this;
}
public function stringMatchesFormatFile(string $formatFile, string $message = ''): self
{
Verify::String($this->actual)->matchesFormatFile($formatFile, $message);
return $this;
}
public function stringMatchesRegExp(string $pattern, string $message = ''): self
{
Verify::String($this->actual)->matchesRegExp($pattern, $message);
return $this;
}
public function stringNotContainsString(string $needle, string $message = ''): self
{
Verify::String($this->actual)->notContainsString($needle, $message);
return $this;
}
public function stringNotContainsStringIgnoringCase(string $needle, string $message = ''): self
{
Verify::String($this->actual)->notContainsStringIgnoringCase($needle, $message);
return $this;
}
public function stringNotEndsWith(string $suffix, string $message = ''): self
{
Verify::String($this->actual)->notEndsWith($suffix, $message);
return $this;
}
public function stringNotEqualsFile(string $expectedFile, string $message = ''): self
{
Verify::String($this->actual)->notEqualsFile($expectedFile, $message);
return $this;
}
public function stringNotEqualsFileCanonicalizing(string $expectedFile, string $message = ''): self
{
Verify::String($this->actual)->notEqualsFileCanonicalizing($expectedFile, $message);
return $this;
}
public function stringNotEqualsFileIgnoringCase(string $expectedFile, string $message = ''): self
{
Verify::String($this->actual)->notEqualsFileIgnoringCase($expectedFile, $message);
return $this;
}
public function stringNotMatchesFormat($format, string $message = ''): self
{
Verify::String($this->actual)->notMatchesFormat($format, $message);
return $this;
}
public function stringNotMatchesFormatFile(string $formatFile, string $message = ''): self
{
Verify::String($this->actual)->notMatchesFormatFile($formatFile, $message);
return $this;
}
public function stringStartsNotWith(string $prefix, string $message = ''): self
{
Verify::String($this->actual)->startsNotWith($prefix, $message);
return $this;
}
public function stringStartsWith(string $prefix, string $message = ''): self
{
Verify::String($this->actual)->startsWith($prefix, $message);
return $this;
}
public function xmlFileEqualsXmlFile(string $expectedFile, string $message = ''): self
{
Verify::XmlFile($this->actual)->equalsXmlFile($expectedFile, $message);
return $this;
}
public function xmlFileNotEqualsXmlFile(string $expectedFile, string $message = ''): self
{
Verify::XmlFile($this->actual)->notEqualsXmlFile($expectedFile, $message);
return $this;
}
public function xmlStringEqualsXmlFile(string $expectedFile, string $message = ''): self
{
Verify::XmlString($this->actual)->equalsXmlFile($expectedFile, $message);
return $this;
}
public function xmlStringEqualsXmlString($expectedXml, string $message = ''): self
{
Verify::XmlString($this->actual)->equalsXmlString($expectedXml, $message);
return $this;
}
public function xmlStringNotEqualsXmlFile(string $expectedFile, string $message = ''): self
{
Verify::XmlString($this->actual)->notEqualsXmlFile($expectedFile, $message);
return $this;
}
public function xmlStringNotEqualsXmlString($expectedXml, string $message = ''): self
{
Verify::XmlString($this->actual)->notEqualsXmlString($expectedXml, $message);
return $this;
}
}

View File

@ -0,0 +1,194 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use ArrayAccess;
use Codeception\Exception\InvalidVerifyException;
use Codeception\Verify\Verify;
use Countable;
use PHPUnit\Framework\Assert;
use function basename;
use function is_array;
use function is_iterable;
class VerifyArray extends Verify
{
/**
* VerifyArray constructor
*
* @param array|ArrayAccess|Countable|iterable $actual
*/
public function __construct($actual)
{
if (
is_array($actual) ||
$actual instanceof ArrayAccess ||
$actual instanceof Countable ||
is_iterable($actual)
) {
parent::__construct($actual);
return;
}
throw new InvalidVerifyException(basename(self::class), $actual);
}
/**
* Verifies that a haystack contains a needle.
*
* @param $needle
* @param string $message
* @return self
*/
public function contains($needle, string $message = ''): self
{
Assert::assertContains($needle, $this->actual, $message);
return $this;
}
public function containsEquals($needle, string $message = ''): self
{
Assert::assertContainsEquals($needle, $this->actual, $message);
return $this;
}
/**
* Verifies that a haystack contains only values of a given type.
*
* @param string $type
* @param bool|null $isNativeType
* @param string $message
* @return self
*/
public function containsOnly(string $type, ?bool $isNativeType = null, string $message = ''): self
{
Assert::assertContainsOnly($type, $this->actual, $isNativeType, $message);
return $this;
}
/**
* Verifies that a haystack contains only instances of a given class name.
*
* @param string $className
* @param string $message
* @return self
*/
public function containsOnlyInstancesOf(string $className, string $message = ''): self
{
Assert::assertContainsOnlyInstancesOf($className, $this->actual, $message);
return $this;
}
/**
* Verifies the number of elements of an array, Countable or Traversable.
*
* @param int $expectedCount
* @param string $message
* @return self
*/
public function count(int $expectedCount, string $message = ''): self
{
Assert::assertCount($expectedCount, $this->actual, $message);
return $this;
}
/**
* Verifies that an array has a specified key.
*
* @param int|string $key
* @param string $message
* @return self
*/
public function hasKey($key, string $message = ''): self
{
Assert::assertArrayHasKey($key, $this->actual, $message);
return $this;
}
/**
* Verifies that an array does not have a specified key.
*
* @param int|string $key
* @param string $message
* @return self
*/
public function hasNotKey($key, string $message = ''): self
{
Assert::assertArrayNotHasKey($key, $this->actual, $message);
return $this;
}
/**
* Verifies that a haystack does not contain a needle.
*
* @param $needle
* @param string $message
* @return self
*/
public function notContains($needle, string $message = ''): self
{
Assert::assertNotContains($needle, $this->actual, $message);
return $this;
}
public function notContainsEquals($needle, string $message = ''): self
{
Assert::assertNotContainsEquals($needle, $this->actual, $message);
return $this;
}
/**
* Verifies that a haystack does not contain only values of a given type.
*
* @param string $type
* @param bool|null $isNativeType
* @param string $message
* @return self
*/
public function notContainsOnly(string $type, ?bool $isNativeType = null, string $message = ''): self
{
Assert::assertNotContainsOnly($type, $this->actual, $isNativeType, $message);
return $this;
}
/**
* Verifies the number of elements of an array, Countable or Traversable.
*
* @param int $expectedCount
* @param string $message
* @return self
*/
public function notCount(int $expectedCount, string $message = ''): self
{
Assert::assertNotCount($expectedCount, $this->actual, $message);
return $this;
}
/**
* Verifies that the size of two arrays (or `Countable` or `Traversable` objects) is not the same.
*
* @param Countable|iterable $expected
* @param string $message
* @return self
*/
public function notSameSize($expected, string $message = ''): self
{
Assert::assertNotSameSize($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that the size of two arrays (or `Countable` or `Traversable` objects) is the same.
*
* @param Countable|iterable $expected
* @param string $message
* @return self
*/
public function sameSize($expected, string $message = ''): self
{
Assert::assertSameSize($expected, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use Codeception\Verify\Verify;
use PHPUnit\Framework\Assert;
class VerifyBaseObject extends Verify
{
use VerifyDataTrait;
/**
* VerifyBaseObject constructor
*
* @param object $object
*/
public function __construct(object $object)
{
parent::__construct($object);
}
/**
* Verifies that an object has a specified attribute.
*
* @deprecated Deprecated in favour of hasProperty
*
* @param string $attributeName
* @param string $message
* @return self
*/
public function hasAttribute(string $attributeName, string $message = ''): self
{
Assert::assertObjectHasProperty($attributeName, $this->actual, $message);
return $this;
}
/**
* Verifies that an object does not have a specified attribute.
*
* @deprecated Deprecated in favour of notHasProperty
*
* @param string $attributeName
* @param string $message
* @return self
*/
public function notHasAttribute(string $attributeName, string $message = ''): self
{
Assert::assertObjectNotHasProperty($attributeName, $this->actual, $message);
return $this;
}
/**
* Verifies that an object has a specified property.
*
* @param string $propertyName
* @param string $message
* @return self
*/
public function hasProperty(string $propertyName, string $message = ''): self
{
Assert::assertObjectHasProperty($propertyName, $this->actual, $message);
return $this;
}
/**
* Verifies that an object does not have a specified property.
*
* @param string $propertyName
* @param string $message
* @return self
*/
public function notHasProperty(string $propertyName, string $message = ''): self
{
Assert::assertObjectNotHasProperty($propertyName, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use Codeception\Verify\Asserts\AssertThrows;
use Codeception\Verify\Verify;
use Exception;
use Throwable;
class VerifyCallable extends Verify
{
use AssertThrows;
public function __construct(callable $callable)
{
parent::__construct($callable);
}
/**
* @param Exception|string|null $throws
* @param string|false $message
* @return VerifyCallable
* @throws Throwable
*/
public function throws($throws = null, $message = false): self
{
return $this->assertThrows($throws, $message);
}
/**
* @param Exception|string|null $throws
* @param string|false $message
* @return $this
*/
public function doesNotThrow($throws = null, $message = false): self
{
return $this->assertDoesNotThrow($throws, $message);
}
}

View File

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use PHPUnit\Framework\Assert;
trait VerifyDataTrait
{
/**
* Verifies that a file/dir is not readable.
*
* @param string $message
* @return self
*/
public function isNotReadable(string $message = ''): self
{
Assert::assertIsNotReadable($this->actual, $message);
return $this;
}
/**
* Verifies that a file/dir is not writable.
*
* @param string $message
* @return self
*/
public function isNotWritable(string $message = ''): self
{
Assert::assertIsNotWritable($this->actual, $message);
return $this;
}
/**
* Verifies that a file/dir is readable.
*
* @param string $message
* @return self
*/
public function isReadable(string $message = ''): self
{
Assert::assertIsReadable($this->actual, $message);
return $this;
}
/**
* Verifies that a file/dir is writable.
*
* @param string $message
* @return self
*/
public function isWritable(string $message = ''): self
{
Assert::assertIsWritable($this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use Codeception\Verify\Verify;
use PHPUnit\Framework\Assert;
class VerifyDirectory extends Verify
{
use VerifyDataTrait;
/**
* VerifyDirectory constructor
*
* @param string $directory
*/
public function __construct(string $directory)
{
parent::__construct($directory);
}
/**
* Verifies that a directory does not exist.
*
* @param string $message
* @return self
*/
public function doesNotExist(string $message = ''): self
{
Assert::assertDirectoryDoesNotExist($this->actual, $message);
return $this;
}
/**
* Verifies that a directory exists.
*
* @param string $message
* @return self
*/
public function exists(string $message = ''): self
{
Assert::assertDirectoryExists($this->actual, $message);
return $this;
}
/**
* Verifies that a directory exists and is not readable.
*
* @param string $message
* @return self
*/
public function existsAndIsNotReadable(string $message = ''): self
{
Assert::assertDirectoryIsNotReadable($this->actual, $message);
return $this;
}
/**
* Verifies that a directory exists and is not writable.
*
* @param string $message
* @return self
*/
public function existsAndIsNotWritable(string $message = ''): self
{
Assert::assertDirectoryIsNotWritable($this->actual, $message);
return $this;
}
/**
* Verifies that a directory exists and is readable.
*
* @param string $message
* @return self
*/
public function existsAndIsReadable(string $message = ''): self
{
Assert::assertDirectoryIsReadable($this->actual, $message);
return $this;
}
/**
* Verifies that a directory exists and is writable.
*
* @param string $message
* @return self
*/
public function existsAndIsWritable(string $message = ''): self
{
Assert::assertDirectoryIsWritable($this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,168 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use Codeception\Verify\Verify;
use PHPUnit\Framework\Assert;
class VerifyFile extends Verify
{
use VerifyDataTrait;
public function __construct(string $actual)
{
parent::__construct($actual);
}
/**
* Verifies that a file does not exist.
*
* @param string $message
* @return self
*/
public function doesNotExists(string $message = ''): self
{
Assert::assertFileDoesNotExist($this->actual, $message);
return $this;
}
/**
* Verifies that the contents of one file is equal to the contents of another file.
*
* @param string $expected
* @param string $message
* @return self
*/
public function equals(string $expected, string $message = ''): self
{
Assert::assertFileEquals($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that the contents of one file is equal to the contents of another file (canonicalizing).
*
* @param string $expected
* @param string $message
* @return self
*/
public function equalsCanonicalizing(string $expected, string $message = ''): self
{
Assert::assertFileEqualsCanonicalizing($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that the contents of one file is equal to the contents of another file (ignoring case).
*
* @param string $expected
* @param string $message
* @return self
*/
public function equalsIgnoringCase(string $expected, string $message = ''): self
{
Assert::assertFileEqualsIgnoringCase($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that a file exists.
*
* @param string $message
* @return self
*/
public function exists(string $message = ''): self
{
Assert::assertFileExists($this->actual, $message);
return $this;
}
/**
* Verifies that a file exists and is not readable.
*
* @param string $message
* @return self
*/
public function existsAndIsNotReadable(string $message = ''): self
{
Assert::assertFileIsNotReadable($this->actual, $message);
return $this;
}
/**
* Verifies that a file exists and is not writable.
*
* @param string $message
* @return self
*/
public function existsAndIsNotWritable(string $message = ''): self
{
Assert::assertFileIsNotWritable($this->actual, $message);
return $this;
}
/**
* Verifies that a file exists and is readable.
*
* @param string $message
* @return self
*/
public function existsAndIsReadable(string $message = ''): self
{
Assert::assertFileIsReadable($this->actual, $message);
return $this;
}
/**
* Verifies that a file exists and is writable.
*
* @param string $message
* @return self
*/
public function existsAndIsWritable(string $message = ''): self
{
Assert::assertFileIsWritable($this->actual, $message);
return $this;
}
/**
* Verifies that the contents of one file is not equal to the contents of another file.
*
* @param $expected
* @param string $message
* @return self
*/
public function notEquals(string $expected, string $message = ''): self
{
Assert::assertFileNotEquals($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that the contents of one file is not equal to the contents of another file (canonicalizing).
*
* @param $expected
* @param string $message
* @return self
*/
public function notEqualsCanonicalizing(string $expected, string $message = ''): self
{
Assert::assertFileNotEqualsCanonicalizing($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that the contents of one file is not equal to the contents of another file (ignoring case).
*
* @param $expected
* @param string $message
* @return self
*/
public function notEqualsIgnoringCase(string $expected, string $message = ''): self
{
Assert::assertFileNotEqualsIgnoringCase($expected, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use Codeception\Verify\Verify;
use PHPUnit\Framework\Assert;
class VerifyJsonFile extends Verify
{
public function __construct(string $actualFile)
{
parent::__construct($actualFile);
}
/**
* Verifies that two JSON files are equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function equalsJsonFile(string $expectedFile, string $message = ''): self
{
Assert::assertJsonFileEqualsJsonFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that two JSON files are not equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notEqualsJsonFile(string $expectedFile, string $message = ''): self
{
Assert::assertJsonFileNotEqualsJsonFile($expectedFile, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use Codeception\Verify\Verify;
use PHPUnit\Framework\Assert;
class VerifyJsonString extends Verify
{
public function __construct(string $actualJson)
{
parent::__construct($actualJson);
}
/**
* Verifies that the generated JSON encoded object and the content of the given file are equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function equalsJsonFile(string $expectedFile, string $message = ''): self
{
Assert::assertJsonStringEqualsJsonFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that two given JSON encoded objects or arrays are equal.
*
* @param string $expectedJson
* @param string $message
* @return self
*/
public function equalsJsonString(string $expectedJson, string $message = ''): self
{
Assert::assertJsonStringEqualsJsonString($expectedJson, $this->actual, $message);
return $this;
}
/**
* Verifies that the generated JSON encoded object and the content of the given file are not equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notEqualsJsonFile(string $expectedFile, string $message = ''): self
{
Assert::assertJsonStringNotEqualsJsonFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that two given JSON encoded objects or arrays are not equal.
*
* @param string $expectedJson
* @param string $message
* @return self
*/
public function notEqualsJsonString(string $expectedJson, string $message = ''): self
{
Assert::assertJsonStringNotEqualsJsonString($expectedJson, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,651 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use Codeception\Verify\Verify;
use PHPUnit\Framework\Assert;
class VerifyMixed extends Verify
{
/**
* VerifyMixed constructor.
*
* @param mixed $actual
*/
public function __construct($actual)
{
parent::__construct($actual);
}
/**
* Verifies that a variable is empty.
*
* @param string $message
* @return self
*/
public function empty(string $message = ''): self
{
Assert::assertEmpty($this->actual, $message);
return $this;
}
/**
* Verifies that two variables are equal.
*
* @param $expected
* @param string $message
* @return self
*/
public function equals($expected, string $message = ''): self
{
Assert::assertEquals($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that two variables are equal (canonicalizing).
*
* @param $expected
* @param string $message
* @return self
*/
public function equalsCanonicalizing($expected, string $message = ''): self
{
Assert::assertEqualsCanonicalizing($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that two variables are equal (ignoring case).
*
* @param $expected
* @param string $message
* @return self
*/
public function equalsIgnoringCase($expected, string $message = ''): self
{
Assert::assertEqualsIgnoringCase($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that two variables are equal (with delta).
*
* @param $expected
* @param float $delta
* @param string $message
* @return self
*/
public function equalsWithDelta($expected, float $delta, string $message = ''): self
{
Assert::assertEqualsWithDelta($expected, $this->actual, $delta, $message);
return $this;
}
/**
* Verifies that a condition is false.
*
* @param string $message
* @return self
*/
public function false(string $message = ''): self
{
Assert::assertFalse($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is finite.
*
* @param string $message
* @return self
*/
public function finite(string $message = ''): self
{
Assert::assertFinite($this->actual, $message);
return $this;
}
/**
* Verifies that a value is greater than another value.
*
* @param $expected
* @param string $message
* @return self
*/
public function greaterThan($expected, string $message = ''): self
{
Assert::assertGreaterThan($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that a value is greater than or equal to another value.
*
* @param $expected
* @param string $message
* @return self
*/
public function greaterThanOrEqual($expected, string $message = ''): self
{
Assert::assertGreaterThanOrEqual($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that a variable is infinite.
*
* @param string $message
* @return self
*/
public function infinite(string $message = ''): self
{
Assert::assertInfinite($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of a given type.
*
* @param string $expected
* @param string $message
* @return self
*/
public function instanceOf(string $expected, string $message = ''): self
{
Assert::assertInstanceOf($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type array.
*
* @param string $message
* @return self
*/
public function isArray(string $message = ''): self
{
Assert::assertIsArray($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type bool.
*
* @param string $message
* @return self
*/
public function isBool(string $message = ''): self
{
Assert::assertIsBool($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type callable.
*
* @param string $message
* @return self
*/
public function isCallable(string $message = ''): self
{
Assert::assertIsCallable($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type resource and is closed.
*
* @param string $message
* @return self
*/
public function isClosedResource(string $message = ''): self
{
Assert::assertIsClosedResource($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type float.
*
* @param string $message
* @return self
*/
public function isFloat(string $message = ''): self
{
Assert::assertIsFloat($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type int.
*
* @param string $message
* @return self
*/
public function isInt(string $message = ''): self
{
Assert::assertIsInt($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type iterable.
*
* @param string $message
* @return self
*/
public function isIterable(string $message = ''): self
{
Assert::assertIsIterable($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type array.
*
* @param string $message
* @return self
*/
public function isNotArray(string $message = ''): self
{
Assert::assertIsNotArray($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type bool.
*
* @param string $message
* @return self
*/
public function isNotBool(string $message = ''): self
{
Assert::assertIsNotBool($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type callable.
*
* @param string $message
* @return self
*/
public function isNotCallable(string $message = ''): self
{
Assert::assertIsNotCallable($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type resource.
*
* @param string $message
* @return self
*/
public function isNotClosedResource(string $message = ''): self
{
Assert::assertIsNotClosedResource($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type float.
*
* @param string $message
* @return self
*/
public function isNotFloat(string $message = ''): self
{
Assert::assertIsNotFloat($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type int.
*
* @param string $message
* @return self
*/
public function isNotInt(string $message = ''): self
{
Assert::assertIsNotInt($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type iterable.
*
* @param string $message
* @return self
*/
public function isNotIterable(string $message = ''): self
{
Assert::assertIsNotIterable($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type numeric.
*
* @param string $message
* @return self
*/
public function isNotNumeric(string $message = ''): self
{
Assert::assertIsNotNumeric($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type object.
*
* @param string $message
* @return self
*/
public function isNotObject(string $message = ''): self
{
Assert::assertIsNotObject($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type resource.
*
* @param string $message
* @return self
*/
public function isNotResource(string $message = ''): self
{
Assert::assertIsNotResource($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type scalar.
*
* @param string $message
* @return self
*/
public function isNotScalar(string $message = ''): self
{
Assert::assertIsNotScalar($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of type string.
*
* @param string $message
* @return self
*/
public function isNotString(string $message = ''): self
{
Assert::assertIsNotString($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type numeric.
*
* @param string $message
* @return self
*/
public function isNumeric(string $message = ''): self
{
Assert::assertIsNumeric($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type object.
*
* @param string $message
* @return self
*/
public function isObject(string $message = ''): self
{
Assert::assertIsObject($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type resource.
*
* @param string $message
* @return self
*/
public function isResource(string $message = ''): self
{
Assert::assertIsResource($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type scalar.
*
* @param string $message
* @return self
*/
public function isScalar(string $message = ''): self
{
Assert::assertIsScalar($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is of type string.
*
* @param string $message
* @return self
*/
public function isString(string $message = ''): self
{
Assert::assertIsString($this->actual, $message);
return $this;
}
/**
* Verifies that a value is smaller than another value.
*
* @param $expected
* @param string $message
* @return self
*/
public function lessThan($expected, string $message = ''): self
{
Assert::assertLessThan($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that a value is smaller than or equal to another value.
*
* @param $expected
* @param string $message
* @return self
*/
public function lessThanOrEqual($expected, string $message = ''): self
{
Assert::assertLessThanOrEqual($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that a variable is nan.
*
* @param string $message
* @return self
*/
public function nan(string $message = ''): self
{
Assert::assertNan($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not empty.
*
* @param string $message
* @return self
*/
public function notEmpty(string $message = ''): self
{
Assert::assertNotEmpty($this->actual, $message);
return $this;
}
/**
* Verifies that two variables are not equal.
*
* @param $expected
* @param string $message
* @return self
*/
public function notEquals($expected, string $message = ''): self
{
Assert::assertNotEquals($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that two variables are not equal (canonicalizing).
*
* @param $expected
* @param string $message
* @return self
*/
public function notEqualsCanonicalizing($expected, string $message = ''): self
{
Assert::assertNotEqualsCanonicalizing($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that two variables are not equal (ignoring case).
*
* @param $expected
* @param string $message
* @return self
*/
public function notEqualsIgnoringCase($expected, string $message = ''): self
{
Assert::assertNotEqualsIgnoringCase($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that two variables are not equal (with delta).
*
* @param $expected
* @param float $delta
* @param string $message
* @return self
*/
public function notEqualsWithDelta($expected, float $delta, string $message = ''): self
{
Assert::assertNotEqualsWithDelta($expected, $this->actual, $delta, $message);
return $this;
}
/**
* Verifies that a condition is not false.
*
* @param string $message
* @return self
*/
public function notFalse(string $message = ''): self
{
Assert::assertNotFalse($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not of a given type.
*
* @param string $expected
* @param string $message
* @return self
*/
public function notInstanceOf(string $expected, string $message = ''): self
{
Assert::assertNotInstanceOf($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that a variable is not null.
*
* @param string $message
* @return self
*/
public function notNull(string $message = ''): self
{
Assert::assertNotNull($this->actual, $message);
return $this;
}
/**
* Verifies that two variables do not have the same type and value.
*
* @param $expected
* @param string $message
* @return self
*/
public function notSame($expected, string $message = ''): self
{
Assert::assertNotSame($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that a condition is not true.
*
* @param string $message
* @return self
*/
public function notTrue(string $message = ''): self
{
Assert::assertNotTrue($this->actual, $message);
return $this;
}
/**
* Verifies that a variable is null.
*
* @param string $message
* @return self
*/
public function null(string $message = ''): self
{
Assert::assertNull($this->actual, $message);
return $this;
}
/**
* Verifies that two variables have the same type and value.
*
* @param $expected
* @param string $message
* @return self
*/
public function same($expected, string $message = ''): self
{
Assert::assertSame($expected, $this->actual, $message);
return $this;
}
/**
* Verifies that a condition is true.
*
* @param string $message
* @return self
*/
public function true(string $message = ''): self
{
Assert::assertTrue($this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,260 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use Codeception\Verify\Verify;
use PHPUnit\Framework\Assert;
class VerifyString extends Verify
{
public function __construct(string $string)
{
parent::__construct($string);
}
public function containsString(string $needle, string $message = ''): self
{
Assert::assertStringContainsString($needle, $this->actual, $message);
return $this;
}
public function containsStringIgnoringCase(string $needle, string $message = ''): self
{
Assert::assertStringContainsStringIgnoringCase($needle, $this->actual, $message);
return $this;
}
/**
* Verifies that a string does not match a given regular expression.
*
* @param string $pattern
* @param string $message
* @return self
*/
public function doesNotMatchRegExp(string $pattern, string $message = ''): self
{
Assert::assertDoesNotMatchRegularExpression($pattern, $this->actual, $message);
return $this;
}
/**
* Verifies that a string ends with a given suffix.
*
* @param string $suffix
* @param string $message
* @return self
*/
public function endsWith(string $suffix, string $message = ''): self
{
Assert::assertStringEndsWith($suffix, $this->actual, $message);
return $this;
}
/**
* Verifies that the contents of a string is equal to the contents of a file.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function equalsFile(string $expectedFile, string $message = ''): self
{
Assert::assertStringEqualsFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that the contents of a string is equal to the contents of a file (canonicalizing).
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function equalsFileCanonicalizing(string $expectedFile, string $message = ''): self
{
Assert::assertStringEqualsFileCanonicalizing($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that the contents of a string is equal to the contents of a file (ignoring case).
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function equalsFileIgnoringCase(string $expectedFile, string $message = ''): self
{
Assert::assertStringEqualsFileIgnoringCase($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that a string is a valid JSON string.
*
* @param string $message
* @return self
*/
public function json(string $message = ''): self
{
Assert::assertJson($this->actual, $message);
return $this;
}
/**
* Verifies that a string matches a given format string.
*
* @param string $format
* @param string $message
* @return self
*/
public function matchesFormat(string $format, string $message = ''): self
{
Assert::assertStringMatchesFormat($format, $this->actual, $message);
return $this;
}
/**
* Verifies that a string matches a given format file.
*
* @param string $formatFile
* @param string $message
* @return self
*/
public function matchesFormatFile(string $formatFile, string $message = ''): self
{
Assert::assertStringMatchesFormatFile($formatFile, $this->actual, $message);
return $this;
}
/**
* Verifies that a string matches a given regular expression.
*
* @param string $pattern
* @param string $message
* @return self
*/
public function matchesRegExp(string $pattern, string $message = ''): self
{
Assert::assertMatchesRegularExpression($pattern, $this->actual, $message);
return $this;
}
public function notContainsString(string $needle, string $message = ''): self
{
Assert::assertStringNotContainsString($needle, $this->actual, $message);
return $this;
}
public function notContainsStringIgnoringCase(string $needle, string $message = ''): self
{
Assert::assertStringNotContainsStringIgnoringCase($needle, $this->actual, $message);
return $this;
}
/**
* Verifies that a string ends not with a given suffix.
*
* @param string $suffix
* @param string $message
* @return self
*/
public function notEndsWith(string $suffix, string $message = ''): self
{
Assert::assertStringEndsNotWith($suffix, $this->actual, $message);
return $this;
}
/**
* Verifies that the contents of a string is not equal to the contents of a file.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notEqualsFile(string $expectedFile, string $message = ''): self
{
Assert::assertStringNotEqualsFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that the contents of a string is not equal to the contents of a file (canonicalizing).
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notEqualsFileCanonicalizing(string $expectedFile, string $message = ''): self
{
Assert::assertStringNotEqualsFileCanonicalizing($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that the contents of a string is not equal to the contents of a file (ignoring case).
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notEqualsFileIgnoringCase(string $expectedFile, string $message = ''): self
{
Assert::assertStringNotEqualsFileIgnoringCase($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that a string does not match a given format string.
*
* @param $format
* @param string $message
* @return self
*/
public function notMatchesFormat(string $format, string $message = ''): self
{
Assert::assertStringNotMatchesFormat($format, $this->actual, $message);
return $this;
}
/**
* Verifies that a string does not match a given format string.
*
* @param string $formatFile
* @param string $message
* @return self
*/
public function notMatchesFormatFile(string $formatFile, string $message = ''): self
{
Assert::assertStringNotMatchesFormatFile($formatFile, $this->actual, $message);
return $this;
}
/**
* Verifies that a string starts not with a given prefix.
*
* @param string $prefix
* @param string $message
* @return self
*/
public function startsNotWith(string $prefix, string $message = ''): self
{
Assert::assertStringStartsNotWith($prefix, $this->actual, $message);
return $this;
}
/**
* Verifies that a string starts with a given prefix.
*
* @param string $prefix
* @param string $message
* @return self
*/
public function startsWith(string $prefix, string $message = ''): self
{
Assert::assertStringStartsWith($prefix, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use Codeception\Verify\Verify;
use PHPUnit\Framework\Assert;
class VerifyXmlFile extends Verify
{
public function __construct(string $actualFile)
{
parent::__construct($actualFile);
}
/**
* Verifies that two XML files are equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function equalsXmlFile(string $expectedFile, string $message = ''): self
{
Assert::assertXmlFileEqualsXmlFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that two XML files are not equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notEqualsXmlFile(string $expectedFile, string $message = ''): self
{
Assert::assertXmlFileNotEqualsXmlFile($expectedFile, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify\Verifiers;
use Codeception\Exception\InvalidVerifyException;
use Codeception\Verify\Verify;
use DOMDocument;
use PHPUnit\Framework\Assert;
use function basename;
use function is_string;
class VerifyXmlString extends Verify
{
/**
* VerifyXmlString constructor
*
* @param DOMDocument|string $actualXml
*/
public function __construct($actualXml)
{
if (is_string($actualXml) || $actualXml instanceof DOMDocument) {
parent::__construct($actualXml);
return;
}
throw new InvalidVerifyException(basename(self::class), $actualXml);
}
/**
* Verifies that two XML documents are equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function equalsXmlFile(string $expectedFile, string $message = ''): self
{
Assert::assertXmlStringEqualsXmlFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that two XML documents are equal.
*
* @param DOMDocument|string $expectedXml
* @param string $message
* @return self
*/
public function equalsXmlString($expectedXml, string $message = ''): self
{
Assert::assertXmlStringEqualsXmlString($expectedXml, $this->actual, $message);
return $this;
}
/**
* Verifies that two XML documents are not equal.
*
* @param string $expectedFile
* @param string $message
* @return self
*/
public function notEqualsXmlFile(string $expectedFile, string $message = ''): self
{
Assert::assertXmlStringNotEqualsXmlFile($expectedFile, $this->actual, $message);
return $this;
}
/**
* Verifies that two XML documents are not equal.
*
* @param DOMDocument|string $expectedXml
* @param string $message
* @return self
*/
public function notEqualsXmlString($expectedXml, string $message = ''): self
{
Assert::assertXmlStringNotEqualsXmlString($expectedXml, $this->actual, $message);
return $this;
}
}

View File

@ -0,0 +1,107 @@
<?php
declare(strict_types=1);
namespace Codeception\Verify;
use ArrayAccess;
use Codeception\Verify\Verifiers\VerifyArray;
use Codeception\Verify\Verifiers\VerifyCallable;
use Codeception\Verify\Verifiers\VerifyDirectory;
use Codeception\Verify\Verifiers\VerifyFile;
use Codeception\Verify\Verifiers\VerifyJsonFile;
use Codeception\Verify\Verifiers\VerifyJsonString;
use Codeception\Verify\Verifiers\VerifyMixed;
use Codeception\Verify\Verifiers\VerifyBaseObject;
use Codeception\Verify\Verifiers\VerifyString;
use Codeception\Verify\Verifiers\VerifyXmlFile;
use Codeception\Verify\Verifiers\VerifyXmlString;
use Countable;
abstract class Verify
{
/** @var mixed */
protected $actual = null;
/**
* Verify constructor
*
* @param mixed $actual
*/
protected function __construct($actual)
{
$this->actual = $actual;
}
/**
* @param mixed $actual
* @return self
*/
public function __invoke($actual): self
{
return $this($actual);
}
public static function File(string $filename): VerifyFile
{
return new VerifyFile($filename);
}
public static function JsonFile(string $filename): VerifyJsonFile
{
return new VerifyJsonFile($filename);
}
public static function JsonString(string $json): VerifyJsonString
{
return new VerifyJsonString($json);
}
public static function XmlFile(string $filename): VerifyXmlFile
{
return new VerifyXmlFile($filename);
}
public static function XmlString(string $xml): VerifyXmlString
{
return new VerifyXmlString($xml);
}
public static function BaseObject(object $object): VerifyBaseObject
{
return new VerifyBaseObject($object);
}
public static function Directory(string $directory): VerifyDirectory
{
return new VerifyDirectory($directory);
}
/**
* @param array|ArrayAccess|Countable|iterable $array
* @return VerifyArray
*/
public static function Array($array): VerifyArray
{
return new VerifyArray($array);
}
public static function String(string $string): VerifyString
{
return new VerifyString($string);
}
public static function Callable(callable $callable): VerifyCallable
{
return new VerifyCallable($callable);
}
/**
* @param mixed $actual
* @return VerifyMixed
*/
public static function Mixed($actual): VerifyMixed
{
return new VerifyMixed($actual);
}
}

View File

@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
use Codeception\Verify\Expectations\ExpectAny;
use Codeception\Verify\Verifiers\VerifyAny;
if (!function_exists('verify'))
{
/**
* @param mixed $actual
* @return VerifyAny
*/
function verify($actual): VerifyAny
{
return new VerifyAny($actual);
}
}
if (!function_exists('verify_that'))
{
/**
* @param mixed $actual
* @return VerifyAny
*/
function verify_that($actual): VerifyAny
{
return new VerifyAny($actual);
}
}
if (!function_exists('expect'))
{
/**
* @param mixed $actual
* @return ExpectAny
*/
function expect($actual): ExpectAny {
return new ExpectAny($actual);
}
}

View File

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
include_once __DIR__.'/../src/Codeception/bootstrap.php';
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase;
final class ExpectTest extends TestCase
{
public function testObjectToHaveProperty(): void
{
$object = new \Stdclass();
$object->bar = 'baz';
expect($object)->baseObjectToHaveProperty('bar');
verify(function () use ($object): void {
expect($object)->baseObjectToHaveProperty('foo', 'foobar');
})->callableThrows(new ExpectationFailedException("foobar\nFailed asserting that object of class \"stdClass\" has property \"foo\"."));
}
public function testObjectNotToHaveProperty(): void
{
$object = new \Stdclass();
$object->bar = 'baz';
expect($object)->baseObjectNotToHaveProperty('foo');
verify(function () use ($object): void {
expect($object)->baseObjectNotToHaveProperty('bar', 'foobar');
})->callableThrows(new ExpectationFailedException("foobar\nFailed asserting that object of class \"stdClass\" does not have property \"bar\"."));
}
}

View File

@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
include_once __DIR__.'/../src/Codeception/bootstrap.php';
use Codeception\Verify\Verify;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
include __DIR__.'/../vendor/autoload.php';
final class InheritanceTest extends TestCase
{
public function testVerifyCanBeExtended(): void
{
$myVerify = new MyVerify;
$myVerify->success();
$myVerify::Mixed('this also')->notEquals('works');
verify(new MyVerify())->instanceOf(Verify::class);
}
}
final class MyVerify extends Verify
{
public function __construct($actual = null)
{
parent::__construct($actual);
}
public function success(string $message = ''): void
{
Assert::assertTrue(true, $message);
}
}

View File

@ -0,0 +1,357 @@
<?php
declare(strict_types=1);
include_once __DIR__.'/../src/Codeception/bootstrap.php';
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\Version;
final class VerifyTest extends TestCase
{
protected DOMDocument $xml;
protected function setUp(): void
{
$this->xml = new DOMDocument;
$this->xml->loadXML('<foo><bar>Baz</bar><bar>Baz</bar></foo>');
}
public function testEquals(): void
{
verify(5)->equals(5);
verify('hello')->equals('hello');
verify(5)->equals(5, 'user have 5 posts');
verify(3.251)->equalsWithDelta(3.25, 0.01);
verify(3.251)->equalsWithDelta(3.25, 0.01, 'respects delta');
verify(__FILE__)->fileEquals(__FILE__);
}
public function testNotEquals(): void
{
verify(3)->notEquals(5);
verify(3.252)->notEqualsWithDelta(3.25, 0.001);
verify(3.252)->notEqualsWithDelta(3.25, 0.001, 'respects delta');
verify(__FILE__)->fileNotEquals(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'composer.json');
}
public function testContains(): void
{
verify([3, 2])->arrayContains(3);
verify([3, 2])->arrayNotContains(5, 'user have 5 posts');
}
public function testGreaterLowerThan(): void
{
verify(7)->greaterThan(5);
verify(7)->lessThan(10);
verify(7)->lessThanOrEqual(7);
verify(7)->lessThanOrEqual(8);
verify(7)->greaterThanOrEqual(7);
verify(7)->greaterThanOrEqual(5);
}
public function testTrueFalseNull(): void
{
verify(true)->true();
verify(false)->false();
verify(null)->null();
verify(true)->notNull();
verify(false)->false('something should be false');
verify(true)->true('something should be true');
}
public function testEmptyNotEmpty(): void
{
verify(array('3', '5'))->notEmpty();
verify(array())->empty();
}
public function testArrayHasKey(): void
{
$errors = ['title' => 'You should add title'];
verify($errors)->arrayHasKey('title');
verify($errors)->arrayHasNotKey('body');
}
public function testIsInstanceOf(): void
{
$testClass = new DateTime();
verify($testClass)->instanceOf(DateTime::class);
verify($testClass)->notInstanceOf(DateTimeZone::class);
}
public function testContainsOnly(): void
{
verify(['1', '2', '3'])->arrayContainsOnly('string');
verify(['1', '2', 3])->arrayNotContainsOnly('string');
}
public function testContainsOnlyInstancesOf(): void
{
verify([new FakeClassForTesting(), new FakeClassForTesting(), new FakeClassForTesting()])
->arrayContainsOnlyInstancesOf('FakeClassForTesting');
}
public function testCount(): void
{
verify([1, 2, 3])->arrayCount(3);
verify([1, 2, 3])->arrayNotCount(2);
}
public function testFileExists(): void
{
verify(__FILE__)->fileExists();
verify('completelyrandomfilename.txt')->fileDoesNotExists();
}
public function testEqualsJsonFile(): void
{
verify(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'json-test-file.json')
->jsonFileEqualsJsonFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'equal-json-test-file.json');
verify('{"some" : "data"}')->jsonStringEqualsJsonFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'equal-json-test-file.json');
}
public function testEqualsJsonString(): void
{
verify('{"some" : "data"}')->jsonStringEqualsJsonString('{"some" : "data"}');
}
public function testRegExp(): void
{
verify('somestring')->stringMatchesRegExp('/string/');
}
public function testMatchesFormat(): void
{
verify('somestring')->stringMatchesFormat('%s');
verify('somestring')->stringNotMatchesFormat('%i');
}
public function testMatchesFormatFile(): void
{
verify('23')->stringMatchesFormatFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'format-file.txt');
verify('asdfas')->stringNotMatchesFormatFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'format-file.txt');
}
public function testSame(): void
{
verify(1)->same(0+1);
verify(1)->notSame(true);
}
public function testEndsWith(): void
{
verify('A completely not funny string')->stringEndsWith('ny string');
verify('A completely not funny string')->stringNotEndsWith('A completely');
}
public function testEqualsFile(): void
{
verify('%i')->stringEqualsFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'format-file.txt');
verify('Another string')->stringNotEqualsFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'format-file.txt');
}
public function testStartsWith(): void
{
verify('A completely not funny string')->stringStartsWith('A completely');
verify('A completely not funny string')->stringStartsNotWith('string');
}
public function testEqualsXmlFile(): void
{
verify(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'xml-test-file.xml')
->xmlFileEqualsXmlFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'xml-test-file.xml');
verify('<foo><bar>Baz</bar><bar>Baz</bar></foo>')
->xmlStringEqualsXmlFile(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'xml-test-file.xml');
}
public function testEqualsXmlString(): void
{
verify('<foo><bar>Baz</bar><bar>Baz</bar></foo>')
->xmlStringEqualsXmlString('<foo><bar>Baz</bar><bar>Baz</bar></foo>');
}
public function testStringContainsString(): void
{
verify('foo bar')->stringContainsString('o b');
verify('foo bar')->stringNotContainsString('BAR');
}
public function testStringContainsStringIgnoringCase(): void
{
verify('foo bar')->stringContainsStringIgnoringCase('O b');
verify('foo bar')->stringNotContainsStringIgnoringCase('baz');
}
public function testIsString(): void
{
verify('foo bar')->isString();
verify(false)->isNotString();
}
public function testIsArray(): void
{
verify([1,2,3])->isArray();
verify(false)->isNotArray();
}
public function testIsBool(): void
{
verify(false)->isBool();
verify([1,2,3])->isNotBool();
}
public function testIsFloat(): void
{
verify(1.5)->isFloat();
verify(1)->isNotFloat();
}
public function testIsInt(): void
{
verify(5)->isInt();
verify(1.5)->isNotInt();
}
public function testIsNumeric(): void
{
verify('1.5')->isNumeric();
verify('foo bar')->isNotNumeric();
}
public function testIsObject(): void
{
verify(new stdClass)->isObject();
verify(false)->isNotObject();
}
public function testIsResource(): void
{
verify(fopen(__FILE__, 'r'))->isResource();
verify(false)->isNotResource();
}
public function testIsScalar(): void
{
verify('foo bar')->isScalar();
verify([1,2,3])->isNotScalar();
}
public function testIsCallable(): void
{
verify(function(): void {})->isCallable();
verify(false)->isNotCallable();
}
public function testEqualsCanonicalizing(): void
{
verify([3, 2, 1])->equalsCanonicalizing([1, 2, 3]);
}
public function testNotEqualsCanonicalizing(): void
{
verify([3, 2, 1])->notEqualsCanonicalizing([2, 3, 0, 1]);
}
public function testEqualsIgnoringCase(): void
{
verify('foo')->equalsIgnoringCase('FOO');
}
public function testNotEqualsIgnoringCase(): void
{
verify('foo')->notEqualsIgnoringCase('BAR');
}
public function testEqualsWithDelta(): void
{
verify(1.01)->equalsWithDelta(1.0, 0.1);
}
public function testNotEqualsWithDelta(): void
{
verify(1.2)->notEqualsWithDelta(1.0, 0.1);
}
public function testThrows(): void
{
$func = function (): void {
throw new Exception('foo');
};
verify($func)->callableThrows();
verify($func)->callableThrows(Exception::class);
verify($func)->callableThrows(Exception::class, 'foo');
verify($func)->callableThrows(new Exception());
verify($func)->callableThrows(new Exception('foo'));
verify(function () use ($func): void {
verify($func)->callableThrows(RuntimeException::class);
})->callableThrows(ExpectationFailedException::class);
verify(function (): void {
verify(function (): void {})->callableThrows(Exception::class);
})->callableThrows(new ExpectationFailedException("exception 'Exception' was not thrown as expected"));
}
public function testDoesNotThrow(): void
{
$func = function (): void {
throw new Exception('foo');
};
verify(function (): void {})->callableDoesNotThrow();
verify($func)->callableDoesNotThrow(RuntimeException::class);
verify($func)->callableDoesNotThrow(RuntimeException::class, 'bar');
verify($func)->callableDoesNotThrow(RuntimeException::class, 'foo');
verify($func)->callableDoesNotThrow(new RuntimeException());
verify($func)->callableDoesNotThrow(new RuntimeException('bar'));
verify($func)->callableDoesNotThrow(new RuntimeException('foo'));
verify($func)->callableDoesNotThrow(Exception::class, 'bar');
verify($func)->callableDoesNotThrow(new Exception('bar'));
verify(function () use ($func): void {
verify($func)->callableDoesNotThrow();
})->callableThrows(new ExpectationFailedException('exception was not expected to be thrown'));
verify(function () use ($func): void {
verify($func)->callableDoesNotThrow(Exception::class);
})->callableThrows(new ExpectationFailedException("exception 'Exception' was not expected to be thrown"));
verify(function () use ($func): void {
verify($func)->callableDoesNotThrow(Exception::class, 'foo');
})->callableThrows(new ExpectationFailedException("exception 'Exception' with message 'foo' was not expected to be thrown"));
}
public function testObjectHasProperty(): void
{
$object = new \Stdclass();
$object->bar = 'baz';
verify($object)->baseObjectHasProperty('bar');
verify(function () use ($object): void {
verify($object)->baseObjectHasProperty('foo', 'foobar');
})->callableThrows(new ExpectationFailedException("foobar\nFailed asserting that object of class \"stdClass\" has property \"foo\"."));
}
public function testObjectNotHasProperty(): void
{
$object = new \Stdclass();
$object->bar = 'baz';
verify($object)->baseObjectNotHasProperty('foo');
verify(function () use ($object): void {
verify($object)->baseObjectNotHasProperty('bar', 'foobar');
})->callableThrows(new ExpectationFailedException("foobar\nFailed asserting that object of class \"stdClass\" does not have property \"bar\"."));
}
}
class FakeClassForTesting
{
static $staticProperty;
}

View File

@ -0,0 +1,3 @@
{
"some" : "data"
}

View File

@ -0,0 +1 @@
%i

View File

@ -0,0 +1,3 @@
{
"some" : "data"
}

View File

@ -0,0 +1 @@
<foo><bar>Baz</bar><bar>Baz</bar></foo>