rzajac / php-test-helper
Classes helping with unit tests
Installs: 8 990
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.0
Requires (Dev)
- mikey179/vfsstream: ^1.6
This package is not auto-updated.
Last update: 2021-06-09 16:43:17 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