Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use phpunit to build a dev db. I wrote a <a href="https://github.com/elcash/mageunit-satellite/blob/master/generate_flat_xml.php" rel="nofollow">short script</a> which dumps xml data from the live database and I used it table-by-table, munging anything sensitive and deleting what I didn't need. The schema for my dev database never changes and never gets rebuilt. Only the data gets dropped and recreated each phpunit run.</p> <p>May not be the right solution for everyone because it's never going to be good for syncing dev up to stage/production, but I don't need to do that.</p> <p>The main benefit is how little data I need for the dev db. It's about 12000 lines of xml, and handles populating maybe 30 different tables. Some small core tables persist as I don't write to them and many tables are empty because I do not use them.</p> <p>The database is a representative sample, and is very small. Small enough to edit as a text file, and only a few seconds to populate each time I run tests.</p> <p>Here's what it looks like at the top of each PHPUnit test. There's good documentation for <a href="http://www.phpunit.de/manual/current/en/index.html" rel="nofollow">PHPUnit</a> and <a href="http://www.phpunit.de/manual/current/en/database.html" rel="nofollow">DbUnit</a></p> <pre><code>&lt;?php require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'top.php'; require_once "PHPUnit/Extensions/Database/TestCase.php"; class SomeTest extends PHPUnit_Extensions_Database_TestCase { /** * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection */ public function getConnection() { $database = MY_DB $hostname = MY_HOST $user = MY_USER $password = MY_PASS $pdo = new PDO("mysql:host=$hostname;dbname=$database", $user, $password); return $this-&gt;createDefaultDBConnection($pdo, $database); } /** * @return PHPUnit_Extensions_Database_DataSet_IDataSet */ public function getDataSet() { return $this-&gt;createXMLDataSet(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Tests/_files/seed.xml'); } } </code></pre> <p>So, now you just need a seed file that DbUnit reads from to repopulate your database each time Unit tests are invoked.</p> <p>Start by copying your complete database twice. One will be your dev database and the second will be your "pristine" database, that you can use to dump xml data in case you start having key issues.</p> <p>Then, use something like my xml dumper againt the "prisine" database to get your xml dumps and begin building your seed file.</p> <pre><code>generate_flat_xml.php -tcatalog_product_entity -centity_id,entity_type_id,attribute_set_id,type_id,sku,has_options,required_options -oentity_id &gt;&gt; my_seed_file.xml </code></pre> <p>Edit the seed file to use only what you need. The small size of the dev db means you can examine differences just by looking at your database versus what's in the text files. Not to mention it is much faster having less data.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload