jeudi 8 septembre 2016

CakePHP unit test not recognizing fixtures

I'm on CakePHP v3.x with phpunit v5.1.3. and my unit test does not seem to be recognizing the existance of my fixtures. It appears that the tests are reading from the local (default) database connection.

Here's my TestCase class:

namespace App\Test\TestCase\Model\Table;

use Cake\Datasource\ConnectionManager;
use Cake\I18n\Time;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;

/**
 * App\Model\Table\ScreensTable Test Case
 *
 * @property \App\Model\Table\ScreensTable ScreensTable
 */
class ScreensTableTest extends TestCase
{
    /**
     * Fixtures
     *
     * @var array
     */
    public $fixtures = [
        'app.screens'
    ];

    /**
     * setUp method
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();
        $config = TableRegistry::exists('Screens') ? [] : ['className' => 'App\Model\Table\ScreensTable'];
        $this->Screens = TableRegistry::get('Screens', $config);
    }

    public testSomethingHere(){...}

Here's my fixture file:

<?php
namespace App\Test\Fixture;

use App\TestSuite\Fixture\TestFixture;

/**
 * ScreensFixture
 *
 */
class ScreensFixture extends TestFixture
{
    /**
     * Records
     *
     * @var array
     */
    public $records = [
        [
            'id' => 2,
            'name' => 'Bla bla',
        ],
        ...

When I debug() the returned value from $this->Screens->find('all')->order(['id'=>'ASC'])->first() I see the first REAL record in the DB. Not my fixture.

What am I missing?

Aucun commentaire:

Enregistrer un commentaire