gpt4 book ai didi

PHPUnit 测试未使用带有 SQLite 数据库的 laravel 6.0 运行

转载 作者:行者123 更新时间:2023-12-03 18:32:21 25 4
gpt4 key购买 nike

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

'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);

};
}

最佳答案

您浏览过the documentation为了这?

The tests are public methods that are named 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*并消费另一个。
// 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
}

关于PHPUnit 测试未使用带有 SQLite 数据库的 laravel 6.0 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58848512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com