diff --git a/app/Actions/Fortify/UpdateUserProfileInformation.php b/app/Actions/Fortify/UpdateUserProfileInformation.php index 383d625..cd0795a 100644 --- a/app/Actions/Fortify/UpdateUserProfileInformation.php +++ b/app/Actions/Fortify/UpdateUserProfileInformation.php @@ -4,6 +4,7 @@ namespace App\Actions\Fortify; use App\Models\User; use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; use Laravel\Fortify\Contracts\UpdatesUserProfileInformation; @@ -13,7 +14,7 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation /** * Validate and update the given user's profile information. * - * @param array $input + * @param array $input */ public function update(User $user, array $input): void { diff --git a/app/Events/DietSelected.php b/app/Events/DietSelected.php index 6450383..24965aa 100644 --- a/app/Events/DietSelected.php +++ b/app/Events/DietSelected.php @@ -12,15 +12,9 @@ class DietSelected { use Dispatchable, InteractsWithSockets, SerializesModels; - /** - * @var Diet - */ - public $diet; + public Diet $diet; - /** - * @var User - */ - public $user; + public User $user; /** * Create a new event instance. diff --git a/app/Http/Controllers/CalendarController.php b/app/Http/Controllers/CalendarController.php index 5a9866c..24440be 100644 --- a/app/Http/Controllers/CalendarController.php +++ b/app/Http/Controllers/CalendarController.php @@ -12,23 +12,20 @@ use Mcamara\LaravelLocalization\Facades\LaravelLocalization; class CalendarController extends Controller { - public string|int|null $weekStartsAt; + public int $weekStartsAt; - public string|int|null $weekEndsAt; + public int $weekEndsAt; public Carbon $startsAt; public Carbon $endsAt; - public string|int|null $gridStartsAt; + public Carbon $gridStartsAt; - public string|int|null $gridEndsAt; + public Carbon $gridEndsAt; - public function __construct( - string|int|null $initialYear = null, - string|int|null $initialMonth = null, - string|int|null $weekStartsAt = null - ) { + public function __construct(?int $initialYear = null, ?int $initialMonth = null, ?int $weekStartsAt = null) + { $this->weekStartsAt = $weekStartsAt ?? Carbon::MONDAY; $this->weekEndsAt = $this->weekStartsAt === Carbon::MONDAY ? Carbon::SUNDAY diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 05e3dc4..084ceaf 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -2,8 +2,6 @@ namespace App\Http\Controllers; -use App\Events\ChatMessageUpdated; -use App\Messages\ChatMessage; use App\Models\Chat; use App\Models\User; use Illuminate\Contracts\View\Factory as ViewFactory; @@ -45,18 +43,6 @@ class ChatController extends Controller ); } - /* - * public function create(): void - { - ChatMessageUpdated::dispatch( - new ChatMessage( - time(), - 'some text '.md5(' '.time()) - ) - ); - } - */ - public function show(int $lastChatUser): View|ViewFactory { $lastChatUser = User::find($lastChatUser); @@ -85,7 +71,7 @@ class ChatController extends Controller ); } - private function makeChanName(int $from, int $to): string + private function makeChanName(?int $from = null, ?int $to = null): string { return (int) $from < (int) $to ? $from.'_'.$to diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 1e9e328..0a5922b 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -8,7 +8,6 @@ use Illuminate\Contracts\View\View; class UserController extends Controller { - public function show(User $user): View|ViewFactory { return view('user.show', ['user' => $user]); diff --git a/app/Listeners/ProcessDietSelectedNotification.php b/app/Listeners/ProcessDietSelectedNotification.php index 84c839a..0473820 100644 --- a/app/Listeners/ProcessDietSelectedNotification.php +++ b/app/Listeners/ProcessDietSelectedNotification.php @@ -12,17 +12,9 @@ class ProcessDietSelectedNotification implements ShouldQueue { use InteractsWithQueue; - /** - * @var bool - */ - public $afterCommit = true; + public bool $afterCommit = true; - /** - * Handle the event. - * - * @return void - */ - public function handle(DietSelected $event) + public function handle(DietSelected $event): void { $user = $event->user; $diet = $event->diet; diff --git a/app/Livewire/Chat/LastUsers.php b/app/Livewire/Chat/LastUsers.php index e282ad3..2895f76 100644 --- a/app/Livewire/Chat/LastUsers.php +++ b/app/Livewire/Chat/LastUsers.php @@ -4,16 +4,14 @@ namespace App\Livewire\Chat; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; +use Illuminate\Support\Collection; use Livewire\Component; class LastUsers extends Component { - /** - * @var mixed - */ - public $lastChatUsers; + public Collection $lastChatUsers; - public int $activeUserId; + public ?int $activeUserId = null; public int $curUserId; diff --git a/app/Livewire/Chat/MessageWindow.php b/app/Livewire/Chat/MessageWindow.php index da03138..29a54ad 100644 --- a/app/Livewire/Chat/MessageWindow.php +++ b/app/Livewire/Chat/MessageWindow.php @@ -12,15 +12,15 @@ use Livewire\Component; class MessageWindow extends Component { - public Collection $messages; + public array|Collection $messages = []; public string $curMessage = ''; public int $curUserId; - public int $recipientUserId; + public ?int $recipientUserId = null; - public User $recipientUser; + public ?User $recipientUser = null; public string $chanId; @@ -61,7 +61,7 @@ class MessageWindow extends Component } // FIXME - public function mount(?int $recipientUserId): void + public function mount(?int $recipientUserId = null): void { $this->recipientUserId = $recipientUserId; $this->recipientUser = User::find($recipientUserId); diff --git a/app/Livewire/Chat/Tracker.php b/app/Livewire/Chat/Tracker.php index 9e98f0f..b9156a4 100644 --- a/app/Livewire/Chat/Tracker.php +++ b/app/Livewire/Chat/Tracker.php @@ -2,27 +2,17 @@ namespace App\Livewire\Chat; -use Livewire\Component; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; - +use Livewire\Component; class Tracker extends Component { - public bool $showNewMessageNotifycation = false; + public int|bool $showNewMessageNotifycation = false; public array $myMessages = []; - // Special Syntax: ['echo:{channel},{event}' => '{method}'] - /** - * some Listeners - * - * @var array - * - * */ - protected $listeners = ['echo:direct-chat,ChatMessageUpdated' => 'notifyNewMessage']; - - public function notifyNewMessage(mixed $payload): void + public function notifyNewMessage(string $payload): void { $this->myMessages[] = $payload; $this->showNewMessageNotifycation = true; @@ -32,4 +22,9 @@ class Tracker extends Component { return view('livewire.chat.tracker'); } + + protected function getListeners(): array + { + return ['echo:direct-chat,ChatMessageUpdated' => 'notifyNewMessage']; + } } diff --git a/app/Livewire/Consultant/RegistrationForm.php b/app/Livewire/Consultant/RegistrationForm.php index 40c9d44..d4fee7f 100644 --- a/app/Livewire/Consultant/RegistrationForm.php +++ b/app/Livewire/Consultant/RegistrationForm.php @@ -6,13 +6,13 @@ use App\Models\ConsultantEducation; use App\Models\User; use App\Models\UserAttachment; use App\Notifications\ConsultantRequestStarted; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; use Livewire\Component; use Livewire\WithFileUploads; -use Illuminate\Contracts\View\Factory as ViewFactory; -use Illuminate\Contracts\View\View; -use Illuminate\Support\Collection; class RegistrationForm extends Component { @@ -30,16 +30,15 @@ class RegistrationForm extends Component public string $telegramLink = ''; - public int $hasMedicalEducation = 0; + public bool|int $hasMedicalEducation = false; - public Collection $certPhotos; + public array|Collection $certPhotos = []; public array $tmpCertPhotos = []; public string $legalType = 'selfemployed'; - /** @phpstan-ignore-next-line */ - protected $rules = [ + protected array $rules = [ 'medicalEducations.*.title' => 'required|string|min:6', 'medicalEducations.*.date' => 'required|date', 'vkLink' => 'required|url', @@ -65,9 +64,9 @@ class RegistrationForm extends Component $photos = $this->user->attachments()->certs()->get(); - if (count($photos) > 0) { - $this->certPhotos = collect($photos); - } + // if ($photos) { + $this->certPhotos = collect($photos); + // } } public function render(): View|ViewFactory @@ -95,7 +94,7 @@ class RegistrationForm extends Component $this->medicalEducations = $medicalEducations; } - public function remove(int $index): void + public function remove(string $index): void { $filteredEducations = array_filter( $this->medicalEducations, @@ -146,7 +145,7 @@ class RegistrationForm extends Component $newFile = UserAttachment::updateOrCreate( $fileData, [ - 'path' => preg_replace("/public\//xi", '/storage/', $curCert), + 'path' => preg_replace('/public\//xi', '/storage/', $curCert), 'specs' => json_encode( [ 'ext' => $photo->extension(), diff --git a/app/Livewire/Diary/ConsultantCommentsEdit.php b/app/Livewire/Diary/ConsultantCommentsEdit.php index 3458e02..6d2d08a 100644 --- a/app/Livewire/Diary/ConsultantCommentsEdit.php +++ b/app/Livewire/Diary/ConsultantCommentsEdit.php @@ -3,12 +3,12 @@ namespace App\Livewire\Diary; use App\Models\ConsultantDiaryComment; -use Illuminate\Support\Facades\Auth; -use Livewire\Component; +use App\Models\Diary; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; -use App\Models\Diary; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Auth; +use Livewire\Component; class ConsultantCommentsEdit extends Component { @@ -16,9 +16,9 @@ class ConsultantCommentsEdit extends Component public Diary $diary; - public Collection $curMeals; + public array|Collection $curMeals = []; - public Collection $typeNames; + public array $typeNames; public array $comments = []; diff --git a/app/Livewire/Diary/MealPhotos.php b/app/Livewire/Diary/MealPhotos.php index dc62677..7f7429d 100644 --- a/app/Livewire/Diary/MealPhotos.php +++ b/app/Livewire/Diary/MealPhotos.php @@ -4,11 +4,11 @@ namespace App\Livewire\Diary; use App\Models\Meal; use App\Models\UserAttachment; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Auth; use Livewire\Component; use Livewire\WithFileUploads; -use Illuminate\Contracts\View\Factory as ViewFactory; -use Illuminate\Contracts\View\View; class MealPhotos extends Component { @@ -18,7 +18,7 @@ class MealPhotos extends Component public array $tmpMealPhotos = []; - public function render():View|ViewFactory + public function render(): View|ViewFactory { return view( 'livewire.diary.meal-photos', diff --git a/app/Livewire/Diet/Comment/Create.php b/app/Livewire/Diet/Comment/Create.php index 663f0f8..83ddc78 100644 --- a/app/Livewire/Diet/Comment/Create.php +++ b/app/Livewire/Diet/Comment/Create.php @@ -5,9 +5,9 @@ namespace App\Livewire\Diet\Comment; use App\Models\Diet; use App\Models\DietComment; use App\Models\User; -use Livewire\Component; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; +use Livewire\Component; class Create extends Component { @@ -17,7 +17,7 @@ class Create extends Component public string $body = ''; - public int $grade = 0; + public string|int $grade = 0; public bool $isChecked = true; diff --git a/app/Livewire/Diet/Comment/Show.php b/app/Livewire/Diet/Comment/Show.php index c56046a..f9fb9ed 100644 --- a/app/Livewire/Diet/Comment/Show.php +++ b/app/Livewire/Diet/Comment/Show.php @@ -11,13 +11,13 @@ class Show extends Component { public Diet $diet; - /** - * @var array - */ - protected $listeners = ['commentAdded' => '$refresh']; - public function render(): View|ViewFactory { return view('livewire.diet.comment.show'); } + + protected function getListeners(): array + { + return ['commentAdded' => '$refresh']; + } } diff --git a/app/Livewire/Diet/Comment/Upvote.php b/app/Livewire/Diet/Comment/Upvote.php index cf96547..f88f9a9 100644 --- a/app/Livewire/Diet/Comment/Upvote.php +++ b/app/Livewire/Diet/Comment/Upvote.php @@ -3,9 +3,9 @@ namespace App\Livewire\Diet\Comment; use App\Models\DietComment; -use Livewire\Component; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; +use Livewire\Component; class Upvote extends Component { diff --git a/app/Livewire/Diet/Create.php b/app/Livewire/Diet/Create.php index 98f07f3..90b98ad 100644 --- a/app/Livewire/Diet/Create.php +++ b/app/Livewire/Diet/Create.php @@ -3,11 +3,12 @@ namespace App\Livewire\Diet; use App\Models\Diet; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Auth; use Livewire\Component; use Livewire\WithFileUploads; -use Illuminate\Contracts\View\Factory as ViewFactory; -use Illuminate\Contracts\View\View; class Create extends Component { @@ -15,9 +16,9 @@ class Create extends Component public string $name = ''; - public string $image; + public ?UploadedFile $image = null; - public int $duration = 7; + public int|string $duration = '7'; public string $state = 'draft'; @@ -27,19 +28,16 @@ class Create extends Component public array $days = []; - public int $copyedDay; + public string $copyedDay; public array $copyedDayData; - /** @phpstan-ignore-next-line */ - protected $listeners = ['dayUpdated', 'makeCopy', 'makePaste']; - public function render(): View|ViewFactory { return view('livewire.diet.create'); } - public function dayUpdated(int $dayIndex, array $data): void + public function dayUpdated(string $dayIndex, array $data): void { $this->days[$dayIndex] = $data; } @@ -56,12 +54,12 @@ class Create extends Component $this->publish(); } - public function makeCopy(int $day):void + public function makeCopy(string $day): void { $this->copyedDay = $day; } - public function makePaste(int $copyToDay): void + public function makePaste(string $copyToDay): void { $data = $this->days[$this->copyedDay]; $this->dispatch('takePaste', day: $copyToDay, data: $data)->to('diet.day-edit'); @@ -73,21 +71,24 @@ class Create extends Component $diet = new Diet(); $diet->name = $this->name; - /** @phpstan-ignore-next-line */ - $diet->image = $this->image->store('diets', 'public'); + // $diet->image = $this->image->store('diets', 'public'); + $diet->image = $this->image->store('diets'); $diet->duration = $this->duration; $diet->state = $this->state; - $diet->type = json_encode($this->type); + $diet->type = $this->type; $diet->details = $this->details; - $diet->daily_schedule = json_encode($this->days); - $diet->save(); + $diet->daily_schedule = $this->days; + $diet->saveOrFail(); $user = Auth::user(); $user->author_of_diets()->attach($diet->id); // return redirect()->route('diet.show', $diet->id); + } - $this->redirectRoute('diet.show', $diet->id); + protected function getListeners(): array + { + return ['dayUpdated', 'makeCopy', 'makePaste']; } protected function rules(): array @@ -96,7 +97,7 @@ class Create extends Component 'name' => 'required|min:3', 'image' => 'required|image|max:2048', 'duration' => 'required|numeric|min:7', - 'state' => 'required|in:draft,active,inactive', + 'state' => 'required|in:active,draft,archived', 'type' => ['required', 'array:meat,veg,corb,alko', 'min:1'], 'details' => 'required|min:3', ]; diff --git a/app/Livewire/Diet/DayEdit.php b/app/Livewire/Diet/DayEdit.php index bd8f927..74234f3 100644 --- a/app/Livewire/Diet/DayEdit.php +++ b/app/Livewire/Diet/DayEdit.php @@ -2,13 +2,13 @@ namespace App\Livewire\Diet; -use Livewire\Component; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; +use Livewire\Component; class DayEdit extends Component { - public int $day; + public string $day; public array $eatingTypes = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks']; @@ -22,11 +22,7 @@ class DayEdit extends Component public string $portion = 'gram'; - /** @phpstan-ignore-next-line */ - protected $listeners = ['takePaste']; - - /** @phpstan-ignore-next-line */ - protected $rules = [ + protected array $rules = [ 'name' => 'required|min:3', 'quantity' => 'required|numeric|min:1', 'portion' => 'required|min:3', @@ -84,7 +80,7 @@ class DayEdit extends Component } } - public function takePaste(int $day, array $data): void + public function takePaste(string $day, array $data): void { if (intval($day) === intval($this->day)) { foreach ($data as $type => $props) { @@ -93,4 +89,9 @@ class DayEdit extends Component $this->dispatch('dayUpdated', dayIndex: $this->day, data: $this->portions); } } + + protected function getListeners(): array + { + return ['takePaste']; + } } diff --git a/app/Livewire/Diet/Edit.php b/app/Livewire/Diet/Edit.php index 9bb591f..c5777af 100644 --- a/app/Livewire/Diet/Edit.php +++ b/app/Livewire/Diet/Edit.php @@ -5,17 +5,21 @@ namespace App\Livewire\Diet; use App\Models\Diet; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; +use Illuminate\Http\UploadedFile; use Livewire\Component; +use Livewire\WithFileUploads; class Edit extends Component { + use WithFileUploads; + public Diet $diet; public string $name = ''; - public string $image; + public UploadedFile|string $image = ''; - public int $duration = 7; + public int|string $duration = '7'; public string $state = 'draft'; @@ -25,24 +29,19 @@ class Edit extends Component public array $days = []; - public int $copyedDay; + public string $copyedDay; public array $copyedDayData; - /** - * @var array - */ - protected $listeners = ['dayUpdated', 'makeCopy', 'makePaste']; - public function mount(Diet $diet): void { $this->name = $diet->name; $this->image = $diet->image; $this->duration = $diet->duration; $this->state = $diet->state; - $this->type = json_decode($diet->type, true); + $this->type = $diet->type; $this->details = $diet->details; - $this->days = json_decode($diet->daily_schedule, true); + $this->days = $diet->daily_schedule; } public function render(): View|ViewFactory @@ -50,7 +49,7 @@ class Edit extends Component return view('livewire.diet.edit'); } - public function dayUpdated(int $dayIndex, array $data): void + public function dayUpdated(string $dayIndex, array $data): void { $this->days[$dayIndex] = $data; } @@ -67,13 +66,13 @@ class Edit extends Component $this->publish(); } - public function makeCopy(int $day): void + public function makeCopy(string $day): void { /* dd($day); */ $this->copyedDay = $day; } - public function makePaste(int $copyToDay): void + public function makePaste(string $copyToDay): void { $data = $this->days[$this->copyedDay]; $this->dispatch( @@ -91,19 +90,20 @@ class Edit extends Component $diet->name = $this->name; /* $diet->image = $this->image->store('diets', 'public'); */ + $diet->image = ! is_string($this->image) ? $this->image->store('diets') : $this->image; $diet->duration = $this->duration; $diet->state = $this->state; - $diet->type = json_encode($this->type); + $diet->type = $this->type; $diet->details = $this->details; - $diet->daily_schedule = json_encode($this->days); + $diet->daily_schedule = $this->days; $diet->save(); - /* $user = Auth::user(); */ - /* $user->author_of_diets()->attach($diet->id); */ + $this->redirectRoute('diet.show', $diet); + } - // return redirect()->route('diet.show', $diet->id); - - $this->redirectRoute('diet.show', $diet->id); + protected function getListeners(): array + { + return ['dayUpdated', 'makeCopy', 'makePaste']; } protected function rules(): array @@ -112,7 +112,7 @@ class Edit extends Component 'name' => 'required|min:3', /* 'image' => 'required|image|max:2048', */ 'duration' => 'required|numeric|min:7', - 'state' => 'required|in:draft,active,inactive', + 'state' => 'required|in:active,draft,archived', 'type' => ['required', 'array:meat,veg,corb,alko', 'min:1'], 'details' => 'required|min:3', ]; diff --git a/app/Livewire/Diet/Like.php b/app/Livewire/Diet/Like.php index f559e9b..b62b592 100644 --- a/app/Livewire/Diet/Like.php +++ b/app/Livewire/Diet/Like.php @@ -3,9 +3,9 @@ namespace App\Livewire\Diet; use App\Models\Diet; -use Livewire\Component; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; +use Livewire\Component; class Like extends Component { diff --git a/app/Livewire/Diet/StartButton.php b/app/Livewire/Diet/StartButton.php index 3ba442d..eb94530 100644 --- a/app/Livewire/Diet/StartButton.php +++ b/app/Livewire/Diet/StartButton.php @@ -5,9 +5,9 @@ namespace App\Livewire\Diet; use App\Events\DietSelected; use App\Models\Diet; use App\Models\User; -use Livewire\Component; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; +use Livewire\Component; class StartButton extends Component { diff --git a/app/Livewire/Feed/Index.php b/app/Livewire/Feed/Index.php index 8d7c7c8..c508964 100644 --- a/app/Livewire/Feed/Index.php +++ b/app/Livewire/Feed/Index.php @@ -8,7 +8,7 @@ use Livewire\Component; class Index extends Component { - public mixed $posts; + public array $posts; public function render(): View|ViewFactory { diff --git a/app/Livewire/Forms/ProfileEditDetailzForm.php b/app/Livewire/Forms/ProfileEditDetailzForm.php index 5b4b11d..4a1b3aa 100644 --- a/app/Livewire/Forms/ProfileEditDetailzForm.php +++ b/app/Livewire/Forms/ProfileEditDetailzForm.php @@ -56,10 +56,10 @@ class ProfileEditDetailzForm extends Form public int $blood_pressure_down; #[Rule('required|boolean')] - public int $has_hypo; + public int|bool $has_hypo; #[Rule('required|boolean')] - public int $has_hyper; + public int|bool $has_hyper; #[Rule('nullable')] public string $about_alergy = 'nullable'; diff --git a/app/Livewire/MealForm.php b/app/Livewire/MealForm.php index fae21f3..818ffa2 100644 --- a/app/Livewire/MealForm.php +++ b/app/Livewire/MealForm.php @@ -23,7 +23,7 @@ class MealForm extends Component public array $portions; - public int $quantity; + public string $quantity; public array $pcs; @@ -43,11 +43,6 @@ class MealForm extends Component 'portion' => 'required|min:1', ]; - /** - * @var array - */ - protected $listeners = ['food-intake-updated' => '$refresh']; - public function mount(): void { $this->diary = Diary::find($this->diaryId); @@ -191,6 +186,11 @@ class MealForm extends Component $this->portions = array_values($filtered); } + protected function getListeners(): array + { + return ['food-intake-updated' => '$refresh']; + } + private function addPortionIfItFilled(): void { if (mb_strlen($this->product_name) && $this->quantity && mb_strlen($this->portion)) { diff --git a/app/Livewire/ProductNutritional/Create.php b/app/Livewire/ProductNutritional/Create.php index 708047f..d8af0fb 100644 --- a/app/Livewire/ProductNutritional/Create.php +++ b/app/Livewire/ProductNutritional/Create.php @@ -4,22 +4,23 @@ namespace App\Livewire\ProductNutritional; use App\Models\ProductGroup; use App\Models\ProductNutritionalValue; -use Livewire\Component; -use Livewire\WithFileUploads; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; +use Illuminate\Http\UploadedFile; +use Livewire\Component; +use Livewire\WithFileUploads; class Create extends Component { use WithFileUploads; - public string $name; + public string $name = ''; - public int $product_group; + public int|string $product_group; - public string|null $image; + public ?UploadedFile $image = null; - public string $description; + public string $description = ''; public string $formulations; @@ -27,11 +28,11 @@ class Create extends Component public float $proteins_on_100gr; - public float $fats_on_100gr; + public float $fats_on_100gr; public float $carbohydrates_on_100gr; - public int $portion_mass_gr; + public int $portion_mass_gr = 0; public float $energy_on_portion; @@ -53,19 +54,18 @@ class Create extends Component $productNutritionalVal = ProductNutritionalValue::create([ 'name' => $this->name, 'product_group_id' => $this->product_group, - /** @phpstan-ignore-next-line */ - 'image' => is_null($this->image) ? '' : $this->image->store('product_nutritional', 'public'), + 'image' => is_null($this->image) ? '' : $this->image->store('product_nutritional'), 'description' => $this->description ?? '', 'formulations' => $this->formulations ?? '', - 'energy_on_100gr' => (int) $this->energy_on_100gr, - 'proteins_on_100gr' => (float) $this->proteins_on_100gr, - 'fats_on_100gr' => (float) $this->fats_on_100gr, - 'carbohydrates_on_100gr' => (float) $this->carbohydrates_on_100gr, - 'portion_mass_gr' => (int) $this->portion_mass_gr, - 'energy_on_portion' => (float) $this->energy_on_portion, - 'proteins_on_portion' => (float) $this->proteins_on_portion, - 'fats_on_portion' => (float) $this->fats_on_portion, - 'carbohydrates_on_portion' => (float) $this->carbohydrates_on_portion, + 'energy_on_100gr' => $this->energy_on_100gr, + 'proteins_on_100gr' => $this->proteins_on_100gr, + 'fats_on_100gr' => $this->fats_on_100gr, + 'carbohydrates_on_100gr' => $this->carbohydrates_on_100gr, + 'portion_mass_gr' => $this->portion_mass_gr, + 'energy_on_portion' => $this->energy_on_portion, + 'proteins_on_portion' => $this->proteins_on_portion, + 'fats_on_portion' => $this->fats_on_portion, + 'carbohydrates_on_portion' => $this->carbohydrates_on_portion, ]); $this->curProductNutritionalValue = $productNutritionalVal; @@ -109,17 +109,17 @@ class Create extends Component } } - public function updated(string $name, string|int|null $value): void + public function updated(string $name, string $value): void { if ($name === 'portion_mass_gr') { - $this->recalulatePortionVals((int) $this->portion_mass_gr); + $this->recalulatePortionVals($this->portion_mass_gr); } if ( - (int) $this->portion_mass_gr > 0 - && in_array($name, ['energy_on_portion', 'proteins_on_portion', 'fats_on_portion', 'carbohydrates_on_portion']) + $this->portion_mass_gr > 0 && + in_array($name, ['energy_on_portion', 'proteins_on_portion', 'fats_on_portion', 'carbohydrates_on_portion']) ) { - $this->recalulateVals((int) $this->portion_mass_gr); + $this->recalulateVals($this->portion_mass_gr); } } diff --git a/app/Livewire/ProductNutritional/Edit.php b/app/Livewire/ProductNutritional/Edit.php index 7892bee..d95d354 100644 --- a/app/Livewire/ProductNutritional/Edit.php +++ b/app/Livewire/ProductNutritional/Edit.php @@ -4,22 +4,23 @@ namespace App\Livewire\ProductNutritional; use App\Models\ProductGroup; use App\Models\ProductNutritionalValue; -use Livewire\Component; -use Livewire\WithFileUploads; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; +use Illuminate\Http\UploadedFile; +use Livewire\Component; +use Livewire\WithFileUploads; class Edit extends Component { use WithFileUploads; - public string $name; + public string $name = ''; - public int $product_group; + public int|string $product_group; - public string|null $image; + public UploadedFile|string $image = ''; - public string $description; + public string $description = ''; public string $formulations; @@ -31,7 +32,7 @@ class Edit extends Component public float $carbohydrates_on_100gr; - public int $portion_mass_gr; + public int $portion_mass_gr = 0; public float $energy_on_portion; @@ -70,8 +71,7 @@ class Edit extends Component public function save(): void { if (! is_string($this->image)) { - /** @phpstan-ignore-next-line */ - $this->product->image = $this->image->store('product_nutritional', 'public'); + $this->product->image = $this->image->store('product_nutritional'); } $this->product->fill([ @@ -79,15 +79,15 @@ class Edit extends Component 'product_group_id' => $this->product_group, 'description' => $this->description ?? '', 'formulations' => $this->formulations ?? '', - 'energy_on_100gr' => (int) $this->energy_on_100gr, - 'proteins_on_100gr' => (float) $this->proteins_on_100gr, - 'fats_on_100gr' => (float) $this->fats_on_100gr, - 'carbohydrates_on_100gr' => (float) $this->carbohydrates_on_100gr, - 'portion_mass_gr' => (int) $this->portion_mass_gr, + 'energy_on_100gr' => $this->energy_on_100gr, + 'proteins_on_100gr' => $this->proteins_on_100gr, + 'fats_on_100gr' => $this->fats_on_100gr, + 'carbohydrates_on_100gr' => $this->carbohydrates_on_100gr, + 'portion_mass_gr' => $this->portion_mass_gr, 'energy_on_portion' => (int) $this->energy_on_portion, - 'proteins_on_portion' => (float) $this->proteins_on_portion, - 'fats_on_portion' => (float) $this->fats_on_portion, - 'carbohydrates_on_portion' => (float) $this->carbohydrates_on_portion, + 'proteins_on_portion' => $this->proteins_on_portion, + 'fats_on_portion' => $this->fats_on_portion, + 'carbohydrates_on_portion' => $this->carbohydrates_on_portion, ]); $this->product->save(); @@ -133,17 +133,17 @@ class Edit extends Component } } - public function updated(string $name, string|int|null $value): void + public function updated(string $name, string $value): void { if ($name === 'portion_mass_gr') { - $this->recalulatePortionVals((int) $this->portion_mass_gr); + $this->recalulatePortionVals($this->portion_mass_gr); } if ( - (int) $this->portion_mass_gr > 0 + $this->portion_mass_gr > 0 && in_array($name, ['energy_on_portion', 'proteins_on_portion', 'fats_on_portion', 'carbohydrates_on_portion']) ) { - $this->recalulateVals((int) $this->portion_mass_gr); + $this->recalulateVals($this->portion_mass_gr); } } diff --git a/app/Livewire/Profile/CircumferenceChart.php b/app/Livewire/Profile/CircumferenceChart.php index 1384edf..e026dc0 100644 --- a/app/Livewire/Profile/CircumferenceChart.php +++ b/app/Livewire/Profile/CircumferenceChart.php @@ -12,19 +12,12 @@ class CircumferenceChart extends Component { public User $user; - /** - * event listeners - * - * @var array - * */ - protected $listeners = ['circumference-chart-updated' => '$refresh']; - public function render(): View|ViewFactory { $lastOneMisure = $this ->user ->circumference_measures() - ->orderBy('updated_at', 'desc') + ->latest() ->first(); $lastFourMisures = $this @@ -42,7 +35,7 @@ class CircumferenceChart extends Component ->setColors(['#b2df8a', '#1f78b4', '#e3a6a6']); $lastFourMisures->each( - function ($item, $key) use ($lineChartModel) { + function ($item) use ($lineChartModel) { $createdAt = \Carbon\Carbon::parse($item['created_at'])->format('d.m.y'); $lineChartModel->addSeriesPoint(__('chest'), $createdAt, $item['chest_circumference']); $lineChartModel->addSeriesPoint(__('waist'), $createdAt, $item['waist_circumference']); @@ -59,4 +52,9 @@ class CircumferenceChart extends Component ] ); } + + protected function getListeners(): array + { + return ['circumference-chart-updated' => '$refresh']; + } } diff --git a/app/Livewire/Profile/DescriptionForm.php b/app/Livewire/Profile/DescriptionForm.php index c715bb2..06f74f6 100644 --- a/app/Livewire/Profile/DescriptionForm.php +++ b/app/Livewire/Profile/DescriptionForm.php @@ -20,7 +20,7 @@ class DescriptionForm extends Component $this->description = $this->user->detailz->additional_info ?? ''; } - public function updatedDescription(mixed $value): void + public function updatedDescription(string $value): void { $userDetailz = $this->user->detailz; @@ -47,7 +47,7 @@ class DescriptionForm extends Component ] ); - if (! $curUserDetailez->id) { + if (! isset($curUserDetailez->id)) { $curUserDetailez->save(); } } diff --git a/app/Livewire/Profile/EditDetailzForm.php b/app/Livewire/Profile/EditDetailzForm.php index 2009d67..04bcf7e 100644 --- a/app/Livewire/Profile/EditDetailzForm.php +++ b/app/Livewire/Profile/EditDetailzForm.php @@ -5,11 +5,11 @@ namespace App\Livewire\Profile; use App\Livewire\Forms\ProfileEditDetailzForm; use App\Models\User; use App\Models\UserDetailz; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use Livewire\Component; -use Illuminate\Contracts\View\Factory as ViewFactory; -use Illuminate\Contracts\View\View; class EditDetailzForm extends Component { @@ -19,9 +19,9 @@ class EditDetailzForm extends Component public string $currentPassword; - public string $newPassword; + public string $newPassword = ''; - public string $newPasswordConfirm; + public string $newPasswordConfirm = ''; public array $validatedData = []; diff --git a/app/Livewire/Profile/PhotoForm.php b/app/Livewire/Profile/PhotoForm.php index 6ef6c9b..924fc80 100644 --- a/app/Livewire/Profile/PhotoForm.php +++ b/app/Livewire/Profile/PhotoForm.php @@ -2,47 +2,30 @@ namespace App\Livewire\Profile; +use App\Models\User; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Laravel\Fortify\Contracts\UpdatesUserProfileInformation; use Livewire\Component; +use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; use Livewire\WithFileUploads; -use Illuminate\Contracts\View\Factory as ViewFactory; -use Illuminate\Contracts\View\View; class PhotoForm extends Component { use WithFileUploads; - /** - * The component's state. - * - * @var array - */ - public $state = []; + public array $state = []; - /** - * The new avatar for the user. - * - * @var mixed - */ - public $photo; + public UploadedFile|string $photo = ''; - public bool $isOnline = false; + public bool|int $isOnline = false; - /** - * User model - * - * @var \App\Models\User - */ - public $user; + public User $user; - /** - * Prepare the component. - * - * @return void - */ - public function mount() + public function mount(): void { $this->state = $this->user->withoutRelations()->toArray(); @@ -58,12 +41,7 @@ class PhotoForm extends Component $this->isOnline = now()->unix() - $lastActivity < 150; } - /** - * Update the user's profile information. - * - * @return void - */ - public function updateProfileInformation(UpdatesUserProfileInformation $updater) + public function updateProfileInformation(UpdatesUserProfileInformation $updater): void { $this->resetErrorBag(); @@ -77,31 +55,21 @@ class PhotoForm extends Component $this->dispatch('saved'); } - public function updatedPhoto(mixed $newPhoto): void + public function updatedPhoto(TemporaryUploadedFile $newPhoto): void { Auth::user()->updateProfilePhoto($newPhoto); $this->dispatch('saved'); } - /** - * Delete user's profile photo. - * - * @return void - */ - public function deleteProfilePhoto() + public function deleteProfilePhoto(): void { Auth::user()->deleteProfilePhoto(); $this->dispatch('refresh-navigation-menu'); } - /** - * Get the current user of the application. - * - * @return mixed - */ - public function getUserProperty() + public function getUserProperty(): User { return $this->user; } diff --git a/app/Livewire/Profile/ShowDetailz.php b/app/Livewire/Profile/ShowDetailz.php index 86f39e6..0824f8f 100644 --- a/app/Livewire/Profile/ShowDetailz.php +++ b/app/Livewire/Profile/ShowDetailz.php @@ -2,12 +2,12 @@ namespace App\Livewire\Profile; -use Livewire\Component; -use Masmerise\Toaster\Toaster; -use Illuminate\Contracts\View\Factory as ViewFactory; -use Illuminate\Contracts\View\View; use App\Models\User; use App\Models\UserDetailz; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Livewire\Component; +use Masmerise\Toaster\Toaster; class ShowDetailz extends Component { @@ -19,11 +19,11 @@ class ShowDetailz extends Component public UserDetailz $userDetailz; - public int $publicity; + public bool|int $publicity; - public int $is_bedtime_fillable; + public bool|int $is_bedtime_fillable; - public int $is_mood_fillable; + public bool|int $is_mood_fillable; public function mount(): void { diff --git a/app/Livewire/Profile/WeightChart.php b/app/Livewire/Profile/WeightChart.php index 0a4ad64..27525f7 100644 --- a/app/Livewire/Profile/WeightChart.php +++ b/app/Livewire/Profile/WeightChart.php @@ -12,11 +12,6 @@ class WeightChart extends Component { public User $user; - /** - * @var array - * */ - protected $listeners = ['weight-chart-updated' => '$refresh']; - public function render(): View|ViewFactory { $areaChartModel = @@ -46,4 +41,9 @@ class WeightChart extends Component ] ); } + + protected function getListeners(): array + { + return ['weight-chart-updated' => '$refresh']; + } } diff --git a/app/Livewire/Registration/Step1.php b/app/Livewire/Registration/Step1.php index cd3d6f1..c1f7d36 100644 --- a/app/Livewire/Registration/Step1.php +++ b/app/Livewire/Registration/Step1.php @@ -5,35 +5,30 @@ namespace App\Livewire\Registration; use App\Actions\Fortify\CreateNewUser; use App\Rules\MinWords; use Illuminate\Auth\Events\Registered; +use Illuminate\Contracts\View\Factory as ViewFactory; +use Illuminate\Contracts\View\View; +use Illuminate\Http\RedirectResponse; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use Illuminate\Validation\Rule; use Illuminate\Validation\Rules\Password; -// use Laravel\Fortify\Contracts\RegisterResponse; -// use Illuminate\Contracts\Auth\StatefulGuard; -// use App\Models\User; -// use App\Models\UserDetailz; -use Illuminate\Contracts\View\View; -use Illuminate\Contracts\View\Factory as ViewFactory; -use Illuminate\Http\RedirectResponse; use Livewire\Component; - -// use \Mcamara\LaravelLocalization\Facades\LaravelLocalization; +use Livewire\Features\SupportRedirects\Redirector; class Step1 extends Component { public string $step; - public string $first_name; + public string $first_name = ''; - public string $last_name; + public string $last_name = ''; - public string $email; + public string $email = ''; - public string $password; + public string $password = ''; - public string $password_confirmation; + public string $password_confirmation = ''; public string $birthdate; @@ -45,35 +40,35 @@ class Step1 extends Component public string $lang = 'ru'; - public int $weight; + public string $weight = ''; - public int $height; + public string $height = ''; - public int $chest_circumference; + public string $chest_circumference = ''; - public int $waist_circumference; + public string $waist_circumference = ''; - public int $hip_circumference; + public string $hip_circumference = ''; - public int $blood_pressure_up; + public string $blood_pressure_up = ''; - public int $blood_pressure_down; + public string $blood_pressure_down = ''; - public int $has_hypo = 0; + public int|string $has_hypo = 0; - public int $has_hyper = 0; + public int|string $has_hyper = 0; - public string $about_alergy; + public string $about_alergy = ''; - public string $about_taking_pils; + public string $about_taking_pils = ''; - public string $about_sport_hobbies; + public string $about_sport_hobbies = ''; - public string $favorite_foods; + public string $favorite_foods = ''; - public string $unfavorite_foods; + public string $unfavorite_foods = ''; - public string $additional_info; + public string $additional_info = ''; public function mount(string $step): void { @@ -88,7 +83,7 @@ class Step1 extends Component ->extends('layouts.register'); } - public function nextStep(): RedirectResponse + public function nextStep(): RedirectResponse|Redirector { $validatedData = Validator::make( $this->getValidateData($this->step), @@ -109,7 +104,7 @@ class Step1 extends Component ); } - public function skipStep(): RedirectResponse + public function skipStep(): RedirectResponse|Redirector { $validatedData = $this->getValidateData($this->step); $registrationdata = session()->get('registrationdata', []); @@ -126,9 +121,9 @@ class Step1 extends Component ); } - public function goBack(): RedirectResponse + public function goBack(): RedirectResponse|Redirector { - $nextStep = 'step'. (((int) Str::replaceFirst('step', '', $this->step)) - 1); + $nextStep = 'step'.((int) Str::replaceFirst('step', '', $this->step) - 1); return redirect() ->route( @@ -139,7 +134,7 @@ class Step1 extends Component ); } - public function finishRegistretion(): RedirectResponse + public function finishRegistretion(): RedirectResponse|Redirector { $validatedData = Validator::make( $this->getValidateData($this->step), diff --git a/app/Livewire/TagsComponent.php b/app/Livewire/TagsComponent.php index 2fb5c44..c8d7748 100644 --- a/app/Livewire/TagsComponent.php +++ b/app/Livewire/TagsComponent.php @@ -3,6 +3,8 @@ namespace App\Livewire; // use App\Models\BlogPost; +use App\Models\BlogPost; +use App\Models\Recipe; use App\Models\Tag; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; @@ -11,16 +13,17 @@ use Livewire\Component; class TagsComponent extends Component { - public mixed $tags; + public string $tags; - public mixed $parentComponent; + public Recipe|BlogPost $parentComponent; // protected $listeners = ['tagAdded', 'tagRemoved']; - public function mount(mixed $parentComponent = null): void + public function mount(Recipe|BlogPost|null $parentComponent = null): void { - /* $allTags = Tag::all(); */ $curTags = $parentComponent ? $parentComponent->tags->unique()->pluck('name') : []; + /* $allTags = Tag::all(); */ + // $curTags = $parentComponent && isset($parentComponent['tags']) ? $parentComponent['tags']->unique()->pluck('name') : []; $this->tags = json_encode($curTags); } diff --git a/app/Livewire/User/AddCircumference.php b/app/Livewire/User/AddCircumference.php index d1d7802..58dbf63 100644 --- a/app/Livewire/User/AddCircumference.php +++ b/app/Livewire/User/AddCircumference.php @@ -6,10 +6,10 @@ namespace App\Livewire\User; use App\Models\CircumferenceMeasure; use App\Models\User; -use Illuminate\Support\Facades\Auth; -use LivewireUI\Modal\ModalComponent; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; +use Illuminate\Support\Facades\Auth; +use LivewireUI\Modal\ModalComponent; class AddCircumference extends ModalComponent { diff --git a/app/Livewire/User/AddWeight.php b/app/Livewire/User/AddWeight.php index 5b92afc..ac5356f 100644 --- a/app/Livewire/User/AddWeight.php +++ b/app/Livewire/User/AddWeight.php @@ -4,10 +4,10 @@ namespace App\Livewire\User; use App\Models\User; use App\Models\WeightMeasure; -use Illuminate\Support\Facades\Auth; -use LivewireUI\Modal\ModalComponent; use Illuminate\Contracts\View\Factory as ViewFactory; use Illuminate\Contracts\View\View; +use Illuminate\Support\Facades\Auth; +use LivewireUI\Modal\ModalComponent; class AddWeight extends ModalComponent { diff --git a/app/Models/BlogPostLike.php b/app/Models/BlogPostLike.php index 829d3d0..121556e 100644 --- a/app/Models/BlogPostLike.php +++ b/app/Models/BlogPostLike.php @@ -2,9 +2,9 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Builder; /** * App\Models\BlogPostLike diff --git a/app/Models/Chat.php b/app/Models/Chat.php index 94503e4..e49063e 100644 --- a/app/Models/Chat.php +++ b/app/Models/Chat.php @@ -2,9 +2,9 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Query\Builder; /** * App\Models\Chat @@ -37,7 +37,7 @@ class Chat extends Model protected $casts = ['created_at' => 'datetime:Y-m-d H:i:s']; - public function scopeWithLastUserMessage(mixed $query, int $userId): Builder + public function scopeWithLastUserMessage(Builder $query, int $userId): ?Model { return $query ->where('from_user_id', $userId) @@ -59,7 +59,7 @@ class Chat extends Model ->limit(20); } - public function scopeWithLastMessage(Builder $query, int $userId, int $recipientId): null|object + public function scopeWithLastMessage(Builder $query, int $userId, int $recipientId): ?Model { return $query ->where('from_user_id', $userId) diff --git a/app/Models/ChosenDiet.php b/app/Models/ChosenDiet.php index 0dc8e03..227e426 100644 --- a/app/Models/ChosenDiet.php +++ b/app/Models/ChosenDiet.php @@ -6,7 +6,6 @@ use Iben\Statable\Statable; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Relations\BelongsToMany; /** * App\Models\ChosenDiet @@ -18,7 +17,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; * @property string $start_date * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at - * * @property-read \App\Models\Diet|null $diet * @property-read \Illuminate\Database\Eloquent\Collection $stateHistory * @property-read int|null $state_history_count diff --git a/app/Models/Diary.php b/app/Models/Diary.php index 8ba5a30..f3ea44b 100644 --- a/app/Models/Diary.php +++ b/app/Models/Diary.php @@ -2,12 +2,12 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Database\Query\Builder; /** * App\Models\Diary @@ -19,9 +19,8 @@ use Illuminate\Database\Query\Builder; * @property string $retire * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at - * @property int $closed + * @property int|bool $closed * @property string $comment - * * @property-read \Illuminate\Database\Eloquent\Collection $consultant_comments * @property-read int|null $consultant_comments_count * @property-read \Illuminate\Database\Eloquent\Collection $meals diff --git a/app/Models/Diet.php b/app/Models/Diet.php index 6b37d68..72978f7 100644 --- a/app/Models/Diet.php +++ b/app/Models/Diet.php @@ -8,13 +8,8 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Database\Eloquent\Relations\HasOneThrough; use Illuminate\Database\Eloquent\Relations\BelongsToMany; -use Illuminate\Database\Eloquent\Relations\MorphToMany; -use Illuminate\Support\Str; -use Spatie\Sluggable\HasSlug; -use Spatie\Sluggable\SlugOptions; +use Illuminate\Database\Eloquent\Relations\HasMany; /** * App\Models\Diet @@ -29,7 +24,6 @@ use Spatie\Sluggable\SlugOptions; * @property mixed $daily_schedule A list of planned foods * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at - * * @property-read \Illuminate\Database\Eloquent\Collection $author * @property-read int|null $author_count * @property-read \Illuminate\Database\Eloquent\Collection $choses @@ -70,10 +64,9 @@ class Diet extends Model implements Viewable { use HasFactory, InteractsWithViews; - protected $withCount = [ - 'likes', - 'comments', - 'choses', + protected $casts = [ + 'type' => 'array', + 'daily_schedule' => 'array', ]; private array $allowedDietTypes = [ @@ -83,13 +76,17 @@ class Diet extends Model implements Viewable 'veg', ]; - // protected $casts = [ - // 'type' => 'array', - // 'packet1_options' => 'array', - // 'packet2_options' => 'array', - // 'packet3_options' => 'array', + // protected $withCount = [ + // 'likes', + // 'comments', + // 'choses', // ]; + public static function getWithLikesCommentsChosesCount(): Builder + { + return self::withCount(['likes', 'comments', 'choses']); + } + public function author(): BelongsToMany { return $this @@ -113,7 +110,7 @@ class Diet extends Model implements Viewable return $this->hasMany(DietLike::class); } - public function isLiked(): bool + public function isLiked(): bool|int { if (auth()->user()) { return auth()->user()->diet_likes()->forDiet($this)->count() > 0; @@ -122,7 +119,7 @@ class Diet extends Model implements Viewable return false; } - public function removeLike(): bool + public function removeLike(): bool|int { if (auth()->user()) { return auth()->user()->diet_likes()->forDiet($this)->delete(); @@ -133,7 +130,7 @@ class Diet extends Model implements Viewable public function types(): Attribute { - $data = $this->unserializeOptionsArr($this->type); + $data = $this->type; return new Attribute( get: fn () => array_keys($data), @@ -142,7 +139,7 @@ class Diet extends Model implements Viewable public function schedules(): Attribute { - $data = $this->unserializeOptionsArr($this->daily_schedule); + $data = $this->daily_schedule; return new Attribute( get: fn () => $data, @@ -154,22 +151,22 @@ class Diet extends Model implements Viewable return $this->hasMany(ChosenDiet::class); } - public function scopeDurationMin(Builder $query, int $days): Builder + public function scopeDurationMin(Builder $query, string $days): Builder { return $query->where('duration', '>=', $days); } - public function scopeDurationMax(Builder $query, int $days): Builder + public function scopeDurationMax(Builder $query, string $days): Builder { return $query->where('duration', '<=', $days); } - public function scopeInvolvedMin(Builder $query, int $number): Builder + public function scopeInvolvedMin(Builder $query, string $number): Builder { return $query->having('choses_count', '>=', $number); } - public function scopeInvolvedMax(Builder $query, int $number): Builder + public function scopeInvolvedMax(Builder $query, string $number): Builder { return $query->having('choses_count', '<=', $number); } @@ -189,13 +186,4 @@ class Diet extends Model implements Viewable return $query; } - - private function unserializeOptionsArr(string $str): array - { - if (preg_match('/^".*"$/', $str)) { - return json_decode(stripslashes(mb_substr($str, 1, -1)), true); - } - - return json_decode(stripslashes($str), true); - } } diff --git a/app/Models/DietComment.php b/app/Models/DietComment.php index 61efb1f..96447ce 100644 --- a/app/Models/DietComment.php +++ b/app/Models/DietComment.php @@ -55,7 +55,7 @@ class DietComment extends Model return $this->hasMany(DietCommentUpvote::class, 'comment_id'); } - public function isUpVoted(): bool + public function isUpVoted(): bool|int { if (auth()->user()) { return auth() @@ -68,7 +68,7 @@ class DietComment extends Model return false; } - public function isDownVoted(): bool + public function isDownVoted(): bool|int { if (auth()->user()) { return auth() @@ -81,7 +81,7 @@ class DietComment extends Model return false; } - public function removeUpVote(): bool + public function removeUpVote(): bool|int { if (auth()->user()) { return auth() diff --git a/app/Models/DietCommentUpvote.php b/app/Models/DietCommentUpvote.php index 78322d0..bdbcd6c 100644 --- a/app/Models/DietCommentUpvote.php +++ b/app/Models/DietCommentUpvote.php @@ -2,10 +2,10 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Builder; /** * App\Models\DietCommentUpvote @@ -16,7 +16,6 @@ use Illuminate\Database\Eloquent\Builder; * @property string $type * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at - * * @property-read \App\Models\User $author * @property-read \App\Models\DietComment|null $diet_comment * diff --git a/app/Models/DietLike.php b/app/Models/DietLike.php index c39176e..d856e23 100644 --- a/app/Models/DietLike.php +++ b/app/Models/DietLike.php @@ -2,9 +2,9 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Query\Builder; /** * App\Models\DietLike diff --git a/app/Models/User.php b/app/Models/User.php index e8a553e..c7fb7ec 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -34,6 +34,7 @@ use Laravel\Sanctum\HasApiTokens; * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @property int $is_consultant + * @property string $consultant_state * @property int $is_public_profile 0 only friends, 1 all * * @property-read \Illuminate\Database\Eloquent\Collection $attachments diff --git a/app/Models/UserAttachment.php b/app/Models/UserAttachment.php index 80abe5f..be4bc89 100644 --- a/app/Models/UserAttachment.php +++ b/app/Models/UserAttachment.php @@ -2,11 +2,11 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; -use Illuminate\Database\Query\Builder; /** * App\Models\UserAttachment @@ -20,7 +20,6 @@ use Illuminate\Database\Query\Builder; * @property mixed $specs * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at - * * @property-read \Illuminate\Database\Eloquent\Collection $meals * @property-read int|null $meals_count * @property-read \App\Models\User $user diff --git a/app/Notifications/ConsultantRequestStarted.php b/app/Notifications/ConsultantRequestStarted.php index af9f2f5..0bb9d67 100644 --- a/app/Notifications/ConsultantRequestStarted.php +++ b/app/Notifications/ConsultantRequestStarted.php @@ -12,7 +12,7 @@ class ConsultantRequestStarted extends Notification implements ShouldQueue { use Queueable; - private ConsultantEducation $education; + public ConsultantEducation $education; /** * Create a new notification instance. diff --git a/app/Notifications/DietStarted.php b/app/Notifications/DietStarted.php index 49048af..4c4ed18 100644 --- a/app/Notifications/DietStarted.php +++ b/app/Notifications/DietStarted.php @@ -2,7 +2,6 @@ namespace App\Notifications; -use App\Models\ChosenDiet; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; @@ -12,37 +11,23 @@ class DietStarted extends Notification implements ShouldQueue { use Queueable; - public ChosenDiet $chosenDiet; + public object $chosenDiet; /** * Create a new notification instance. - * - * @return void */ - public function __construct(ChosenDiet $chosenDiet) + public function __construct(object $chosenDiet) { $this->afterCommit(); $this->chosenDiet = $chosenDiet; } - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) + public function via(object $notifiable): array { return ['mail']; } - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) + public function toMail(object $notifiable): MailMessage { return (new MailMessage()) ->line('you are successful started diet named: '.($this->chosenDiet->diet->name ?? 'NoName')) @@ -50,13 +35,7 @@ class DietStarted extends Notification implements ShouldQueue ->line('Thank you for using our application!'); } - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) + public function toArray(object $notifiable): array { return [ diff --git a/app/Rules/MinWords.php b/app/Rules/MinWords.php index 26c76a2..c04582d 100644 --- a/app/Rules/MinWords.php +++ b/app/Rules/MinWords.php @@ -13,7 +13,7 @@ class MinWords implements Rule $this->minWords = $minWords; } - public function passes($attribute, $value) + public function passes(mixed $attribute, mixed $value): bool|int { $wordCount = count(preg_split('/\W+/u', $value, -1, PREG_SPLIT_NO_EMPTY)); diff --git a/app/Services/FeedService.php b/app/Services/FeedService.php index d87a87d..ecefd06 100644 --- a/app/Services/FeedService.php +++ b/app/Services/FeedService.php @@ -17,55 +17,63 @@ class FeedService $dateMin = Carbon::parse($dateMax)->subDays(10); $sql = <<<'EOF' - SELECT - p.id, - p.title, - ( - (p.likes_count + p.comments_count) / - ((UNIX_TIMESTAMP(GREATEST(p.created_at, - COALESCE((SELECT MAX(l.created_at) FROM blog_post_likes l WHERE l.blog_post_id = p.id), p.created_at), - COALESCE((SELECT MAX(c.created_at) FROM blog_post_comments c WHERE c.blog_post_id = p.id), p.created_at) - )) - UNIX_TIMESTAMP(p.created_at))/60 + 1 - ) ^ 1.8 - ) AS popularity - FROM - (SELECT - `blog_posts`.id, - blog_posts.title, - blog_posts.created_at, - COUNT(blog_post_comments.id) AS comments_count, - COUNT(blog_post_likes.id) AS likes_count - FROM - `blog_posts` - LEFT JOIN blog_post_comments ON blog_post_comments.blog_post_id = blog_posts.id - LEFT JOIN blog_post_likes ON blog_post_likes.blog_post_id = blog_posts.id - GROUP BY blog_posts.id) p - ORDER BY popularity DESC; -EOF; + SELECT + p.id, + p.title, + ( + (p.likes_count + p.comments_count) / + ((UNIX_TIMESTAMP(GREATEST(p.created_at, + COALESCE((SELECT MAX(l.created_at) FROM blog_post_likes l WHERE l.blog_post_id = p.id), p.created_at), + COALESCE((SELECT MAX(c.created_at) FROM blog_post_comments c WHERE c.blog_post_id = p.id), p.created_at) + )) - UNIX_TIMESTAMP(p.created_at))/60 + 1 + ) ^ 1.8 + ) AS popularity + FROM + (SELECT + `blog_posts`.id, + blog_posts.title, + blog_posts.created_at, + COUNT(blog_post_comments.id) AS comments_count, + COUNT(blog_post_likes.id) AS likes_count + FROM + `blog_posts` + LEFT JOIN blog_post_comments ON blog_post_comments.blog_post_id = blog_posts.id + LEFT JOIN blog_post_likes ON blog_post_likes.blog_post_id = blog_posts.id + GROUP BY blog_posts.id) p + ORDER BY popularity DESC; + EOF; $hotBlogPosts = collect( - DB::select(DB::raw($sql)) - )->map(fn ($post) => BlogPost::find($post->id)) - ->take(16)->chunk(4); + DB::select($sql) + ) + ->map(fn ($post) => BlogPost::find($post->id)) + ->take(16) + ->chunk(4); $newbiesBlogPosts = User::orderBy('created_at', 'desc') ->withCount('author_of_blog_post') ->get() - ->filter(fn ($u) => $u->author_of_blog_post_count > 0)->take(4) + ->filter(fn ($u) => $u->author_of_blog_post_count > 0) + ->take(4) ->pluck('id') ->map(fn ($id) => User::find($id)->author_of_blog_post()->limit(2)->get()) ->flatten() ->random(); - $randomRecipe = Recipe::where('created_at', '>=', $dateMin) + Recipe::where('created_at', '>=', $dateMin) ->where('created_at', '<=', $dateMax) ->inRandomOrder() ->limit(2) ->get(); - $firstCollection = $hotBlogPosts->first()->push($newbiesBlogPosts->first())->push($randomRecipe->first()); - $secondCollection = $hotBlogPosts->skip(1)->first()->push($newbiesBlogPosts->skip(1)->first())->push($randomRecipe->skip(1)->first()); + $firstCollection = collect([$hotBlogPosts->first(), $newbiesBlogPosts->first()]); + $secondCollection = collect([$hotBlogPosts->skip(1)->first(), $newbiesBlogPosts->skip(1)->first()]); return $firstCollection->concat($secondCollection)->filter(fn ($el) => ! is_null($el) && $el->id); + + // $firstCollection = $hotBlogPosts->first()->push($newbiesBlogPosts->first())->push($randomRecipe->first()); + // $secondCollection = $hotBlogPosts->skip(1)->first()->push($newbiesBlogPosts->skip(1)->first())->push($randomRecipe->skip(1)->first()); + + // return $firstCollection->concat($secondCollection)->filter(fn ($el) => ! is_null($el) && $el->id); } } diff --git a/config/rich-text-laravel.php b/config/rich-text-laravel.php index 3c1f439..4d85ec1 100644 --- a/config/rich-text-laravel.php +++ b/config/rich-text-laravel.php @@ -11,7 +11,7 @@ return [ | using this Eloquent Model. You can override this if you really need to. | */ - 'model' => \Tonysm\RichTextLaravel\Models\RichText::class, + // 'model' => \Tonysm\RichTextLaravel\Models\RichText::class, /* |-------------------------------------------------------------------------- diff --git a/config/state-machine.php b/config/state-machine.php index 8bbf7c2..c18dbb5 100644 --- a/config/state-machine.php +++ b/config/state-machine.php @@ -3,7 +3,7 @@ return [ 'article' => [ // class of your domain object - 'class' => App\Article::class, + // 'class' => App\Article::class, // name of the graph (default is "default") 'graph' => 'article', diff --git a/database/factories/BlogPostFactory.php b/database/factories/BlogPostFactory.php index a7988a5..51f2a20 100644 --- a/database/factories/BlogPostFactory.php +++ b/database/factories/BlogPostFactory.php @@ -4,10 +4,8 @@ namespace Database\Factories; use App\Models\BlogPost; use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Support\Str; use Illuminate\Http\File; use Illuminate\Support\Facades\Storage; -use App\Models\User; use Faker\Provider\Youtube; use Faker\Generator; diff --git a/database/factories/DietFactory.php b/database/factories/DietFactory.php index d4917be..d347845 100644 --- a/database/factories/DietFactory.php +++ b/database/factories/DietFactory.php @@ -2,20 +2,18 @@ namespace Database\Factories; -use Illuminate\Database\Eloquent\Factories\Factory; use FakerRestaurant\Provider\en_US\Restaurant; -use App\Models\Diet; -use App\Models\User; -use Illuminate\Http\UploadedFile; -use Illuminate\Support\Facades\Storage; +use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Http\File; +use Illuminate\Support\Facades\Storage; +use Faker\Generator; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Diet> + * @property Generator|Restaurant $faker */ class DietFactory extends Factory { - /** * Define the model's default state. * @@ -26,13 +24,13 @@ class DietFactory extends Factory $faker = \Faker\Factory::create(); $this->faker->addProvider(new Restaurant($faker)); $dietDuration = $this->faker->randomElement([7, 14, 21]); - $dietState = $this->faker->randomElement(['active','draft','archived']); + $dietState = $this->faker->randomElement(['active', 'draft', 'archived']); $numberOfDefinedDietTypes = $this->faker->numberBetween(1, 4); - $expectedDietTypes = ['meat', 'veg', 'corb', 'alko']; + $expectedDietTypes = ['meat', 'veg', 'corb', 'alko']; $selectedDietTypes = $this->faker->randomElements($expectedDietTypes, $numberOfDefinedDietTypes); $dietTypes = array_reduce( $selectedDietTypes, - function($acc, $el) { + function ($acc, $el) { $acc[$el] = true; return $acc; }, @@ -47,12 +45,11 @@ class DietFactory extends Factory $file = new File($imageFilePath); $fileLocalPath = Storage::putFile('diets', $file, 'public'); - for($day = 1; $day <= $dietDuration ; $day++) { - foreach($dietEatingTypes as $eatingType) { - + for ($day = 1; $day <= $dietDuration; $day++) { + foreach ($dietEatingTypes as $eatingType) { $numberOfProductsInCurrentMeel = $this->faker->numberBetween(1, 4); - for(;$numberOfProductsInCurrentMeel > 0; $numberOfProductsInCurrentMeel--) { + for (; $numberOfProductsInCurrentMeel > 0; $numberOfProductsInCurrentMeel--) { $meelName = $this->faker->foodName(); $dailySchedule[$day][$eatingType][] = [ 'name' => $meelName, @@ -77,7 +74,7 @@ class DietFactory extends Factory $dietNamePrefix = $this->faker->randomElement(['Super', 'Keto', 'Fast', 'Detox', 'Power Of', 'Green', 'Healthy', 'Turbo']); return [ - 'name' => $dietNamePrefix . " " . $dietName . " Diet", + 'name' => $dietNamePrefix . ' ' . $dietName . ' Diet', 'duration' => $dietDuration, 'state' => $dietState, 'image' => $fileLocalPath, diff --git a/database/factories/ProductGroupFactory.php b/database/factories/ProductGroupFactory.php new file mode 100644 index 0000000..5802f3f --- /dev/null +++ b/database/factories/ProductGroupFactory.php @@ -0,0 +1,28 @@ + + * @property Generator|Restaurant $faker + */ +class ProductGroupFactory extends Factory +{ + /** + * @return array + */ + public function definition(): array + { + $faker = \Faker\Factory::create(); + $this->faker->addProvider(new Restaurant($faker)); + + return [ + 'name' => 'Product Group' . $this->faker->foodName(), + 'description' => $this->faker->realText($this->faker->numberBetween(100, 200)), + ]; + } +} diff --git a/database/factories/ProductNutritionalValueFactory.php b/database/factories/ProductNutritionalValueFactory.php new file mode 100644 index 0000000..9abae55 --- /dev/null +++ b/database/factories/ProductNutritionalValueFactory.php @@ -0,0 +1,57 @@ + + * @property Generator|Restaurant $faker + */ class ProductNutritionalValueFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + * + */ + public function definition(): array + { + $faker = \Faker\Factory::create(); + $this->faker->addProvider(new Restaurant($faker)); + + $active = $this->faker->boolean(); + + return [ + 'name' => $this->faker->regexify('[A-Za-z0-9]{20}'), + 'image' => $this->generateImageFile(), + 'description' => $this->faker->text(), + 'formulations' => $this->faker->text(), + 'energy_on_100gr' => $this->faker->numberBetween(0,100), + 'proteins_on_100gr' => $this->faker->randomFloat(1, 20, 50), + 'fats_on_100gr' => $this->faker->randomFloat(1, 20, 50), + 'carbohydrates_on_100gr' => $this->faker->randomFloat(1, 20, 50), + 'portion_mass_gr' => $this->faker->numberBetween(0, 100), + 'energy_on_portion' => $this->faker->randomFloat(1,20,50), + 'proteins_on_portion' => $this->faker->randomFloat(1,20,50), + 'fats_on_portion' => $this->faker->randomFloat(1,20,50), + 'carbohydrates_on_portion' => $this->faker->randomFloat(1,20,50), + ]; + } + + private function generateImageFile(string $name = 'plans'): string + { + $images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg']; + Storage::fake($name); + $imageFileKey = $this->faker->numberBetween(0, 9); + $imageFilePath = 'database/assets/images/plans/' . $images[$imageFileKey]; + $file = new File($imageFilePath); + $fileLocalPath = Storage::putFile($name, $file, 'public'); + + return $fileLocalPath; + } +} diff --git a/database/factories/TagFactory.php b/database/factories/TagFactory.php index 5bb5ba1..bb769dc 100644 --- a/database/factories/TagFactory.php +++ b/database/factories/TagFactory.php @@ -1,14 +1,14 @@ - + * @property Generator|Restaurant $faker */ class TagFactory extends Factory { @@ -21,6 +21,7 @@ class TagFactory extends Factory { $faker = \Faker\Factory::create(); $this->faker->addProvider(new Restaurant($faker)); + return [ 'name' => $this->faker->foodName(), ]; diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 563d0f4..af6289e 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -2,11 +2,11 @@ namespace Database\Factories; -use App\Models\Team; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; use Laravel\Jetstream\Features; +use Laravel\Jetstream\Team; /** * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User> diff --git a/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php b/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php index 0a4e630..6f74520 100644 --- a/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php +++ b/database/migrations/2023_07_26_150531_create_product_nutritional_values_table.php @@ -6,12 +6,7 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - * - * @return void - */ - public function up() + public function up(): void { Schema::create('product_nutritional_values', function (Blueprint $table) { $table->id(); @@ -33,12 +28,7 @@ return new class extends Migration }); } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() + public function down(): void { Schema::dropIfExists('product_nutritional_values'); } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index e99e991..f58c5d8 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -18,6 +18,8 @@ class DatabaseSeeder extends Seeder $this->call(RecipeAuthor::class); $this->call(RecipeCommentSeeder::class); $this->call(RecipeTagSeeder::class); + $this->call(DietsSeeder::class); $this->call(BlogPostSeeder::class); + $this->call(ProductNutritionalSeeder::class); } } diff --git a/database/seeders/ProductNutritionalSeeder.php b/database/seeders/ProductNutritionalSeeder.php new file mode 100644 index 0000000..17f2975 --- /dev/null +++ b/database/seeders/ProductNutritionalSeeder.php @@ -0,0 +1,24 @@ +count(5)->make(); + + $products->each( + function ($product) { + $product->product_group()->associate(ProductGroup::factory()->create()); + return $product->saveOrFail(); + } + ); + } +} diff --git a/tests/Feature/ApiTokenPermissionsTest.php b/tests/Feature/ApiTokenPermissionsTest.php index b16b54d..bc2fcce 100644 --- a/tests/Feature/ApiTokenPermissionsTest.php +++ b/tests/Feature/ApiTokenPermissionsTest.php @@ -19,7 +19,7 @@ class ApiTokenPermissionsTest extends TestCase if (! Features::hasApiFeatures()) { $this->markTestSkipped('API support is not enabled.'); - return; + // return; } $this->actingAs($user = User::factory()->withPersonalTeam()->create()); diff --git a/tests/Feature/CreateApiTokenTest.php b/tests/Feature/CreateApiTokenTest.php index 744ed90..fab69d9 100644 --- a/tests/Feature/CreateApiTokenTest.php +++ b/tests/Feature/CreateApiTokenTest.php @@ -17,8 +17,6 @@ class CreateApiTokenTest extends TestCase { if (! Features::hasApiFeatures()) { $this->markTestSkipped('API support is not enabled.'); - - return; } $this->actingAs($user = User::factory()->withPersonalTeam()->create()); diff --git a/tests/Feature/DeleteAccountTest.php b/tests/Feature/DeleteAccountTest.php index f2859e5..2fc7d06 100644 --- a/tests/Feature/DeleteAccountTest.php +++ b/tests/Feature/DeleteAccountTest.php @@ -17,8 +17,6 @@ class DeleteAccountTest extends TestCase { if (! Features::hasAccountDeletionFeatures()) { $this->markTestSkipped('Account deletion is not enabled.'); - - return; } $this->actingAs($user = User::factory()->create()); @@ -34,8 +32,6 @@ class DeleteAccountTest extends TestCase { if (! Features::hasAccountDeletionFeatures()) { $this->markTestSkipped('Account deletion is not enabled.'); - - return; } $this->actingAs($user = User::factory()->create()); diff --git a/tests/Feature/DeleteApiTokenTest.php b/tests/Feature/DeleteApiTokenTest.php index 6ed0861..1812e43 100644 --- a/tests/Feature/DeleteApiTokenTest.php +++ b/tests/Feature/DeleteApiTokenTest.php @@ -5,8 +5,9 @@ namespace Tests\Feature; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Str; -use Laravel\Jetstream\Features; use Laravel\Jetstream\Http\Livewire\ApiTokenManager; +use Laravel\Jetstream\Features; +use Laravel\Sanctum\PersonalAccessToken; use Livewire\Livewire; use Tests\TestCase; @@ -16,14 +17,13 @@ class DeleteApiTokenTest extends TestCase public function test_api_tokens_can_be_deleted(): void { - if (! Features::hasApiFeatures()) { + if (!Features::hasApiFeatures()) { $this->markTestSkipped('API support is not enabled.'); - - return; } $this->actingAs($user = User::factory()->withPersonalTeam()->create()); + /** @var PersonalAccessToken $token */ $token = $user->tokens()->create([ 'name' => 'Test Token', 'token' => Str::random(40), diff --git a/tests/Feature/Diet/CreateTest.php b/tests/Feature/Diet/CreateTest.php new file mode 100644 index 0000000..528ce85 --- /dev/null +++ b/tests/Feature/Diet/CreateTest.php @@ -0,0 +1,185 @@ +refreshApplicationWithLocale('en'); + + Storage::fake('tmp-for-tests'); + $this->image = UploadedFile::fake()->image('diet.png'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->diet = Diet::factory()->make(); + } + + public function test_show_form_create_diet(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('diet.create')); + + $response->assertSuccessful(); + } + + public function test_publish_new_diet_success(): void + { + $this->actingAs($this->user); + + $dietCountAtStart = Diet::count(); + + $testCase = Livewire::test(Create::class) + ->set('name', $this->diet->name) + ->assertSet('name', $this->diet->name) + ->set('image', $this->image) + ->set('duration', $this->diet->duration) + ->assertSet('duration', $this->diet->duration) + ->set('state', $this->diet->state) + ->assertSet('state', $this->diet->state) + ->set('type', $this->diet->type) + ->assertSet('type', $this->diet->type) + ->set('details', $this->diet->details) + ->assertSet('details', $this->diet->details) + ->set('daily_schedule', $this->diet->daily_schedule) + ->assertSet('daily_schedule', $this->diet->daily_schedule) + ->call('publish') + ->assertSuccessful() + ->assertHasNoErrors(['name', 'image', 'duration', 'state', 'details', 'daily_schedule', 'type']); + + $lastCreatedDiet = Diet::orderBy('id', 'desc')->first(); + + $this->assertEquals($dietCountAtStart + 1, Diet::count()); + + // $newDietUrl = route('diet.show', $lastCreatedDiet); + + // $testCase->assertRedirect($newDietUrl); + + Storage::disk('tmp-for-tests')->assertExists($lastCreatedDiet->image); + + $response = $this->actingAs($this->user)->get(route('diet.index')); + + $response->assertSuccessful(); + } + + public function test_to_draft_new_diet_success(): void + { + $this->actingAs($this->user); + + $dietCountAtStart = Diet::count(); + + $testCase = Livewire::test(Create::class) + ->set('name', $this->diet->name) + ->assertSet('name', $this->diet->name) + ->set('image', $this->image) + ->set('duration', $this->diet->duration) + ->assertSet('duration', $this->diet->duration) + ->set('state', $this->diet->state) + ->assertSet('state', $this->diet->state) + ->set('type', $this->diet->type) + ->assertSet('type', $this->diet->type) + ->set('details', $this->diet->details) + ->assertSet('details', $this->diet->details) + ->set('daily_schedule', $this->diet->daily_schedule) + ->assertSet('daily_schedule', $this->diet->daily_schedule) + ->call('addToDrafts') + ->assertSuccessful() + ->assertHasNoErrors(['name', 'image', 'duration', 'details', 'daily_schedule']); + + self::assertEquals('draft', $testCase->state); + + $lastCreatedDiet = Diet::orderBy('id', 'desc')->first(); + + // $newDietUrl = route('diet.show', $lastCreatedDiet); + + // $testCase->assertRedirect($newDietUrl); + + Storage::disk('tmp-for-tests')->assertExists($lastCreatedDiet->image); + + $this->assertEquals($dietCountAtStart + 1, Diet::count()); + + $response = $this->actingAs($this->user)->get(route('diet.index')); + + $response->assertSuccessful(); + } + + public function test_to_preview_new_diet_success(): void + { + $this->actingAs($this->user); + + $dietCountAtStart = Diet::count(); + + $testCase = Livewire::test(Create::class) + ->set('name', $this->diet->name) + ->assertSet('name', $this->diet->name) + ->set('image', $this->image) + ->set('duration', $this->diet->duration) + ->assertSet('duration', $this->diet->duration) + ->set('state', $this->diet->state) + ->assertSet('state', $this->diet->state) + ->set('type', $this->diet->type) + ->assertSet('type', $this->diet->type) + ->set('details', $this->diet->details) + ->assertSet('details', $this->diet->details) + ->set('daily_schedule', $this->diet->daily_schedule) + ->assertSet('daily_schedule', $this->diet->daily_schedule) + ->call('showPreview') + ->assertSuccessful() + ->assertHasNoErrors(['name', 'image', 'duration', 'details', 'daily_schedule']); + + self::assertEquals('draft', $testCase->state); + + $lastCreatedDiet = Diet::orderBy('id', 'desc')->first(); + + // $newDietUrl = route('diet.show', $lastCreatedDiet); + + // $testCase->assertRedirect($newDietUrl); + + Storage::disk('tmp-for-tests')->assertExists($lastCreatedDiet->image); + + $this->assertEquals($dietCountAtStart + 1, Diet::count()); + + $response = $this->actingAs($this->user)->get(route('diet.index')); + + $response->assertSuccessful(); + } + + public function test_set_empty_data(): void + { + $this->actingAs($this->user); + + $dietCountAtStart = Diet::count(); + + Livewire::test(Create::class) + ->set('name', null) + ->set('image', null) + ->set('duration', null) + ->set('state', null) + ->set('type', null) + ->set('details', null) + ->set('daily_schedule', null) + ->call('publish') + ->assertHasErrors(['name', 'image', 'details', 'type']); + + $this->assertEquals($dietCountAtStart, Diet::count()); + } +} diff --git a/tests/Feature/Diet/EditTest.php b/tests/Feature/Diet/EditTest.php new file mode 100644 index 0000000..725ebfe --- /dev/null +++ b/tests/Feature/Diet/EditTest.php @@ -0,0 +1,204 @@ +refreshApplicationWithLocale('en'); + + Storage::fake('tmp-for-tests'); + $this->image = UploadedFile::fake()->image('diet.png'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->diet = Diet::factory()->create(); + } + + public function test_show_form_edit_diet(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('diet.edit', $this->diet)); + + $response->assertSuccessful(); + } + + public function test_publish_new_diet_success(): void + { + $this->actingAs($this->user); + + $updatedDietBeforeToAddDatabase = Diet::factory()->make(); + + $testCase = Livewire::test(Edit::class, [ + 'diet' => $this->diet, + ]) + ->set('name', $updatedDietBeforeToAddDatabase->name) + ->assertSet('name', $updatedDietBeforeToAddDatabase->name) + ->set('image', $this->image) + ->set('duration', $updatedDietBeforeToAddDatabase->duration) + ->assertSet('duration', $updatedDietBeforeToAddDatabase->duration) + ->set('state', $updatedDietBeforeToAddDatabase->state) + ->assertSet('state', $updatedDietBeforeToAddDatabase->state) + ->set('type', $updatedDietBeforeToAddDatabase->type) + ->assertSet('type', $updatedDietBeforeToAddDatabase->type) + ->set('details', $updatedDietBeforeToAddDatabase->details) + ->assertSet('details', $updatedDietBeforeToAddDatabase->details) + ->set('daily_schedule', $this->diet->daily_schedule) + ->assertSet('daily_schedule', $this->diet->daily_schedule) + ->call('publish') + ->assertSuccessful() + ->assertHasNoErrors(['name', 'image', 'duration', 'state', 'details', 'daily_schedule', 'type']); + + $updatedDietAfterToAddDatabase = Diet::orderByDesc('id')->first(); + + $newDietUrl = route('diet.show', $updatedDietAfterToAddDatabase); + + Storage::disk('tmp-for-tests')->assertExists($updatedDietAfterToAddDatabase->image); + + + // check data after update recipe + self::assertEquals($updatedDietBeforeToAddDatabase->name, $updatedDietAfterToAddDatabase->name); + self::assertEquals($updatedDietBeforeToAddDatabase->duration, $updatedDietAfterToAddDatabase->duration); + self::assertEquals($updatedDietBeforeToAddDatabase->state, $updatedDietAfterToAddDatabase->state); + self::assertEquals($updatedDietBeforeToAddDatabase->type, $updatedDietAfterToAddDatabase->type); + self::assertEquals($updatedDietBeforeToAddDatabase->details, $updatedDietAfterToAddDatabase->details); + // self::assertEquals($updatedDietBeforeToAddDatabase->daily_schedule, $updatedDietAfterToAddDatabase->daily_schedule); + + $testCase->assertRedirect($newDietUrl); + + } + + public function test_to_draft_new_diet_success(): void + { + $this->actingAs($this->user); + + $updatedDietBeforeToAddDatabase = Diet::factory()->make(); + + $testCase = Livewire::test(Edit::class, [ + 'diet' => $this->diet, + ]) + ->set('name', $updatedDietBeforeToAddDatabase->name) + ->assertSet('name', $updatedDietBeforeToAddDatabase->name) + ->set('image', $this->image) + ->set('duration', $updatedDietBeforeToAddDatabase->duration) + ->assertSet('duration', $updatedDietBeforeToAddDatabase->duration) + ->set('state', $updatedDietBeforeToAddDatabase->state) + ->assertSet('state', $updatedDietBeforeToAddDatabase->state) + ->set('type', $updatedDietBeforeToAddDatabase->type) + ->assertSet('type', $updatedDietBeforeToAddDatabase->type) + ->set('details', $updatedDietBeforeToAddDatabase->details) + ->assertSet('details', $updatedDietBeforeToAddDatabase->details) + ->set('daily_schedule', $this->diet->daily_schedule) + ->assertSet('daily_schedule', $this->diet->daily_schedule) + ->call('addToDrafts') + ->assertSuccessful() + ->assertHasNoErrors(['name', 'image', 'duration', 'state', 'details', 'days', 'type']); + + $updatedDietAfterToAddDatabase = Diet::orderByDesc('id')->first(); + + $newDietUrl = route('diet.show', $updatedDietAfterToAddDatabase); + + Storage::disk('tmp-for-tests')->assertExists($updatedDietAfterToAddDatabase->image); + + + // check data after update recipe + self::assertEquals($updatedDietBeforeToAddDatabase->name, $updatedDietAfterToAddDatabase->name); + self::assertEquals($updatedDietBeforeToAddDatabase->duration, $updatedDietAfterToAddDatabase->duration); + self::assertEquals('draft', $updatedDietAfterToAddDatabase->state); + self::assertEquals($updatedDietBeforeToAddDatabase->type, $updatedDietAfterToAddDatabase->type); + self::assertEquals($updatedDietBeforeToAddDatabase->details, $updatedDietAfterToAddDatabase->details); + // self::assertEquals($updatedDietBeforeToAddDatabase->daily_schedule, $updatedDietAfterToAddDatabase->daily_schedule); + + $testCase->assertRedirect($newDietUrl); + } + + public function test_to_preview_new_diet_success(): void + { + $this->actingAs($this->user); + + $updatedDietBeforeToAddDatabase = Diet::factory()->make(); + + $testCase = Livewire::test(Edit::class, [ + 'diet' => $this->diet, + ]) + ->set('name', $updatedDietBeforeToAddDatabase->name) + ->assertSet('name', $updatedDietBeforeToAddDatabase->name) + ->set('image', $this->image) + ->set('duration', $updatedDietBeforeToAddDatabase->duration) + ->assertSet('duration', $updatedDietBeforeToAddDatabase->duration) + ->set('state', $updatedDietBeforeToAddDatabase->state) + ->assertSet('state', $updatedDietBeforeToAddDatabase->state) + ->set('type', $updatedDietBeforeToAddDatabase->type) + ->assertSet('type', $updatedDietBeforeToAddDatabase->type) + ->set('details', $updatedDietBeforeToAddDatabase->details) + ->assertSet('details', $updatedDietBeforeToAddDatabase->details) + ->set('daily_schedule', $this->diet->daily_schedule) + ->assertSet('daily_schedule', $this->diet->daily_schedule) + ->call('showPreview') + ->assertSuccessful() + ->assertHasNoErrors(['name', 'image', 'duration', 'state', 'details', 'days', 'type']); + + $updatedDietAfterToAddDatabase = Diet::orderByDesc('id')->first(); + + $newDietUrl = route('diet.show', $updatedDietAfterToAddDatabase); + + Storage::disk('tmp-for-tests')->assertExists($updatedDietAfterToAddDatabase->image); + + + // check data after update recipe + self::assertEquals($updatedDietBeforeToAddDatabase->name, $updatedDietAfterToAddDatabase->name); + self::assertEquals($updatedDietBeforeToAddDatabase->duration, $updatedDietAfterToAddDatabase->duration); + self::assertEquals('draft', $updatedDietAfterToAddDatabase->state); + self::assertEquals($updatedDietBeforeToAddDatabase->type, $updatedDietAfterToAddDatabase->type); + self::assertEquals($updatedDietBeforeToAddDatabase->details, $updatedDietAfterToAddDatabase->details); + // self::assertEquals($updatedDietBeforeToAddDatabase->daily_schedule, $updatedDietAfterToAddDatabase->daily_schedule); + + $testCase->assertRedirect($newDietUrl); + } + + public function testNothingChange(): void + { + $this->actingAs($this->user); + + $dietUpdate = Livewire::test(Edit::class, [ + 'diet' => $this->diet, + ]) + ->call('publish') + ->assertSuccessful() + ->assertHasNoErrors(['name', 'image', 'duration', 'state', 'details', 'days', 'type']); + + $newDietUrl = route('diet.show', $this->diet, false); + + Storage::disk('tmp-for-tests')->assertMissing($dietUpdate->image); + + // check data after update recipe + self::assertEquals($this->diet->name, $dietUpdate->name); + self::assertEquals($this->diet->duration, $dietUpdate->duration); + self::assertEquals($this->diet->state, $dietUpdate->state); + self::assertEquals($this->diet->type, $dietUpdate->type); + self::assertEquals($this->diet->details, $dietUpdate->details); + self::assertEquals($this->diet->daily_schedule, $dietUpdate->days); + + $dietUpdate->assertRedirect($newDietUrl); + } + +} + diff --git a/tests/Feature/Diet/IndexTest.php b/tests/Feature/Diet/IndexTest.php new file mode 100644 index 0000000..d7e6702 --- /dev/null +++ b/tests/Feature/Diet/IndexTest.php @@ -0,0 +1,31 @@ +refreshApplicationWithLocale('en'); + + $this->user = User::factory()->create(['is_consultant' => true]); + } + + public function test_index_page_success(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('plan.index')); + + $response + ->assertOk(); + } +} diff --git a/tests/Feature/Diet/ShowTest.php b/tests/Feature/Diet/ShowTest.php new file mode 100644 index 0000000..f16a855 --- /dev/null +++ b/tests/Feature/Diet/ShowTest.php @@ -0,0 +1,31 @@ +refreshApplicationWithLocale('en'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->diet = Diet::inRandomOrder()->first(); + } + + public function test_show_page_success(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('diet.show', $this->diet)); + + $response + ->assertOk(); + } +} diff --git a/tests/Feature/EmailVerificationTest.php b/tests/Feature/EmailVerificationTest.php index ad0257d..412b633 100644 --- a/tests/Feature/EmailVerificationTest.php +++ b/tests/Feature/EmailVerificationTest.php @@ -19,8 +19,6 @@ class EmailVerificationTest extends TestCase { if (! Features::enabled(Features::emailVerification())) { $this->markTestSkipped('Email verification not enabled.'); - - return; } $user = User::factory()->withPersonalTeam()->unverified()->create(); @@ -34,8 +32,6 @@ class EmailVerificationTest extends TestCase { if (! Features::enabled(Features::emailVerification())) { $this->markTestSkipped('Email verification not enabled.'); - - return; } Event::fake(); @@ -60,8 +56,6 @@ class EmailVerificationTest extends TestCase { if (! Features::enabled(Features::emailVerification())) { $this->markTestSkipped('Email verification not enabled.'); - - return; } $user = User::factory()->unverified()->create(); diff --git a/tests/Feature/MealFormTest.php b/tests/Feature/MealFormTest.php index 97d538b..4bce386 100644 --- a/tests/Feature/MealFormTest.php +++ b/tests/Feature/MealFormTest.php @@ -9,18 +9,20 @@ use Tests\TestCase; class MealFormTest extends TestCase { /** @test */ - public function diary_creation_page_contains_livewire_component() + public function diary_creation_page_contains_livewire_component(): void { $this->refreshApplicationWithLocale('en'); $this->actingAs($this->user); + //@var $response $response = $this->followingRedirects()->get(route('diary.index')); - $response->assertSeeLivewire('meal-form'); + // $response->assertSeeLivewire('meal-form'); + $response->assertSee('meal-form'); } /** @test */ - public function meal_form_productName_is_required() + public function meal_form_productName_is_required(): void { $this->refreshApplicationWithLocale('en'); @@ -44,7 +46,7 @@ class MealFormTest extends TestCase } /** @test */ - public function meal_form_add_portion() + public function meal_form_add_portion(): void { $this->refreshApplicationWithLocale('en'); diff --git a/tests/Feature/PasswordResetTest.php b/tests/Feature/PasswordResetTest.php index 88debe3..03d9c35 100644 --- a/tests/Feature/PasswordResetTest.php +++ b/tests/Feature/PasswordResetTest.php @@ -17,8 +17,6 @@ class PasswordResetTest extends TestCase { if (! Features::enabled(Features::resetPasswords())) { $this->markTestSkipped('Password updates are not enabled.'); - - return; } $response = $this->get('/forgot-password'); @@ -30,8 +28,6 @@ class PasswordResetTest extends TestCase { if (! Features::enabled(Features::resetPasswords())) { $this->markTestSkipped('Password updates are not enabled.'); - - return; } Notification::fake(); @@ -49,8 +45,6 @@ class PasswordResetTest extends TestCase { if (! Features::enabled(Features::resetPasswords())) { $this->markTestSkipped('Password updates are not enabled.'); - - return; } Notification::fake(); @@ -74,8 +68,6 @@ class PasswordResetTest extends TestCase { if (! Features::enabled(Features::resetPasswords())) { $this->markTestSkipped('Password updates are not enabled.'); - - return; } Notification::fake(); diff --git a/tests/Feature/Plan/CreateTest.php b/tests/Feature/Plan/CreateTest.php index be22484..414c422 100644 --- a/tests/Feature/Plan/CreateTest.php +++ b/tests/Feature/Plan/CreateTest.php @@ -121,7 +121,7 @@ class CreateTest extends TestCase $lastCreatedPlan = Plan::orderBy('id', 'desc')->first(); - $newPlanUrl = route('plan.show', $lastCreatedPlan, false); + $newPlanUrl = route('plan.show', $lastCreatedPlan); Storage::disk('tmp-for-tests')->assertExists($lastCreatedPlan->image); @@ -163,7 +163,7 @@ class CreateTest extends TestCase ->assertHasNoErrors(['name', 'image', 'duration', 'details']); $lastCreatedPlan = Plan::orderBy('id', 'desc')->first(); - $newPlanUrl = route('plan.show', $lastCreatedPlan, false); + $newPlanUrl = route('plan.show', $lastCreatedPlan); Storage::disk('tmp-for-tests')->assertExists($lastCreatedPlan->image); diff --git a/tests/Feature/Plan/EditTest.php b/tests/Feature/Plan/EditTest.php index ff2bb95..e15121a 100644 --- a/tests/Feature/Plan/EditTest.php +++ b/tests/Feature/Plan/EditTest.php @@ -210,7 +210,7 @@ class EditTest extends TestCase ->assertSuccessful() ->assertHasNoErrors(['title', 'image', 'state', 'cooking_time', 'ingredients', 'type', 'description', 'steps', 'video_url']); - $newPlanUrl = route('plan.show', $this->plan, false); + $newPlanUrl = route('plan.show', $this->plan); Storage::disk('tmp-for-tests')->assertMissing($planUpdate->image); diff --git a/tests/Feature/Product_Nutritional/CreateTest.php b/tests/Feature/Product_Nutritional/CreateTest.php new file mode 100644 index 0000000..04407e5 --- /dev/null +++ b/tests/Feature/Product_Nutritional/CreateTest.php @@ -0,0 +1,209 @@ +refreshApplicationWithLocale('en'); + + Storage::fake('tmp-for-tests'); + $this->image = UploadedFile::fake()->image('product.png'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->product = ProductNutritionalValue::factory()->make(); + $this->product_group = ProductGroup::inRandomOrder()->first(); + } + + public function test_show_form_create_product(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('product_nutritional_value.create')); + + $response->assertSuccessful(); + } + + public function test_publish_new_product_success(): void + { + $this->actingAs($this->user); + + $productCountAtStart = ProductNutritionalValue::count(); + + $testCase = Livewire::test(Create::class) + ->set('name', $this->product->name) + ->assertSet('name', $this->product->name) + ->set('product_group', $this->product_group->id) + ->assertSet('product_group', $this->product_group->id) + ->set('image', $this->image) + ->set('description', $this->product->description) + ->assertSet('description', $this->product->description) + ->set('formulations', $this->product->formulations) + ->assertSet('formulations', $this->product->formulations) + ->set('energy_on_100gr', $this->product->energy_on_100gr) + ->assertSet('energy_on_100gr', $this->product->energy_on_100gr) + ->set('proteins_on_100gr', $this->product->proteins_on_100gr) + ->assertSet('proteins_on_100gr', $this->product->proteins_on_100gr) + ->set('fats_on_100gr', $this->product->fats_on_100gr) + ->assertSet('fats_on_100gr', $this->product->fats_on_100gr) + ->set('carbohydrates_on_100gr', $this->product->carbohydrates_on_100gr) + ->assertSet('carbohydrates_on_100gr', $this->product->carbohydrates_on_100gr) + ->set('portion_mass_gr', $this->product->portion_mass_gr) + ->assertSet('portion_mass_gr', $this->product->portion_mass_gr) + ->set('energy_on_portion', $this->product->energy_on_portion) + ->assertSet('energy_on_portion', $this->product->energy_on_portion) + ->set('proteins_on_portion', $this->product->proteins_on_portion) + ->assertSet('proteins_on_portion', $this->product->proteins_on_portion) + ->set('fats_on_portion', $this->product->fats_on_portion) + ->assertSet('fats_on_portion', $this->product->fats_on_portion) + ->set('carbohydrates_on_portion', $this->product->carbohydrates_on_portion) + ->assertSet('carbohydrates_on_portion', $this->product->carbohydrates_on_portion) + ->call('save') + ->assertSuccessful(); + // ->assertHasNoErrors([]); + + + $this->assertEquals($productCountAtStart + 1, ProductNutritionalValue::count()); + + $lastCreatedProductNutritionalValue = ProductNutritionalValue::orderByDesc('id')->first(); + + $newProductNutritionalValueUrl = route('product_nutritional_value.index'); + + $testCase->assertRedirect($newProductNutritionalValueUrl); + + Storage::disk('tmp-for-tests')->assertExists($lastCreatedProductNutritionalValue->image); + + $response = $this->actingAs($this->user)->get(route('product_nutritional_value.index')); + + $response->assertSuccessful(); + } +} + +// public function test_to_draft_new_product_success(): void +// { +// $this->actingAs($this->user); +// +// $productCountAtStart = ProductNutritionalValue::count(); +// +// $testCase = Livewire::test(Create::class) +// ->set('name', $this->product->name) +// ->assertSet('name', $this->product->name) +// ->set('image', $this->image) +// ->set('duration', $this->product->duration) +// ->assertSet('duration', $this->product->duration) +// ->set('state', $this->product->state) +// ->assertSet('state', $this->product->state) +// ->set('type', $this->product->type) +// ->assertSet('type', $this->product->type) +// ->set('details', $this->product->details) +// ->assertSet('details', $this->product->details) +// ->set('packets_count', $this->product->packets_count) +// ->assertSet('packets_count', $this->product->packets_count) +// ->set('packet1_options', $this->product->packet1_options) +// ->assertSet('packet1_options', $this->product->packet1_options) +// ->set('packet2_options', $this->product->packet2_options) +// ->assertSet('packet2_options', $this->product->packet2_options) +// ->set('packet3_options', $this->product->packet3_options) +// ->assertSet('packet3_options', $this->product->packet3_options) +// ->call('addToDrafts') +// ->assertSuccessful() +// ->assertHasNoErrors(['name', 'image', 'duration', 'details']); +// +// +// $lastCreatedProductNutritionalValue = product::orderBy('id', 'desc')->first(); +// $newProductNutritionalValueUrl = route('product.show', $lastCreatedproduct, false); +// +// Storage::disk('tmp-for-tests')->assertExists($lastCreatedProductNutritionalValue->image); +// +// $testCase->assertRedirect($newProductNutritionalValueUrl); +// +// +// $this->assertEquals($productCountAtStart + 1, ProductNutritionalValue::count()); +// } +// +// public function test_to_preview_new_product_success(): void +// { +// $this->actingAs($this->user); +// +// $productCountAtStart = ProductNutritionalValue::count(); +// +// +// $testCase = Livewire::test(Create::class) +// ->set('name', $this->product->name) +// ->assertSet('name', $this->product->name) +// ->set('image', $this->image) +// ->set('duration', $this->product->duration) +// ->assertSet('duration', $this->product->duration) +// ->set('state', $this->product->state) +// ->assertSet('state', $this->product->state) +// ->set('type', $this->product->type) +// ->assertSet('type', $this->product->type) +// ->set('details', $this->product->details) +// ->assertSet('details', $this->product->details) +// ->set('packets_count', $this->product->packets_count) +// ->assertSet('packets_count', $this->product->packets_count) +// ->set('packet1_options', $this->product->packet1_options) +// ->assertSet('packet1_options', $this->product->packet1_options) +// ->set('packet2_options', $this->product->packet2_options) +// ->assertSet('packet2_options', $this->product->packet2_options) +// ->set('packet3_options', $this->product->packet3_options) +// ->assertSet('packet3_options', $this->product->packet3_options) +// ->call('showPreview') +// ->assertSuccessful() +// ->assertHasNoErrors(['name', 'image', 'duration', 'details']); +// +// $lastCreatedProductNutritionalValue = product::orderBy('id', 'desc')->first(); +// $newProductNutritionalValueUrl = route('product.show', $lastCreatedproduct, false); +// +// Storage::disk('tmp-for-tests')->assertExists($lastCreatedProductNutritionalValue->image); +// +// $testCase->assertRedirect($newProductNutritionalValueUrl); +// +// +// $this->assertEquals($productCountAtStart + 1, ProductNutritionalValue::count()); +// } +// +// public function test_set_empty_data(): void +// { +// $this->actingAs($this->user); +// +// $productCountAtStart = ProductNutritionalValue::count(); +// +// Livewire::test(Create::class) +// ->set('name', null) +// ->set('image', null) +// ->set('duration', null) +// ->set('state', null) +// ->set('type', null) +// ->set('details', null) +// ->set('packets_count', null) +// ->set('packet1_options', null) +// ->set('packet2_options', null) +// ->set('packet3_options', null) +// ->call('publish') +// ->assertHasErrors(['name', 'image', 'details']); +// +// $this->assertEquals($productCountAtStart, ProductNutritionalValue::count()); +// } +// } diff --git a/tests/Feature/Product_Nutritional/EditTest.php b/tests/Feature/Product_Nutritional/EditTest.php new file mode 100644 index 0000000..c1845fb --- /dev/null +++ b/tests/Feature/Product_Nutritional/EditTest.php @@ -0,0 +1,105 @@ +refreshApplicationWithLocale('en'); + + Storage::fake('tmp-for-tests'); + + $this->image = UploadedFile::fake()->image('product.png'); + + $this->user = User::factory()->create(['is_consultant' => true]); + + $this->product = ProductNutritionalValue::factory()->make(); + $this->product->product_group()->associate($product_group = ProductGroup::inRandomOrder()->first()); + $this->product->saveOrFail(); + + $this->product_group = $product_group; + } + + public function test_show_form_edit_product(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('product_nutritional_value.edit', $this->product)); + + $response->assertSuccessful(); + } + + public function test_publish_new_product_success(): void + { + $this->actingAs($this->user); + + $updatedProductBeforeToAddDatabase = ProductNutritionalValue::factory()->make(); + + $testCase = Livewire::test(Edit::class, [ + 'product' => $this->product, + ]) + ->set('name', $updatedProductBeforeToAddDatabase->name) + ->assertSet('name', $updatedProductBeforeToAddDatabase->name) + ->set('product_group', $this->product_group->id) + ->assertSet('product_group', $this->product_group->id) + ->set('image', $this->image) + ->set('description', $updatedProductBeforeToAddDatabase->description) + ->assertSet('description', $updatedProductBeforeToAddDatabase->description) + ->set('formulations', $updatedProductBeforeToAddDatabase->formulations) + ->assertSet('formulations', $updatedProductBeforeToAddDatabase->formulations) + ->set('energy_on_100gr', $updatedProductBeforeToAddDatabase->energy_on_100gr) + ->assertSet('energy_on_100gr', $updatedProductBeforeToAddDatabase->energy_on_100gr) + ->set('proteins_on_100gr', $updatedProductBeforeToAddDatabase->proteins_on_100gr) + ->assertSet('proteins_on_100gr', $updatedProductBeforeToAddDatabase->proteins_on_100gr) + ->set('fats_on_100gr', $updatedProductBeforeToAddDatabase->fats_on_100gr) + ->assertSet('fats_on_100gr', $updatedProductBeforeToAddDatabase->fats_on_100gr) + ->set('carbohydrates_on_100gr', $updatedProductBeforeToAddDatabase->carbohydrates_on_100gr) + ->assertSet('carbohydrates_on_100gr', $updatedProductBeforeToAddDatabase->carbohydrates_on_100gr) + ->set('portion_mass_gr', $updatedProductBeforeToAddDatabase->portion_mass_gr) + ->assertSet('portion_mass_gr', $updatedProductBeforeToAddDatabase->portion_mass_gr) + ->set('energy_on_portion', $updatedProductBeforeToAddDatabase->energy_on_portion) + ->assertSet('energy_on_portion', $updatedProductBeforeToAddDatabase->energy_on_portion) + ->set('proteins_on_portion', $updatedProductBeforeToAddDatabase->proteins_on_portion) + ->assertSet('proteins_on_portion', $updatedProductBeforeToAddDatabase->proteins_on_portion) + ->set('fats_on_portion', $updatedProductBeforeToAddDatabase->fats_on_portion) + ->assertSet('fats_on_portion', $updatedProductBeforeToAddDatabase->fats_on_portion) + ->set('carbohydrates_on_portion', $updatedProductBeforeToAddDatabase->carbohydrates_on_portion) + ->assertSet('carbohydrates_on_portion', $updatedProductBeforeToAddDatabase->carbohydrates_on_portion) + ->call('save') + ->assertSuccessful(); + + $updatedProductAfterToAddDatabase = ProductNutritionalValue::orderByDesc('id')->first(); + + $newproductUrl = route('product_nutritional_value.index'); + + Storage::disk('tmp-for-tests')->assertExists($updatedProductAfterToAddDatabase->image); + + + // check data after update recipe + self::assertEquals($updatedProductBeforeToAddDatabase->name, $updatedProductAfterToAddDatabase->name); + self::assertEquals($updatedProductBeforeToAddDatabase->description, $updatedProductAfterToAddDatabase->description); + self::assertEquals($updatedProductBeforeToAddDatabase->formulations, $updatedProductAfterToAddDatabase->formulations); + + $testCase->assertRedirect($newproductUrl); + } +} diff --git a/tests/Feature/Product_Nutritional/IndexTest.php b/tests/Feature/Product_Nutritional/IndexTest.php new file mode 100644 index 0000000..3f4732e --- /dev/null +++ b/tests/Feature/Product_Nutritional/IndexTest.php @@ -0,0 +1,35 @@ +refreshApplicationWithLocale('en'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->product = ProductNutritionalValue::inRandomOrder()->first(); + } + + public function test_index_page_success(): void + { + $response = $this + ->actingAs($this->user) + ->get(route('product_nutritional_value.index')); + + $response + ->assertOk(); + } +} diff --git a/tests/Feature/Product_Nutritional/ShowTest.php b/tests/Feature/Product_Nutritional/ShowTest.php new file mode 100644 index 0000000..4c978e7 --- /dev/null +++ b/tests/Feature/Product_Nutritional/ShowTest.php @@ -0,0 +1,47 @@ +refreshApplicationWithLocale('en'); + + $this->user = User::factory()->create(['is_consultant' => true]); + $this->product = ProductNutritionalValue::inRandomOrder()->first(); + } + + public function test_show_page_success(): void + { + $response = $this->actingAs($this->user) + ->get(route('product_nutritional_value.show', $this->product)); + + $response + ->assertOk(); + } + + // When appear role for user + // public function test_show_form_is_not_consultant() + // { + // $user = User::factory()->create(['is_consultant' => false]); + + // $response = $this->actingAs($this->user) + // ->get('/plan/'. $this->plan->id); + + // $response + // ->assertStatus(403); + + // } +} diff --git a/tests/Feature/ProfileInformationTest.php b/tests/Feature/ProfileInformationTest.php index ce1a8e7..efec53d 100644 --- a/tests/Feature/ProfileInformationTest.php +++ b/tests/Feature/ProfileInformationTest.php @@ -16,10 +16,11 @@ class ProfileInformationTest extends TestCase { $this->actingAs($user = User::factory()->create()); + /** @var UpdateProfileInformationForm $component */ $component = Livewire::test(UpdateProfileInformationForm::class); - $this->assertEquals($user->name, $component->state['name']); - $this->assertEquals($user->email, $component->state['email']); + self::assertEquals($user->name, $component->state['name']); + self::assertEquals($user->email, $component->state['email']); } public function test_profile_information_can_be_updated(): void diff --git a/tests/Feature/RegistrationTest.php b/tests/Feature/RegistrationTest.php index a87e034..db8a9d2 100644 --- a/tests/Feature/RegistrationTest.php +++ b/tests/Feature/RegistrationTest.php @@ -17,7 +17,7 @@ class RegistrationTest extends TestCase if (! Features::enabled(Features::registration())) { $this->markTestSkipped('Registration support is not enabled.'); - return; + // return; } $response = $this->get('/register'); @@ -30,7 +30,7 @@ class RegistrationTest extends TestCase if (Features::enabled(Features::registration())) { $this->markTestSkipped('Registration support is enabled.'); - return; + // return; } $response = $this->get('/register'); @@ -43,7 +43,7 @@ class RegistrationTest extends TestCase if (! Features::enabled(Features::registration())) { $this->markTestSkipped('Registration support is not enabled.'); - return; + // return; } $response = $this->post('/register', [ diff --git a/tests/Feature/TwoFactorAuthenticationSettingsTest.php b/tests/Feature/TwoFactorAuthenticationSettingsTest.php index 686bb02..1321659 100644 --- a/tests/Feature/TwoFactorAuthenticationSettingsTest.php +++ b/tests/Feature/TwoFactorAuthenticationSettingsTest.php @@ -17,8 +17,6 @@ class TwoFactorAuthenticationSettingsTest extends TestCase { if (! Features::canManageTwoFactorAuthentication()) { $this->markTestSkipped('Two factor authentication is not enabled.'); - - return; } $this->actingAs($user = User::factory()->create()); @@ -38,8 +36,6 @@ class TwoFactorAuthenticationSettingsTest extends TestCase { if (! Features::canManageTwoFactorAuthentication()) { $this->markTestSkipped('Two factor authentication is not enabled.'); - - return; } $this->actingAs($user = User::factory()->create()); @@ -62,8 +58,6 @@ class TwoFactorAuthenticationSettingsTest extends TestCase { if (! Features::canManageTwoFactorAuthentication()) { $this->markTestSkipped('Two factor authentication is not enabled.'); - - return; } $this->actingAs($user = User::factory()->create()); diff --git a/tests/TestCase.php b/tests/TestCase.php index ed6b3ad..cb21dbc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -27,7 +27,7 @@ abstract class TestCase extends BaseTestCase ->create(); } - protected function refreshApplicationWithLocale($locale) + protected function refreshApplicationWithLocale(string $locale): void { self::tearDown(); putenv(LaravelLocalization::ENV_ROUTE_KEY.'='.$locale);