Download the PHP package codeception/domain-assert without Composer
On this page you can find all versions of the php package codeception/domain-assert. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codeception/domain-assert
More information about codeception/domain-assert
Files in codeception/domain-assert
Package domain-assert
Short Description Custom assertions for PHPUnit and Codeception
License MIT
Homepage http://codeception.com/
Informations about the package domain-assert
Domain Assertions
Assertion library for PHPUnit or Codeception powered by Symfony Expression Language.
Pitch
This tiny library helps you to create domain-specific assertions in tests:
Instead of:
use
Why?
See how test fails in first example:
And how test fails in second example:
What makes more sense to you? In second example you get the business logic behind the assertion as well as values passed into it.
That's why if you have business logic in your project domain-assert
is your choice.
How To Use It
Install this package:
Create a trait with a custom assertion. We recommend using traits as you can reuse them accross different test cases.
In this example we check that $user
exists and $user->isValid()
return true;
That's all! Now inject this trait to TestCases and use it.
Defining Business Rules
This library uses Expression Language to define domain rules for assertions.
Let's define a rule to check if we have enough products in the stock:
We have 3 items here: product
, stock
, and amount
which is a number of items we need.
Let's create assertion according to this rule:
Now it can be used inside your tests:
Advanced Concepts
- Instead of
$this->assertThat
you can call static version of this method:PHPUnit\Framework\Assert::assertThat
Codeception\DomainRule
extendsPHPUnit\Framework\Constraint
.Codeception\DomainRule
usesSymfony\Component\ExpressionLanguage\ExpressionLanguage
- Expression Language can be extended by calling
$domainRule->getLanguage()
assertThat
can receive first parameter as scalar value. In this case it will be treated asexpected
inside an expression:
License
Open-source software licensed under the MIT License. © Codeception PHP Testing Framework