Download the PHP package brunty/kahlan-pdo without Composer
On this page you can find all versions of the php package brunty/kahlan-pdo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brunty/kahlan-pdo
More information about brunty/kahlan-pdo
Files in brunty/kahlan-pdo
Package kahlan-pdo
Short Description ? Provides functionality to work with PDO, reset a database and load fixtures within Kahlan
License MIT
Informations about the package kahlan-pdo
Kahlan PDO
🗄 Provides functionality to work with PDO, reset a database and load fixtures within Kahlan
Requirements
- PHP >= 7.0
- Kahlan ^3.0
Installation
composer require brunty/kahlan-pdo --dev
Setup
Folders:
- Create a folder to store your database related files (
/spec/db
is suggested) - Create a folder to store your SQL files to load into the database (
/spec/db/sql
is suggested) - Within the folder where your database related files will be stored created a file
reset.php
which will be the file you'll use to reset your DB whenever you call the function to do so. - Within the folder where your database related files will be stored, created a
fixtures
folder - Create fixtures as you need for your tests in the
fixtures
folder.
Config:
In kahlan-config.php
setup the path to your db folder and if you wish to use the \Brunty\Kahlan\PDO\sql()
helper function, add the path to a directory that will hold SQL files as follows:
Usage
Using the \Brunty\Kahlan\PDO\reset()
function without a parameter will create an in-memory database in SQLite, but you can pass the DSN, username and password to it and it'll use those instead.
With loading fixtures, you can then create a file within /spec/db/fixtures
and call the name of that file (without the .php
extension) to do whatever you might need to load data into the database.
For example:
\Brunty\Kahlan\PDO\load('things');
would load the file: /spec/db/fixtures/things.php
into the database.
You could setup objects yourself with something like Faker or you could just load SQL into the database directly:
In /spec/db/fixtures/things.php
:
The helper function \Brunty\Kahlan\PDO\db()
returns the instance of PDO that is in the Kahlan box.
The helper function \Brunty\Kahlan\PDO\sql()
loads SQL from the file given (in the \Kahlan\box('db.path.sql')
directory, without the .sql
extension) into the PDO instance in the Kahlan box.
Contributing
This started as a small personal project.
Although this project is small, openness and inclusivity are taken seriously. To that end a code of conduct (listed in the contributing guide) has been adopted.
Contributor Guide