【问题标题】:Include fixture from Tags plugin in app test在应用程序测试中包含来自标签插件的夹具
【发布时间】:2014-04-29 01:27:31
【问题描述】:

我在我的解决方案模型上使用了出色的 CakeDC Tags 插件:

class Solution extends AppModel {
    public $actsAs = array(
        'Tags.Taggable',
        'Search.Searchable',
    );
}

我有一个 SolutionsController::search() 方法:

App::uses('AppController', 'Controller');
class SolutionsController extends AppController {
    public $components = array(
        'Paginator',
        'Search.Prg',
    );
    public $presetVars = true; // using the model configuration ('Search' plugin)

    public function search() {
        $this->Prg->commonProcess();
        $this->Paginator->settings['conditions'] = $this->Solution->parseCriteria($this->Prg->parsedParams());
        $solutions = $this->Paginator->paginate();
        if (!empty($solutions)) {
            $this->Session->setFlash('Solutions found');
        } else {
            $this->Session->setFlash('No solutions found');
        }
        $this->set('solutions', $solutions);
        $this->render('index');
    }

我正在尝试为此方法编写测试:

App::uses('SolutionsController', 'Controller');
class SolutionsControllerTest extends ControllerTestCase {

    public $fixtures = array(
            'app.solution',
            'plugin.tags.tag'
    );

    public function testSearchForOneResultShouldOutputText() {
        $data = array('search' => 'fiery');
        $result = $this->Solution->search($data);
        debug($result);
        $expected = array(
            'id' => 3,
            'name' => 'fiery-colored horse',
            'shortdesc' => 'war',
            'body' => 'it was granted to the one seated on it..',
            'category_id' => 3,
            'created_by' => 1,
            'modified_by' => 1,
            'created' => '2014-02-14 21:28:46',
            'modified' => '2014-02-14 21:28:46'
        );
        $this->assertContains($expected);
    }
}

运行测试时出现此错误: 缺少数据库表 错误:在数据源测试中找不到模型标签的表格标签。

我已尝试将插件 Tag 固定装置复制到我的应用程序 Test/fixtures 文件夹中,并将其作为应用固定装置包含在内。我无法让我的测试运行。如何让我的测试看到来自app\Plugin\tags\Test\Fixture\TagFixture.php 的标签夹具并运行?

【问题讨论】:

  • 您是否在配置中配置了测试数据库?指定用户是否拥有CREATE TABLE 权限?
  • 是的,是的;测试数据库和夹具创建(用于我的应用程序中的模型)一直有效,直到我将插件可标记行为添加到我的解决方案模型中。
  • 如果您从 Web 界面运行插件测试,它们会运行吗?您的代码看起来没问题。
  • 标签插件测试运行良好:32/32 个测试方法完成:32 个通过,0 个失败,80 个断言和 0 个异常。
  • app\Plugin\tags,注意你的外壳。应该是“标签”文件夹。

标签: cakephp phpunit cakedc


【解决方案1】:

问题原来是我的 SolutionsFixture,它导入了表模式和记录,然后 包含了一个 $records 数组(oops)。重新烘焙此夹具以既不导入模式也不导入记录解决了错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多