CakePHP Fixure Does Not Generate Tables

Asked 2 years ago, Updated 2 years ago, 144 views

UnitTest with CakePHPv2.5.5.

configuration

databases.php

public$xxxx=array(
    // ...
);
public$test_xxxx=array(
    'datasource' = > 'Database/MysqlExportDb',
    'persistent' = > false,
    'host' = > 'localhost',
    'login' = > 'root',
    'password' = > 'root',
    'database' = > 'test',
    'prefix' = >',
    'encoding' = > 'utf8',
);

Fixure Definition

class KeywordFixture extensions CakeTestFixture
{
    public$useDbConfig='test_xxxx';

    public$fields=array(...);

    public$records=array(...);
}

Test Code Side

class ShellTest extensions CakeTestCase
{
    public$fixes=array(
        'plugin.search_export.keyword',
    );
...

Symptom 1

If you run the test without the keywords table present, the following error occurs:

MissingTableException: Table keywords for model keyword was not found in datasource test_xxxx.

Symptom 2

If you manually create and run the keywords table, the keywords table disappears after the test runs correctly.

Question

As the table disappeared in phenomenon 2, we believe that Fixure is recognized in some way.
However, I do not know why the table is not generated.
What are the possible causes?

https://book.cakephp.org/2.0/ja/development/testing.html#id15

cakephp phpunit

2022-09-30 21:28

1 Answers

Since useDbConfig is specified, it may be the following symptoms:

Bottom line:
In order to specify DataSource in useDbConfig in Fixure, a pair of DataSource had to be defined.
Example)
$test_hoge=array(/*.../); then $hoge=array(/...*/);
must be defined.

CakePHP's $useDbConfig (memorandum) - nmtysh.log http://nmtysh.hatenablog.com/entry/2013/11/27/005000


2022-09-30 21:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.