【问题标题】:Laravel 5.1 - phpunit - ErrorException: Undefined property: ExampleTest::$baseUrlLaravel 5.1 - phpunit - ErrorException:未定义的属性:ExampleTest::$baseUrl
【发布时间】:2015-12-07 12:49:00
【问题描述】:

我有默认设置。我的 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());
    }

}

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

【问题讨论】:

    标签: phpunit laravel-5.1


    【解决方案1】:

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

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

    解决了问题

    【讨论】:

      猜你喜欢
      • 2015-10-09
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      相关资源
      最近更新 更多