【问题标题】:Laravel 5.3 - Win10 - PHPUnit - Test code or tested code did not (only) close its own output buffersLaravel 5.3 - Win10 - PHPUnit - 测试代码或测试代码没有(仅)关闭自己的输出缓冲区
【发布时间】:2017-04-07 17:34:06
【问题描述】:

Laravel 5.3,Windows 10,VS 代码。 PHPUnit 将最简单的测试标记为“有风险”。 任何想法为什么?

我已经尝试了各种 PHPUnit 设置来切换“风险”输出缓冲区错误,这是最简单的测试,所以我不确定从哪里开始了解它发生的原因。

VS Code 终端输出...

C:/Source/laravel/vendor/bin/phpunit.bat -v -c
C:/Source/laravel/phpunit.xml ./laravel/tests/ExampleTest.php PHPUnit
5.6.2 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.0.12 with Xdebug 2.4.1 Configuration:
C:\Source\laravel\phpunit.xml R                                       
1 / 1 (100%) Time: 562 ms, Memory: 28.00MB There was 1 risky test: 1)
ExampleTest::testBasicExample Test code or tested code did not (only)
close its own output buffers

控制器。

    <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class TestController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
    }

    public function index()
    {
        return 'OK';
    }
}

测试

    <?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ExampleTest extends TestCase
{
    /**
     * A basic functional test example.
     *
     * @return void
     */
    public function testBasicExample()
    { 
        $this->visitRoute('test')
              ->seeText('OK');
    }
}

路线:

Route::get('/test', 'TestController@index')->name('test');

【问题讨论】:

    标签: php laravel phpunit


    【解决方案1】:

    我刚刚想通了...问题出在 TestCase '要求/包括' wp-load.php 文件上,因为我在控制器中使用了一些 wordpress 功能。删除它就可以了。

    【讨论】:

      猜你喜欢
      • 2014-08-15
      • 2013-11-10
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 2023-04-01
      • 2018-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多