Download the PHP package xp-framework/test without Composer
On this page you can find all versions of the php package xp-framework/test. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xp-framework/test
More information about xp-framework/test
Files in xp-framework/test
Package test
Short Description Testing for the XP Framework
License BSD-3-Clause
Homepage http://xp-framework.net/
Informations about the package test
Tests
Unit and integration tests for the XP Framework
Writing a test
Tests reside inside a class suffixed by "Test" (a test group) and consist of methods annotated with the Test
attribute (the test cases). The convention for test method naming is to use lowercase, words separated by underscores, though this is not strictly necessary.
To run these tests, use the test
subcommand:
Assertions
The following shorthand methods exist on the Assert
class:
equals(mixed $expected, mixed $actual)
- check two values are equal. Uses theutil.Objects::equal()
method internally, which allows overwriting object comparison.notEquals(mixed $expected, mixed $actual)
- opposite of abovetrue(mixed $actual)
- check a given value is equal to the true booleanfalse(mixed $actual)
- check a given value is equal to the false booleannull(mixed $actual)
- check a given value is nullinstance(string|lang.Type $expected, mixed $actual)
- check a given value is an instance of the given type.matches(string $pattern, mixed $actual)
- verify the given value matches a given regular expression.throws(string|lang.Type $expected, callable $actual)
- verify the given callable raises an exception.
Expected failures
Using the Expect
annotation, we can write tests that assert a given exception is raised:
To check the expected exceptions' messages, use the following:
- Any message:
Expect(DivisionByZero::class)
- Exact message:
Expect(DivisionByZero::class, 'Division by zero')
- Message matching regular expression:
Expect(DivisionByZero::class, '/Division by (0|zero)/i')
Value-driven tests
To keep test code short and concise, tests may be value-driven. Values can be provided either directly inline:
...or by referencing a provider method as follows:
Prerequisites
Test classes and methods may have prerequisites, which must successfully verify in order for the tests to run:
The following verifications are included:
Runtime(os: '^WIN', php: '^8.0', extensions: ['bcmath'])
- runtime verifications.Condition(assert: 'function_exists("random_int")')
- verify given expression in the context of the test class.
Passing arguments to tests
Especially for integration tests, passing values like a connection string from the command line to the test class is important. Add the Args
annotation to the class as follows:
...then pass the arguments as follows:
See also
All versions of test with dependencies
xp-framework/reflection Version ^3.0 | ^2.9
php Version >=7.4.0