0

我的应用程序通过 http://sm1/app/web/app_dev.php (symfony3) 在本地启动。PHPUnit 测试由框架构建。

namespace Tests\AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class GoodControllerTest extends WebTestCase
{
    public function testCompleteScenario()
    {
        // Create a new client to browse the application
        $client = static::createClient([], ['HTTP_HOST' => 'sm1']);
        // Create a new entry in the database
        $crawler = $client->request('GET', '/good/');
        $this->assertEquals(200, 
            $client->getResponse()->getStatusCode(), 
            "Unexpected HTTP status code for GET /good/"
        );
        $crawler = $client->click(
            $crawler->selectLink('Create a new entry')->link());

但是在测试运行后我有一个错误

There was 1 error:
1) Tests\AppBundle\Controller\GoodControllerTest::testCompleteScenario
InvalidArgumentException: The current node list is empty.

/home/sm1/www/app/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php:735
/home/sm1/www/app/tests/AppBundle/Controller/GoodControllerTest.php:18

并在日志文件中显示此消息:

request.INFO: Matched route "{route}".
    {"route":"good_index","route_parameters":
        {"_controller":"AppBundle\Controller\GoodController::indexAction",
            "_route":"good_index"},
        "request_uri":"http://sm1/good/","method":"GET"} []

如何将“request_uri”从“http://sm1/good/”修复为“http://sm1/app/web/app_dev.php/good/”?

4

1 回答 1

0

必须仅通过http://app启动 Web 应用程序。也就是说,要使用 PHPUnit,您需要一个虚拟主机。如果输入脚本的名称不同于默认名称,请在文件 .htaccess 中注明。

于 2016-12-23T10:58:33.813 回答