Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for IN operator in Db Module #17

Open
krukru opened this issue Jun 20, 2017 · 3 comments
Open

Support for IN operator in Db Module #17

krukru opened this issue Jun 20, 2017 · 3 comments

Comments

@krukru
Copy link

krukru commented Jun 20, 2017

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
@Evil-Devil
Copy link

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.

@kvelicheti
Copy link

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

@krukru
Copy link
Author

krukru commented Aug 20, 2020

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! :)

@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants