Support for IN operator in Db Module
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
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.
Hey Krukru, I encountered the same issue. By any chance, did u find a solution for it?
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! :)