Symfony2 + Codeception给出“您必须重写KernelTestCase :: createKernel()”。 [英] Symfony2 + Codeception gives "You must override the KernelTestCase::createKernel()"

查看:57
本文介绍了Symfony2 + Codeception给出“您必须重写KernelTestCase :: createKernel()”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个继承自WebTestCase的新测试。当我运行代码接受测试时,出现以下错误:

I created a new test that inherits from WebTestCase. When I run my codeception tests, I get the following error:

 [RuntimeException] You must override the KernelTestCase::createKernel() method.

我不清楚我需要覆盖什么。我想要的是一个可以调用特定URI以获得我的http响应的客户端

It is very unclear to me with what I need to override it. What I want is a client that can call a certain URI to get my http response

这是测试:

  public function testSearchAction()
    {
        $searchUri = '/search';
        $client = static::createClient();
        $client->request('GET', $searchUri);
        $response = $client->getResponse();
        $this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
    }

这是我的unit.suite.yml文件

This is my unit.suite.yml file

类名:UnitTester

class_name: UnitTester

modules:
    enabled:
        - Symfony2:
            app_path: '../../app'
            var_path: '../../app'
        - Doctrine2:
            depends: Symfony2
        - AppBundle\Helper\Unit


推荐答案

我刚遇到尝试将现有的测试从WebTestCase扩展到Codeception时,会遇到相同的问题。在 tests / functional / _bootstrap.php 中设置 KERNEL_DIR 为我解决了这个问题:

I just ran into the same problem when trying to integrate existing tests extending from WebTestCase into Codeception. Setting KERNEL_DIR in tests/functional/_bootstrap.php solved the issue for me:

<?php
$_SERVER['KERNEL_DIR'] = __DIR__ . '/../../app/';

这篇关于Symfony2 + Codeception给出“您必须重写KernelTestCase :: createKernel()”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆