Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Setting up testing database

Ariel Vallese edited this page Dec 14, 2016 · 12 revisions

Introduction

This page will guide you to setup your testing database to be able to run PHPUnit, for development.

Prerequisites

Make sure you have already installed timegrid and updated composer packages with --dev parameter.

Steps

From your command-line, access to the mysql prompt.

mysql -u root -p

Once into the MySQL console

-- Create a database called `testing_timegrid`:

CREATE DATABASE testing_timegrid;

-- Create a user with the same name:

CREATE USER 'testing_timegrid'@'localhost' IDENTIFIED BY 'testing_timegrid';

-- Grant all permissions:

GRANT ALL PRIVILEGES ON `testing_timegrid`.* TO 'testing_timegrid'@'localhost';

Logout from mysql prompt

Ctrl + D

From your command-line, run the migrations:

php artisan migrate --database=testing

You should be ready to run unit tests with phpunit:

vendor/bin/phpunit

Test Coverage

You will find the current test coverage status on CodeClimate

Generating your own local Test Coverage report

You may run:

php -d xdebug.profiler_enable=on vendor/bin/phpunit --coverage-html build/coverage --testdox-html build/testdox.html

Or enable xdebug and the logging directive on phpunit.xml

The reports will be generated on the build/ directory.

Troubleshooting

If it seems like the environment is incorrect when you run tests. Before running them, make sure your config is not cached:

php artisan config:clear

Known Random Failures

Due to random generated data, some test cases may randomly fail.

Follows a list of failures that can be retried and get them pass.

1) ManagerBusinessServiceControllerTest::it_shows_the_business_service_page_for_management

1) ManagerBusinessServiceControllerTest::it_shows_the_business_service_edit_page_for_management

1) SeedingUnitTest::it_creates_a_demo_scenario
Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry

1) UserAgendaControllerTest::it_takes_a_reservation_with_timeslot_on_shifted_timezone

1) ManagerSearchControllerTest::it_finds_an_appointment_by_code

1) UserContactControllerTest::it_can_change_nin_of_a_contact

They are, of course, marked for improvement on either the test or production code to handle those annoying border scenarios.