Sacharski Bartłomiej d3b6eaf9fe
Added support for code coverage in E2E tests (#2533)
The E2E docker-compose stack has been modified to include code
coverage for all scripts that are kept in /project and are not
in the exclusion list.

The start command for `deployer` container has been replaced
with a `start-e2e-test.sh` script, which will execute E2E tests,
generate a Clover report and then return the exit code of E2E test
process to make sure that CI is aware of the test result.

Whole idea for collecting E2E coverage has been inspired by the
[this][1] article. All of scripts in `deployer` container will
now start with additional wrapper-like PHP code, which checks
if the `PHP_CCOV_START_FILE` variable is present. If not,
then nothing happens, but if the variable points to a PHP file,
then that file is being included.

The `docker-compose.yml` file has `PHP_CCOV_START_FILE` configured
to point to a file, which sets up code coverage, that starts counting
which instructions in `/project` directory have been called. Once
`php` interpreter starts shutting down, the coverage report is being
dumped into temporary files.

Once all tests have been processed, a script for merging partial
coverage reports is executed and finally a Clover code coverage file
is stored in the path defined in the `PHP_CCOV_OUTPUT_FILE` env var.

[1]: https://tarunlalwani.com/post/php-code-coverage-web-selenium/
2021-05-02 15:15:19 +02:00
..

Deployer E2E testing environment

This directory contains an end-to-end testing environment for Deployer.

All commands mentioned in this readme, should be executed in the docker directory.

Requirements

  • Docker
  • docker-compose

Running tests

The E2E are started when running the docker-compose up command. This will start the server container that has the Apache, OpenSSH & PHP 7.3 enabled.

Once the server is up and running, the deployer container will be started and alongside it the tests will be ran.

Adding new E2E tests

The E2E test should be a part of the e2e test suite. Each e2e test class should inherit from AbstractE2ETest class.

Note: E2E tests will only run in an environment where env variable E2E_ENV has been set and has a truthy value.

Manually accessing the deployer container.

The container can be accessed by running:

docker-compose run deployer sh

This command will spawn a sh shell inside the deployer container.

About containers

deployer container

The deployer container contains:

  • git
  • PHP 7.3 with XDebug enabled
  • rsync
  • SSH client

It is possible to access the server container via ssh by running:

ssh deployer@server

root's public key has been added to authorized keys for deployer user.

Enabling XDebug

To enable XDebug create a docker-compose.override.yml file with following content:

services:
  deployer:
    environment:
      # See https://docs.docker.com/docker-for-mac/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
      # See https://github.com/docker/for-linux/issues/264
      # The `remote_host` below may optionally be replaced with `remote_connect_back=1`
      XDEBUG_CONFIG: >-
        remote_enable=1
        remote_host=${XDEBUG_HOST:-host.docker.internal}
        remote_autostart=1
        remote_port=9000
        idekey=PHPSTORM
      # This should correspond to the server declared in PHPStorm `Preferences | Languages & Frameworks | PHP | Servers`
      # Then PHPStorm will use the corresponding path mappings
      PHP_IDE_CONFIG: serverName=deployer-e2e

Note: you may want to set the XDEBUG_HOST env variable to point to your IP address when running tests in Linux.

server container

The server container contains:

  • Apache (with the DocumentRoot set to /var/www/html/current)
  • git
  • PHP 7.3
  • SSH server with
  • sudo (user deployer can use sudo after providing a password: deployer)