Download the PHP package xp-framework/unittest without Composer
On this page you can find all versions of the php package xp-framework/unittest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xp-framework/unittest
More information about xp-framework/unittest
Files in xp-framework/unittest
Package unittest
Short Description Unittests for the XP Framework
License BSD-3-Clause
Homepage http://xp-framework.net/
Informations about the package unittest
Unittests
Unittests for the XP Framework
Writing a test
Tests reside inside a class and are annotated with the @test
attribute.
To run the test, use the test
subcommand:
Assertion methods
The unittest package provides the following six assertion methods:
If you need more than that, you can use xp-forge/assert on top of this library.
Setup and teardown
In order to run a method before and after the tests are run, annotate methods with the @before
and @after
attributes:
Note: All test methods are run with the same instance of CalculatorTest!
Expected exceptions
The Expect attribute is a shorthand for catching exceptions and verifying their type manually.
Ignoring tests
The Ignore attribute can be used to ignore tests. This can be necessary as a temporary measure or when overriding a test base class and not wanting to run one of its methods.
Parameterization
The Values attribute can be used to run a test with a variety of values which are passed as parameters.
Actions
To execute code before and after tests, test actions can be used. The unittest library comes with the following built-in actions:
unittest.actions.ExtensionAvailable(string $extension)
- Verifies a given PHP extension is loaded.unittest.actions.IsPlatform(string $platform)
- Verifies tests are running on a given platform via case-insensitive match onPHP_OS
. Prefix with!
to invert.unittest.actions.RuntimeVersion(string $version)
- Verifies tests are running on a given PHP runtime. See version_compare for valid syntax.unittest.actions.VerifyThat(function(): var|string $callable)
- Runs the given function, verifying it neither raises an exception nor return a false value.
Multiple actions can be run around a test by passing an array to the @action attribute.
Further reading
- XP RFC #0283: Unittest closure actions
- XP RFC #0272: Unittest actions
- XP RFC #0267: Unittest parameterization
- XP RFC #0188: Test outcome
- XP RFC #0187: @expect withMessage
- XP RFC #0150: Before and after methods for test cases
- XP RFC #0145: Make unittests strict
- XP RFC #0059: Timeouts for unittests
- XP RFC #0032: Add attributes for Unittest API
- XP RFC #0020: Metadata for unittests