CakePHP 3灯具不能导入

时间:2015-09-02 11:11:41

标签: php phpunit cakephp-3.0 fixtures

我使用phpunit测试CakePHP 3控制器。问题是它没有导入灯具。它只是导入实时DB数据。即使我已经定义了测试DB和夹具,读取和写入也只使用LIVE DB。我下面做错了吗?

我的夹具

class ToursFixture extends TestFixture {

    public $connection = 'test';
    public $fields = [
    'id' => ['type' => 'integer'],
    'title' => ['type' => 'string', 'length' => 255, 'null' => false],
    'created' => 'datetime',
    'modified' => 'datetime'
    '_constraints' => [
        'primary' => ['type' => 'primary', 'columns' => ['id']]
    ]
];

public $records = [
    [
        'title' => 'tour 1',
        'created' => '2015-07-24 09:15:48',
        'modified' => '2015-07-24 09:15:48',
    ],
];

}

我的测试班

namespace App\Test\TestCase\Controller;

use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestCase;
use Cake\TestSuite\TestCase;
use App\Controller\ToursController;
use Cake\TestSuite\Fixture\TestFixture;

require '../../bootstrap.php';

class ToursControllerTest extends IntegrationTestCase {

    public $fixtures = ['app.tours'];

App Config DB

'test' => [
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Mysql',
        'persistent' => false,
        'host' => 'localhost',

0 个答案:

没有答案