Mirko Pagliai
Mirko Pagliai

Reputation: 1246

CakePHP 3.3: on tests, it asks for error templates

I've a plugin with only one controller with only one action:

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;
    }
}

This only sends an asset file.

Now I'm writing a test for an asset file that does not exist.

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

    $this->assertResponseFailure();
}

But it asks for error template:

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

The plugin does not have template and there is no app with templates. So I would expect that it uses templates from CakePHP core, but this does not happen. Where am I wrong?

Upvotes: 0

Views: 432

Answers (1)

ndm
ndm

Reputation: 60503

There is no Error/error500.ctp template in the core, that's something that the application has to supply.

When testing plugins, you should register a proper test application environment, and provide the necessary templates for it. If you look at how the CakePHP core and plugins do it, they create/register a dummy application in the tests folder where such template files can then be placed.

See also

Upvotes: 1

Related Questions