update to laravel 10

pull/24/head
Mikiyas Tibebu 4 years ago
parent 6f270ecb08
commit e707c40a4e

@ -8,20 +8,15 @@ use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel { class Kernel extends ConsoleKernel {
/** /**
* Define the application's command schedule. * Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/ */
protected function schedule(Schedule $schedule) { protected function schedule(Schedule $schedule): void {
// $schedule->command('inspire')->hourly(); // $schedule->command('inspire')->hourly();
} }
/** /**
* Register the commands for the application. * Register the commands for the application.
*
* @return void
*/ */
protected function commands() { protected function commands(): void {
$this->load(__DIR__.'/Commands'); $this->load(__DIR__.'/Commands');
require base_path('routes/console.php'); require base_path('routes/console.php');

@ -39,10 +39,8 @@ class Handler extends ExceptionHandler {
/** /**
* Register the exception handling callbacks for the application. * Register the exception handling callbacks for the application.
*
* @return void
*/ */
public function register() { public function register(): void {
$this->reportable(function (Throwable $e) { $this->reportable(function (Throwable $e) {
// //
}); });

@ -2,14 +2,17 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Http\Response;
class HydraController extends Controller { class HydraController extends Controller {
public function hydra() { public function hydra(): Response {
return response([ return response([
'message' => 'Welcome to Hydra, the zero config API boilerplate with roles and abilities for Laravel Sanctum. Please visit https://hasinhayder.github.io/hydra to know more.', 'message' => 'Welcome to Hydra, the zero config API boilerplate with roles and abilities for Laravel Sanctum. Please visit https://hasinhayder.github.io/hydra to know more.',
]); ]);
} }
public function version() { public function version(): Response {
return response([ return response([
'version' => config('hydra.version'), 'version' => config('hydra.version'),
]); ]);

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Models\Role; use App\Models\Role;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response;
class RoleController extends Controller { class RoleController extends Controller {
/** /**
@ -17,11 +18,8 @@ class RoleController extends Controller {
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/ */
public function store(Request $request) { public function store(Request $request): Role|Response {
$data = $request->validate([ $data = $request->validate([
'name' => 'required', 'name' => 'required',
'slug' => 'required', 'slug' => 'required',
@ -43,22 +41,15 @@ class RoleController extends Controller {
/** /**
* Display the specified resource. * Display the specified resource.
*
* @param \App\Models\Role $role
* @return \App\Models\Role $role
*/ */
public function show(Role $role) { public function show(Role $role): Role {
return $role; return $role;
} }
/** /**
* Update the specified resource in storage. * Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Role $role
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response|Role
*/ */
public function update(Request $request, Role $role = null) { public function update(Request $request, Role $role = null): Role|Response {
if (! $role) { if (! $role) {
return response(['error' => 1, 'message' => 'role doesn\'t exist'], 404); return response(['error' => 1, 'message' => 'role doesn\'t exist'], 404);
} }
@ -79,11 +70,8 @@ class RoleController extends Controller {
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
*
* @param \App\Models\Role $role
* @return \Illuminate\Http\Response
*/ */
public function destroy(Role $role) { public function destroy(Role $role): Response {
if ($role->slug != 'admin' && $role->slug != 'super-admin') { if ($role->slug != 'admin' && $role->slug != 'super-admin') {
//don't allow changing the admin slug, because it will make the routes inaccessbile due to faile ability check //don't allow changing the admin slug, because it will make the routes inaccessbile due to faile ability check
$role->delete(); $role->delete();

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use App\Models\Role; use App\Models\Role;
use App\Models\User; use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Laravel\Sanctum\Exceptions\MissingAbilityException; use Laravel\Sanctum\Exceptions\MissingAbilityException;
@ -20,11 +21,8 @@ class UserController extends Controller {
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/ */
public function store(Request $request) { public function store(Request $request): User|Response {
$creds = $request->validate([ $creds = $request->validate([
'email' => 'required|email', 'email' => 'required|email',
'password' => 'required', 'password' => 'required',
@ -50,11 +48,8 @@ class UserController extends Controller {
/** /**
* Authenticate an user and dispatch token. * Authenticate an user and dispatch token.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/ */
public function login(Request $request) { public function login(Request $request): Response {
$creds = $request->validate([ $creds = $request->validate([
'email' => 'required|email', 'email' => 'required|email',
'password' => 'required', 'password' => 'required',
@ -78,24 +73,17 @@ class UserController extends Controller {
/** /**
* Display the specified resource. * Display the specified resource.
*
* @param \App\Models\User $user
* @return \App\Models\User $user
*/ */
public function show(User $user) { public function show(User $user): User {
return $user; return $user;
} }
/** /**
* Update the specified resource in storage. * Update the specified resource in storage.
* *
* @param \Illuminate\Http\Request $request
* @param \App\Models\User $user
* @return User
*
* @throws MissingAbilityException * @throws MissingAbilityException
*/ */
public function update(Request $request, User $user) { public function update(Request $request, User $user): User {
$user->name = $request->name ?? $user->name; $user->name = $request->name ?? $user->name;
$user->email = $request->email ?? $user->email; $user->email = $request->email ?? $user->email;
$user->password = $request->password ? Hash::make($request->password) : $user->password; $user->password = $request->password ? Hash::make($request->password) : $user->password;
@ -117,11 +105,8 @@ class UserController extends Controller {
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
*
* @param \App\Models\User $user
* @return \Illuminate\Http\Response
*/ */
public function destroy(User $user) { public function destroy(User $user): Response {
$adminRole = Role::where('slug', 'admin')->first(); $adminRole = Role::where('slug', 'admin')->first();
$userRoles = $user->roles; $userRoles = $user->roles;
@ -139,10 +124,7 @@ class UserController extends Controller {
} }
/** /**
* Return Auth user * Return Auth user.
*
* @param Request $request
* @return mixed
*/ */
public function me(Request $request) { public function me(Request $request) {
return $request->user(); return $request->user();

@ -5,26 +5,20 @@ namespace App\Http\Controllers;
use App\Models\Role; use App\Models\Role;
use App\Models\User; use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response;
class UserRoleController extends Controller { class UserRoleController extends Controller {
/** /**
* Display a listing of the resource. * Display a listing of the resource.
*
* @param \App\Models\User $user
* @return \App\Models\User $user
*/ */
public function index(User $user) { public function index(User $user): User {
return $user->load('roles'); return $user->load('roles');
} }
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\User $user
* @return \App\Models\User $user
*/ */
public function store(Request $request, User $user) { public function store(Request $request, User $user): User|Response {
$data = $request->validate([ $data = $request->validate([
'role_id' => 'required|integer', 'role_id' => 'required|integer',
]); ]);
@ -38,12 +32,8 @@ class UserRoleController extends Controller {
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
*
* @param \App\Models\User $user
* @param \App\Models\Role $role
* @return \App\Models\User $user
*/ */
public function destroy(User $user, Role $role) { public function destroy(User $user, Role $role): User {
$user->roles()->detach($role); $user->roles()->detach($role);
return $user->load('roles'); return $user->load('roles');

@ -7,13 +7,8 @@ use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware { class Authenticate extends Middleware {
/** /**
* Get the path the user should be redirected to when they are not authenticated. * Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/ */
protected function redirectTo($request) { protected function redirectTo($request): ?string {
if (! $request->expectsJson()) { return $request->expectsJson() ? null : route('login');
return route('login');
}
} }
} }

@ -4,19 +4,16 @@ namespace App\Http\Middleware;
use App\Providers\RouteServiceProvider; use App\Providers\RouteServiceProvider;
use Closure; use Closure;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated { class RedirectIfAuthenticated {
/** /**
* Handle an incoming request. * Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param string|null ...$guards
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/ */
public function handle(Request $request, Closure $next, ...$guards) { public function handle(Request $request, Closure $next, ...$guards): Response|RedirectResponse {
$guards = empty($guards) ? [null] : $guards; $guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) { foreach ($guards as $guard) {

@ -10,7 +10,7 @@ class TrustHosts extends Middleware {
* *
* @return array<int, string|null> * @return array<int, string|null>
*/ */
public function hosts() { public function hosts(): array {
return [ return [
$this->allSubdomainsOfApplicationUrl(), $this->allSubdomainsOfApplicationUrl(),
]; ];

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Role extends Model { class Role extends Model {
use HasFactory; use HasFactory;
@ -18,7 +19,7 @@ class Role extends Model {
'updated_at', 'updated_at',
]; ];
public function users() { public function users(): BelongsToMany {
return $this->belongsToMany(User::class, 'user_roles'); return $this->belongsToMany(User::class, 'user_roles');
} }
} }

@ -3,6 +3,7 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens; use Laravel\Sanctum\HasApiTokens;
@ -43,7 +44,7 @@ class User extends Authenticatable {
'email_verified_at' => 'datetime', 'email_verified_at' => 'datetime',
]; ];
public function roles() { public function roles(): BelongsToMany {
return $this->belongsToMany(Role::class, 'user_roles'); return $this->belongsToMany(Role::class, 'user_roles');
} }
} }

@ -7,19 +7,15 @@ use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider { class AppServiceProvider extends ServiceProvider {
/** /**
* Register any application services. * Register any application services.
*
* @return void
*/ */
public function register() { public function register(): void {
// //
} }
/** /**
* Bootstrap any application services. * Bootstrap any application services.
*
* @return void
*/ */
public function boot() { public function boot(): void {
// //
} }
} }

@ -16,12 +16,8 @@ class AuthServiceProvider extends ServiceProvider {
/** /**
* Register any authentication / authorization services. * Register any authentication / authorization services.
*
* @return void
*/ */
public function boot() { public function boot(): void {
$this->registerPolicies();
// //
} }
} }

@ -8,10 +8,8 @@ use Illuminate\Support\ServiceProvider;
class BroadcastServiceProvider extends ServiceProvider { class BroadcastServiceProvider extends ServiceProvider {
/** /**
* Bootstrap any application services. * Bootstrap any application services.
*
* @return void
*/ */
public function boot() { public function boot(): void {
Broadcast::routes(); Broadcast::routes();
require base_path('routes/channels.php'); require base_path('routes/channels.php');

@ -21,19 +21,15 @@ class EventServiceProvider extends ServiceProvider {
/** /**
* Register any events for your application. * Register any events for your application.
*
* @return void
*/ */
public function boot() { public function boot(): void {
// //
} }
/** /**
* Determine if events and listeners should be automatically discovered. * Determine if events and listeners should be automatically discovered.
*
* @return bool
*/ */
public function shouldDiscoverEvents() { public function shouldDiscoverEvents(): bool {
return false; return false;
} }
} }

@ -20,10 +20,8 @@ class RouteServiceProvider extends ServiceProvider {
/** /**
* Define your route model bindings, pattern filters, and other route configuration. * Define your route model bindings, pattern filters, and other route configuration.
*
* @return void
*/ */
public function boot() { public function boot(): void {
$this->configureRateLimiting(); $this->configureRateLimiting();
$this->routes(function () { $this->routes(function () {
@ -38,10 +36,8 @@ class RouteServiceProvider extends ServiceProvider {
/** /**
* Configure the rate limiters for the application. * Configure the rate limiters for the application.
*
* @return void
*/ */
protected function configureRateLimiting() { protected function configureRateLimiting(): void {
RateLimiter::for('api', function (Request $request) { RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()); return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
}); });

@ -10,18 +10,18 @@
"require": { "require": {
"php": "^8.0.2", "php": "^8.0.2",
"guzzlehttp/guzzle": "^7.4.4", "guzzlehttp/guzzle": "^7.4.4",
"laravel/framework": "^9.23", "laravel/framework": "^10.0",
"laravel/sanctum": "^2.15.1", "laravel/sanctum": "^3.2",
"laravel/tinker": "^2.7" "laravel/tinker": "^2.8"
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.9.1", "fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.1.0", "laravel/pint": "^1.1.0",
"laravel/sail": "^1.15", "laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4", "mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.2", "nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^9.5.10", "phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^1.0" "spatie/laravel-ignition": "^2.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@ -60,6 +60,6 @@
"preferred-install": "dist", "preferred-install": "dist",
"sort-packages": true "sort-packages": true
}, },
"minimum-stability": "dev", "minimum-stability": "stable",
"prefer-stable": true "prefer-stable": true
} }

@ -14,7 +14,7 @@ class UserFactory extends Factory {
* *
* @return array<string, mixed> * @return array<string, mixed>
*/ */
public function definition() { public function definition(): array {
return [ return [
'name' => $this->faker->name(), 'name' => $this->faker->name(),
'email' => $this->faker->unique()->safeEmail(), 'email' => $this->faker->unique()->safeEmail(),
@ -29,7 +29,7 @@ class UserFactory extends Factory {
* *
* @return static * @return static
*/ */
public function unverified() { public function unverified(): static {
return $this->state(function (array $attributes) { return $this->state(function (array $attributes) {
return [ return [
'email_verified_at' => null, 'email_verified_at' => null,

@ -7,10 +7,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration {
/** /**
* Run the migrations. * Run the migrations.
*
* @return void
*/ */
public function up() { public function up(): void {
Schema::create('users', function (Blueprint $table) { Schema::create('users', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name'); $table->string('name');
@ -24,10 +22,8 @@ return new class extends Migration {
/** /**
* Reverse the migrations. * Reverse the migrations.
*
* @return void
*/ */
public function down() { public function down(): void {
Schema::dropIfExists('users'); Schema::dropIfExists('users');
} }
}; };

@ -7,10 +7,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration {
/** /**
* Run the migrations. * Run the migrations.
*
* @return void
*/ */
public function up() { public function up(): void {
Schema::create('password_resets', function (Blueprint $table) { Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index(); $table->string('email')->index();
$table->string('token'); $table->string('token');
@ -20,10 +18,8 @@ return new class extends Migration {
/** /**
* Reverse the migrations. * Reverse the migrations.
*
* @return void
*/ */
public function down() { public function down(): void {
Schema::dropIfExists('password_resets'); Schema::dropIfExists('password_resets');
} }
}; };

@ -7,10 +7,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration {
/** /**
* Run the migrations. * Run the migrations.
*
* @return void
*/ */
public function up() { public function up(): void {
Schema::create('failed_jobs', function (Blueprint $table) { Schema::create('failed_jobs', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('uuid')->unique(); $table->string('uuid')->unique();
@ -24,10 +22,8 @@ return new class extends Migration {
/** /**
* Reverse the migrations. * Reverse the migrations.
*
* @return void
*/ */
public function down() { public function down(): void {
Schema::dropIfExists('failed_jobs'); Schema::dropIfExists('failed_jobs');
} }
}; };

@ -7,10 +7,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration {
/** /**
* Run the migrations. * Run the migrations.
*
* @return void
*/ */
public function up() { public function up(): void {
Schema::create('personal_access_tokens', function (Blueprint $table) { Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->id(); $table->id();
$table->morphs('tokenable'); $table->morphs('tokenable');
@ -18,16 +16,15 @@ return new class extends Migration {
$table->string('token', 64)->unique(); $table->string('token', 64)->unique();
$table->text('abilities')->nullable(); $table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable(); $table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamps(); $table->timestamps();
}); });
} }
/** /**
* Reverse the migrations. * Reverse the migrations.
*
* @return void
*/ */
public function down() { public function down(): void {
Schema::dropIfExists('personal_access_tokens'); Schema::dropIfExists('personal_access_tokens');
} }
}; };

@ -7,10 +7,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration {
/** /**
* Run the migrations. * Run the migrations.
*
* @return void
*/ */
public function up() { public function up(): void {
Schema::create('roles', function (Blueprint $table) { Schema::create('roles', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name'); $table->string('name');
@ -21,10 +19,8 @@ return new class extends Migration {
/** /**
* Reverse the migrations. * Reverse the migrations.
*
* @return void
*/ */
public function down() { public function down(): void {
Schema::dropIfExists('roles'); Schema::dropIfExists('roles');
} }
}; };

@ -7,10 +7,8 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration {
/** /**
* Run the migrations. * Run the migrations.
*
* @return void
*/ */
public function up() { public function up(): void {
Schema::create('user_roles', function (Blueprint $table) { Schema::create('user_roles', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete(); $table->foreignId('user_id')->constrained()->cascadeOnDelete();
@ -22,10 +20,8 @@ return new class extends Migration {
/** /**
* Reverse the migrations. * Reverse the migrations.
*
* @return void
*/ */
public function down() { public function down(): void {
Schema::dropIfExists('user_roles'); Schema::dropIfExists('user_roles');
} }
}; };

@ -7,10 +7,8 @@ use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder { class DatabaseSeeder extends Seeder {
/** /**
* Seed the application's database. * Seed the application's database.
*
* @return void
*/ */
public function run() { public function run(): void {
// \App\Models\User::factory(10)->create(); // \App\Models\User::factory(10)->create();
// \App\Models\User::factory()->create([ // \App\Models\User::factory()->create([

@ -10,10 +10,8 @@ use Illuminate\Support\Facades\Schema;
class RoleSeeder extends Seeder { class RoleSeeder extends Seeder {
/** /**
* Run the database seeds. * Run the database seeds.
*
* @return void
*/ */
public function run() { public function run(): void {
Schema::disableForeignKeyConstraints(); Schema::disableForeignKeyConstraints();
DB::table('roles')->truncate(); DB::table('roles')->truncate();
Schema::enableForeignKeyConstraints(); Schema::enableForeignKeyConstraints();

@ -12,10 +12,8 @@ use Illuminate\Support\Facades\Schema;
class UsersSeeder extends Seeder { class UsersSeeder extends Seeder {
/** /**
* Run the database seeds. * Run the database seeds.
*
* @return void
*/ */
public function run() { public function run(): void {
Schema::disableForeignKeyConstraints(); Schema::disableForeignKeyConstraints();
DB::table('users')->truncate(); DB::table('users')->truncate();
Schema::enableForeignKeyConstraints(); Schema::enableForeignKeyConstraints();

@ -12,7 +12,7 @@
<directory suffix="Test.php">./tests/Feature</directory> <directory suffix="Test.php">./tests/Feature</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<coverage processUncoveredFiles="true"> <coverage>
<include> <include>
<directory suffix=".php">./app</directory> <directory suffix=".php">./app</directory>
</include> </include>

@ -1,13 +1,12 @@
window._ = require('lodash');
/** /**
* We'll load the axios HTTP library which allows us to easily issue requests * We'll load the axios HTTP library which allows us to easily issue requests
* to our Laravel back-end. This library automatically handles sending the * to our Laravel back-end. This library automatically handles sending the
* CSRF token as a header based on the value of the "XSRF" token cookie. * CSRF token as a header based on the value of the "XSRF" token cookie.
*/ */
window.axios = require('axios'); import axios from 'axios';
// window.axios.defaults.withCredentials = true; window.axios = axios;
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
/** /**
@ -18,11 +17,16 @@ window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
// import Echo from 'laravel-echo'; // import Echo from 'laravel-echo';
// window.Pusher = require('pusher-js'); // import Pusher from 'pusher-js';
// window.Pusher = Pusher;
// window.Echo = new Echo({ // window.Echo = new Echo({
// broadcaster: 'pusher', // broadcaster: 'pusher',
// key: process.env.MIX_PUSHER_APP_KEY, // key: import.meta.env.VITE_PUSHER_APP_KEY,
// cluster: process.env.MIX_PUSHER_APP_CLUSTER, // cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER ?? 'mt1',
// forceTLS: true // wsHost: import.meta.env.VITE_PUSHER_HOST ? import.meta.env.VITE_PUSHER_HOST : `ws-${import.meta.env.VITE_PUSHER_APP_CLUSTER}.pusher.com`,
// wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80,
// wssPort: import.meta.env.VITE_PUSHER_PORT ?? 443,
// forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'https') === 'https',
// enabledTransports: ['ws', 'wss'],
// }); // });

File diff suppressed because one or more lines are too long

@ -3,14 +3,13 @@
namespace Tests; namespace Tests;
use Illuminate\Contracts\Console\Kernel; use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;
trait CreatesApplication { trait CreatesApplication {
/** /**
* Creates the application. * Creates the application.
*
* @return \Illuminate\Foundation\Application
*/ */
public function createApplication() { public function createApplication(): Application {
$app = require __DIR__.'/../bootstrap/app.php'; $app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap(); $app->make(Kernel::class)->bootstrap();

@ -8,10 +8,8 @@ use Tests\TestCase;
class AdminLoginTest extends TestCase { class AdminLoginTest extends TestCase {
/** /**
* A basic feature test example. * A basic feature test example.
*
* @return void
*/ */
public function test_admin_login() { public function test_admin_login(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -24,7 +22,7 @@ class AdminLoginTest extends TestCase {
); );
} }
public function test_admin_login_fail() { public function test_admin_login_fail(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydrax', 'password' => 'hydrax',

@ -7,10 +7,8 @@ use Tests\TestCase;
class HelloHydraTest extends TestCase { class HelloHydraTest extends TestCase {
/** /**
* A basic feature test example. * A basic feature test example.
*
* @return void
*/ */
public function test_hello_hydra() { public function test_hello_hydra(): void {
$response = $this->get('/api/hydra'); $response = $this->get('/api/hydra');
$response $response
@ -20,7 +18,7 @@ class HelloHydraTest extends TestCase {
]); ]);
} }
public function test_hydra_version() { public function test_hydra_version(): void {
$response = $this->get('/api/hydra/version'); $response = $this->get('/api/hydra/version');
$response $response

@ -9,10 +9,8 @@ use Tests\TestCase;
class RoleTest extends TestCase { class RoleTest extends TestCase {
/** /**
* A basic feature test example. * A basic feature test example.
*
* @return void
*/ */
public function test_list_roles() { public function test_list_roles(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -37,7 +35,7 @@ class RoleTest extends TestCase {
); );
} }
public function test_update_role_name_as_admin() { public function test_update_role_name_as_admin(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -60,7 +58,7 @@ class RoleTest extends TestCase {
); );
} }
public function test_update_role_slug_as_admin() { public function test_update_role_slug_as_admin(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -83,7 +81,7 @@ class RoleTest extends TestCase {
); );
} }
public function test_update_role_namd_and_slug_as_admin() { public function test_update_role_namd_and_slug_as_admin(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -108,7 +106,7 @@ class RoleTest extends TestCase {
); );
} }
public function test_update_admin_slug_as_admin_should_fail() { public function test_update_admin_slug_as_admin_should_fail(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -131,7 +129,7 @@ class RoleTest extends TestCase {
); );
} }
public function test_create_new_role_as_admin() { public function test_create_new_role_as_admin(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -156,7 +154,7 @@ class RoleTest extends TestCase {
); );
} }
public function test_duplicate_role_will_not_be_created() { public function test_duplicate_role_will_not_be_created(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -179,7 +177,7 @@ class RoleTest extends TestCase {
); );
} }
public function test_delete_role_as_admin() { public function test_delete_role_as_admin(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -201,7 +199,7 @@ class RoleTest extends TestCase {
); );
} }
public function test_delete_admin_role_should_fail() { public function test_delete_admin_role_should_fail(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',

@ -8,7 +8,7 @@ use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase; use Tests\TestCase;
class UserRoleTest extends TestCase { class UserRoleTest extends TestCase {
public function test_user_role_is_present() { public function test_user_role_is_present(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -33,7 +33,7 @@ class UserRoleTest extends TestCase {
); );
} }
public function test_assign_role_to_a_user() { public function test_assign_role_to_a_user(): void {
$newUser = User::create([ $newUser = User::create([
'name' => 'Test User', 'name' => 'Test User',
'password' => Hash::make('abcd'), 'password' => Hash::make('abcd'),
@ -66,7 +66,7 @@ class UserRoleTest extends TestCase {
$newUser->delete(); $newUser->delete();
} }
public function test_assign_role_multiple_times_to_a_user_should_fail() { public function test_assign_role_multiple_times_to_a_user_should_fail(): void {
$newUser = User::create([ $newUser = User::create([
'name' => 'Test User', 'name' => 'Test User',
'password' => Hash::make('abcd'), 'password' => Hash::make('abcd'),
@ -99,7 +99,7 @@ class UserRoleTest extends TestCase {
$newUser->delete(); $newUser->delete();
} }
public function test_assign_multiple_roles_to_a_user() { public function test_assign_multiple_roles_to_a_user(): void {
$newUser = User::create([ $newUser = User::create([
'name' => 'Test User', 'name' => 'Test User',
'password' => Hash::make('abcd'), 'password' => Hash::make('abcd'),
@ -132,7 +132,7 @@ class UserRoleTest extends TestCase {
$newUser->delete(); $newUser->delete();
} }
public function test_delete_role_from_a_user() { public function test_delete_role_from_a_user(): void {
$newUser = User::create([ $newUser = User::create([
'name' => 'Test User', 'name' => 'Test User',
'password' => Hash::make('abcd'), 'password' => Hash::make('abcd'),
@ -168,7 +168,7 @@ class UserRoleTest extends TestCase {
$newUser->delete(); $newUser->delete();
} }
public function test_delete_all_roles_from_a_user() { public function test_delete_all_roles_from_a_user(): void {
$newUser = User::create([ $newUser = User::create([
'name' => 'Test User', 'name' => 'Test User',
'password' => Hash::make('abcd'), 'password' => Hash::make('abcd'),

@ -11,14 +11,12 @@ use Tests\TestCase;
class UserTest extends TestCase { class UserTest extends TestCase {
/** /**
* A basic feature test example. * A basic feature test example.
*
* @return void
*/ */
private $token; private $token;
private $user_id; private $user_id;
public function test_new_user_registration() { public function test_new_user_registration(): void {
$response = $this->postJson('/api/users', [ $response = $this->postJson('/api/users', [
'name' => 'Test User', 'name' => 'Test User',
'email' => 'test@test.com', 'email' => 'test@test.com',
@ -33,7 +31,7 @@ class UserTest extends TestCase {
); );
} }
public function test_existing_email_registration_fail() { public function test_existing_email_registration_fail(): void {
$response = $this->postJson('/api/users', [ $response = $this->postJson('/api/users', [
'name' => 'Test User', 'name' => 'Test User',
'email' => 'test@test.com', 'email' => 'test@test.com',
@ -47,7 +45,7 @@ class UserTest extends TestCase {
); );
} }
public function test_new_user_login() { public function test_new_user_login(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'test@test.com', 'email' => 'test@test.com',
'password' => 'test', 'password' => 'test',
@ -65,7 +63,7 @@ class UserTest extends TestCase {
); );
} }
public function test_new_user_failed_login() { public function test_new_user_failed_login(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'test@test.com', 'email' => 'test@test.com',
'password' => 'testX', 'password' => 'testX',
@ -78,7 +76,7 @@ class UserTest extends TestCase {
); );
} }
public function test_new_user_name_update_with_user_token() { public function test_new_user_name_update_with_user_token(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'test@test.com', 'email' => 'test@test.com',
'password' => 'test', 'password' => 'test',
@ -100,7 +98,7 @@ class UserTest extends TestCase {
); );
} }
public function test_new_user_name_update_with_admin_token() { public function test_new_user_name_update_with_admin_token(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -122,7 +120,7 @@ class UserTest extends TestCase {
); );
} }
public function test_new_user_destroy_as_user_should_fail() { public function test_new_user_destroy_as_user_should_fail(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'test@test.com', 'email' => 'test@test.com',
'password' => 'test', 'password' => 'test',
@ -144,7 +142,7 @@ class UserTest extends TestCase {
); );
} }
public function test_new_user_destroy_as_admin() { public function test_new_user_destroy_as_admin(): void {
$response = $this->postJson('/api/login', [ $response = $this->postJson('/api/login', [
'email' => 'admin@hydra.project', 'email' => 'admin@hydra.project',
'password' => 'hydra', 'password' => 'hydra',
@ -166,7 +164,7 @@ class UserTest extends TestCase {
); );
} }
public function test_delete_admin_user_if_multiple_admins_are_present() { public function test_delete_admin_user_if_multiple_admins_are_present(): void {
$newAdminUser = User::create([ $newAdminUser = User::create([
'name' => 'Test Admin', 'name' => 'Test Admin',
'password' => Hash::make('abcd'), 'password' => Hash::make('abcd'),

@ -7,10 +7,8 @@ use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase { class ExampleTest extends TestCase {
/** /**
* A basic test example. * A basic test example.
*
* @return void
*/ */
public function test_that_true_is_true() { public function test_that_true_is_true(): void {
$this->assertTrue(true); $this->assertTrue(true);
} }
} }

Loading…
Cancel
Save