Armandisimo's avatar

How use sqlite3 for my testings in windows 7

This is my setup so far:

.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=payforu
DB_USERNAME=root
DB_PASSWORD=

phpunit.xml

<php>
    <server name="APP_ENV" value="testing"/>
    <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"/>
    <server name="DB_CONNECTION" value="sqlite"/>
    <server name="DB_DATABASE" value=":memory:"/>
</php>

Console sqlite3 version

C:\xampp\htdocs\payforu>sqlite3 --version
3.31.1 2020-01-27 19:55:54 3bfa9cc97da10598521b342961df8f5f68c7388fa117345eeb516
eaa837bb4d6

PassportTest.php

<?php

namespace Tests\Feature;

use Tests\TestCase;
use App\Models\User;
use Laravel\Passport\Passport;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class PassportTest extends TestCase
{
    use WithFaker, RefreshDatabase;

    /** @test */
    public function it_return_token_after_signup()
    {
        $this->withoutExceptionHandling();

        $this->postJson(
            '/api/signup',
            [
                'name' => $this->faker->name,
                'email' => $this->faker->email,
                'password' => '12345678',
                'password_confirmation' => '12345678',
                'platform' => $this->faker->company,
                'country' => $this->faker->country,
            ]
        )->assertJsonStructure([
            'access_token',
            'token_type',
            'expires_at'
        ])->assertStatus(200);
    }
}

After all of this, the user is created in my mysql database and i want use sqlite for my tests

Any help would be appreciated.

0 likes
4 replies
Sinnbeck's avatar

Any chance you have set $connection on the User model?

Armandisimo's avatar

User.php

<?php

namespace App\Models;

use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password', 'platform', 'country', 'token'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}
Sinnbeck's avatar

Do you have a env.testing file by any chance?

Please or to participate in this conversation.