M
M
Marcuzy2015-07-15 12:03:32
Yii
Marcuzy, 2015-07-15 12:03:32

Why doesn't codeception see the temporary table?

I'm testing a class for batch insertion into the database.
I create a temporary table for the test (in setUp or in the test method, it doesn't matter)

Yii::$app->db->createCommand(
      'CREATE TEMPORARY TABLE {{%table_loading}} SELECT * FROM {{%table}} LIMIT 0'
    )->execute();

After some operations, I check for the presence of:
$I->canSeeInDatabase('table_loading', ['brand_name'=>'brand_1', 'article_name'=>'article_1', 'no_in_part'=>1]);

As a result of this statement I get an error
Base table or view not found: 1146 Table 'mydatabase.table_loading' doesn't exist

To check in the same test, I added (new \yii\db\Query)->from('{{%table_loading}}')->count() - it works properly. As I understand it, codeception has one connection for the Db module, and Yii::$app->db has another connection, which is why the temporary table is not available.
If my guesses are correct, then the question is for the guru - how to test in such situations, what is good practice?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Paulus, 2015-07-24
@ppokrovsky

If we are talking about Yii2, Codeception for connecting the database inherits the Yii config, redefining only dsn (the name of the test base, see tests/codeception/config/config.php). In this case, the simplest thing is to stick a debugger after CREATE TEMPORARY TABLE and see where the table is being created.

E
ejkot, 2019-01-22
@ejkot

Because the temporary table lives within one session of a DB. The tested script works with one session, codeception creates its own session, from which the first one is not visible. But what to do with it is not clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question