Download the PHP package metamodels/phpunit-contao-database without Composer
On this page you can find all versions of the php package metamodels/phpunit-contao-database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download metamodels/phpunit-contao-database
More information about metamodels/phpunit-contao-database
Files in metamodels/phpunit-contao-database
Package phpunit-contao-database
Short Description MetaModels phpunit contao database classes
License LGPL-3.0+
Homepage http://now.metamodel.me/
Informations about the package phpunit-contao-database
MetaModels database objects for phpunit
What you can expect here.
This repository holds a small subset of classes that can be used to fake a Contao database connection.
To do so, you define the queries and their result sets.
Installation
Add "metamodels/phpunit-contao-database": "~1.0"
to your composer.json
in the require-dev
section and you are set.
How to use it.
In your unit test you simply replace the original Contao database classes by calling the following code (before the
original Contao database classes get loaded via autoloading!). A good place might be the setUp()
-method of your test
case.
Using it in unit tests
You should use dependency injection for proper unit testing, then you can use something like this:
If you should be in the unfortunate position that you can not use dependency injection, as the underlying code is using , you are not out of luck. You can use the method which will return the "default" database instance then.
However using this approach is not suggested as the instance will be shared over all unit tests.