Edit in GitHubLog an issue

Code testing

In a Cloud Docker for Commerce development environment, you can use the integrated test suite in each Cloud Suite for Commerce package for application code testing.

Test resources

The test suites, which use the Codeception testing framework for PHP, provide acceptance tests to validate code intended for contribution to Commerce Cloud package repositories.

  • Acceptance tests are in the package src/Test/Functional/Acceptance folder.
  • Test configuration is the codeception.dist.yml file in the package folder.

Use the following table to access the files and available tests for each Cloud package. The links use the develop branch, so be sure to select the appropriate tag for your project:

PackageTest configuration linkAcceptance test link
ECE-tools
Cloud components
Cloud Docker
Cloud patches

Prepare the Docker environment for testing

To set up and configure the test environment:

  1. Clone the GitHub repository for the package to test.

    Copied to your clipboard
    git clone git@github.com:magento/<cloud-suite-package-repository>.git

    For example, clone the ECE-Tools package:

    Copied to your clipboard
    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. Add the following hostname to your /etc/hosts file.

    Copied to your clipboard
    127.0.0.1 magento2.docker

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

    Copied to your clipboard
    echo "127.0.0.1 magento2.docker" | sudo tee -a /etc/hosts
  4. Add required project dependencies if you are testing the following packages.

    • For the magento/magento-cloud-patches package:

      Copied to your clipboard
      composer require "magento/magento-cloud-docker:^1.0.0" --no-update
    • For the magento/magento-cloud-components package:

      Copied to your clipboard
      composer require "magento/magento-cloud-docker:^1.0.0" --no-update
      composer require "magento/framework:*" --no-update
      composer require "magento/module-store:*" --no-update
      composer require "magento/module-url-rewrite:*" --no-update
  5. Switch to the preferred PHP version for running tests.

  6. Update the project dependencies.

    Copied to your clipboard
    composer update

Add credentials

Add credentials to your Docker environment using any of the following methods:

  • Use environment variables
  • Load credentials from the environment configuration file
  • Add variables directly to the test configuration file

To add credentials using environment variables:

  1. Create environment variables for your GitHub authentication keys.

    Copied to your clipboard
    export REPO_USERNAME=your_public_key
    Copied to your clipboard
    export REPO_PASSWORD=your_private_key
  2. Some packages require a GitHub authentication during installation. Create an environment variable with your GitHub token that can be used to install these packages.

    Copied to your clipboard
    `export GITHUB_TOKEN=your_github_token

To load credentials from the environment configuration file:

  1. Run the following commands to write credentials to the ./.env file:

    Copied to your clipboard
    echo "REPO_USERNAME=your_public_key" >> ./.env
    Copied to your clipboard
    echo "REPO_PASSWORD=your_private_key" >> ./.env
  2. Edit the codeception.dist.yml file.

    Copied to your clipboard
    params:
    - tests/functional/configuration.dist.yml
    - env
    - .env
  3. Add a dependency for the vlucas/phpdotenv package required to load the environment variables.

    Copied to your clipboard
    composer require "vlucas/phpdotenv": "^3.0"

To add credentials directly to the test configuration file:

  1. Open the codeception.dist.yml file in an editor.

  2. Replace the %REPO_USERNAME%, %REPO_PASSWORD%, and %GITHUB_TOKEN% placeholder values with your credentials:

    Copied to your clipboard
    modules:
    config:
    Magento\CloudDocker\Test\Functional\Codeception\TestInfrastructure:
    ...
    composer_magento_username: "%REPO_USERNAME%"
    composer_magento_password: "%REPO_PASSWORD%"
    composer_github_token: "%GITHUB_TOKEN%"
    ...

Run tests

Before you run tests, you must prepare your Docker environment and update the test configuration file. See Prepare the test environment. By default, functional tests produce a short output. You can receive more detailed output by editing the codeception.dist.yml test configuration file to set the printOutput: property to true.

Copied to your clipboard
modules:
config:
Magento\CloudDocker\Test\Functional\Codeception\TestInfrastructure:
...
printOutput: true
...
Magento\CloudDocker\Test\Functional\Codeception\Docker:
...
printOutput: true
...

Run a specific test

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

Copied to your clipboard
./vendor/bin/codecept run Acceptance <TestName>Cest

For example, the following test for magento/ece-tools code verifies that the post-deploy task runs successfully.

Copied to your clipboard
./vendor/bin/codecept run Acceptance PostDeployCest

Sample response:

Copied to your clipboard
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-docker build:compose
--mode=functional --php=7.2
...
...
✔ PostDeployCest: Test post deploy | {"ADMIN_EMAIL":"admin@example.com"} (210.41s)

Run all tests

Use the following commands to run all available tests for each PHP version:

  • PHP 7.1

    Copied to your clipboard
    ./vendor/bin/codecept run -g php71 --steps
  • PHP 7.2

    Copied to your clipboard
    ./vendor/bin/codecept run -g php72 --steps
  • PHP 7.3

    Copied to your clipboard
    ./vendor/bin/codecept run -g php73 --steps
  • PHP 7.4

    Copied to your clipboard
    ./vendor/bin/codecept run -g php74 --steps

    If you are testing magento/ece-tools code, use the following command:

    Copied to your clipboard
    ./vendor/bin/codecept run -x php71 -x php72 -x php73 -x php74 --steps
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.