我是kahlan单元测试的新手,我已将其安装在Symfony上。尝试运行时出现以下错误-vendor / bin / kahlan
错误:
/类别/列表
x它显示类别列表
C:\web\simple-symfony-api-v2\vendor\kahlan\kahlan\src\Scope.php
第109行中抛出了未捕获的异常
message:`Exception` Code(0) with message "Undefined variable `request`."
代码:
namespace App\Spec\Controller;
describe('CategotyController', function() {
describe('/category/list', function() {
it('shows category list', function() {
$request = $this - > request - > create('/category/list', 'GET');
$response = $this - > kernel - > handle($request);
var_dump($response);
});
});
});
答案 0 :(得分:0)
经过测试,调试和对google / documentation的一些阅读后,我发现我不见了-kahlan-config.php-该文件需要添加到Symfony项目的根目录中。
代码:
<?php // kahlan-config.php
use App\Kernel;
use Kahlan\Filter\Filters;
use Symfony\Component\HttpFoundation\Request;
Filters::apply($this, 'bootstrap', function($next) {
require __DIR__ . '/vendor/autoload.php';
$root = $this->suite()->root();
$root->beforeAll(function () {
$this->request = Request::createFromGlobals();
$this->kernel = new Kernel('test', false);
});
return $next();
});