<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 24, 2013 at 11:41 AM, Ayush Chaudhary <span dir="ltr"><<a href="mailto:ayushchd@gmail.com" target="_blank">ayushchd@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div>
Hi,
</div><div><br></div><div>I was testing Tracker.class.php. There are a quite a few assertions related to database queries I might need to implement. I wanted to know what would be the best approach between using dummy queries and mocking the database interface class. </div>
<div><br></div><div>What I thought was to use dummy queries when the SQL query is a SELECT statement and the result of the query is being further used. </div>
<div><div><br></div><div>Please advice.</div><div><br></div><div>Thanks!</div><span class=""><font color="#888888"><div>-- </div><div>Ayush Chaudhary</div><div><br></div></font></span></div>
</blockquote></div><br>Hi Ayush,</div><div class="gmail_extra"><br></div><div class="gmail_extra">Dummy DBI and mocking has it's own advantages and choosing between them should be based on the case at hand. Dummy DBI would make it easy to add a common behavior for a query that is used in more than one test case where the expected output of all the tests are the same. On the other hand mocking would give you more control over the behavior. If different tests need to see the database interface return different results for the same query, you have no choice other than mocking.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Another situation where you cannot use dummy DBI is ascertaining the correctness of the queries generated. For example, in Node::getData() to test the correctness of the generated query you need to use mocking. In this case the solution would be to create a mock database interface which expected the correct query just once. </div>
<div class="gmail_extra"><div><br></div>-- <br>Thanks and Regards,<div><br></div><div>Madhura Jayaratne<br><div><br></div></div>
</div></div>