Joh*_*ans 4 php phpunit laravel
我希望有人可以帮助我.我正在使用laravel 4,我正在编写我的第一个单元测试一段时间但遇到了麻烦.我正在尝试扩展TestCase类,但是我收到以下错误:
PHP Fatal error:  Class registrationTest contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Illuminate\Foundation\Testing\TestCase::createApplication) in /home/john/www/projects/MyPainChart.com/app/tests/registrationTest.php on line 4
现在,如果我有这个权利,那么错误是指一个方法是抽象的事实,那么它所在的类也必须是抽象的.从下面的TestCase类可以看出它是抽象的.我已经搜索了这个错误,但已经画了一个空白.
试图在Laracasts https://laracasts.com/lessons/tdd-by-example上关注这个演员,虽然你必须是一个订阅者才能观看视频,文件在它下面,你可以看到我没有做任何不同的事情.杰弗里路.
我的测试:
<?php
class registrationTests extends \Illuminate\Foundation\Testing\TestCase
{
    /**
     * Make sure the registration page loads
     * @test
     */
    public function make_sure_the_registration_page_loads_ok()
    {
        $this->assertTrue(true);
    }
}
TestCase类的开头:
<?php namespace Illuminate\Foundation\Testing;
use Illuminate\View\View;
use Illuminate\Auth\UserInterface;
abstract class TestCase extends \PHPUnit_Framework_TestCase {
顺便说一句 - Laravel测试类默认不自动加载,因此我尝试了两个完全限定的类名,并使用Illuminate\Foundation\Testing,然后只扩展TestCase.我知道它可以看到它,因为我没有完全限定它抱怨该类无法找到的名称.我也尝试过:
composer dump-autoload
和
composer update
任何帮助赞赏
根据你的错误消息:Class registrationTest contains 1 abstract method在Base Class包含abstract method当一个Child Class扩展了的抽象方法的另一个类,然后在子类应该实现中提供的抽象方法Base class.所以,registrationTest是子类,   \Illuminate\Foundation\Testing\TestCase是基类,它包含一个抽象方法:
\Illuminate\Foundation\Testing\TestCase:abstract public function createApplication();
因此,在您child class/registrationTest必须实现此方法:
public function createApplication(){
    //...
}
但是,实际上你不需要直接扩展,\Illuminate\Foundation\Testing\TestCase因为在app/tests文件夹中有一个类TestCase/TestCase.php,你可以扩展这个类:
// In app/tests folder
class registrationTest extends TestCase {
    //...
}
这个TestCase.php类看起来像这样:
class TestCase extends Illuminate\Foundation\Testing\TestCase {
public function createApplication()
{
        $unitTesting = true;
        $testEnvironment = 'testing';
        return require __DIR__.'/../../bootstrap/start.php';
    }
}
请注意,TestCase已实现该抽象方法,createApplication因此您无需在类中扩展它.您应该使用TestCaseclass作为基类来创建测试用例.因此,在app/tests文件夹中创建测试并创建类,如:
class registrationTest extends TestCase {
    public function testBasicExample()
    {
        $crawler = $this->client->request('GET', '/');
        $this->assertTrue($this->client->getResponse()->isOk());
    }
}
阅读课堂抽象.
| 归档时间: | 
 | 
| 查看次数: | 3193 次 | 
| 最近记录: |