Functional testing in Docker

You can use the ece-tools package to run functional tests in the Docker environment, which is helpful when testing code intended for ece-tools contribution. Functional tests are in the src/Test/Functional/Acceptance folder. See an example in the ece-tools repository.

For testing the Magento application, see the Magento Functional Testing Framework (MFTF).

Prerequisites

Before you run functional tests, you must prepare your environment with the following steps.

  1. Clone the ece-tools GitHub repository.

    1
    
     git clone git@github.com:magento/ece-tools.git
    
  2. Stop all services that use the following ports:

    • 80—varnish
    • 443—web, tls
    • 3306—apache, mysql
  3. Update the hosts file.

    Before you begin, you must add the following hostname to your /etc/hosts file:

    1
    
     127.0.0.1 web
    

    Alternatively, you can run the following command to add it to the file:

    1
    
     echo "127.0.0.1 web" | sudo tee -a /etc/hosts
    
  4. Switch to the preferred PHP version for running tests.

  5. Update the project dependencies.

    1
    
     composer update
    
  6. Add credentials to the Docker environment.

    1
    
     echo "COMPOSER_MAGENTO_USERNAME=your_public_key" >> ./.docker/composer.env
    
    1
    
     echo "COMPOSER_MAGENTO_PASSWORD=your_private_key" >> ./.docker/composer.env
    

Run tests

The codeception.dist.yml file in the ece-tools root directory contains the global testing configuration. See the ece-tools repository.

By default, functional tests produce a short output. You can receive a more detailed output by editing the codeception.dist.yml file to set the printOutput: property to true.

1
2
3
4
5
modules:
  config:
    Magento\MagentoCloud\Test\Functional\Codeception\Docker:
      ...
      printOutput: true

Run a specific test

Use the following command format to run a specific functional test:

1
./vendor/bin/codecept run Acceptance <TestName>Cest

For example, the following test verifies that the post-deploy task runs successfully.

1
./vendor/bin/codecept run Acceptance PostDeployCest

Sample response:

1
2
3
4
5
6
7
8
9
10
11
12
Codeception PHP Testing Framework v2.5.6
Powered by PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
Running with seed:
Acceptance Tests (1) -----------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------
PostDeployCest: Test post deploy | {"ADMIN_EMAIL":"admin@example.com"}
 [Magento\MagentoCloud\Test\Functional\Robo\Tasks\GenerateDockerCompose] Running ./bin/ece-tools docker:build
 --mode=functional --php=7.2
...
...
✔ PostDeployCest: Test post deploy | {"ADMIN_EMAIL":"admin@example.com"} (210.41s)

Run all tests

The following list provides the commands to run all available tests for each version of PHP.

  • PHP 7.0

    1
    
     ./vendor/bin/codecept run -g php70 --steps
    
  • PHP 7.1

    1
    
     ./vendor/bin/codecept run -g php71 --steps
    
  • PHP 7.2

    1
    
     ./tests/travis/prepare_functional_parallel.sh
    
    1
    
     ./vendor/bin/codecept run -g php72parallel_1 --steps
    
    1
    
     ./vendor/bin/codecept run -g php72parallel_2 --steps
    
    1
    
     ./vendor/bin/codecept run -g php72parallel_3 --steps
    
Updated