CakePHP 3.3:在测试中,它要求提供错误模板

米尔科·帕格莱(Mirko Pagliai)

我有一个只有一个控制器且只有一个动作的插件:

class AssetsController extends Controller
{
    /**
     * Renders an asset
     * @param string $filename Asset filename
     * @param string $type Asset type (`css` or `js`)
     * @return Cake\Network\Response|null
     */
    public function asset($filename, $type)
    {
        $this->response->type($type);
        $this->response->file(ASSETS . DS . $filename);

        return $this->response;
    }
}

这仅发送资产文件。

现在,我正在为不存在的资产文件编写测试。

public function testAssetNoExistingFile()
{
    $this->get('/assets/css/noexistingfile.css');

    $this->assertResponseFailure();
}

但它要求错误模板:

1) Assets\Test\TestCase\Controller\AssetsControllerTest::testAssetNoExistingFile
Cake\View\Exception\MissingTemplateException: Template file "Error/error500.ctp" is missing.

该插件没有模板,也没有带有模板的应用程序。因此,我希望它使用来自CakePHP核心的模板,但这不会发生。我哪里错了?

ndm

Error/error500.ctp核心中没有模板,这是应用程序必须提供的模板。

在测试插件时,您应该注册一个适当的测试应用程序环境,并为其提供必要的模板。如果您查看CakePHP核心和插件的工作方式,它们将tests在可放置此类模板文件文件夹中创建/注册一个虚拟应用程序

也可以看看

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章