Laravel,phpunit测试完成但它说它有风险吗?

时间:2017-09-21 14:54:57

标签: php laravel phpunit

我刚刚创建了一个简单的测试:

<?php

namespace Tests\Unit;

use Tests\TestCase;
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ResponseTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testHomePage()
    {
        $user = factory(User::class)->create();
        $response = $this->actingAs($user)
                                    ->get('/');
        $response->assertSuccessful();
        $user->forceDelete();
    }
}

我运行phpunit然后得到:

PHPUnit 6.3.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.1.9-1+ubuntu16.04.1+deb.sury.org+1
Configuration: /home/vagrant/laravel/phpunit.xml

R                                                                   1 / 1 (100%)

Time: 1.87 seconds, Memory: 14.00MB

There was 1 risky test:

1) Tests\Unit\ResponseTest::testHomePage
Test code or tested code did not (only) close its own output buffers

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 1, Risky: 1.

现在有人可以向我解释如何避免这种冒险错误吗?这是我的phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    backupGlobals="false"
    backupStaticAttributes="false"
    bootstrap="vendor/autoload.php"
    colors="true"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    processIsolation="false"
    stopOnFailure="false">
    <testsuites>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>

        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
    </php>
</phpunit>

我看不出我的代码有什么问题我也不知道为什么它一直说最好的是有风险的。这是我第一次参加测试,所以任何帮助都会受到赞赏。

0 个答案:

没有答案