YamlExportBundle
, (*1)
Symfony2 bundle to export database records into YAML format using a Symfony2 Command., (*2)
This bundle allows you to export specific database records into YAML format enabling DBUnit testing on your repositories functions. This can be used as a very generic export of all rows such as SELECT * FROM table
or you can create a very specific use case using powerful DQL (or native SQL) to export those rows that enable you to have a full test suite for your repository functions., (*3)
What you need
This bundle requires Symfony 2 (or greater) including Doctrine 2, (*4)
Installation
Step 1: Download the YamlExportBundle using composer
Add YamlExportBundle in your composer.json:, (*5)
{
"require": {
"psamatt/yaml-export-bundle": "dev-master"
}
}
Now tell *composer to download the bundle by running the command:, (*6)
$ php composer.phar update psamatt/yaml-export-bundle
, (*7)
Composer will install the bundle to your project's vendor/psamatt
directory., (*8)
- Note: If you don't have Composer yet, download it following the instructions on
http://getcomposer.org/ or just run the following command:
curl -s https://getcomposer.org/installer | php
, (*9)
Step 2: Enable the bundle
Enable the bundle in the kernel:, (*10)
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Psamatt\YamlExportBundle\PsamattYamlExportBundle(),
);
}
Example usage
Using DQL and writing out to Terminal
php app/console psamatt:yaml-export:dump "SELECT * FROM AcmeStoreBundle:BlogPost"
, (*11)
Using DQL and storing output to a specified file
php app/console psamatt:yaml-export:dump "SELECT * FROM AcmeStoreBundle:BlogPost" "/path/to/file.yml"
, (*12)
Using DQL namespaced entity to a specified file
php app/console psamatt:yaml-export:dump "SELECT * FROM \Acme\StoreBundle\Entity\BlogPost" "/path/to/file.yml"
, (*13)
Using SQL and writing out to Terminal
php app/console psamatt:yaml-export:dump "SELECT * FROM blog_posts" --sql
, (*14)
Using SQL and storing output to a specified file
php app/console psamatt:yaml-export:dump "SELECT * FROM blog_posts" "/path/to/file.yml" --sql
, (*15)
** Then in your Unit Test file you need to specify the YAML file **, (*16)
// ..
public function getDataSet()
{
$dataSet = new \PHPUnit_Extensions_Database_DataSet_YamlDataSet(dirname(__FILE__) . "/_files/BlogPost/seed.yml");
// .. Add further YAML files
// $dataSet->addYamlFile(dirname(__FILE__) . "/_files/path/to/other/seed.yml");
return $dataSet;
}
// ..