rzajac/php-test-helper

This package is abandoned and no longer maintained. No replacement package was suggested.

Classes helping with unit tests

2.0.3 2018-03-19 12:24 UTC

README

Unit testing helper.

What does it help with?

  • Load database fixtures (sql).
  • Load file fixtures (json, txt, php).
  • Tests where you interact with database.
  • Database helper methods see database interface.

Supported databases.

  • MySQL

Install.

{
    "require": {
        "rzajac/php-test-helper": "^2.0"
    }
}

Run unit tests.

Yes! The package has it's own unit tests.

$ vendor/bin/phpunit --coverage-html=./coverage 

Setup database for unit tests.

MySQL.

Create test users and database tables:

CREATE DATABASE testHelper1 DEFAULT CHARACTER SET = 'utf8' DEFAULT COLLATE = 'utf8_general_ci';
CREATE DATABASE testHelper2 DEFAULT CHARACTER SET = 'utf8' DEFAULT COLLATE = 'utf8_general_ci';

CREATE USER 'testUser'@'localhost' IDENTIFIED BY 'testUserPass';
CREATE USER 'testUser'@'%' IDENTIFIED BY 'testUserPass';
GRANT ALL ON `testHelper1`.* TO 'testUser'@'localhost';
GRANT ALL ON `testHelper2`.* TO 'testUser'@'localhost';
GRANT ALL ON `testHelper1`.* TO 'testUser'@'%';
GRANT ALL ON `testHelper2`.* TO 'testUser'@'%';
FLUSH PRIVILEGES;

Run tests:

$ vendor/bin/phpunit

When you have XDebug enabled running unit tests creates coverage report in coverage directory.

Loading time zone tables.

$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql -p

License.

Apache License Version 2.0