2017 © Pedro Peláez
 

library verify

BDD assertion library for PHPUnit

image

codeception/verify

BDD assertion library for PHPUnit

  • Sunday, November 12, 2017
  • by davert
  • Repository
  • 11 Watchers
  • 69 Stars
  • 2,536,566 Installations
  • PHP
  • 579 Dependents
  • 19 Suggesters
  • 17 Forks
  • 0 Open issues
  • 16 Versions
  • 10 % Grown

The README.md

Verify

BDD Assertions for PHPUnit or Codeception, (*1)

Latest Stable Version Total Downloads Build Status License StandWithUkraine, (*2)

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., (*3)

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

Installation

Requires PHP 7.4 or higher, (*5)

composer require codeception/verify --dev

:arrow_up: Upgrade from 1.x by following [the upgrade guide.][10], (*6)

Usage

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

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., (*8)

Alternative Syntax

If you follow TDD/BDD you'd rather use expect instead of verify:, (*9)

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

:page_facing_up: See Expectations full list here., (*10)

Or verify_that which is just an alias function:, (*11)

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:, (*12)

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!, (*13)

$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, (*14)

The Versions

12/11 2017

dev-master

9999999-dev

BDD assertion library for PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2017

1.0.0

1.0.0.0

BDD assertion library for PHPUnit

  Sources   Download

MIT

The Requires

 

12/07 2017

0.4.0

0.4.0.0

BDD assertion library for PHPUnit

  Sources   Download

MIT

The Development Requires

09/01 2017

0.3.3

0.3.3.0

BDD assertion library for PHPUnit

  Sources   Download

MIT

The Development Requires

30/08 2016

0.3.2

0.3.2.0

BDD assertion library for PHPUnit

  Sources   Download

MIT

The Development Requires

13/07 2016

0.3.1

0.3.1.0

BDD assertion library for PHPUnit

  Sources   Download

The Development Requires

27/11 2015

0.3.0

0.3.0.0

BDD assertion library for PHPUnit

  Sources   Download

The Development Requires

22/01 2014

0.2.7

0.2.7.0

BDD assertion library for PHPUnit

  Sources   Download

The Development Requires

17/01 2014

0.2.6

0.2.6.0

BDD assertion library for PHPUnit

  Sources   Download

The Development Requires

05/01 2014

0.2.5

0.2.5.0

BDD assertion library for PHPUnit

  Sources   Download

The Development Requires

04/01 2014

0.2.4

0.2.4.0

BDD assertion library for PHPUnit

  Sources   Download

The Development Requires

03/01 2014

0.2.3

0.2.3.0

BDD assertion library for PHPUnit

  Sources   Download

The Development Requires

04/10 2013

0.2.2

0.2.2.0

BDD assertion library for PHPUnit

  Sources   Download

The Development Requires

03/10 2013

0.2.1

0.2.1.0

BDD assertion library for PHPUnit

  Sources   Download

The Development Requires

03/10 2013

0.2.0

0.2.0.0

BDD assertion library for PHPUnit

  Sources   Download

The Development Requires

25/07 2013

0.1.0

0.1.0.0

BDD assertion library for PHPUnit

  Sources   Download

The Development Requires