2013-08-02 56 views
0

當前,在編寫測試之後,如果函數名爲link_to(),以下函數將返回PHPUnit的輸出,但如果命名爲link_tox(),則返回結果。爲什麼是這樣?爲什麼在Laravel中,PHPUnit中沒有名爲'link_to'的函數返回值?

應用程序/ helpers.php

<?php 

function link_to($url, $body) { 
    $url = url($url); 
    return "<a href='{$url}'>{$body}</a>"; 
} 

應用程序/測試/ ExampleTests.php

<?php 


class FunctionsTest extends TestCase { 

    public function testGeneratesAnchorTag() { 
     $actual = link_to('dogs/1', 'Show Dog'); 
     $expected = "<a href='http://localhost/dogs/1'>Show Dog</a>"; 

     $this->assertEquals($expected, $actual); 
    } 

} 
+1

可能已經有一個名爲link_to()的函數 - 也許讓你的幫助函數成爲一個名爲MyHelpers :: link_to()的類? – Laurence

+0

@TheShiftExchange爲什麼沒有顯示錯誤? – Nyxynyx

回答

相關問題