2013-10-28 26 views
0

我寫了這個簡單的測試:symfony的2和PHPUnit的履帶客戶端沒有達到ngnix

<?php 
namespace Hello\ApiBundle\Tests\Controller; 

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; 

class HelloControllerTest extends WebTestCase { 
    public function test() { 
     $client = static::createClient(); 
     $crawler = $client->request("GET","http://localhost/hello"); 
     $response = $client->getResponse()->getStatusCode(); 
     var_dump($response); 
    } 
} 
?> 

當我運行這個測試,它打印404個狀態碼。

奇怪的是,我沒有看到ngninx訪問日誌上的請求。即使我將URL更改爲"/hello",它仍然看起來像請求未到達本地Web服務器。

不用說,如果我只是打開Chrome並正常嘗試使用此URL(http://localhost/hello),它就可以工作。

  • 我錯過了什麼?

回答

4

這是因爲Symfony的測試框架實際上只模擬請求(並直接在後面運行調度器)。它不發送真正的請求。

當您在測試您的應用程序,使用相對路徑:

$crawler = $client->request("GET","/hello");