Download the PHP package codeception/specify without Composer
On this page you can find all versions of the php package codeception/specify. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codeception/specify
More information about codeception/specify
Files in codeception/specify
Package specify
Short Description BDD code blocks for PHPUnit and Codeception
License MIT
Informations about the package specify
Specify
BDD style code blocks for PHPUnit or Codeception
Specify allows you to write your tests in more readable BDD style, the same way you might have experienced with Jasmine. Inspired by MiniTest of Ruby now you combine BDD and classical TDD style in one test.
Installation
Requires PHP >= 7.4
-
Install with Composer:
- Include
Codeception\Specify
trait in your tests.
Usage
Specify $this->specify
method to add isolated test blocks for your PHPUnit tests!
BDD Example
Specify supports describe-it
and describe-should
BDD syntax inside PHPUnit
Specify + Verify Example
Use Codeception/Verify for simpler assertions:
Use Case
This tiny library makes your tests readable by organizing them in nested code blocks. This allows to combine similar tests into one but put them inside nested sections.
This is very similar to BDD syntax as in RSpec or Mocha but works inside PHPUnit:
Each code block is isolated. This means call to $this->specify
does not change values of properties of a test class.
Isolated properties should be marked with @specify
annotation.
Failure in specify
block won't get your test stopped.
If a test fails you will see specification text in the result.
Isolation
Isolation is achieved by cloning object properties for each specify block.
Only properties marked with @specify
annotation are cloned.
Objects are cloned using deep cloning method.
If object cloning affects performance, consider turning the clonning off.
Mocks are isolated by default.
A mock defined inside a specify block won't be executed inside an outer test, and mock from outer test won't be triggered inside codeblock.
Examples: DataProviders alternative
You can also use DataProvider functions in examples
param.
Can also be used with real data providers:
Before/After
There are also before and after callbacks, which act as setUp/tearDown but for specify.
API
Available methods:
Printer Options
For PHPUnit, add Codeception\Specify\ResultPrinter
printer into phpunit.xml
Recommended
- Use Codeception/AssertThrows for exception assertions
- Use Codeception/DomainAssert for verbose domain logic assertions
- Combine this with Codeception/Verify library, to get BDD style assertions.
License: MIT.