Table of Contents

Gitlab Codeception

Codeception covers unit-, functional-, and acceptance tests To use it together with Gitlab is kinda tricky due to the need of selenium for acceptance testing.

Most important part is that the selenium server can call urls in your docker webapp container. For details see https://cappers.ca/web-application-acceptance-tests-in-gitlab-ci-using-codeception-and-selenium/

Gitlab-CI config

.gitlab-ci.yml
stages:
- test
 
# For use in multiple jobs when webserver is needed
.run_webserver: &run_webserver
    image: composer:1
    before_script:
        # Get ip of your webapp container and export it as $WEB_APP_IP env var for use in codeception config
        - export WEB_APP_IP="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
        - composer install
        - ./flow server:run --host 0.0.0.0 --port 8081 &
        # Wait for webserver to get ready
        - sleep 10

codeception:
    <<: *run_webserver  # Merge content of 'run_webserver'
    stage: test
    services:
        - name: selenium/standalone-chrome
          alias: selenium
    variables:
        SELENIUM_HOST: 'selenium'
    script:
        - echo $WEB_APP_IP
        - composer install
        - echo "Run acceptance tests"
        - bin/codecept run acceptance
        - echo "Run api tests"
        - bin/codecept run api
    artifacts:
        paths:
            - tests/_output/
        expire_in: 2 weeks

Codeception config

Nothing special here except for params:env

codeception.yml
paths:
    tests: tests
    output: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
actor_suffix: Tester
extensions:
    enabled:
        - Codeception\Extension\RunFailed
coverage:
    enabled: true
    include:
        - DistributionPackages/*
modules:
    enabled: [ Asserts ]
params:
    - env

Api test config:

tests/api.suite.yml
class_name: ApiTester
modules:
    enabled:
        - REST:
              url: 'http://%WEB_APP_IP%:8081/api/v1'
              depends: PhpBrowser
              part: Json

Acceptance test config:

tests/acceptance.suite.yml
actor: AcceptanceTester
modules:
    enabled:
        - \Helper\Acceptance
        - WebDriver:
            host: '%SELENIUM_HOST%'
            url: 'http://%WEB_APP_IP%:8081'
            browser: chrome