Installation


#Requirements

  1. PHP 8.1+
  2. PHP Gd extension
  3. PrestaShop 1.7, 8 or 9
  4. It's all ! ✨

#PrestaShop version

PrestaShop versions 1.7, 8 and 9 are supported by the library.

#Install the library

Copied!
1composer require prestaflow/php-library

#The prestaflow binary

Installing the library creates vendor/bin/prestaflow, so you can run it directly:

Copied!
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 :

Copied!
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).

Copied!
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.

Copied!
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/FrontOffice
12 
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 :

Copied!
1task prestaflow
2task prestaflow:fo
3task prestaflow:modules

#Run

Copied!
1composer prestaflow:default
2composer 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.

Copied!
1composer prestaflow:default ./FolderName

#JSON output

Also, you can get the JSON output if wanted.

Copied!
1composer prestaflow:json
2composer prestaflow:default -- -o "json"
3composer prestaflow:default -- --output="json"
Copied!
1composer prestaflow:json:file

When several suites run, the file holds all of them, and each test records where it is declared:

Copied!
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.

Copied!
1public $draft = true | false;
Copied!
1composer prestaflow:default -- --draft
2composer 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.

Copied!
1public $groups = 'tutorial';
2public $groups = ['scenarios', 'en'];
Copied!
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:

Copied!
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.