Download the PHP package keboola/datadir-tests without Composer
On this page you can find all versions of the php package keboola/datadir-tests. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download keboola/datadir-tests
More information about keboola/datadir-tests
Files in keboola/datadir-tests
Package datadir-tests
Short Description Tool for functional testing of Keboola Connection components
License MIT
Informations about the package datadir-tests
Datadir Tests
Usage
Require this package in you component
In the tests folder create a directory structure mimicking the directory structure in production:
Note: expected-stdout
and expected-stderr
are compared with real output using assertStringMatchesFormat
method,
so you can use placeholders.
Then create empty /path/to/tests/DatadirTest
that extends Keboola\DatadirTests\DatadirTestCase
:
Run it using
The script then executes /code/src/run.php
with KBC_DATADIR
set to the test directory. There can be any number of test directories and the script automatically discovers them using DatadirTestsFromDirectoryProvider
. You can supply your own provider that implements DatadirTestsProviderInterface
. It needs to return array of arrays (!) of DatadirTestSpecificationInterface
instances.
When the expected-code
file is present, the return code of execution is checked. The file contains a single number number - the execution code, allowed values are 0
, 1
, 2
.
What is DatadirTestSpecificationInterface
?
DatadirTestSpecificationInterface
contains all the information you need to create and assert a datadir test:
getSourceDatadirDirectory(): ?string
: returns the directory that initializes the test. You should prepareconfig.json
and potentially also/in/files
or/in/tables
contents. That directory is mirrored to the temporary directory that the test is ran in.null
means just barebones directory structure is created and you need to createconfig.json
, etc. in the temporary directory yourself.getExpectedReturnCode(): ?int
: expected exit code,null
means "non-zero"getExpectedStdout(): ?string
: if supplied, whole stdout output is checked against supplied valuegetExpectedStderr(): ?string
: if supplied, whole stderr output is checked against supplied value-
getExpectedOutDirectory(): ?string
: if supplied, the temporary directory'sout
directory is compared with this directory after the component is ran. Any differences result in test failure.Custom test
Just add a test method and reuse the existing helper methods in
AbstractDatadirTestCase
.
Environment variables
- In
config.json
you can use placeholders for environment variables. - Format is
%env(TYPE:VAR_NAME)%
, eg.%env(int:DB_PORT)%
. - All string values in
config.json
that match specified format are replaced. - It is implemented in
AbstractDatadirTestCase::modifyConfigJsonContent
. - Allowed types are
string
,int
,float
,bool
. - See example in the test.
Functionality adjustments
- To modify temp data dir before execution, you can extend the method
AbstractDatadirTestCase::setUpDatadir
.
Development
Clone this repository and init the workspace with following command:
License
MIT licensed, see LICENSE file.
All versions of datadir-tests with dependencies
ext-json Version *
keboola/php-temp Version ^2.0
phpunit/phpunit Version ^9.5
symfony/filesystem Version ^5.0|^6.0
symfony/finder Version ^5.0|^6.0
symfony/process Version ^5.0|^6.0