Download the PHP package hotel-quickly/nette-phpunit without Composer
On this page you can find all versions of the php package hotel-quickly/nette-phpunit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hotel-quickly/nette-phpunit
More information about hotel-quickly/nette-phpunit
Files in hotel-quickly/nette-phpunit
Package nette-phpunit
Short Description Nette + PHPunit + Multiple dbs + fixtures
License MIT
Informations about the package nette-phpunit
Nette PHPUnit 
- Support multiple database connections
- Support multiple fixtures formats loading (for each connection)
Getting started
Installation
Run the following commands to install this package
Usage
In order to use Database test case, you must extend your base class from HQ\Test\AbstractDbTestCase
and implement these 3 methods
getContainer
- This method will returnNette\Di\Container
instance.getConnections
- Return an array ofHQ\Test\Connection\AbstractConnection(connectionName, baseSchema, ...)
connections object.- connectionName - A database connection name, which will be used as a prefix of fixture file.
- baseSchema - Database schema which includes
CREATE TABLE ...
sql statements.
getBaseFixtureDir
- Return a base directory for searching base fixture file (see
Working with fixtures
Loading fixtures
By default, fixtures will be automatically loaded from 3 places, in the following orders
base fixtures
class fixtures
instance fixtures
1. base fixtures
This is a primary fixtures that will be loaded for all test cases (think of it as initial data for the whole apps)
2. class fixtures
This will be loaded each time test case was invoked.
3. instance fixtures
This is pretty much the same as class fixtures
, except that we define the fixture inside TestCase
itself (so only php array
is supported.
Fixture formats + structure
This library currently supports 3 fixture formats e.g. json
, yaml
and php
.
All formats has the same fixture structure i.e.
json
example
yaml
example
php
example - NOTE - Don't forget to put return
statement
Improving testing speed
Due to the overhead of creating database schema at the beginning of the tests (only once). This might slow down your test suites speed. You can avoid this problem by exporting UNITTEST_CREATE_SCHEMA=false
env and then run unit test as usual. This will make it skips database schema create overhead.
Common problems
- InvalidArgumentException: There is already a table named account with different table definition.
This error indicates that your fixtures for same dataset (table
e.g. user
) has different column structure.
For example, you have default-fixtures.yaml
that contains user
table and it has the following fields
But somewhere in other fixtures, you have same user table with different fields e.g.
This will cause the above error. To fix this, just make sure you define the same fields on each fixtures.
- ErrorException: ini_set(): Cannot change zlib.output_compression - headers already sent
This happens when Nette has php ini zlib.output_compression
enabled in the container. Removing this config during testing will fix this error