mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 08:12:15 +00:00
added UserFactory and UserTest.php
This commit is contained in:
@@ -6,79 +6,19 @@ use App\Notifications\ResetPassword;
|
|||||||
use App\Notifications\ResetUserPasswordNotification;
|
use App\Notifications\ResetUserPasswordNotification;
|
||||||
use ByteUnits\Metric;
|
use ByteUnits\Metric;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Laravel\Cashier\Billable;
|
use Laravel\Cashier\Billable;
|
||||||
use Laravel\Passport\HasApiTokens;
|
use Laravel\Passport\HasApiTokens;
|
||||||
use Kyslik\ColumnSortable\Sortable;
|
use Kyslik\ColumnSortable\Sortable;
|
||||||
use Rinvex\Subscriptions\Traits\HasSubscriptions;
|
use Rinvex\Subscriptions\Traits\HasSubscriptions;
|
||||||
|
|
||||||
/**
|
|
||||||
* App\User
|
|
||||||
*
|
|
||||||
* @property int $id
|
|
||||||
* @property string $name
|
|
||||||
* @property string $email
|
|
||||||
* @property \Illuminate\Support\Carbon|null $email_verified_at
|
|
||||||
* @property string $password
|
|
||||||
* @property \Illuminate\Contracts\Routing\UrlGenerator|string $avatar
|
|
||||||
* @property string|null $remember_token
|
|
||||||
* @property \Illuminate\Support\Carbon|null $created_at
|
|
||||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Passport\Client[] $clients
|
|
||||||
* @property-read int|null $clients_count
|
|
||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\FileManagerFolder[] $favourites
|
|
||||||
* @property-read int|null $favourites_count
|
|
||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\FileManagerFile[] $files
|
|
||||||
* @property-read int|null $files_count
|
|
||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\FileManagerFile[] $files_with_trashed
|
|
||||||
* @property-read int|null $files_with_trashed_count
|
|
||||||
* @property-read mixed $used_capacity
|
|
||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\FileManagerFile[] $latest_uploads
|
|
||||||
* @property-read int|null $latest_uploads_count
|
|
||||||
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
|
|
||||||
* @property-read int|null $notifications_count
|
|
||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Passport\Token[] $tokens
|
|
||||||
* @property-read int|null $tokens_count
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User newModelQuery()
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User newQuery()
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User query()
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAvatar($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCreatedAt($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEmail($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEmailVerifiedAt($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereId($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereName($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePassword($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRememberToken($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereUpdatedAt($value)
|
|
||||||
* @mixin \Eloquent
|
|
||||||
* @property string $role
|
|
||||||
* @property string|null $stripe_id
|
|
||||||
* @property string|null $card_brand
|
|
||||||
* @property string|null $card_last_four
|
|
||||||
* @property string|null $trial_ends_at
|
|
||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\FileManagerFolder[] $favourite_folders
|
|
||||||
* @property-read int|null $favourite_folders_count
|
|
||||||
* @property-read mixed $folder_tree
|
|
||||||
* @property-read mixed $storage
|
|
||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Invoice[] $invoices
|
|
||||||
* @property-read int|null $invoices_count
|
|
||||||
* @property-read int|null $payment_cards_count
|
|
||||||
* @property-read \App\UserSettings|null $settings
|
|
||||||
* @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Cashier\Subscription[] $subscriptions
|
|
||||||
* @property-read int|null $subscriptions_count
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCardBrand($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCardLastFour($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRole($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereStripeId($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereTrialEndsAt($value)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|User sortable($defaultParameters = null)
|
|
||||||
*/
|
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
use HasApiTokens, Notifiable, Billable, Sortable;
|
use Notifiable, Billable, Sortable, HasFactory, \Laravel\Sanctum\HasApiTokens;
|
||||||
|
|
||||||
protected $guarded = ['id', 'role'];
|
protected $guarded = ['id', 'role'];
|
||||||
|
|
||||||
@@ -126,6 +66,10 @@ class User extends Authenticatable
|
|||||||
'storage_capacity',
|
'storage_capacity',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
|
protected $keyType = 'string';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get tax rate id for user
|
* Get tax rate id for user
|
||||||
*
|
*
|
||||||
@@ -345,4 +289,16 @@ class User extends Authenticatable
|
|||||||
{
|
{
|
||||||
return $this->hasOne(UserSettings::class);
|
return $this->hasOne(UserSettings::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate uuid
|
||||||
|
*/
|
||||||
|
protected static function boot()
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
|
||||||
|
static::creating(function ($model) {
|
||||||
|
$model->id = (string)Str::uuid();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -32,10 +32,10 @@
|
|||||||
"require-dev": {
|
"require-dev": {
|
||||||
"barryvdh/laravel-ide-helper": "^2.7",
|
"barryvdh/laravel-ide-helper": "^2.7",
|
||||||
"facade/ignition": "^2.3.6",
|
"facade/ignition": "^2.3.6",
|
||||||
"fzaninotto/faker": "^1.4",
|
"fzaninotto/faker": "^1.9.1",
|
||||||
"mockery/mockery": "^1.0",
|
"mockery/mockery": "^1.3.1",
|
||||||
"nunomaduro/collision": "^5.0",
|
"nunomaduro/collision": "^5.0",
|
||||||
"phpunit/phpunit": "^9.0"
|
"phpunit/phpunit": "^9.5.2"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"optimize-autoloader": true,
|
"optimize-autoloader": true,
|
||||||
|
|||||||
2
composer.lock
generated
2
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "31b80dcbc3703ef7b5654f9afe18d13e",
|
"content-hash": "9f04ec7084949f2d0a1c343da44c30cd",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "asm89/stack-cors",
|
"name": "asm89/stack-cors",
|
||||||
|
|||||||
61
database/factories/UserFactory.php
Normal file
61
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\User;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class UserFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name of the factory's corresponding model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $model = User::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function definition()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'role' => $this->faker->randomElement(['user', 'admin']),
|
||||||
|
'name' => $this->faker->name(),
|
||||||
|
'email' => $this->faker->unique()->safeEmail,
|
||||||
|
'email_verified_at' => now(),
|
||||||
|
'password' => Hash::make('secret'),
|
||||||
|
'remember_token' => Str::random(10),
|
||||||
|
'created_at' => $this->faker->dateTimeBetween($startDate = '-36 months', $endDate = 'now', $timezone = null),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure the model factory.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function configure()
|
||||||
|
{
|
||||||
|
return $this->afterCreating(function (User $user) {
|
||||||
|
$user
|
||||||
|
->settings()
|
||||||
|
->create([
|
||||||
|
'storage_capacity' => $this->faker->randomNumber(1),
|
||||||
|
'name' => $this->faker->name,
|
||||||
|
'address' => $this->faker->address,
|
||||||
|
'state' => $this->faker->state,
|
||||||
|
'city' => $this->faker->city,
|
||||||
|
'postal_code' => $this->faker->postcode,
|
||||||
|
'country' => $this->faker->randomElement(['SK', 'CZ', 'DE', 'FR']),
|
||||||
|
'phone_number' => $this->faker->phoneNumber,
|
||||||
|
'timezone' => $this->faker->randomElement(['+1.0', '+2.0', '+3.0']),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\User;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Foundation\Testing\WithFaker;
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
@@ -12,14 +13,20 @@ class UserTest extends TestCase
|
|||||||
use DatabaseMigrations;
|
use DatabaseMigrations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic feature test example.
|
* @test
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function test_example()
|
public function it_generate_and_store_user()
|
||||||
{
|
{
|
||||||
$response = $this->get('/');
|
$user = User::factory(User::class)
|
||||||
|
->create(['role' => 'user']);
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$this->assertDatabaseHas('users', [
|
||||||
|
'id' => $user->id,
|
||||||
|
'role' => 'user',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('user_settings', [
|
||||||
|
'user_id' => $user->id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user