0

I am writing a custom plugin for the awesome framework CakePHP, called: TableTool.

My plugin has a default folder structure, created by cake bake:

-app   (some subfolders omitted)
--plugin  
---TableTool
----Config
----Console
----Controller
-----TableToolAppController.php
----Lib
----Model
-----TableToolAppModel.php
                   <= old location of the model
----Test
-----Case
------View
-------Helper
--------TableToolHelperTest.php
------Fixture
--------PostFixtureTest.php
-----TestApp        <= manually added
------Model
-------Post.php     <= new location of the model
----Vendor
----View
-----Helper
------TableToolHelper.php

The plugin is a helper-tool without a specific model. For test purposes a use a Model: Post. It is located in app\plugin\TableTool\Model\Post.php (old location) and works fine in my test case.
Because the model Post.php is only for test purposes I have tried to change the location to: app\plugin\TableTool\Test\TestApp\Model\Post. After the change my test case started with complaining: Model Post could not be found. That wasn`t a surprise. The fixture needs a folder location for the model. I have tried the following:

 class PostFixture extends CakeTestFixture {

    public $import = array('model' => 'TableTool.Model/Post', 'records' => true, 'connection' => 'test_tooltable');

    public function init() {
        App::build(array('TableTool.Model' => array(APP . 'Plugin' . DS . 'TableTool' . DS . 'Test' . DS . 'TestApp' . DS . 'Model' . DS)));
        parent::init();
    }

}

In the lib\cake\Test folder, I have seen a test_app.... I have look around for examples in it, but I didn't found the solution....

Thanks for reading.

4

1 回答 1

0

这是一个插件示例,它使用模型纯粹用于测试目的:https ://github.com/josegonzalez/cakephp-upload

特别是,请参阅此文件:https ://github.com/josegonzalez/cakephp-upload/blob/master/Test/Case/Model/Behavior/UploadTest.php刚刚声明了测试模型类(几乎没有任何代码)在测试文件的顶部。请注意,模型扩展CakeTestModel而不是AppModel

然后夹具非常简单:https ://github.com/josegonzalez/cakephp-upload/blob/master/Test/Fixture/UploadFixture.php

它只包含以下行:

public $name = 'Upload';
于 2013-10-20T23:14:55.583 回答