All Projects → Codeception → Verify

Codeception / Verify

Licence: mit
BDD Assertions for PHPUnit and Codeception

Projects that are alternatives of or similar to Verify

Expect More
Curried Type Testing library, and Test Matchers for Jest
Stars: ✭ 124 (-2.36%)
Mutual labels:  bdd, assertions
karate
Test Automation Made Simple
Stars: ✭ 6,384 (+4926.77%)
Mutual labels:  bdd, assertions
Expekt
BDD assertion library for Kotlin
Stars: ✭ 163 (+28.35%)
Mutual labels:  bdd, assertions
Grappa
Behavior-oriented, expressive, human-friendly Python assertion library for the 21st century
Stars: ✭ 119 (-6.3%)
Mutual labels:  bdd, assertions
Tester
Tester: enjoyable unit testing in PHP with code coverage reporter. 🍏🍏🍎🍏
Stars: ✭ 281 (+121.26%)
Mutual labels:  assertions, phpunit
Should.js
BDD style assertions for node.js -- test framework agnostic
Stars: ✭ 1,908 (+1402.36%)
Mutual labels:  bdd, assertions
chai
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
Stars: ✭ 7,842 (+6074.8%)
Mutual labels:  bdd, assertions
Postman Bdd
A BDD test framework for Postman and Newman
Stars: ✭ 139 (+9.45%)
Mutual labels:  bdd, assertions
phpunit-expect
BDD-style assertions for PHPUnit
Stars: ✭ 15 (-88.19%)
Mutual labels:  bdd, phpunit
codeceptjs-bdd
Javascript BDD UI Automation Framework. Exclusive LWC Shadow DOM Support. Playwright, Webdriver.io, Appium, Saucelabs.
Stars: ✭ 35 (-72.44%)
Mutual labels:  bdd, assertions
Catch Exception
Stars: ✭ 137 (+7.87%)
Mutual labels:  bdd, assertions
Karate
Test Automation Made Simple
Stars: ✭ 5,497 (+4228.35%)
Mutual labels:  assertions, bdd
Pester
Pester is the ubiquitous test and mock framework for PowerShell.
Stars: ✭ 2,620 (+1962.99%)
Mutual labels:  bdd, assertions
concise
✅ Concise is test framework for using plain English and minimal code, built on PHPUnit.
Stars: ✭ 47 (-62.99%)
Mutual labels:  phpunit, assertions
Codeception
Full-stack testing PHP framework
Stars: ✭ 4,401 (+3365.35%)
Mutual labels:  bdd, phpunit
Should Enzyme
Useful functions for testing React Components with Enzyme.
Stars: ✭ 41 (-67.72%)
Mutual labels:  bdd, assertions
Dd
Binary Decision Diagrams (BDDs) in pure Python and Cython wrappers of CUDD, Sylvan, and BuDDy
Stars: ✭ 102 (-19.69%)
Mutual labels:  bdd
Scram
Probabilistic Risk Analysis Tool (fault tree analysis, event tree analysis, etc.)
Stars: ✭ 98 (-22.83%)
Mutual labels:  bdd
Cucumberjvmexamples
Cucumber JVM with Selenium Java
Stars: ✭ 98 (-22.83%)
Mutual labels:  bdd
Behat Wordpress Extension
WordHat: Behat for WordPress
Stars: ✭ 109 (-14.17%)
Mutual labels:  bdd

Verify

BDD Assertions for PHPUnit or Codeception

Latest Stable Version Total Downloads Build Status License

This is very tiny wrapper for PHPUnit assertions, that are aimed to make tests a bit more readable. With BDD assertions influenced by Chai, Jasmine, and RSpec your assertions would be a bit closer to natural language.

⚠️ This is the Verify 2.0 documentation, to see v1.x docs click here.

Installation

Requires PHP 7.1 or higher

composer require codeception/verify --dev

⬆️ Upgrade from 1.x by following the upgrade guide.

Usage

Use in any test verify function instead of $this->assert* methods:

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 !

📄 See Verifiers full list here.

Alternative Syntax

If you follow TDD/BDD you'd rather use expect instead of verify:

expect($user->getNumPosts())
    ->notToBeNull()
    ->toBeInt()
    ->toEqual(5, 'user have 5 posts');

📄 See Expectations full list here.

Or verify_that which is just an alias function:

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:

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!

$myVerify = new MyVerify;

$myVerify->success('it works!');

$myVerify::Mixed('this also')->notEquals('works');

License

Verify is open-sourced software licensed under the MIT License. © Codeception PHP Testing Framework

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].