Test automation and pipelines: one step at a time

A presentation at PHPMinds - March 7th 2019 in March 2019 in Nottingham, UK by Antonios Pavlakis

Slide 1

Slide 1

Test automation and pipelines one step at a time Antonis Pavlakis @pavlakis

Slide 2

Slide 2

Code

Slide 3

Slide 3

Unit Tests (local environment) Possible steps required ● ● composer install bin/phpunit -c tests/phpunit/phpunit.xml

Slide 4

Slide 4

Unit Tests (CI environment) Possible steps required ● ● ● Download composer composer install bin/phpunit -c tests/phpunit/phpunit.xml

Slide 5

Slide 5

Bitbucket Pipelines

Slide 6

Slide 6

Pipeline status

Slide 7

Slide 7

Cache performance

Slide 8

Slide 8

Using a custom Docker image Dockerfile

Slide 9

Slide 9

Build Docker image docker build -t phpminds/php:7.2.15 . docker push phpminds/php:7.2.15

Slide 10

Slide 10

Pipeline with custom image

Slide 11

Slide 11

Pipeline performance

Slide 12

Slide 12

Integration Tests (local environment) Possible steps required ● ● ● ● composer install composer reset-db composer populate-db bin/phpunit -c tests/phpunit/phpunit.xml —group integration

Slide 13

Slide 13

Set DB to a known state “scripts”: { “reset-db”: [ “bin/console doctrine:database:drop —force”, “bin/console doctrine:database:create”, “bin/console doctrine:schema:update —force” Using composer scripts ], “populate-db”: [ “bin/console doctrine:fixtures:load” ] }

Slide 14

Slide 14

Docker Compose

Slide 15

Slide 15

Update Docker image Update Docker image ● Add mysql client

Slide 16

Slide 16

Run integration tests using Docker Compose If docker compose is not already running: docker-compose up —build -d Run tests from inside the running container: docker-compose exec -T phpminds-php sh -c “bin/phpunit -c tests/phpunit/phpunit.xml —group integration”

Slide 17

Slide 17

Docker Compose in Bitbucket Pipelines Steps required ● ● ● ● ● ● ● Install Docker Compose docker-compose up —build -d composer install (wait for DB container to start) composer reset-db composer populate-db bin/phpunit -c tests/phpunit/phpunit.xml —group integration

Slide 18

Slide 18

Install Docker Compose

Slide 19

Slide 19

Check DB connection

Slide 20

Slide 20

Putting it all together

Slide 21

Slide 21

A build with Docker Compose

Slide 22

Slide 22

Environment Variables

Slide 23

Slide 23

Using .env ci/assets/env.ci

Slide 24

Slide 24

Using .env

Slide 25

Slide 25

Managing secrets

Slide 26

Slide 26

Using repository variables

Slide 27

Slide 27

Acceptance Tests Possible steps required ● ● ● ● composer install composer reset-db composer populate-db bin/behat -c tests/behat/behat.yml

Slide 28

Slide 28

Example behat.yml

Slide 29

Slide 29

Add pipeline step

Slide 30

Slide 30

Thank You Antonis Pavlakis @pavlakis