Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gammamatrix authored Mar 13, 2024
1 parent 6e5e90a commit 7b4d964
Show file tree
Hide file tree
Showing 23 changed files with 402 additions and 229 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Tests: Playground Test'
name: 'CI'

on:
push:
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
env:
XDEBUG_MODE: coverage
with:
version: "10.5"
version: "11.0"
php_version: "8.2"
php_extensions: intl xdebug
coverage_clover: clover.xml
Expand Down
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"playground",
"test"
],
"homepage": "https://github.com/gammamatrix/playground-test/wiki",
"homepage": "https://gammamatrix-playground.readthedocs.io/",
"license": "MIT",
"authors": [
{
Expand All @@ -17,18 +17,17 @@
}
],
"require": {
"php": "^8.1",
"fakerphp/faker": "^1.9.1",
"php": "^8.2",
"fakerphp/faker": "^1.23",
"friendsofphp/php-cs-fixer": "^3.41",
"larastan/larastan": "^2.0",
"orchestra/testbench": "8.*",
"orchestra/testbench": "9.*",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "10.5.*",
"timacdonald/log-fake": "^2.0.1",
"laravel/sanctum": "^3.3"
"phpunit/phpunit": "^11.0",
"laravel/sanctum": "^4.0"
},
"require-dev": {
"gammamatrix/playground": "dev-develop|dev-master|dev-feature/*|^73.0"
"gammamatrix/playground": "dev-feature/GH-25"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
123 changes: 123 additions & 0 deletions database/factories/DefaultUserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

declare(strict_types=1);
/**
* Playground
*/
namespace Database\Factories\Playground\Test\Models;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Playground\Test\Models\DefaultUser;

/**
* \Database\Factories\Playground\Test\Models\DefaultUserFactory
*/
class DefaultUserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var class-string<DefaultUser>
*/
protected $model = DefaultUser::class;

/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
if (empty(static::$password)) {
$password = config('auth.testing.password');
$test_password_hashed = config('auth.testing.hashed');

if (empty($password) || ! is_string($password)) {
$password = md5(Carbon::now()->format('c'));
$test_password_hashed = false;
}

if (! $test_password_hashed) {
$password = Hash::make($password);
}

static::$password = $password;
}

return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => Carbon::now()->format('Y-m-d H:i:s'),
'password' => static::$password,
'remember_token' => Str::random(10),
];
}

/**
* The current password being used by the factory.
*/
protected static ?string $password = null;

/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}

/**
* Set the user up as an admin user.
*/
public function admin(): Factory
{
return $this->state(fn (array $attributes) => [
'email' => '[email protected]',
]);
}

/**
* Set the user up as a guest user.
*/
public function guest(): Factory
{
return $this->state(fn (array $attributes) => [
'email' => '[email protected]',
]);
}

/**
* Set the user up as a manager user.
*/
public function manager(): Factory
{
return $this->state(fn (array $attributes) => [
'email' => '[email protected]',
]);
}

/**
* Indicate that the user has the root role.
*/
public function root(): Factory
{
return $this->state(fn (array $attributes) => [
'email' => '[email protected]',
]);
}

/**
* Indicate that the user has the wheel role.
*/
public function wheel(): Factory
{
return $this->state(fn (array $attributes) => [
'email' => '[email protected]',
]);
}
}
53 changes: 1 addition & 52 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,17 @@
*/
namespace Database\Factories\Playground\Test\Models;

use Illuminate\Database\Eloquent\Factories\Factory;
use Playground\Test\Models\User;

/**
* \Database\Factories\Playground\Test\Models\UserFactory
*/
class UserFactory extends AbstractUserFactory
class UserFactory extends DefaultUserFactory
{
/**
* The name of the factory's corresponding model.
*
* @var class-string<User>
*/
protected $model = User::class;

/**
* Set the user up as an admin user.
*/
public function admin(): Factory
{
return $this->state(fn (array $attributes) => [
'email' => '[email protected]',
]);
}

/**
* Set the user up as a guest user.
*/
public function guest(): Factory
{
return $this->state(fn (array $attributes) => [
'email' => '[email protected]',
]);
}

/**
* Set the user up as a manager user.
*/
public function manager(): Factory
{
return $this->state(fn (array $attributes) => [
'email' => '[email protected]',
]);
}

/**
* Indicate that the user has the root role.
*/
public function root(): Factory
{
return $this->state(fn (array $attributes) => [
'email' => '[email protected]',
]);
}

/**
* Indicate that the user has the wheel role.
*/
public function wheel(): Factory
{
return $this->state(fn (array $attributes) => [
'email' => '[email protected]',
]);
}
}
44 changes: 33 additions & 11 deletions src/Models/AbstractUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
*/
namespace Playground\Test\Models;

use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as BaseUser;

/**
* \Playground\Test\Models\AbstractUser
*
* @see Illuminate\Foundation\Auth\User
*
* @property int $id
* @property ?Carbon $created_at
* @property ?Carbon $updated_at
* @property ?Carbon $email_verified_at
* @property string $name
* @property string $email
*/
abstract class AbstractUser extends Model implements AuthenticatableContract, AuthorizableContract
abstract class AbstractUser extends BaseUser
{
use Authenticatable;
use Authorizable;
use HasFactory;
use Notifiable;

/**
* @var array<string, mixed>
*/
protected $attributes = [
'name' => '',
'email' => '',
'password' => '',
];

/**
Expand All @@ -40,11 +40,33 @@ abstract class AbstractUser extends Model implements AuthenticatableContract, Au
protected $fillable = [
'name',
'email',
'email_verified_at',
'password',
'remember_token',
];

public $timestamps = false;
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

protected $table = 'users';

/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
}
25 changes: 2 additions & 23 deletions src/Models/AppPlaygroundUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,14 @@
*/
namespace Playground\Test\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum;
use Playground\Models\Interfaces\WithCreatorInterface;
use Playground\Models\Interfaces\WithModifierInterface;
use Playground\Models\Traits;
use Playground\Models\Traits\WithCreator;
use Playground\Models\Traits\WithModifier;
use Playground\Models\User as BaseUser;

/**
* \Playground\Test\Models\AppPlaygroundUser
*
* This model includes all possible and/or compatible Playground features.
* NOTE: This model should be the same as a \App\Models\User extends \Playground\Models\User.
*/
class AppPlaygroundUser extends BaseUser implements MustVerifyEmail, Sanctum\Contracts\HasApiTokens, WithCreatorInterface, WithModifierInterface
class AppPlaygroundUser extends BaseUser
{
use Notifiable;
use Sanctum\HasApiTokens;
use SoftDeletes;
use Traits\ScopeFilterColumns;
use Traits\ScopeFilterDates;
use Traits\ScopeFilterFlags;
use Traits\ScopeFilterIds;
use Traits\ScopeFilterTrash;
use Traits\ScopeSort;
use WithCreator;
use WithModifier;

protected $table = 'users';
}
Loading

0 comments on commit 7b4d964

Please sign in to comment.