Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 建立测试环境laravel_Php_Laravel_Testing - Fatal编程技术网

Php 建立测试环境laravel

Php 建立测试环境laravel,php,laravel,testing,Php,Laravel,Testing,我最近设置了一个新的laravel 8项目,我想在内存中运行测试,因此我将测试环境设置为以下: 在phpunit.xml中,我设置了数据库 .env.testing 在测试班: 所有这些之后,当我运行php artisan测试--filter create_new_user时,测试通过了,但它清除了我的真实数据库,而不是使用:内存: 任何建议 <server name="DB_CONNECTION" value="sqlite"/>

我最近设置了一个新的
laravel 8
项目,我想在内存中运行测试,因此我将测试环境设置为以下:

  • phpunit.xml
    中,我设置了数据库
  • .env.testing
  • 在测试班:
所有这些之后,当我运行php artisan测试--filter create_new_user时,测试通过了,但它清除了我的真实数据库,而不是使用
:内存:

任何建议

<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],
APP_NAME="Laravel 8 Project"
APP_ENV=testing
APP_KEY=base64:kNA1tcEgBCybuoN456B4iRqyvfImfTmdKzqYeYGEJhg=

DB_CONNECTION=sqlite
DB_DATABASE=db.sqlite

TELESCOPE_ENABLED=false
<?php

namespace Tests\Feature;

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

class ContactFormComponentTest extends TestCase
{
    use RefreshDatabase;

    /** @test  */
    function create_new_user()
    {
        $user = new User();
        $user->name = 'john doe';
        $user->email = 'john.doe@gmail.com';
        $user->password = 'password';

        $savedUser = $user->save();

        $this->assertTrue($savedUser);
    }
}
php artisan config:cache
php artisan cache:clear