Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I setup database testing in our project and here are some answers and lessons that worked for us:</p> <blockquote> <p><strong>Should I create a testdb database or is that all emulated/virtual ?</strong></p> </blockquote> <p>I was asking the same question at the beginning and we both learned that it is indeed, a real database running.</p> <blockquote> <p><strong>I've seen many examples using sqlite::memory: , is it a good idea to test MySQL based query with sqlite ? Can I use mysql::memory: instead ?</strong></p> </blockquote> <p>I tried to use sqlite for performance, but found that the SQL would be different enough not to be usable every where with our existing code. I was able to use the MySQL MEMORY engine for most tables thought (not possible for some tables such as BLOB columns).</p> <blockquote> <p><strong>If it's a real DB, how do I restore all the data from dbData.xml in the DB before each test run ?</strong></p> </blockquote> <p>I wrote a script to call mysqldump of the schemas and all their tables from our remote test server, insert them in the local server, and convert all possible table engines to MEMORY. This does take time, but as the schemas don't change between tests, it is only run once at the top most TestSuite or separately as a developer needs on their local system.</p> <p>The datasets are loaded at the beginning of each test and since the table already exists and is in memory, the inserting and truncating between tests is fast.</p> <blockquote> <blockquote> <p><strong>Where am I supposed to call getConnection() and getDataSet() ?</strong></p> </blockquote> </blockquote> <p>We already had a helper class that extended TestCase, so I couldn't use PHPUnit_Extensions_Database_TestCase. I add setup functions into that helper class and never called or had to implement getDataSet(). I did use getConnection() to create datasets from modified data in an assert function.</p> <pre><code>/** * @param PHPUnit_Extensions_Database_DataSet_IDataSet $expected_data_fixture * @param string|array $tables */ protected function assertDataFixturesEqual($expected_data_fixture, $tables){ if(!is_array($tables)){ $tables = array($tables); } PHPUnit_Extensions_Database_TestCase::assertDataSetsEqual($expected_data_fixture, $this-&gt;DbTester-&gt;getConnection()-&gt;createDataSet($tables)); } </code></pre> <p>EDIT: I found some bookmarks of resources I used as the PHPUnit documentation is a little lacking:</p> <p><a href="http://www.ds-o.com/archives/63-PHPUnit-Database-Extension-DBUnit-Port.html" rel="nofollow">http://www.ds-o.com/archives/63-PHPUnit-Database-Extension-DBUnit-Port.html</a></p> <p><a href="http://www.ds-o.com/archives/64-Adding-Database-Tests-to-Existing-PHPUnit-Test-Cases.html" rel="nofollow">http://www.ds-o.com/archives/64-Adding-Database-Tests-to-Existing-PHPUnit-Test-Cases.html</a></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.
    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