GithubHelp home page GithubHelp logo

how-to-use-phpunit's Introduction

What is this ?

MIT licensed

Example project to demonstrate how to use PHPUnit and Selenium with certain test cases that you need to implement.

Table of Contents

Requirements

Installation

Clone repository

Get a clone from GitHub or alternatively just download codes as a zip archive and extract those to your computer.

git clone https://github.com/tarlepp/how-to-use-phpunit.git

Install packages

After you've got the codes you need to install required dependencies via docker with following command:

docker run -v $(pwd):/app composer install

Note that this command must be run on the same directory where you cloned or unzipped project source files.

Also note that installation is made via composer container - so no need for extra installations to get that working.

Notes for Windows environment

  • Within commands use %cd% (in PowerShell use ${PWD}) instead of $(pwd)
  • Check that you've activated shared drives, open Docker settings from your tray and open Shared Drives
  • If you're using eg. VirtualBox or VMware you need to disable Hyper-V manually if/when you want to use those again

Usage

Start the containers

To start all necessary containers you need to run following command.

docker-compose up -d

This command will download and build all containers at first runtime - and it will take some time.

Performing tests

After previous command is run without errors, you can run phpunit inside container with following command.

docker-compose exec phpunit ./bin/phpunit

You will get test output to your shell where you'll see all possible errors and other information about those tests.

Note that at first time you run this command it will install necessary packages for PhpUnit.

You can run this command at any time you want to run tests again

Next steps

Implement all tests. See next chapter for instructions.

Development

Basics

When your containers are running all code changes are synced automatically to containers - so you don't need to worried about that at all.

Demo 'application'

Application source code lives under ./src directory. Note that application is not a real application - just simple classes that you need to test.

Application itself is built with Symfony framework.

Tests

You can find all the tests under ./tests directory. Tests are divided to three (3) categories:

  • Functional
  • Integration
  • Unit

By default there is base structure for each test that you need to implement by yourself.

Reports

After you have run the tests you can see actual code coverage report under ./build/report/ directory - just open that index.html file with your favorite browser to see if you missed something in your tests.

Seeing what browser is doing

Within Selenium tests it's quite usefully to actually see what browser is actually doing - no worries this is also covered.

For this you need a VNC Viewer so download and install it first.

Next step is to change default password for VNC connection with following command:

docker-compose exec chrome x11vnc -storepasswd <your_password_here> /home/seluser/.vnc/passwd

After that open VNC Viewer and connect to 0.0.0.0:5900

Useful commands

There's few useful commands you can use to manage with containers.

# get shell access to running container
docker-compose exec phpunit /bin/bash

# stop containers
docker-compose down

Need more? Just run docker or docker-compose and you will be provided a list of available commands or give online documentation a change.

Authors

Tarmo Leppänen

License

The MIT License (MIT)

Copyright (c) 2018 Tarmo Leppänen

how-to-use-phpunit's People

Contributors

tarlepp avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

how-to-use-phpunit's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.