我在尝试使用固定装置测试插件时遇到了麻烦。
我已经在tests/Fixture下创建了fixture文件,其结构作为文档:
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'
],
];
}
然后在测试用例中我使用公共(public)变量固定装置加载固定装置:
<?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'
];
...
当我尝试运行 phpunit 时,出现下一个错误:
..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]
我尝试创建一个自定义 bootstrap.php 进行测试,但我不知道那里必须有什么。我复制了这个https://github.com/Xety/Cake3-Upload/blob/master/tests/bootstrap.php但它会引发很多错误。
我也用谷歌搜索过,但找不到任何有关插件测试的信息,也找不到官方文档。
关于如何实现这一目标有什么想法吗?
最佳答案
好吧,最后我认为错误出在生成 Composer 自动加载器的方式上。我一直在研究如何在运行 composer dump-autoload
的 autoload_psr4.php
上添加我的 Test\Fixture\命名空间。
因此,我解决此问题的方法是在插件的 composer.json
上添加正确的行,并运行 composer update
以很好地生成自动加载。
注意,当插件安装在供应商下时,composer dump-autoload
不会更新您的插件 psr4 路由。
关于php - 如何使用装置测试 cake3 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31056333/