Laravel 5.1 - phpunit - ErrorException:Undefined属性:ExampleTest :: $ baseUrl

时间:2015-09-11 04:12:27

标签: phpunit laravel-5.1

我有默认设置。我的composer.json有这个:

"require-dev": {
  "fzaninotto/faker": "~1.4",
  "mockery/mockery": "0.9.*",
  "phpunit/phpunit": "~4.0",
  "phpspec/phpspec": "~2.1"
},

当我运行phpunit时,我收到以下错误:我不确定原因?

Sebastian Bergmann和贡献者的PHPUnit 4.8.6。

E

Time: 272 ms, Memory: 13.25Mb

There was 1 error:

1) ExampleTest::testBasicExample
ErrorException: Undefined property: ExampleTest::$baseUrl

我的ExampleTest.php包含以下代码

<?php

class ExampleTest extends TestCase {

    /**
     * A basic functional test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $response = $this->call('GET', '/');

        $this->assertEquals(200, $response->getStatusCode());
    }

}

我对测试很陌生。谢谢你的帮助。

1 个答案:

答案 0 :(得分:4)

从@tk获取信息。您所要做的就是在父类 TestCase

中添加受保护的属性
protected $baseUrl = 'http://yoursite.dev';

它解决了问题