我正在尝试编写一个简单的web测试来使用phpunit测试我的silex api,但是当我尝试运行它时,我一直收到这个错误。
1) App\Tests\BlogControllerTest::testInitialPage
TypeError: Argument 1 passed to Symfony\Component\HttpKernel\Client::__construct() must implement interface Symfony\Component\HttpKernel\HttpKernelInterface, null given, called in C:\vendor\silex\silex\src\Silex\WebTestCase.php on line 63这是我的网络测试
<?php
namespace App\Tests;
use Silex\WebTestCase;
class BlogControllerTest extends WebTestCase
{
public function createApplication()
{
require dirname(dirname(__DIR__)) . '/src/Application.php';
}
public function testInitialPage()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/Blog/1');
$this->assertTrue($client->getResponse()->isOk());
}
}我的Composer文件的内容:
{
"require": {
"silex/silex": "~2.0",
"symfony/validator": "^4.0",
"crell/api-problem": "~1.7",
"tobiassjosten/responsible-service-provider": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "6",
"symfony/browser-kit": "^4.0",
"symfony/css-selector": "^4.0"
},
"autoload": {
"psr-4": {
"App\\": "src/",
"Tests\\": "tests/"
}
}
}发布于 2018-01-15 06:37:11
对于您的
WebTestCase,您必须实现一个createApplication方法,该方法将返回您的应用程序实例:
公共函数createApplication() { // app.php必须返回应用程序实例return require __DIR__.'/path/to/app.php';}
所以这是你需要的:
public function createApplication()
{
return new Application();
}但在大多数情况下,最好从引导程序(bootstrap example)中返回已配置的应用程序:
public function createApplication()
{
require __DIR__.'../web/index-test.php'; // path to your bootstrap file
return $app;
}https://stackoverflow.com/questions/48225255
复制相似问题