Installation
On this page
#Requirements
- PHP 8.1+
- PHP Gd extension
- PrestaShop 1.7, 8 or 9
- It's all ! ✨
#PrestaShop version
PrestaShop versions 1.7, 8 and 9 are supported by the library.
#Install the library
1composer require prestaflow/php-library
#The prestaflow binary
Installing the library creates vendor/bin/prestaflow, so you can run it
directly:
1vendor/bin/prestaflow run tests
Before 1.8.0 the library declared no Composer binary, and you had to call
vendor/prestaflow/php-library/bin/prestaflow. That path still works, so the
scripts below need no change.
#Composer scripts
Into your composer.json, add theses scripts :
1"scripts": {2 "prestaflow:default": "./vendor/prestaflow/php-library/bin/prestaflow run",3 "prestaflow:json": "@prestaflow:default --output=JSON"4},
While using JSON output, you can save the results into a file (prestaflow/results.json).
1"scripts": {2 "prestaflow:default": "./vendor/prestaflow/php-library/bin/prestaflow run",3 "prestaflow:json": "@prestaflow:default --output=JSON",4 "prestaflow:json:file": "@prestaflow:json --file"5},
#Alternatively, Task.yml
You also can use the Task.yml to add your own tasks.
1tasks: 2 3 prestaflow: 4 desc: "Tous les tests E2E PrestaFlow" 5 cmds: 6 - cd prestaflow && /opt/homebrew/opt/php@8.4/bin/php vendor/prestaflow/php-library/bin/prestaflow run Tests 7 8 prestaflow:fo: 9 desc: "Tests FrontOffice uniquement"10 cmds:11 - cd prestaflow && /opt/homebrew/opt/php@8.4/bin/php vendor/prestaflow/php-library/bin/prestaflow run Tests/FrontOffice12 13 prestaflow:modules:14 desc: "Tests modules custom uniquement"15 cmds:16 - cd prestaflow && /opt/homebrew/opt/php@8.4/bin/php vendor/prestaflow/php-library/bin/prestaflow run Tests/Modules
To run a task, you will use this :
1task prestaflow2task prestaflow:fo3task prestaflow:modules
#Run
1composer prestaflow:default2composer prestaflow:default -- --output="compact"
As now, if you doesn't have a <Tests> folder, you will have an error ouput.
If you have a <Tests> folder but without PrestaFlow's suites, it will show a success message.
You can also specify a different folder if needed.
1composer prestaflow:default ./FolderName
#JSON output
Also, you can get the JSON output if wanted.
1composer prestaflow:json2composer prestaflow:default -- -o "json"3composer prestaflow:default -- --output="json"
1composer prestaflow:json:file
When several suites run, the file holds all of them, and each test records where it is declared:
1{ 2 "suites": [ 3 { 4 "suite": "Tests\\FrontOffice\\Home", 5 "title": "Home page", 6 "stats": { "passes": 2, "failures": 1, "skips": 0, "skippeds": 0, "todos": 0, "assertions": 5, "time": 4210 }, 7 "tests": [ 8 { "title": "shows the logo", "state": "fail", "file": "/app/tests/FrontOffice/Home.php", "line": 24, "time": 812 } 9 ]10 }11 ]12}
Before 1.8.0 each suite overwrote the file, so only the last one survived.
#Working with drafts
Tests can be written at each key stage of a project.
To allow you to implement these without making the output cumbersome, you can define a test as a draft.
This gives you the option to test only drafts or, conversely, ignore them during execution.
1public $draft = true | false;
1composer prestaflow:default -- --draft2composer prestaflow:default -- --no-draft
#Working with groups
Within a set of tests, it is sometimes possible to group some of them to refer to the test typology.
You can define one or more groups (using an array).
By default, a test that does not belong to any group will be included in the "All" group.
1public $groups = 'tutorial';2public $groups = ['scenarios', 'en'];
1composer prestaflow:default -- --group=tutorial --group=other-group
#Run a subset of suites
--suites takes comma-separated sub-folders of the suites path and runs only
those. Nested paths are allowed, and each folder is scanned recursively as
usual:
1composer prestaflow:default -- tests --suites=BackOffice,FrontOffice/Checkout
When the option is absent, the list is read from PRESTAFLOW_SUITES, which is
what the GitHub Action's suites input
sets. --group and --draft then apply to what is left.
A name that matches no folder fails the run, listing the missing names and the
sub-folders that do exist: a typo must not become a green job that ran zero
tests. Absolute paths and .. are refused, since the filter only narrows the
suites path, and combining a filter with a single suite file is an error.
#Exit code
The run exits with a non-zero status when a test fails, and also when the run cannot even start: Chrome failing to launch, a suites path that does not exist, a mistyped command. Before 1.8.0 that second kind of failure ended with status 0, which turned a CI job green.