使用Laravel 6.0和SQLite数据库无法运行PHPUnit测试

这是我的配置/数据库,如果我能及时得到答复

'connections' => [

    'sqlite' => [
        'driver' => 'sqlite','url' => env('DATABASE_URL'),'database' => env('DB_DATABASE',database_path('database.sqlite')),'prefix' => '','foreign_key_constraints' => env('DB_FOREIGN_KEYS',true),]

...这是phpunit.ml .....

 <testsuite name="Feature">
        <directory suffix="Test.php">./tests/Feature</directory>
    </testsuite>
</testsuites>
<filter>
    <whitelist processUncoveredFilesFromWhitelist="true">
        <directory suffix=".php">./app</directory>
    </whitelist>
</filter>
<php>
    <server name="APP_ENV" value="testing"/>
    <server name="DB_CONNECTION" value="sqlite"/>
     <server name="DB_DATABASE" value=":memory:"/>
    <server name="BCRYPT_ROUNDS" value="4"/>
    <server name="CACHE_DRIVER" value="array"/>
    <server name="MAIL_DRIVER" value="array"/>
    <server name="QUEUE_CONNECTION" value="sync"/>
    <server name="SESSION_DRIVER" value="array"/>
</php>

这是test.php 已经创建了database.sqlite,已经让我感到困惑了

namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

class ThreadTest extends TestCase
 {
   use DatabaseMigrations ;

  public function a_user_can_browse_threads()
 {
     $thread=factory('App\Thread')->create();
     $response = $this->get('/threads');

     $response->assertSee($thread->title);

     };
  }
jingleee 回答:使用Laravel 6.0和SQLite数据库无法运行PHPUnit测试

您是否为此浏览过the documentation

  

测试是名为test *的公共方法。

尝试使用以下内容:

public function testUserCanBrowseThreads() // <-- note the camelCase
{
    $thread = factory(\App\Thread::class)->create();

    $response = $this->get('/threads');

    $response->assertStatus(200); // <-- did you view the thread?

    $response->assertSee($value); //<-- whatever you want to look for 
}

您始终可以编写名为test*的函数 not 并使用另一个函数。

// This won't run by itself
public function fooBar()
{
    $foo = factory(\App\Foo::class)->create();

    $this->assertDatabaseHas('foos',[
        'id' => $foo->id
    ]);

    return $foo;
}


// This will 
public function testFoo()
{
    $bar = $this->fooBar();

    // Use the information in your test
}
,

您需要以test开头测试方法的名称,或在方法的docblock中添加@test批注:

public function test_a_user_can_browse_threads()
{
    // Starting the tests name with 'test'
}

public function testUserCanBrowseThreads()
{
    // Starting the tests name with 'test' in another format
}

/**
 * @test
 */
public function a_user_can_browse_threads()
{
    // Using the @test annotation
}

PHPUnit Docs - Writing Tests

,

已解决

./ vendor / bin / phpunit达到了目的。.直接调用phpunit不适用于最新的laravel versio

本文链接:https://www.f2er.com/3105646.html

大家都在问