Acceptance testing

via Codeception + Selenium (GitLab CI)

manual testing

is wasting our time
is error prune.

automated testing

is saving our time

Topics

PHP webserver + MailHog

PHP webserver + MailHog

  • PHP webserver

    Start from command line:
    php -S 127.0.0.1:8080 -t web
  • MailHog

    Configure TYPO3 (and PHP) to use MailHog:
    $GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport'] = 'smtp';
    $GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport_smtp_server'] = '127.0.0.1:1025';

PHP webserver + MailHog

  • PHP webserver

    Add TYPO3 Context when running:
    TYPO3_CONTEXT=Testing/Acceptance php -S 127.0.0.1:8080 -t web

Next up: Codeception PhpBrowser

Codeception (PhpBrowser)

  • Install Codeception

    composer require --dev codeception/codeception

Codeception (PhpBrowser)

  • Configuration

    Done within yaml files.

    modules:
        enabled:
            - PhpBrowser:
                  url: http://127.0.0.1:8080/

Codeception (PhpBrowser)

  • Configuration

    Configure DB module

    modules:
        enabled:
            - Db:
                dsn: 'mysql:host=localhost;dbname=dev'
                user: 'dev'
                password: 'dev'
                dump: tests/_data/typo3.sql
                populate: true
                cleanup: true

Codeception (PhpBrowser)

  • Tests

    Written as single files or PHP Classes

    Extendable with Actors, Pages, Modules and Helpers

Codeception (PhpBrowser)

  • Execution

    ./vendor/bin/codecept run

Example output

Next up: Codeception Selenium

Codeception (Selenium)

Codeception (Selenium)

  • Configuration

    Enable WebDriver module instead of PhpBrowser

    modules:
        enabled:
            - WebDriver:
                url: http://127.0.0.1:8080/
                browser: chrome
                                    

Codeception (Selenium)

  • Execution

    ChromeDriver=~/Applications/chromedriver-76 \
        java -Djava.awt.headless=true \
        -jar ~/Applications/selenium-server-standalone-3.141.59.jar

Next up: GitLab-CI

GitLab-CI

  • Adding Services

    test:acceptance:
        image: php:7.2-alpine
        services:
            - mysql:5.7
            - mailhog/mailhog:v1.0.0
            - selenium/standalone-chrome
        variables:
            MYSQL_ROOT_PASSWORD: "dev"
            MYSQL_DATABASE: "dev"
            MYSQL_USER: "dev"
            MYSQL_PASSWORD: "dev"
        before_script:
            - docker-php-ext-install pdo pdo_mysql mysqli

GitLab-CI

  • Running Tests

    test:acceptance:
        before_script:
            - export LOCAL_IP=$(ip a | grep inet | sed -n 2p | xargs | cut -d" " -f2 | cut -d"/" -f1)
            - export TESTING_DOMAIN="$LOCAL_IP:8080"
            - export TYPO3_CONTEXT=Testing/Acceptance
            - php -S "$TESTING_DOMAIN" -t web &> php.log.txt &
        script:
            - ./vendor/bin/codecept run --env=gitlab-ci

GitLab-CI

  • Storing Artifacts

    test:acceptance:
        artifacts:
            when: on_failure
            expire_in: 10 mins
            paths:
                - tests/_output/
                - php.log.txt

Example output

Done

Sponsoring

Paypal me

2,50

Thanks

Hopefully this helped you.
Feedback and questions are welcome.

Slack: danielsiepmann
GitHub: DanielSiepmann
Twitter: @daniel_siepmann

Presentation: https://tmp.daniel-siepmann.de/events/t3cm19/
Example: https://gitlab.com/DanielSiepmann/workshop-gitlab-acceptance/

Daniel Siepmann.

Pictures taken from: https://www.comedywildlifephoto.com