簡體   English   中英

Laravel 6.x 命令測試中缺少 TestCase::artisan()

[英]Missing TestCase::artisan() in Laravel 6.x Command Test

我按照文檔創建了一個非常基本的控制台命令測試:

<?php

namespace Tests\Feature;

use PHPUnit\Framework\TestCase;

class QueueJobCommandTest extends TestCase
{


    /**
     * Test a job argument is requied
     *
     * @return void
     */
    public function testNoArgumentsIsError()
    {
        $this->artisan('queue:job')
            ->expectsOutput('No job specified')
            ->assertExitCode(0);
    }
}

但是當我運行 phpunit 時出現錯誤:

Error: Call to undefined method Tests\\Feature\\QueueJobCommandTest::artisan()

關於為什么TestCase::artisan()未定義的任何幫助都將受到極大的贊賞。

擴展 Laravel 版本的 TestCase

use Tests\TestCase;

希望這可以幫助

您必須從 Laravel 擴展包含所有 Laravel 功能的 TestCase。 在這一點上,文檔非常好。

https://laravel.com/docs/5.8/testing

<?php

namespace Tests\Unit;

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

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $this->assertTrue(true);
    }
}

那應該可以解決您的問題。 有時我創建一個類,我可以在其中添加一些用於身份驗證的特殊函數,並從該類擴展,該類從 Laravel TestCase 類擴展而來。 然后您可以在該類中添加您的自定義函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM