2017-07-12 31 views
1

我想用Request::fullUrl來測試一個幫助函數。Laravel5.4:如何模擬當前頁面?

function foo($arg) 
{ 
    // Get current full URL. 
    $url = Request::fullUrl(); 

    // Return modified URL. 
    return $url; 
} 

docs說:

你不應該嘲笑請求門面。相反,在運行測試時,將所需的輸入傳遞給HTTP輔助方法,例如get和post。

什麼是「HTTP幫手方法」? 他們的意思是「TestCase::get」和「TestCase::post」?

是的,我的問題是通過使用$this->get()解決的。 但這是正確的方式?

class MyHelperTest extends TestCase 
{ 
    public function testFoo() 
    { 
     // Move to index page. 
     $this->get('/'); 

     // Get a modified URL. 
     $url = foo('arg'); 

     $this->assertEquals('Expected URL', $url); 
    } 
} 

回答