Download the PHP package rawsrc/exacodis without Composer
On this page you can find all versions of the php package rawsrc/exacodis. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rawsrc/exacodis
More information about rawsrc/exacodis
Files in rawsrc/exacodis
Package exacodis
Short Description a PHP very minimalist test engine for PHP
License MIT
Informations about the package exacodis
Exacodis
2022-08-15
PHP 8.0+
v.1.2.3
A PHP TESTING ENGINE
Exacodis
is a very minimalist testing engine for PHP (very lightweight PHP testing framework).
This engine is really far from others tools as it is very simple to use. No complex architecture,
not even a huge testing engine, just the basic (and a little more) to help you to validate
your PHP code.
Just 3 classes :
- One to pilot the tests (called
Pilot
), - One to encapsulate and execute the test code (called
Runner
) - One to produce the report (called
Report
)
And many helpers to check the returned values against the expected types and/or values. The helpers are not exhaustive, you'll be able to create easily yours.
INSTALLATION
IMPORTANT
Please note that your source code for tests must be perfectly clean: you can't
override a test run nor a result nor a resource.
If you do, then the code will fail with an Exception
until you fix it.
CHANGELOG
- Add the possibility to test any protected/private method from a class
- Add the possibility to test any protected/private static method from a class
- Does not break the compatibility with the previous version
HOW TO USE
I will directly use Exacodis
to test itself as a learning support.
As Exacodis
is a very lightweight engine, it's your responsibility to set up
a test environment. Clearly, it's as simple as :
For projects with many classes, you must tell PHP how to load your classes either by including them or using an autoloader.
That's enough to start to test your code.
CONCEPT
- The
Pilot
class does absolutely everything. You do not have to use the two other classes;Runner
andReport
. - All the test code must be encapsulated in a
Closure
that MUST return a value. - The helpers you can create are used for the
assert
part of the engine. You are free to create as many assertions as you want. There are already many helpers included in the standard library.
LET'S START
- RESOURCES
To use everything you need to test your code, the engine is able to store and retrieve any resource you want (objects, arrays, scalar values, even unit tests...). Each resource must have a unique name, and you can't override it by error.
- TEST
As written, a test is a simple snippet of code encapsulated in a Closure
that
returns a value :
- ASSERTIONS
Assertions use the standard helpers and of course yours.
You must know that assertions (->assertXXX
) always apply to the latest run.
If you want to change the current runner, then you can ask for it:
Then the assertions will apply to this one (see below: NESTED RUNS)
- DYNAMIC ASSERTION
Here's the way to write a dynamic test:
- COMPLEX TEST CODE
You can write your test code as raw code, especially for complex test code.
- TESTING PROTECTED/PRIVATE AND/OR STATIC METHODS IN CLASSES
To be able to test any protected
or private
(static
or not) method,
you must use $pilot->runClassMethod(...)
instead of $pilot->run(...)
.
The signature of the method is:
Please note:
- if the class has a complex constructor with required arguments, then you must
provide a clean object instance for
$class
. - in other cases,
$class
can be a string likeFoo
or evenFoo::method
. This work for classes without constructor or with one that have no required parameters. - The array
$params
must have all the required parameters for the invocation of the method. It's also compatible with named parameters.
Everything else is similar to the method $pilot->run()
.
Let's have an example from the php test file: Here all tests are equivalent:
Have a look at the call of a private method with two parameters and another call
to a private static function()
:
The named parameters must follow the same order as defined in the function prototype.
- REPORT
The engine compute internally the data and, you can ask for a HTML report, as simply as:
You will find in the repository two reports: one totally passed and another one failed. You'll exactly see how the engine follows the runs and what kind of data is kept.
- HELPERS
You can create your own helpers to validate any result using à simple Closure
.
Have a look at:
This assertion is one of the standard library and is injected right after the
start of a new project.
It is also possible to define a helper on the fly using
$pilot->addHelper($name, $closure);
.
- NESTED RUNS
For really complex tests, you can also define nested runs.
This is the only tricky point of Exacodis
. This keeps the code more readable as there's
no need to have tons of parameters for each function call.
Enjoy!
rawsrc