Unit_Testing

Isaac Bennetch edited this page Aug 26, 2017 · 7 revisions
Clone this wiki locally

This is a first draft...feel free to elaborate.

phpMyAdmin has two types of unit tests build on PHPUnit:

  • Classic unit tests
  • Browser scenarios (run via Selenium RC, introduced in phpMyAdmin 3.3)

We also use BrowserStack for additional browser tests, which can be run through Travis or locally. Some additional information is available in the phpMyAdmin file .test/README.rst.

PHP Unit

Setup

See: TestingEnvironment

Configuration files

tests/bootstrap.php

This file runs before starting test and contain all general code that should run before tests. You generally don't need to touch it as it does all global setup needed to run testsuite.

phpunit.xml

phpUnit configuation located in file phpunit.xml.dist, phpunit.xml.nocoverage or phpunit.xml.hhvm. In this file located all configuration related for automated testing

  • Organization of TestSuites
  • Selenium browsers configuration
  • Type of logging that phpUnit needs to create
  • php.ini settings, constants and globals variables

More detailed information could be found in PHPUnit official documentation.

Running tests

You can run PHPUnit test from command line for whole suite.

$ cd <pma_dir>
$ ./vendor/bin/phpunit -c phpunit.xml.nocoverage 

PHPUnit 3.5.13 by Sebastian Bergmann.
...............................................................  63 / 317 ( 19%)
.............SSSSS............................................. 126 / 317 ( 39%)
............................................................... 189 / 317 ( 59%)
............................................................... 252 / 317 ( 79%)
............................................................SSS 315 / 317 ( 99%)
SS
Time: 4 seconds, Memory: 28.50Mb

You can also exclude some tests groups, for example:

# Do not run selenium tests
./vendor/bin/phpunit -c phpunit.xml.nocoverage --exclude-group selenium
# Do not run tests which need network
./vendor/bin/phpunit -c phpunit.xml.nocoverage --exclude-group network

# List all available groups
./vendor/bin/phpunit -c phpunit.xml.nocoverage --list-groups

You can filter specific test to run:

./vendor/bin/phpunit -c phpunit.xml.nocoverage --filter URL

Test Class structure

TODO: link to phpdoc ?

The following class hierarchy is used:

  • PHPUnit_Framework_TestCase
    • PHPUnit_Extensions_SeleniumTestCase
      • PmaSeleniumTestCase
        • PmaSeleniumLoginTest
    • PmaTestCase
      • PmaMessageTest

Unit testing