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 に答える