提问人:Floris 提问时间:9/28/2023 更新时间:9/28/2023 访问量:35
Symfony WebTestCase InvalidArgumentException: 无效的 “base_uri” 选项
Symfony WebTestCase InvalidArgumentException: Invalid "base_uri" option
问:
我正在尝试为我的symfony 5.4应用程序设置功能测试。 但是,我不断收到以下异常:
App\\Tests\\Functional\\LoginTest::testSomething
Symfony\\Component\\HttpClient\\Exception\\InvalidArgumentException: Invalid "base_uri" option: host or scheme is missing in "".
/home/wwwroot/app/vendor/symfony/http-client/HttpClientTrait.php:449
/home/wwwroot/app/vendor/symfony/http-client/ScopingHttpClient.php:49
/home/wwwroot/app/var/cache/test/ContainerQAJT6OS/App_KernelTestDebugContainer.php:4986
/home/wwwroot/app/var/cache/test/ContainerQAJT6OS/App_KernelTestDebugContainer.php:10601
/home/wwwroot/app/var/cache/test/ContainerQAJT6OS/App_KernelTestDebugContainer.php:629
/home/wwwroot/app/var/cache/test/ContainerQAJT6OS/App_KernelTestDebugContainer.php:13645
/home/wwwroot/app/var/cache/test/ContainerQAJT6OS/App_KernelTestDebugContainer.php:2150
/home/wwwroot/app/vendor/symfony/event-dispatcher/EventDispatcher.php:245
/home/wwwroot/app/vendor/symfony/event-dispatcher/EventDispatcher.php:76
/home/wwwroot/app/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:293
/home/wwwroot/app/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:148
/home/wwwroot/app/vendor/symfony/http-kernel/HttpKernel.php:223
/home/wwwroot/app/vendor/symfony/http-kernel/HttpKernel.php:86
/home/wwwroot/app/vendor/symfony/http-kernel/Kernel.php:202
/home/wwwroot/app/vendor/symfony/http-kernel/HttpKernelBrowser.php:65
/home/wwwroot/app/vendor/symfony/framework-bundle/KernelBrowser.php:183
/home/wwwroot/app/vendor/symfony/browser-kit/AbstractBrowser.php:398
/home/wwwroot/app/tests/Functional/LoginTest.php:12
我不知道为什么我会遇到这个问题,因为我的LoginTest.php中的代码几乎与Symfony 5.4文档提供的代码相同(链接)。
我的代码如下:
<?php
namespace App\Tests\Functional;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class LoginTest extends WebTestCase
{
public function testSomething(): void
{
$client = static::createClient();
$crawler = $client->request('GET', '/login');
$this->assertResponseIsSuccessful();
}
}
有谁知道如何解决这个问题?
我尝试将基本 uri 设置为 createClient 参数。这是行不通的。我只是不明白为什么代码在普通的symfony系统中工作,而在我的系统中却不行。
答: 暂无答案
评论