module-db icon indicating copy to clipboard operation
module-db copied to clipboard

Support for IN operator in Db Module

Open krukru opened this issue 8 years ago • 3 comments

What are you trying to achieve?

I wanted to check that $I->dontSeeInDatabase from a list of values. Instead of writing

$I->dontSeeInDatabase('someTable', ['foo' => 'cond1']);
$I->dontSeeInDatabase('someTable', ['foo' => 'cond2']);
$I->dontSeeInDatabase('someTable', ['foo' => 'cond3']);

I ended up writing

$I->dontSeeInDatabase('someTable', [
    'foo' => ['cond1', 'cond2', 'cond3']
]);

hoping that it would generate the following query SELECT count(*) FROM someTable WHERE foo IN ('cond1', 'cond2', 'cond3') and assert that the result must be 0. However I ended up getting an exception, saying array-to-string conversion - obviously enough since this is not supported.

Do you think this is something good to have, or just bad test design on my part?

  • Codeception version: 2.3.3

krukru avatar Jun 20 '17 17:06 krukru

This is hard to argue about. I have seen such custom method in past projects as well. From a strict perspective I would not recommend it. It is convenient to use, although the IN command in SQL will query for all given conditions.

TL;TR: When you have different conditions I would advise to either write a custom method or query for each of them individually. Maybe a wildcard condition might for your scenario as well.

Evil-Devil avatar Jun 28 '17 14:06 Evil-Devil

Hey Krukru, I encountered the same issue. By any chance, did u find a solution for it?

kvelicheti avatar Aug 20 '20 13:08 kvelicheti

Hey @kvelicheti, was a long ago - but I think I just ended up going with multiple dontSeeInDatabase conditions, wrapped in some helper method. Good luck with your testing! :)

krukru avatar Aug 20 '20 14:08 krukru