Skip to content

Commit be6f863

Browse files
committed
wip
1 parent 8d6afb7 commit be6f863

File tree

6 files changed

+98
-23
lines changed

6 files changed

+98
-23
lines changed

tests/ArchTest.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/ExampleTest.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/Pest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<?php
22

3-
use Foxws\UserCache\Tests\TestCase;
3+
use Illuminate\Database\Eloquent\Model;
44

5-
uses(TestCase::class)->in(__DIR__);
5+
expect()
6+
->extend('toBeSameModel', fn(Model $model) => $this->is($model)->toBeTrue());
7+
8+
beforeEach(function () {
9+
// Fake instances
10+
\Illuminate\Support\Facades\Bus::fake();
11+
\Illuminate\Support\Facades\Mail::fake();
12+
\Illuminate\Support\Facades\Notification::fake();
13+
\Illuminate\Support\Facades\Queue::fake();
14+
\Illuminate\Support\Facades\Storage::fake();
15+
});

tests/TestCase.php

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,32 @@
33
namespace Foxws\UserCache\Tests;
44

55
use Foxws\UserCache\UserCacheServiceProvider;
6-
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
use Orchestra\Testbench\Concerns\WithWorkbench;
79
use Orchestra\Testbench\TestCase as Orchestra;
810

9-
class TestCase extends Orchestra
11+
abstract class TestCase extends Orchestra
1012
{
13+
use WithWorkbench;
14+
1115
protected function setUp(): void
1216
{
1317
parent::setUp();
1418

15-
Factory::guessFactoryNamesUsing(
16-
fn (string $modelName) => 'Foxws\\UserCache\\Database\\Factories\\'.class_basename($modelName).'Factory'
17-
);
19+
$this->setUpDatabase($this->app);
20+
}
21+
22+
protected function getEnvironmentSetUp($app)
23+
{
24+
$app['config']->set('cache.default', 'file');
25+
26+
$app['config']->set('database.default', 'sqlite');
27+
$app['config']->set('database.connections.sqlite', [
28+
'driver' => 'sqlite',
29+
'database' => ':memory:',
30+
'prefix' => '',
31+
]);
1832
}
1933

2034
protected function getPackageProviders($app)
@@ -24,13 +38,22 @@ protected function getPackageProviders($app)
2438
];
2539
}
2640

27-
public function getEnvironmentSetUp($app)
41+
/**
42+
* @param \Illuminate\Foundation\Application $app
43+
*/
44+
protected function setUpDatabase($app)
2845
{
29-
config()->set('database.default', 'testing');
46+
Schema::dropAllTables();
3047

31-
/*
32-
$migration = include __DIR__.'/../database/migrations/create_laravel-user-cache_table.php.stub';
33-
$migration->up();
34-
*/
48+
Schema::create('users', function (Blueprint $table) {
49+
$table->id();
50+
$table->uuid();
51+
$table->string('email')->unique();
52+
$table->string('name')->nullable();
53+
$table->string('password');
54+
$table->rememberToken();
55+
$table->timestamp('email_verified_at')->nullable();
56+
$table->timestamps();
57+
});
3558
}
3659
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Foxws\UserCache\Tests\Database\Factories;
4+
5+
use Foxws\UserCache\Tests\Models\User;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
use Illuminate\Support\Facades\Hash;
8+
use Illuminate\Support\Str;
9+
10+
class UserFactory extends Factory
11+
{
12+
protected $model = User::class;
13+
14+
public function definition(): array
15+
{
16+
return [
17+
'uuid' => $this->faker->uuid(),
18+
'name' => $this->faker->name(),
19+
'email' => $this->faker->unique()->safeEmail(),
20+
'email_verified_at' => now(),
21+
'password' => Hash::make('password'),
22+
'remember_token' => Str::random(10),
23+
];
24+
}
25+
}

tests/src/Models/User.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Foxws\UserCache\Tests\Models;
4+
5+
use Foxws\UserCache\Tests\Database\Factories\UserFactory;
6+
use Illuminate\Contracts\Auth\MustVerifyEmail;
7+
use Illuminate\Database\Eloquent\Factories\HasFactory;
8+
use Illuminate\Foundation\Auth\User as Authenticatable;
9+
use Illuminate\Notifications\Notifiable;
10+
11+
class User extends Authenticatable implements MustVerifyEmail
12+
{
13+
use HasFactory;
14+
use Notifiable;
15+
16+
protected $guarded = [];
17+
18+
protected $hidden = [
19+
'password',
20+
'remember_token',
21+
];
22+
23+
protected static function newFactory(): UserFactory
24+
{
25+
return UserFactory::new();
26+
}
27+
}

0 commit comments

Comments
 (0)