-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New testing library #344
Comments
First POC @ https://github.com/xp-framework/test |
Migration script |
Group (class) and case (method) prerequisites @ xp-framework/test#1 |
Test prerequisites analysisUsage of test actions:
Usage of
|
Transform values before comparison @ xp-framework/test#3 |
https://github.com/xp-forge/assert has been set to public archive. |
Submitted to Packagist -> https://packagist.org/packages/xp-framework/test |
Generalized provider concept @ xp-framework/test#4 |
First migration for Dialog done partially by migration script. The integration test needed to be migrated manually, as constructor arguments are not passed by default - see xp-framework/test#7 |
Current library is less than 1000 LOC, compared to 2974 for $ cloc-1.82.pl src/main/php/
39 text files.
39 unique files.
9 files ignored.
github.com/AlDanial/cloc v 1.82 T=0.10 s (404.0 files/s, 15444.7 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
PHP 39 221 368 902
-------------------------------------------------------------------------------
SUM: 39 221 368 902
------------------------------------------------------------------------------- |
First release @ https://github.com/xp-framework/test/releases/tag/v1.0.0 🎉 |
Project created for tracking progress: https://github.com/orgs/xp-framework/projects/3/views/1?layout=board |
All of |
All of |
Finally, XP Core is migrated 🎉 |
The repository https://github.com/xp-framework/unittest is now archived |
Remaining libraries: $ grep 'xp-framework/unittest' */composer.json | grep -v ^unittest
caching/composer.json: "xp-framework/unittest": "^11.0 | ^10.0"
coverage/composer.json: "xp-framework/unittest": "^11.0 | ^10.0 | ^9.7",
ftp/composer.json: "xp-framework/unittest": "^11.0 | ^10.1"
imaging/composer.json: "xp-framework/unittest": "^11.0 | ^10.0"
io-collections/composer.json: "xp-framework/unittest": "^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0 | ^6.5"
ldap/composer.json: "xp-framework/unittest": "^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0"
mail/composer.json: "xp-framework/unittest": "^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0"
measure/composer.json: "xp-framework/unittest": "^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0"
meilisearch/composer.json: "xp-framework/unittest": "^11.0 | ^10.0"
mocks/composer.json: "xp-framework/unittest": "^11.0 | ^10.0 | ^9.0 | ^8.0 |^7.0",
patterns/composer.json: "xp-framework/unittest": "^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0"
sql-parser/composer.json: "xp-framework/unittest": "^11.1"
text-encode/composer.json: "xp-framework/unittest": "^11.0 | ^10.0"
webtest/composer.json: "xp-framework/unittest": "^11.0 | ^10.0 | ^9.0 | ^8.0", |
Scope of Change
This RFC suggests to create a new testing library for the XP Framework. It will only work with baseless, single-instance test classes.
Rationale
extends TestCase
, supporting of which costs lots of codeValues
variations or external provider methodsAssert::that()
extended assertions to simplify commonly used test codeFunctionality
In a nutshell, tests reside inside a class and are annotated with the
Test
attribute. Except for the changed namespace (see below) and the changed default output, this is basically identical to the current usage of the unittest library.To run this test, use the
test
subcommand:Naming
The library will be called test, because it can not only run unittests. The top-level package used follows this, meaning the Assert class' fully qualified name is
test.Assert
.Assert DSL
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.Extended assertions
The
Assert::that()
method starts an assertion chain:Fluent assertions
Each of the following may be chained to Assert::that():
is(unittest.assert.Condition $condition)
- Asserts a given condition matchesisNot(unittest.assert.Condition $condition)
- Asserts a given condition does not matchisEqualTo(var $compare)
- Asserts the value is equal to a given comparisonisNotEqualTo(var $compare)
- Asserts the value is not equal to a given comparisonisNull()
- Asserts the value is nullisTrue()
- Asserts the value is trueisFalse()
- Asserts the value is falseisInstanceOf(string|lang.Type $type)
- Asserts the value is of a given typeTransformation
Transforming the value before comparison can make it easier to create the value to compare against. This can be achieved by chaining
map()
to Assert::that():Values and providers
#[Values]
is a basic provider implementation. It can either return a static list of values as follows:...or invoke a method, as seen in this example:
Provider implementation example
Provider values are passed as method argument, just like
#[Values]
, the previous only implementation.Provider values are passed to the constructor and the connection can be used for all test cases. Note: The provider's
values()
method is invoked with $instance= null!Test prerequisites
Prerequisites can exist on a test class or a test method. Unlike in the old library, they do not require the
Action
annotation, but stand alone.Security considerations
n/a
Speed impact
Same
Dependencies
Related documents
The text was updated successfully, but these errors were encountered: