PHPackages                             branchonline/yii2-pgsqltester - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. branchonline/yii2-pgsqltester

ActiveYii2-extension[Testing &amp; Quality](/categories/testing)

branchonline/yii2-pgsqltester
=============================

Extends Yii2 framework with a powerful console controller for tests requiring a postgres database.

1.40(6y ago)12.8k2BSD-3-ClausePHPPHP &gt;=7.0CI failing

Since Jan 17Pushed 4y ago3 watchersCompare

[ Source](https://github.com/BranchOnline/yii2-pgsqltester)[ Packagist](https://packagist.org/packages/branchonline/yii2-pgsqltester)[ RSS](/packages/branchonline-yii2-pgsqltester/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)DependenciesVersions (24)Used By (0)

Yii2 PostgreSQL automated testing setup
=======================================

[](#yii2-postgresql-automated-testing-setup)

Automated setup of empty database and powerful console control of available tests.

#### Example usage

[](#example-usage)

First set up the environment using the instructions in example setup below.

Run all tests:

`./yii_test test/run` or `./yii_test test` (action run is default)

Run all unit tests using (only when you are not using modules, otherwise you have to specify the module):

`./yii_test test -s=unit`

Run all unit tests in module admin using:

`./yii_test test -m=admin`

Run all unit tests in module admin from suite acceptance:

`./yii_test test -s=acceptance -m=admin`

Run specific test by name:

`./yii_test test TestName`

Force to remigrate the test database:

`./yii_test test/prepare-db true`

#### Example setup

[](#example-setup)

**Read carefully and make sure you understand what you're doing before setting anything up!**

###### Databases

[](#databases)

This package provides a clean separation of databases so your tests can always run on an empty database that is in the correct state. To see how it works we identify 4 databases:

- The *dev* database. This database is not touched by the testing mechanism, but should remain accessible for developing.
- The *template* database. This is the database that is migrated to the correct version by the testing system, and may contain all kinds of data that your migrations add by default.
- The *test* databse. This is the database that the actual tests run on. It is prepared by the testing mechanism to be a completely empty copy of the template database.
- The *postgres* databse. This is the default database provided by postgres, that is used by the tester to automatically setup both *template* and *test* database.

###### Yii setup

[](#yii-setup)

You need 2 config files for this setup to work:

- *test.php* should contain credentials for the *postgres* and *test* database.
- *test-setup.php* should overwrite the credentials of *test* with that of *template* and make the test controller available through the controller map.

An example for *test.php*:

```
