Codeception/module-db

[Feature] Add function to check table existence

Closed this issue · 2 comments

Hi,

I need a function to check, if a table exists in the database or not. Maybe it would be possible to extend the functions (dont)SeeInDatabase to do this with empty search parameters.

Thx

seeInDatabase would fail if the table is empty.
I think that the most suitable method is grabColumnFromDatabase.

$I->grabColumnFromDatabase('table', 'column');

It would pass if the table exists and has such column and would fail with error if it doesn't exist.
But it wouldn't coun't assertion. You can use assertIsArray method from Asserts module (or directly from PHPUnit's Assert class.

$column = $I->grabColumnFromDatabase('table', 'column');
$I->assertIsArray($column);

I think this is not so often used thing, as in web development we usually work with pre-defined schema and check the data inside of it. If you test something bigger or different write a custom helper