jeudi 25 juin 2015

How to test cake3 plugins with fixtures

I'm having troubles trying to test a plugin using fixtures.

I've created the fixtures files under tests/fixtures with the structure as documentation:

namespace Files\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

/**
 * FiledFixture
 *
 */
class FiledFixture extends TestFixture {

    /**
     * Table name
     *
     * @var string
     */
    public $table = 'filed';

    /**
     * Fields
     *
     * @var array
     */
    public $fields = [
        'id' => [
            'type' => 'integer',
            'length' => 11,
            ...
        ],
        'foreign_key' => [
            'type' => 'integer',
            ...
        ],
        ...
    ];

    /**
     * Records
     *
     * @var array
     */
    public $records = [
        [
            'id' => 1,
            'foreign_key' => 1,
            'file_id' => 1,
            'filedtype_id' => 1,
            'model' => 'Lorem ipsum dolor sit amet',
            'language' => 'Lore',
            'created' => '2014-11-01 19:21:54',
            'modified' => '2014-11-01 19:21:54'
        ],
    ];
}

And then in the TestCase i load the fixtures with the public variable fixtures:

<?php
namespace Files\Test\TestCase\Model\Table;

use Cake\ORM\TableRegistry;
use Files\Model\Table\FiledTable;
use Cake\TestSuite\TestCase;

/**
 * Files\Model\Table\FiledTable Test Case
 */
class FiledTableTest extends TestCase {

    /**
     * Fixtures
     *
     * @var array
     */
    public $fixtures = [
        'plugin.files.filed',
        'plugin.files.files',
        'plugin.files.filedtypes',
        'plugin.files.thumbs'
    ];
...

When I try to run phpunit I get the next error:

..Exception: Referenced fixture class "Files\Test\Fixture\FiledFixture" not found. Fixture "plugin.files.filed" was referenced in test case "Files\Test\TestCase\Model\Table\FiledTableTest". in [/home/genar/src/metropolitan-web-2015/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureManager.php, line 180]

I tryed to create a custom bootstrap.php for testing but I cannot figure what has to be there. I copyed this one http://ift.tt/1Nfdv5G but it raises a lot of errors.

I've googled as well but I cannot find any information about testing on plugins, nor on the oficial documentation.

Any thoughts on how can I achieve this?

Aucun commentaire:

Enregistrer un commentaire