Pergunta

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.

Foi útil?

Solução

Here's an example of a Plugin that uses a model purely for testing purposes: https://github.com/josegonzalez/cakephp-upload

In particular, see this file: https://github.com/josegonzalez/cakephp-upload/blob/master/Test/Case/Model/Behavior/UploadTest.php where the test model class (having barely any code) is just declared up the top of the test file. Note that the model extends CakeTestModel rather than AppModel

Then the fixture is pretty simple: https://github.com/josegonzalez/cakephp-upload/blob/master/Test/Fixture/UploadFixture.php

It just contains the line:

public $name = 'Upload';
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top