Skip to content

Testing with Docker

Erik Giberti edited this page Jan 21, 2018 · 2 revisions

Docker makes testing existing behavior easier since this library only loads when the PECL OAuth extension is not loaded. This walkthrough assumes you have some familiarity with Docker.

  1. Checkout the code
  2. Install dependencies via composer
  3. Build the docker containers
  4. Run tests

Checkout the code

Get a copy of the code directly from the repository and create a branch to do your development work in.

git clone git@github.com:giberti/ext-oauth-shim.git
cd ext-oauth-shim
git checkout -b my-feature-branch

Install dependencies via composer

Install the development dependencies, with composer. If you do not already have composer installed on your system, download composer first.

cd ext-oauth-shim
composer install

Build the Docker containers

To avoid differences between development systems, the following Dockerfiles provide an environment agnostic platform for testing the extension code. The two builds are identical except that one includes the PECL OAuth extension. Both containers will automatically run the PHPUnit tests when started.

Container with PECL OAuth

This will build with PHP 7.1.x and PECL OAuth installed.

FROM php:7.1-cli

RUN apt-get update \
    && apt-get -y upgrade \
    && apt-get install -y \
        libpcre3-dev 

RUN pecl install oauth \
    && docker-php-ext-enable oauth 

WORKDIR /usr/src/project

CMD ["vendor/bin/phpunit"]

Continer without PECL OAuth

This will build with just the default PHP 7.1.x.

FROM php:7.1-cli

RUN apt-get update \
    && apt-get -y upgrade \
    && apt-get install -y

WORKDIR /usr/src/project

CMD ["vendor/bin/phpunit"]

Build the containers

Both containers need to be built before they can be invoked. If you used a directory structure like ./phpunit-71-oauth and ./phpunit-71, you can build the containers from the parent directory using the following:

docker build -t phpunit-71-oauth ./phpunit-71-oauth
docker build -t phpunit-71 ./phpunit-71

Run the tests

Now as you actively develop, you can check that the tests are still passing by running the newly created containers and passing the git working directory as a volume to the container. The container will mount the volume each time it's run so you can simply re-run the following run command to run the tests.

Running the tests with the PECL extension
docker run -v /path/to/repo/checkout/on/your/system:/usr/src/project phpunit-71-oauth:latest
Running the tests against the local branch
docker run -v /path/to/repo/checkout/on/your/system:/usr/src/project phpunit-71:latest