如何使用phpspec在Laravel中编写方法测试


How to write a test for method in Laravel using phpspec

嗨,我想在Laravel 4.1中测试一个非常简单的方法。我开始在拉拉维尔进行测试,我希望能在这里得到一些帮助。

我正在使用phpspec。。

方法如下:

public function hasTag($codename)
{
    $tag = $this->tags()->where('codename', '=', $codename)->first();
    if (is_null($tag))
    {
        return false;
    }
    return true;
}

您可以执行以下操作:

function it_looks_for_tag_correctly(Tag $tag)
{
    $tag->setCodeName('Codename');  
    $this->addTag($tag);  // I guess you have a method to add tags
    $this->hasTag($tag)->shouldReturn(true); 
}