Compare commits

..

No commits in common. "3c5f2d5df174ea30ff0c5f062962487b198a31ff" and "71614848baa0a5f1064727de7619a60a7924faee" have entirely different histories.

143 changed files with 607 additions and 12764 deletions

View file

@ -1,25 +0,0 @@
APP_NAME=DishPlanner
APP_ENV=testing
APP_KEY=base64:2ADW3imsmRMo+UDw3GR6852wQu37/aNK1ooxEdaJIC0=
APP_DEBUG=true
APP_URL=http://localhost
APP_MAINTENANCE_DRIVER=file
BCRYPT_ROUNDS=4
LOG_CHANNEL=stack
LOG_STACK=single
DB_CONNECTION=sqlite
DB_DATABASE=:memory:
SESSION_DRIVER=array
BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
CACHE_STORE=array
MAIL_MAILER=array

View file

@ -1,42 +0,0 @@
name: Build and Push Docker Image
on:
push:
branches: [main]
tags: ['v*']
jobs:
build:
runs-on: docker
container:
image: catthehacker/ubuntu:act-latest
steps:
- uses: https://data.forgejo.org/actions/checkout@v4
- name: Set up Docker Buildx
uses: https://data.forgejo.org/docker/setup-buildx-action@v3
- name: Login to Forgejo Registry
uses: https://data.forgejo.org/docker/login-action@v3
with:
registry: forge.lvl0.xyz
username: ${{ github.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Determine tags
id: meta
run: |
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
TAG="${{ github.ref_name }}"
echo "tags=forge.lvl0.xyz/lvl0/dishplanner:${TAG},forge.lvl0.xyz/lvl0/dishplanner:latest" >> $GITHUB_OUTPUT
else
echo "tags=forge.lvl0.xyz/lvl0/dishplanner:latest" >> $GITHUB_OUTPUT
fi
- name: Build and push
uses: https://data.forgejo.org/docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}

View file

@ -1,32 +0,0 @@
name: CI
on:
push:
branches: ['release/*']
pull_request:
branches: [main, 'release/*']
jobs:
ci:
runs-on: docker
container:
image: forge.lvl0.xyz/lvl0/dishplanner-ci:php8.3-4
steps:
- uses: https://data.forgejo.org/actions/checkout@v4
- name: Prepare environment
run: cp .env.testing .env
- name: Restore dependencies
run: |
cp -a /opt/deps/vendor ./vendor
composer install --no-interaction --no-progress --prefer-source
- name: Lint
run: vendor/bin/pint --test
- name: Static analysis
run: vendor/bin/phpstan analyse --memory-limit=1G
- name: Tests
run: php -d memory_limit=512M vendor/bin/phpunit

View file

@ -1,46 +0,0 @@
name: Build and Push Base Images
on:
push:
branches: [main]
paths:
- 'docker/build/**'
- 'composer.json'
- 'composer.lock'
- '.forgejo/workflows/images.yml'
workflow_dispatch:
jobs:
images:
runs-on: docker
container:
image: catthehacker/ubuntu:act-latest
strategy:
matrix:
include:
- name: dishplanner-ci
file: docker/build/Dockerfile.ci
version: php8.3-4
steps:
- uses: https://data.forgejo.org/actions/checkout@v4
- name: Set up Docker Buildx
uses: https://data.forgejo.org/docker/setup-buildx-action@v3
- name: Login to Forgejo Registry
uses: https://data.forgejo.org/docker/login-action@v3
with:
registry: forge.lvl0.xyz
username: ${{ github.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Build and push
uses: https://data.forgejo.org/docker/build-push-action@v5
with:
context: .
file: ${{ matrix.file }}
push: true
tags: |
forge.lvl0.xyz/lvl0/${{ matrix.name }}:${{ matrix.version }}
forge.lvl0.xyz/lvl0/${{ matrix.name }}:latest
forge.lvl0.xyz/lvl0/${{ matrix.name }}:${{ github.sha }}

2
.gitattributes vendored
View file

@ -6,4 +6,6 @@
*.md diff=markdown *.md diff=markdown
*.php diff=php *.php diff=php
/.github export-ignore
CHANGELOG.md export-ignore CHANGELOG.md export-ignore
.styleci.yml export-ignore

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/composer.lock
/.phpunit.cache /.phpunit.cache
/coverage /coverage
/node_modules /node_modules

View file

@ -5,30 +5,6 @@ # Changelog
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.8.0] - 2026-08-17
### Added
- **Forgejo CI pipeline** (#45) — added a CI workflow that runs Laravel Pint code-style checks, PHPStan static analysis, and the PHPUnit suite against SQLite in memory.
- **Static analysis** — added PHPStan via `larastan/larastan` and `phpstan/phpstan-mockery`, with `phpstan.neon` and a baseline.
- **Code style** — added Laravel Pint configuration (`pint.json`).
- **CI and app image build workflows** (#46) — automated Docker image builds for the app and the CI base image, published to the Forgejo registry.
- **CI base image** (#46) — added `docker/build/Dockerfile.ci`, a Debian-based PHP 8.3 CLI image with the project's PHP dependencies pre-loaded so CI doesn't pay a per-run Composer install.
- **Contributing guide** (#47) — added `CONTRIBUTING.md`.
- **Nix shell completion** (#44) — finished the `nix-shell` development commands.
### Changed
- **Dependencies**`composer.lock` is now committed to the repository.
- **Code style** — reformatted the codebase with Laravel Pint.
- **Documentation** (#47) — professionalized the `README.md`.
- **Git hygiene** — dropped stale `.github`/StyleCI export rules from `.gitattributes`.
### Fixed
- **CI dependency installation** (#46, #50) — retried `composer install` on transient HTTP 429s, switched to `--prefer-source` and pre-loaded dependencies to avoid `codeload.github.com` rate limits, and added the missing `zip` extension to the CI image.
- **Test suite** (#50) — fixed feature tests failing on a missing Vite manifest by disabling Vite resolution during tests.
## [0.7.0] - 2026-08-17 ## [0.7.0] - 2026-08-17
### Removed ### Removed

View file

@ -1,97 +0,0 @@
# Contributing
Thanks for your interest in DishPlanner. It's a small self-hosted project —
issues and pull requests are both welcome.
## Reporting issues
Use [Issues](https://forge.lvl0.xyz/lvl0/dishplanner/issues).
For bugs, include what you expected, what happened, and enough detail to
reproduce it. Relevant log output helps; `dev-logs` follows the application log.
## Development setup
Requires PHP 8.2+ and a container runtime (Podman or Docker). The development
environment runs in containers defined by `docker-compose.yml`.
On NixOS, or anywhere with Nix installed:
```bash
git clone https://forge.lvl0.xyz/lvl0/dishplanner.git
cd dishplanner
nix-shell
```
The shell prints the available commands on entry and can start the containers
for you:
| Command | Description |
|---------|-------------|
| `dev-up` | Start the development environment |
| `dev-down` | Stop the development environment |
| `dev-restart` | Restart the containers |
| `dev-rebuild` | Full rebuild (removes volumes) |
| `dev-rebuild-quick` | Quick rebuild (keeps volumes) |
| `dev-logs [service]` | Follow logs |
| `dev-logs-db` | Tail database logs |
| `dev-shell` | Enter the app container |
| `dev-artisan <cmd>` | Run an artisan command |
| `dev-test [path]` | Run the PHPUnit suite the CI way |
| `dev-fix-permissions` | Fix Docker-created file permissions |
Once running:
| Service | URL |
|---------|-----|
| App | http://localhost:8000 |
| Vite | http://localhost:5173 |
| Mailhog | http://localhost:8025 |
| MariaDB | localhost:3306 |
Without Nix, start the same containers directly from `docker-compose.yml`.
Contributions improving the setup instructions for other platforms are welcome.
## Before opening a pull request
Three checks run in CI, and all three must pass. Run them locally first, from
inside the app container or anywhere the project's dependencies are available:
```bash
vendor/bin/pint --test # code style, Laravel preset
vendor/bin/phpstan analyse --memory-limit=1G # static analysis, level 7
php -d memory_limit=512M vendor/bin/phpunit # PHPUnit on SQLite in memory
```
Or run the test suite the CI way with `dev-test`.
Some conventions:
- **Static analysis.** PHPStan runs at level 7 with a baseline
(`phpstan-baseline.neon`) covering pre-existing findings. Don't add baseline
entries to silence errors in code you're writing — fix the cause instead. The
baseline is for cases where the analyzer or an upstream docblock is wrong,
not real bugs.
- **Tests.** New behaviour needs a test. Tests run against SQLite in memory and
must not reach for the network.
- **Dependencies.** `composer.lock` is committed. If you change dependencies,
commit the updated lockfile alongside `composer.json`.
## Commits
One commit does one thing. Keep each commit passing all three checks so history
stays bisectable. Separate renames from behaviour changes, and mechanical edits
from logic.
Commit messages are a single line, referencing the ticket they belong to:
```
45 - Add Forgejo CI workflow
```
No body, no trailers.
## License
By contributing, you agree that your contributions are licensed under the
[GNU AGPL-3.0](LICENSE.md), the same license as the project.

View file

@ -1,8 +1,5 @@
# 🍽️ Dish Planner # 🍽️ Dish Planner
[![CI](https://forge.lvl0.xyz/lvl0/dishplanner/badges/workflows/ci.yml/badge.svg)](https://forge.lvl0.xyz/lvl0/dishplanner/actions)
[![License: AGPL-3.0](https://img.shields.io/badge/license-AGPL--3.0-blue)](LICENSE.md)
A Laravel-based meal planning application that helps households organize and schedule their dishes among multiple users. Built with Laravel, Livewire, and FrankenPHP for a modern, single-container deployment. A Laravel-based meal planning application that helps households organize and schedule their dishes among multiple users. Built with Laravel, Livewire, and FrankenPHP for a modern, single-container deployment.
## ✨ Features ## ✨ Features
@ -16,7 +13,7 @@ ## ✨ Features
## 🚀 Self-hosting ## 🚀 Self-hosting
The production image is available at `forge.lvl0.xyz/lvl0/dishplanner:latest`. See [CHANGELOG.md](CHANGELOG.md) before upgrading. The production image is available at `forge.lvl0.xyz/lvl0/dishplanner:latest`.
### docker-compose.yml ### docker-compose.yml
@ -105,10 +102,8 @@ #### Available Commands
| `dev-rebuild` | Full rebuild (removes volumes) | | `dev-rebuild` | Full rebuild (removes volumes) |
| `dev-rebuild-quick` | Quick rebuild (keeps volumes) | | `dev-rebuild-quick` | Quick rebuild (keeps volumes) |
| `dev-logs [service]` | Follow logs | | `dev-logs [service]` | Follow logs |
| `dev-logs-db` | Tail database logs |
| `dev-shell` | Enter app container | | `dev-shell` | Enter app container |
| `dev-artisan <cmd>` | Run artisan commands | | `dev-artisan <cmd>` | Run artisan commands |
| `dev-test [path]` | Run the PHPUnit suite the CI way |
| `dev-fix-permissions` | Fix Docker-created file permissions | | `dev-fix-permissions` | Fix Docker-created file permissions |
#### Services #### Services
@ -124,11 +119,6 @@ ### Other Platforms
Contributions welcome for development setup instructions on other platforms. Contributions welcome for development setup instructions on other platforms.
## 🤝 Contributing
Issues and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for
the development setup, the checks that run in CI, and the commit conventions.
## 📄 License ## 📄 License
This project is open-source software licensed under the [AGPL-3.0 license](LICENSE.md). This project is open-source software licensed under the [AGPL-3.0 license](LICENSE.md).

View file

@ -17,11 +17,11 @@ public function execute(array $data): User
{ {
try { try {
// Validate required fields first // Validate required fields first
if (! isset($data['name']) || empty($data['name'])) { if (!isset($data['name']) || empty($data['name'])) {
throw new InvalidArgumentException('Name is required'); throw new InvalidArgumentException('Name is required');
} }
if (! isset($data['planner_id']) || empty($data['planner_id'])) { if (!isset($data['planner_id']) || empty($data['planner_id'])) {
throw new InvalidArgumentException('Planner ID is required'); throw new InvalidArgumentException('Planner ID is required');
} }
@ -38,7 +38,7 @@ public function execute(array $data): User
'planner_id' => $data['planner_id'], 'planner_id' => $data['planner_id'],
]); ]);
if (! $user) { if (!$user) {
throw new Exception('User creation returned null'); throw new Exception('User creation returned null');
} }
@ -50,7 +50,7 @@ public function execute(array $data): User
// Verify the user was actually created // Verify the user was actually created
$createdUser = User::find($user->id); $createdUser = User::find($user->id);
if (! $createdUser) { if (!$createdUser) {
throw new Exception('User creation did not persist to database'); throw new Exception('User creation did not persist to database');
} }

View file

@ -29,7 +29,7 @@ public function execute(User $user, array $data): bool
'user_id' => $user->id, 'user_id' => $user->id,
]); ]);
if (! $result) { if (!$result) {
throw new \Exception('User update returned false'); throw new \Exception('User update returned false');
} }

View file

@ -24,7 +24,6 @@ public function handle(): int
if ($planners->isEmpty()) { if ($planners->isEmpty()) {
$this->warn('No planners found. Aborting schedule generation.'); $this->warn('No planners found. Aborting schedule generation.');
return self::FAILURE; return self::FAILURE;
} }

View file

@ -13,7 +13,8 @@ public function response(
?array $payload = null, ?array $payload = null,
array|string|null $errors = null, array|string|null $errors = null,
int $statusCode = 200, int $statusCode = 200,
): JsonResponse { ): JsonResponse
{
return response()->json(resolve(OutputService::class)->response($success, $payload, $errors), $statusCode); return response()->json(resolve(OutputService::class)->response($success, $payload, $errors), $statusCode);
} }

View file

@ -17,7 +17,7 @@ public function toArray(Request $request): array
'recurrences' => $this->recurrences->map(fn ($recurrence) => [ 'recurrences' => $this->recurrences->map(fn ($recurrence) => [
'id' => $recurrence->id, 'id' => $recurrence->id,
'type' => $recurrence->recurrence_type, 'type' => $recurrence->recurrence_type,
'value' => $recurrence->getValue(), 'value' => $recurrence->getValue()
]), ]),
]; ];
} }

View file

@ -12,18 +12,14 @@ class DishesList extends Component
use WithPagination; use WithPagination;
public $showCreateModal = false; public $showCreateModal = false;
public $showEditModal = false; public $showEditModal = false;
public $showDeleteModal = false; public $showDeleteModal = false;
public $editingDish = null; public $editingDish = null;
public $deletingDish = null; public $deletingDish = null;
// Form fields // Form fields
public $name = ''; public $name = '';
public $selectedUsers = []; public $selectedUsers = [];
protected $rules = [ protected $rules = [
@ -43,7 +39,7 @@ public function render()
return view('livewire.dishes.dishes-list', [ return view('livewire.dishes.dishes-list', [
'dishes' => $dishes, 'dishes' => $dishes,
'users' => $users, 'users' => $users
]); ]);
} }
@ -64,7 +60,7 @@ public function store()
]); ]);
// Attach selected users // Attach selected users
if (! empty($this->selectedUsers)) { if (!empty($this->selectedUsers)) {
$dish->users()->attach($this->selectedUsers); $dish->users()->attach($this->selectedUsers);
} }
@ -130,7 +126,7 @@ public function toggleAllUsers(): void
if (count($this->selectedUsers) === $users->count()) { if (count($this->selectedUsers) === $users->count()) {
$this->selectedUsers = []; $this->selectedUsers = [];
} else { } else {
$this->selectedUsers = $users->pluck('id')->map(fn ($id) => (string) $id)->toArray(); $this->selectedUsers = $users->pluck('id')->map(fn($id) => (string) $id)->toArray();
} }
} }
} }

View file

@ -19,39 +19,25 @@
class ScheduleCalendar extends Component class ScheduleCalendar extends Component
{ {
public $currentMonth; public $currentMonth;
public $currentYear; public $currentYear;
public $calendarDays = []; public $calendarDays = [];
public $showRegenerateModal = false; public $showRegenerateModal = false;
public $regenerateDate = null; public $regenerateDate = null;
public $regenerateUserId = null; public $regenerateUserId = null;
// Edit dish modal // Edit dish modal
public $showEditDishModal = false; public $showEditDishModal = false;
public $editDate = null; public $editDate = null;
public $editUserId = null; public $editUserId = null;
public $selectedDishId = null; public $selectedDishId = null;
public $availableDishes = []; public $availableDishes = [];
// Add dish modal // Add dish modal
public $showAddDishModal = false; public $showAddDishModal = false;
public $addDate = null; public $addDate = null;
public $addUserIds = []; public $addUserIds = [];
public $addSelectedDishId = null; public $addSelectedDishId = null;
public $addAvailableUsers = []; public $addAvailableUsers = [];
public $addAvailableDishes = []; public $addAvailableDishes = [];
public function mount(): void public function mount(): void
@ -75,7 +61,7 @@ public function refreshCalendar(): void
public function loadCalendar(): void public function loadCalendar(): void
{ {
$service = new ScheduleCalendarService; $service = new ScheduleCalendarService();
$this->calendarDays = $service->getCalendarDays( $this->calendarDays = $service->getCalendarDays(
auth()->user(), auth()->user(),
$this->currentMonth, $this->currentMonth,
@ -107,9 +93,8 @@ public function nextMonth(): void
public function regenerateForUserDate($date, $userId): void public function regenerateForUserDate($date, $userId): void
{ {
if (! $this->authorizeUser($userId)) { if (!$this->authorizeUser($userId)) {
session()->flash('error', 'Unauthorized action.'); session()->flash('error', 'Unauthorized action.');
return; return;
} }
@ -121,13 +106,12 @@ public function regenerateForUserDate($date, $userId): void
public function confirmRegenerate(): void public function confirmRegenerate(): void
{ {
try { try {
if (! $this->authorizeUser($this->regenerateUserId)) { if (!$this->authorizeUser($this->regenerateUserId)) {
session()->flash('error', 'Unauthorized action.'); session()->flash('error', 'Unauthorized action.');
return; return;
} }
$action = new DeleteScheduledUserDishForDateAction; $action = new DeleteScheduledUserDishForDateAction();
$action->execute( $action->execute(
auth()->user(), auth()->user(),
Carbon::parse($this->regenerateDate), Carbon::parse($this->regenerateDate),
@ -147,13 +131,12 @@ public function confirmRegenerate(): void
public function skipDay($date, $userId): void public function skipDay($date, $userId): void
{ {
try { try {
if (! $this->authorizeUser($userId)) { if (!$this->authorizeUser($userId)) {
session()->flash('error', 'Unauthorized action.'); session()->flash('error', 'Unauthorized action.');
return; return;
} }
$action = new SkipScheduledUserDishForDateAction; $action = new SkipScheduledUserDishForDateAction();
$action->execute( $action->execute(
auth()->user(), auth()->user(),
Carbon::parse($date), Carbon::parse($date),
@ -172,7 +155,6 @@ public function skipDay($date, $userId): void
private function authorizeUser(int $userId): bool private function authorizeUser(int $userId): bool
{ {
$user = User::find($userId); $user = User::find($userId);
return $user && $user->planner_id === auth()->id(); return $user && $user->planner_id === auth()->id();
} }
@ -197,9 +179,8 @@ public function cancel(): void
public function removeDish($date, $userId): void public function removeDish($date, $userId): void
{ {
try { try {
if (! $this->authorizeUser($userId)) { if (!$this->authorizeUser($userId)) {
session()->flash('error', 'Unauthorized action.'); session()->flash('error', 'Unauthorized action.');
return; return;
} }
@ -242,7 +223,7 @@ public function toggleAllUsers(): void
if (count($this->addUserIds) === count($this->addAvailableUsers)) { if (count($this->addUserIds) === count($this->addAvailableUsers)) {
$this->addUserIds = []; $this->addUserIds = [];
} else { } else {
$this->addUserIds = $this->addAvailableUsers->pluck('id')->map(fn ($id) => (string) $id)->toArray(); $this->addUserIds = $this->addAvailableUsers->pluck('id')->map(fn($id) => (string) $id)->toArray();
} }
$this->updateAvailableDishes(); $this->updateAvailableDishes();
} }
@ -271,13 +252,11 @@ public function saveAddDish(): void
try { try {
if (empty($this->addUserIds)) { if (empty($this->addUserIds)) {
session()->flash('error', 'Please select at least one user.'); session()->flash('error', 'Please select at least one user.');
return; return;
} }
if (! $this->addSelectedDishId) { if (!$this->addSelectedDishId) {
session()->flash('error', 'Please select a dish.'); session()->flash('error', 'Please select a dish.');
return; return;
} }
@ -294,9 +273,8 @@ public function saveAddDish(): void
$skippedCount = 0; $skippedCount = 0;
foreach ($this->addUserIds as $userId) { foreach ($this->addUserIds as $userId) {
if (! $this->authorizeUser((int) $userId)) { if (!$this->authorizeUser((int) $userId)) {
$skippedCount++; $skippedCount++;
continue; continue;
} }
@ -307,7 +285,6 @@ public function saveAddDish(): void
if ($existing) { if ($existing) {
$skippedCount++; $skippedCount++;
continue; continue;
} }
@ -316,9 +293,8 @@ public function saveAddDish(): void
->where('dish_id', $this->addSelectedDishId) ->where('dish_id', $this->addSelectedDishId)
->first(); ->first();
if (! $userDish) { if (!$userDish) {
$skippedCount++; $skippedCount++;
continue; continue;
} }
@ -360,9 +336,8 @@ private function closeAddDishModal(): void
public function editDish($date, $userId): void public function editDish($date, $userId): void
{ {
if (! $this->authorizeUser($userId)) { if (!$this->authorizeUser($userId)) {
session()->flash('error', 'Unauthorized action.'); session()->flash('error', 'Unauthorized action.');
return; return;
} }
@ -395,15 +370,13 @@ public function editDish($date, $userId): void
public function saveDish(): void public function saveDish(): void
{ {
try { try {
if (! $this->authorizeUser($this->editUserId)) { if (!$this->authorizeUser($this->editUserId)) {
session()->flash('error', 'Unauthorized action.'); session()->flash('error', 'Unauthorized action.');
return; return;
} }
if (! $this->selectedDishId) { if (!$this->selectedDishId) {
session()->flash('error', 'Please select a dish.'); session()->flash('error', 'Please select a dish.');
return; return;
} }
@ -421,9 +394,8 @@ public function saveDish(): void
->where('dish_id', $this->selectedDishId) ->where('dish_id', $this->selectedDishId)
->first(); ->first();
if (! $userDish) { if (!$userDish) {
session()->flash('error', 'This dish is not assigned to this user.'); session()->flash('error', 'This dish is not assigned to this user.');
return; return;
} }
@ -455,8 +427,7 @@ public function saveDish(): void
public function getMonthNameProperty(): string public function getMonthNameProperty(): string
{ {
$service = new ScheduleCalendarService; $service = new ScheduleCalendarService();
return $service->getMonthName($this->currentMonth, $this->currentYear); return $service->getMonthName($this->currentMonth, $this->currentYear);
} }
} }

View file

@ -7,27 +7,19 @@
use DishPlanner\Schedule\Actions\ClearScheduleForMonthAction; use DishPlanner\Schedule\Actions\ClearScheduleForMonthAction;
use DishPlanner\Schedule\Actions\GenerateScheduleForMonthAction; use DishPlanner\Schedule\Actions\GenerateScheduleForMonthAction;
use DishPlanner\Schedule\Actions\RegenerateScheduleForDateForUsersAction; use DishPlanner\Schedule\Actions\RegenerateScheduleForDateForUsersAction;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Livewire\Component; use Livewire\Component;
class ScheduleGenerator extends Component class ScheduleGenerator extends Component
{ {
private const YEARS_IN_PAST = 1; private const YEARS_IN_PAST = 1;
private const YEARS_IN_FUTURE = 5; private const YEARS_IN_FUTURE = 5;
public $selectedMonth; public $selectedMonth;
public $selectedYear; public $selectedYear;
public $selectedUsers = []; public $selectedUsers = [];
public $clearExisting = true; public $clearExisting = true;
public $showAdvancedOptions = false; public $showAdvancedOptions = false;
public $isGenerating = false; public $isGenerating = false;
public function mount(): void public function mount(): void
@ -40,7 +32,7 @@ public function mount(): void
->toArray(); ->toArray();
} }
public function render(): Factory|View public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
{ {
$users = User::where('planner_id', auth()->id()) $users = User::where('planner_id', auth()->id())
->orderBy('name') ->orderBy('name')
@ -51,7 +43,7 @@ public function render(): Factory|View
return view('livewire.schedule.schedule-generator', [ return view('livewire.schedule.schedule-generator', [
'users' => $users, 'users' => $users,
'months' => $this->getMonthNames(), 'months' => $this->getMonthNames(),
'years' => $years, 'years' => $years
]); ]);
} }
@ -60,13 +52,13 @@ public function generate(): void
$this->validate([ $this->validate([
'selectedUsers' => 'required|array|min:1', 'selectedUsers' => 'required|array|min:1',
'selectedMonth' => 'required|integer|min:1|max:12', 'selectedMonth' => 'required|integer|min:1|max:12',
'selectedYear' => 'required|integer|min:'.(now()->year - self::YEARS_IN_PAST).'|max:'.(now()->year + self::YEARS_IN_FUTURE), 'selectedYear' => 'required|integer|min:' . (now()->year - self::YEARS_IN_PAST) . '|max:' . (now()->year + self::YEARS_IN_FUTURE),
]); ]);
$this->isGenerating = true; $this->isGenerating = true;
try { try {
$action = new GenerateScheduleForMonthAction; $action = new GenerateScheduleForMonthAction();
$action->execute( $action->execute(
auth()->user(), auth()->user(),
$this->selectedMonth, $this->selectedMonth,
@ -78,8 +70,8 @@ public function generate(): void
$this->isGenerating = false; $this->isGenerating = false;
$this->dispatch('schedule-generated'); $this->dispatch('schedule-generated');
session()->flash('success', 'Schedule generated successfully for '. session()->flash('success', 'Schedule generated successfully for ' .
$this->getSelectedMonthName().' '.$this->selectedYear); $this->getSelectedMonthName() . ' ' . $this->selectedYear);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->isGenerating = false; $this->isGenerating = false;
@ -91,7 +83,7 @@ public function generate(): void
public function regenerateForDate($date): void public function regenerateForDate($date): void
{ {
try { try {
$action = new RegenerateScheduleForDateForUsersAction; $action = new RegenerateScheduleForDateForUsersAction();
$action->execute( $action->execute(
auth()->user(), auth()->user(),
Carbon::parse($date), Carbon::parse($date),
@ -99,7 +91,7 @@ public function regenerateForDate($date): void
); );
$this->dispatch('schedule-generated'); $this->dispatch('schedule-generated');
session()->flash('success', 'Schedule regenerated for '.Carbon::parse($date)->format('M d, Y')); session()->flash('success', 'Schedule regenerated for ' . Carbon::parse($date)->format('M d, Y'));
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('Schedule regeneration failed', ['exception' => $e, 'date' => $date]); Log::error('Schedule regeneration failed', ['exception' => $e, 'date' => $date]);
@ -110,7 +102,7 @@ public function regenerateForDate($date): void
public function clearMonth(): void public function clearMonth(): void
{ {
try { try {
$action = new ClearScheduleForMonthAction; $action = new ClearScheduleForMonthAction();
$action->execute( $action->execute(
auth()->user(), auth()->user(),
$this->selectedMonth, $this->selectedMonth,
@ -119,8 +111,8 @@ public function clearMonth(): void
); );
$this->dispatch('schedule-generated'); $this->dispatch('schedule-generated');
session()->flash('success', 'Schedule cleared for '. session()->flash('success', 'Schedule cleared for ' .
$this->getSelectedMonthName().' '.$this->selectedYear); $this->getSelectedMonthName() . ' ' . $this->selectedYear);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('Clear month failed', ['exception' => $e]); Log::error('Clear month failed', ['exception' => $e]);
@ -130,7 +122,7 @@ public function clearMonth(): void
public function toggleAdvancedOptions() public function toggleAdvancedOptions()
{ {
$this->showAdvancedOptions = ! $this->showAdvancedOptions; $this->showAdvancedOptions = !$this->showAdvancedOptions;
} }
private function getMonthNames(): array private function getMonthNames(): array
@ -138,7 +130,7 @@ private function getMonthNames(): array
return [ return [
1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April',
5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August',
9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December'
]; ];
} }

View file

@ -2,10 +2,10 @@
namespace App\Livewire\Users; namespace App\Livewire\Users;
use App\Models\User;
use App\Actions\User\CreateUserAction; use App\Actions\User\CreateUserAction;
use App\Actions\User\DeleteUserAction; use App\Actions\User\DeleteUserAction;
use App\Actions\User\EditUserAction; use App\Actions\User\EditUserAction;
use App\Models\User;
use Exception; use Exception;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Livewire\Component; use Livewire\Component;
@ -16,13 +16,10 @@ class UsersList extends Component
use WithPagination; use WithPagination;
public bool $showCreateModal = false; public bool $showCreateModal = false;
public bool $showEditModal = false; public bool $showEditModal = false;
public bool $showDeleteModal = false; public bool $showDeleteModal = false;
public ?User $editingUser = null; public ?User $editingUser = null;
public ?User $deletingUser = null; public ?User $deletingUser = null;
// Form fields // Form fields
@ -39,7 +36,7 @@ public function render(): View
->paginate(10); ->paginate(10);
return view('livewire.users.users-list', [ return view('livewire.users.users-list', [
'users' => $users, 'users' => $users
]); ]);
} }
@ -55,7 +52,7 @@ public function store(): void
$this->validate(); $this->validate();
try { try {
(new CreateUserAction)->execute([ (new CreateUserAction())->execute([
'name' => $this->name, 'name' => $this->name,
'planner_id' => auth()->id(), 'planner_id' => auth()->id(),
]); ]);
@ -65,7 +62,7 @@ public function store(): void
session()->flash('success', 'User created successfully.'); session()->flash('success', 'User created successfully.');
} catch (Exception $e) { } catch (Exception $e) {
session()->flash('error', 'Failed to create user: '.$e->getMessage()); session()->flash('error', 'Failed to create user: ' . $e->getMessage());
} }
} }
@ -82,7 +79,7 @@ public function update(): void
$this->validate(); $this->validate();
try { try {
(new EditUserAction)->execute($this->editingUser, ['name' => $this->name]); (new EditUserAction())->execute($this->editingUser, ['name' => $this->name]);
$this->showEditModal = false; $this->showEditModal = false;
$this->reset(['name', 'editingUser']); $this->reset(['name', 'editingUser']);
@ -92,7 +89,7 @@ public function update(): void
// Force component to re-render with fresh data // Force component to re-render with fresh data
$this->resetPage(); $this->resetPage();
} catch (Exception $e) { } catch (Exception $e) {
session()->flash('error', 'Failed to update user: '.$e->getMessage()); session()->flash('error', 'Failed to update user: ' . $e->getMessage());
} }
} }
@ -105,7 +102,7 @@ public function confirmDelete(User $user): void
public function delete(): void public function delete(): void
{ {
try { try {
(new DeleteUserAction)->execute($this->deletingUser); (new DeleteUserAction())->execute($this->deletingUser);
$this->showDeleteModal = false; $this->showDeleteModal = false;
$this->deletingUser = null; $this->deletingUser = null;
@ -115,7 +112,7 @@ public function delete(): void
// Force component to re-render with fresh data // Force component to re-render with fresh data
$this->resetPage(); $this->resetPage();
} catch (Exception $e) { } catch (Exception $e) {
session()->flash('error', 'Failed to delete user: '.$e->getMessage()); session()->flash('error', 'Failed to delete user: ' . $e->getMessage());
} }
} }

View file

@ -21,7 +21,6 @@
* @property Carbon $updated_at * @property Carbon $updated_at
* @property Collection<User> $users * @property Collection<User> $users
* @property Collection<UserDish> $userDishes * @property Collection<UserDish> $userDishes
*
* @method static create(array $data) * @method static create(array $data)
* @method static findOrFail(int $dish_id) * @method static findOrFail(int $dish_id)
* @method static DishFactory factory($count = null, $state = []) * @method static DishFactory factory($count = null, $state = [])

View file

@ -13,7 +13,6 @@
* @property int $id * @property int $id
* @property static PlannerFactory factory($count = null, $state = []) * @property static PlannerFactory factory($count = null, $state = [])
* @property Collection<User> $users * @property Collection<User> $users
*
* @method static first() * @method static first()
* @method static create(array $array) * @method static create(array $array)
*/ */

View file

@ -22,9 +22,8 @@
* @property Dish $dish * @property Dish $dish
* @property User $user * @property User $user
* @property Carbon $date * @property Carbon $date
* @property bool $is_skipped * @property boolean $is_skipped
* @property Collection<ScheduledUserDish> $scheduledUserDishes * @property Collection<ScheduledUserDish> $scheduledUserDishes
*
* @method static create(array $array) * @method static create(array $array)
* @method static Builder where(array|Closure|Expression|string $column, mixed $operator = null, mixed $value = null, string $boolean = 'and') * @method static Builder where(array|Closure|Expression|string $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
* @method static ScheduleFactory factory($count = null, $state = []) * @method static ScheduleFactory factory($count = null, $state = [])
@ -39,8 +38,6 @@ class Schedule extends Model
public $timestamps = false; public $timestamps = false;
protected $dateFormat = 'Y-m-d';
protected $fillable = ['planner_id', 'date', 'is_skipped']; protected $fillable = ['planner_id', 'date', 'is_skipped'];
protected $casts = [ protected $casts = [

View file

@ -17,7 +17,6 @@
* @property int $user_dish_id * @property int $user_dish_id
* @property UserDish $userDish * @property UserDish $userDish
* @property bool $is_skipped * @property bool $is_skipped
*
* @method static create(array $array) * @method static create(array $array)
* @method static ScheduledUserDishFactory factory($count = null, $state = []) * @method static ScheduledUserDishFactory factory($count = null, $state = [])
* @method static firstOrCreate(array $array, array $array1) * @method static firstOrCreate(array $array, array $array1)
@ -30,7 +29,7 @@ class ScheduledUserDish extends Model
'schedule_id', 'schedule_id',
'user_id', 'user_id',
'user_dish_id', 'user_dish_id',
'is_skipped', 'is_skipped'
]; ];
protected $casts = [ protected $casts = [

View file

@ -6,10 +6,10 @@
use Database\Factories\UserFactory; use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Model;
/** /**
* @property int $id * @property int $id
@ -17,7 +17,6 @@
* @property string $name * @property string $name
* @property Collection<Dish> $dishes * @property Collection<Dish> $dishes
* @property Collection<UserDish> $userDishes * @property Collection<UserDish> $userDishes
*
* @method static User findOrFail(int $user_id) * @method static User findOrFail(int $user_id)
* @method static UserFactory factory($count = null, $state = []) * @method static UserFactory factory($count = null, $state = [])
* @method static create(array $array) * @method static create(array $array)

View file

@ -17,7 +17,6 @@
* @method static UserDish|null find(int|null $user_dish_id) * @method static UserDish|null find(int|null $user_dish_id)
* @method static create(array $array) * @method static create(array $array)
* @method static where(string $string, int $id) * @method static where(string $string, int $id)
*
* @property int $id * @property int $id
* @property int $dish_id * @property int $dish_id
* @property int $user_id * @property int $user_id

View file

@ -36,7 +36,7 @@ public function getValue(): int
return match ($this->recurrence_type) { return match ($this->recurrence_type) {
WeeklyRecurrence::class => $this->recurrence->weekday->value, WeeklyRecurrence::class => $this->recurrence->weekday->value,
MinimumRecurrence::class => $this->recurrence->days, MinimumRecurrence::class => $this->recurrence->days,
default => throw new InvalidRecurrenceTypeException default => throw new InvalidRecurrenceTypeException()
}; };
} }
} }

View file

@ -12,11 +12,10 @@
/** /**
* @property int $weekday * @property int $weekday
*
* @method static create(array $array) * @method static create(array $array)
* @method static WeeklyRecurrenceFactory factory($count = null, $state = []) * @method static WeeklyRecurrenceFactory factory($count = null, $state = [])
*/ */
class WeeklyRecurrence extends Model implements FixedRecurrenceInterface, RecurrenceInterface class WeeklyRecurrence extends Model implements RecurrenceInterface, FixedRecurrenceInterface
{ {
/** @use HasFactory<WeeklyRecurrenceFactory> */ /** @use HasFactory<WeeklyRecurrenceFactory> */
use HasFactory; use HasFactory;

View file

@ -16,6 +16,7 @@
use Illuminate\Contracts\Debug\ExceptionHandler; use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Foundation\Exceptions\Handler as BaseHandler; use Illuminate\Foundation\Exceptions\Handler as BaseHandler;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Throwable; use Throwable;
@ -24,8 +25,7 @@ class AppServiceProvider extends ServiceProvider
public function register(): void public function register(): void
{ {
$this->app->bind(ExceptionHandler::class, function ($app) { $this->app->bind(ExceptionHandler::class, function ($app) {
return new class($app) extends BaseHandler return new class($app) extends BaseHandler {
{
public function render($request, Throwable $e) public function render($request, Throwable $e)
{ {
// Handle specific custom exception // Handle specific custom exception

View file

@ -2,6 +2,7 @@
namespace App\Services; namespace App\Services;
class OutputService class OutputService
{ {
public function response(bool $success = true, ?array $payload = null, array|string|null $errors = null): array public function response(bool $success = true, ?array $payload = null, array|string|null $errors = null): array

View file

@ -1,7 +1,5 @@
<?php <?php
use App\Providers\AppServiceProvider;
return [ return [
AppServiceProvider::class, App\Providers\AppServiceProvider::class,
]; ];

View file

@ -17,14 +17,12 @@
}, },
"require-dev": { "require-dev": {
"fakerphp/faker": "^1.23", "fakerphp/faker": "^1.23",
"larastan/larastan": "^3.10",
"laravel/dusk": "^8.3", "laravel/dusk": "^8.3",
"laravel/pail": "^1.1", "laravel/pail": "^1.1",
"laravel/pint": "^1.13", "laravel/pint": "^1.13",
"laravel/sail": "^1.26", "laravel/sail": "^1.26",
"mockery/mockery": "^1.6", "mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.1", "nunomaduro/collision": "^8.1",
"phpstan/phpstan-mockery": "^2.0",
"phpunit/phpunit": "^11.0.1" "phpunit/phpunit": "^11.0.1"
}, },
"autoload": { "autoload": {

8923
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,5 @@
<?php <?php
use App\Models\Planner;
return [ return [
/* /*
@ -52,7 +50,7 @@
'providers' => [ 'providers' => [
'planners' => [ 'planners' => [
'driver' => 'eloquent', 'driver' => 'eloquent',
'model' => Planner::class, 'model' => App\Models\Planner::class,
], ],
// 'users' => [ // 'users' => [

View file

@ -1,8 +1,5 @@
<?php <?php
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
use Laravel\Sanctum\Http\Middleware\AuthenticateSession;
use Laravel\Sanctum\Sanctum; use Laravel\Sanctum\Sanctum;
return [ return [
@ -78,9 +75,9 @@
*/ */
'middleware' => [ 'middleware' => [
'authenticate_session' => AuthenticateSession::class, 'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
'encrypt_cookies' => EncryptCookies::class, 'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class,
'validate_csrf_token' => ValidateCsrfToken::class, 'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class,
], ],
]; ];

View file

@ -3,8 +3,8 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Dish; use App\Models\Dish;
use App\Models\User;
use App\Models\UserDish; use App\Models\UserDish;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
/** /**

View file

@ -2,6 +2,7 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\User;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents; // use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;

View file

@ -14,7 +14,7 @@ public function run(): void
[ [
'name' => 'Admin', 'name' => 'Admin',
'email' => 'admin@test.com', 'email' => 'admin@test.com',
'password' => 'password', 'password' => 'password'
], ],
])->each(fn (array $data) => Planner::create([ ])->each(fn (array $data) => Planner::create([
'name' => $data['name'], 'name' => $data['name'],

View file

@ -41,10 +41,11 @@ private function createScheduleForPeriod(CarbonPeriod $period): void
$planner = Planner::all()->first() ?? Planner::factory()->create(); $planner = Planner::all()->first() ?? Planner::factory()->create();
collect($period) collect($period)
->each(fn (Carbon $date) => User::query() ->each(fn (Carbon $date) =>
User::query()
->inRandomOrder() ->inRandomOrder()
->get() ->get()
->each(fn (User $user) => (new CreateScheduledUserDishAction) ->each(fn (User $user) => (new CreateScheduledUserDishAction())
->execute( ->execute(
planner: $planner, planner: $planner,
schedule: resolve(ScheduleRepository::class)->findOrCreate($planner, $date), schedule: resolve(ScheduleRepository::class)->findOrCreate($planner, $date),

View file

@ -16,6 +16,7 @@ public function run(): void
->each(fn (string $name) => User::factory()->create([ ->each(fn (string $name) => User::factory()->create([
'planner_id' => $planner->id, 'planner_id' => $planner->id,
'name' => $name, 'name' => $name,
])); ]))
;
} }
} }

View file

@ -1,44 +0,0 @@
# CI image: PHP + Composer only, no runtime server or frontend toolchain.
# Tests run against SQLite in memory (see .env.testing), so no database client
# or cache extension is needed.
#
# Published as dishplanner-ci:php8.3-<revision>. Bump the revision in the tag
# (.forgejo/workflows/images.yml) and in .forgejo/workflows/ci.yml whenever
# this file changes (runners cache mutable tags and will not re-pull them).
#
# Debian-based rather than Alpine to avoid the DNS resolution timeouts against
# codeload.github.com that the Alpine base hit during composer install.
FROM php:8.3-cli
COPY --from=mlocati/php-extension-installer:2 /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions \
pdo_sqlite \
mbstring \
dom \
xml \
fileinfo \
pcntl \
zip
# git is needed by the checkout action; nodejs runs the Forgejo JavaScript
# actions (checkout, cache); unzip lets Composer extract dist archives.
RUN apt-get update \
&& apt-get install -y --no-install-recommends git unzip nodejs \
&& rm -rf /var/lib/apt/lists/*
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
# Bake the project's PHP dependencies (dev included) into the image so CI
# restores them with a local copy instead of paying a per-run composer install
# over the network. Build this image on a network that isn't
# codeload-rate-limited (e.g. locally) — the Forgejo runner hits codeload 429
# under --prefer-dist.
#
# --no-scripts skips `php artisan package:discover` (the app isn't present
# here). CI runs `composer install` after restoring vendor, which regenerates
# bootstrap/cache and tops up any lockfile drift between main and release/*.
WORKDIR /opt/deps
COPY composer.json composer.lock ./
RUN composer install --no-interaction --no-progress --prefer-dist --no-scripts

File diff suppressed because it is too large Load diff

View file

@ -1,16 +0,0 @@
includes:
- vendor/larastan/larastan/extension.neon
- vendor/phpstan/phpstan-mockery/extension.neon
- phpstan-baseline.neon
parameters:
level: 7
paths:
- app/
- src/
- tests/
excludePaths:
- bootstrap/*.php
- storage/*

View file

@ -23,6 +23,13 @@
<directory>app/Providers</directory> <directory>app/Providers</directory>
</exclude> </exclude>
</source> </source>
<coverage>
<report>
<html outputDirectory="coverage"/>
<text outputFile="coverage/coverage.txt" showOnlySummary="true"/>
<clover outputFile="coverage/clover.xml"/>
</report>
</coverage>
<php> <php>
<env name="APP_ENV" value="testing"/> <env name="APP_ENV" value="testing"/>
<env name="APP_MAINTENANCE_DRIVER" value="file"/> <env name="APP_MAINTENANCE_DRIVER" value="file"/>
@ -33,8 +40,12 @@
<env name="QUEUE_CONNECTION" value="sync"/> <env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/> <env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/> <env name="TELESCOPE_ENABLED" value="false"/>
<env name="DB_CONNECTION" value="sqlite"/> <env name="DB_CONNECTION" value="mysql"/>
<env name="DB_DATABASE" value=":memory:"/> <env name="DB_HOST" value="mysql"/>
<env name="DB_PORT" value="3306"/>
<env name="DB_DATABASE" value="testing"/>
<env name="DB_USERNAME" value="sail"/>
<env name="DB_PASSWORD" value="password"/>
</php> </php>
</phpunit> </phpunit>

View file

@ -1,3 +0,0 @@
{
"preset": "laravel"
}

View file

@ -5,12 +5,12 @@
Route::group([ Route::group([
'as' => 'api.', 'as' => 'api.',
], function () { ], function () {
require __DIR__.'/api/auth.php'; require __DIR__ . '/api/auth.php';
Route::middleware('auth:sanctum')->group(function () { Route::middleware('auth:sanctum')->group(function () {
require __DIR__.'/api/users.php'; require __DIR__ . '/api/users.php';
require __DIR__.'/api/dishes.php'; require __DIR__ . '/api/dishes.php';
require __DIR__.'/api/schedule.php'; require __DIR__ . '/api/schedule.php';
require __DIR__.'/api/scheduledUserDishes.php'; require __DIR__ . '/api/scheduledUserDishes.php';
}); });
}); });

View file

@ -18,3 +18,4 @@
->json($request->user()) ->json($request->user())
)->name('me'); )->name('me');
}); });

View file

@ -1,8 +1,8 @@
<?php <?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Auth\LoginController; use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\RegisterController; use App\Http\Controllers\Auth\RegisterController;
use Illuminate\Support\Facades\Route;
Route::get('/', function () { Route::get('/', function () {
return redirect()->route('dashboard'); return redirect()->route('dashboard');

View file

@ -68,10 +68,6 @@ pkgs.mkShell {
podman-compose logs -f "$@" podman-compose logs -f "$@"
} }
dev-logs-db() {
podman-compose logs -f db "$@"
}
dev-shell() { dev-shell() {
podman-compose exec app sh podman-compose exec app sh
} }
@ -80,10 +76,6 @@ pkgs.mkShell {
podman-compose exec app php artisan "$@" podman-compose exec app php artisan "$@"
} }
dev-test() {
podman-compose exec -T app env $(grep -vE '^\s*(#|$)' .env.testing) php -d memory_limit=512M vendor/bin/phpunit "$@"
}
dev-fix-permissions() { dev-fix-permissions() {
echo "🔧 Fixing file permissions..." echo "🔧 Fixing file permissions..."
echo "This will require sudo to fix Docker-created files" echo "This will require sudo to fix Docker-created files"
@ -157,10 +149,8 @@ pkgs.mkShell {
echo " dev-rebuild - Full rebuild (removes volumes)" echo " dev-rebuild - Full rebuild (removes volumes)"
echo " dev-rebuild-quick - Quick rebuild (keeps volumes)" echo " dev-rebuild-quick - Quick rebuild (keeps volumes)"
echo " dev-logs [svc] - Follow logs (default: all)" echo " dev-logs [svc] - Follow logs (default: all)"
echo " dev-logs-db - Tail database logs"
echo " dev-shell - Enter app container" echo " dev-shell - Enter app container"
echo " dev-artisan - Run artisan commands" echo " dev-artisan - Run artisan commands"
echo " dev-test [path] - Run PHPUnit suite (CI invocation)"
echo " dev-fix-permissions - Fix Docker-created file permissions" echo " dev-fix-permissions - Fix Docker-created file permissions"
echo "" echo ""
echo "Production commands:" echo "Production commands:"

View file

@ -17,7 +17,7 @@ public function login(Request $request): JsonResponse
'password' => ['required'], 'password' => ['required'],
]); ]);
if (! Auth::attempt($credentials)) { if (!Auth::attempt($credentials)) {
return response()->json([ return response()->json([
'message' => 'The provided credentials are incorrect.', 'message' => 'The provided credentials are incorrect.',
], 401); ], 401);

View file

@ -31,7 +31,7 @@ public function index(): JsonResponse
public function store(StoreDishRequest $request): JsonResponse public function store(StoreDishRequest $request): JsonResponse
{ {
$dish = (new CreateDishAction)->execute($request->validated()); $dish = (new CreateDishAction())->execute($request->validated());
return $this->success(['dish' => new DishResource($dish)]); return $this->success(['dish' => new DishResource($dish)]);
} }
@ -47,7 +47,7 @@ public function update(UpdateDishRequest $request, Dish $dish): JsonResponse
{ {
Gate::authorize('update', $dish); Gate::authorize('update', $dish);
$dish = (new UpdateDishAction)->execute($dish, $request->validated()); $dish = (new UpdateDishAction())->execute($dish, $request->validated());
return $this->success(['dish' => new DishResource($dish)]); return $this->success(['dish' => new DishResource($dish)]);
} }
@ -56,14 +56,14 @@ public function destroy(Dish $dish): JsonResponse
{ {
Gate::authorize('delete', $dish); Gate::authorize('delete', $dish);
(new DeleteDishAction)->execute($dish); (new DeleteDishAction())->execute($dish);
return $this->success(null); return $this->success(null);
} }
public function syncUsers(SyncUsersRequest $request, Dish $dish): JsonResponse public function syncUsers(SyncUsersRequest $request, Dish $dish): JsonResponse
{ {
(new SyncUsersAction)->execute($dish, Arr::get($request->validated(), 'users', [])); (new SyncUsersAction())->execute($dish, Arr::get($request->validated(), 'users', []));
return $this->success(['dish' => new DishResource($dish->refresh())]); return $this->success(['dish' => new DishResource($dish->refresh())]);
} }
@ -72,14 +72,14 @@ public function addUsers(AddUsersToDishRequest $request, Dish $dish): JsonRespon
{ {
Gate::authorize('update', $dish); Gate::authorize('update', $dish);
(new AddUsersToDishAction)->execute($dish, Arr::get($request->validated(), 'users', [])); (new AddUsersToDishAction())->execute($dish, Arr::get($request->validated(), 'users', []));
return $this->success(['dish' => new DishResource($dish->refresh())]); return $this->success(['dish' => new DishResource($dish->refresh())]);
} }
public function removeUsers(RemoveUsersFromDishRequest $request, Dish $dish): JsonResponse public function removeUsers(RemoveUsersFromDishRequest $request, Dish $dish): JsonResponse
{ {
(new RemoveUsersFromDishAction)->execute($dish, Arr::get($request->validated(), 'users', [])); (new RemoveUsersFromDishAction())->execute($dish, Arr::get($request->validated(), 'users', []));
return $this->success(['dish' => new DishResource($dish->refresh())]); return $this->success(['dish' => new DishResource($dish->refresh())]);
} }

View file

@ -7,6 +7,5 @@
class InvalidDishException extends CustomException class InvalidDishException extends CustomException
{ {
protected $message = 'INVALID_DISH'; protected $message = 'INVALID_DISH';
protected $code = 422; protected $code = 422;
} }

View file

@ -11,7 +11,7 @@ class DraftScheduleForDateAction
public function execute(Schedule $schedule): Schedule public function execute(Schedule $schedule): Schedule
{ {
User::all() User::all()
->reject(fn ($user) => $schedule ->reject(fn($user) => $schedule
->scheduledUserDishes ->scheduledUserDishes
->map(fn (ScheduledUserDish $scheduledUserDish) => $scheduledUserDish->userDish?->user) ->map(fn (ScheduledUserDish $scheduledUserDish) => $scheduledUserDish->userDish?->user)
->filter() ->filter()

View file

@ -7,6 +7,7 @@
use App\Models\ScheduledUserDish; use App\Models\ScheduledUserDish;
use App\Models\User; use App\Models\User;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
class GenerateScheduleForMonthAction class GenerateScheduleForMonthAction
@ -83,7 +84,7 @@ private function generateSchedulesForPeriod(
); );
foreach ($userIds as $userId) { foreach ($userIds as $userId) {
if (! isset($userDishesMap[$userId]) || $userDishesMap[$userId]->isEmpty()) { if (!isset($userDishesMap[$userId]) || $userDishesMap[$userId]->isEmpty()) {
continue; continue;
} }

View file

@ -29,7 +29,7 @@ public function execute(Planner $planner, Schedule $schedule, User $user, bool $
); );
} }
if (! $overwrite && $scheduledUserDish->userDish) { if (!$overwrite && $scheduledUserDish->userDish) {
return $scheduledUserDish; return $scheduledUserDish;
} }

View file

@ -5,6 +5,8 @@
use App\Http\Controllers\Api\ApiController; use App\Http\Controllers\Api\ApiController;
use App\Models\Planner; use App\Models\Planner;
use App\Models\Schedule; use App\Models\Schedule;
use Carbon\CarbonPeriod;
use DishPlanner\Schedule\Actions\DraftScheduleForPeriodAction;
use DishPlanner\Schedule\Actions\GenerateScheduleForPeriodAction; use DishPlanner\Schedule\Actions\GenerateScheduleForPeriodAction;
use DishPlanner\Schedule\Actions\UpdateScheduleAction; use DishPlanner\Schedule\Actions\UpdateScheduleAction;
use DishPlanner\Schedule\Repositories\ScheduleRepository; use DishPlanner\Schedule\Repositories\ScheduleRepository;
@ -81,7 +83,7 @@ public function generate(GenerateScheduleRequest $request): JsonResponse
/** @var Planner $planner */ /** @var Planner $planner */
$planner = auth()->user(); $planner = auth()->user();
(new GenerateScheduleForPeriodAction)->execute($planner, $request->get('overwrite', false)); (new GenerateScheduleForPeriodAction())->execute($planner, $request->get('overwrite', false));
return $this->success(null); return $this->success(null);
} }

View file

@ -37,7 +37,7 @@ public function __invoke(ScheduleUserDishRequest $request, Carbon $date): JsonRe
->first(); ->first();
if (! $scheduledUserDish) { if (! $scheduledUserDish) {
$scheduledUserDish = new ScheduledUserDish; $scheduledUserDish = new ScheduledUserDish();
} }
abort_if( abort_if(

View file

@ -12,7 +12,7 @@ public function rules(): array
'user_dish_id' => [ 'user_dish_id' => [
'required_without:skipped', 'required_without:skipped',
'exists:user_dishes,id', 'exists:user_dishes,id',
'nullable', 'nullable'
], ],
'user_id' => ['required', 'exists:users,id'], 'user_id' => ['required', 'exists:users,id'],
'skipped' => ['required_if:user_dish_id,null', 'boolean'], 'skipped' => ['required_if:user_dish_id,null', 'boolean'],

View file

@ -5,7 +5,7 @@
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
/** /**
* @property bool $is_skipped * @property boolean $is_skipped
*/ */
class UpdateScheduleRequest extends FormRequest class UpdateScheduleRequest extends FormRequest
{ {

View file

@ -43,7 +43,7 @@ private function buildCalendarDays(int $year, int $month, int $daysInMonth, Coll
'date' => $date, 'date' => $date,
'isToday' => $date->isToday(), 'isToday' => $date->isToday(),
'scheduledDishes' => $scheduledDishes, 'scheduledDishes' => $scheduledDishes,
'isEmpty' => $scheduledDishes->isEmpty(), 'isEmpty' => $scheduledDishes->isEmpty()
]; ];
} else { } else {
$calendarDays[] = [ $calendarDays[] = [
@ -51,7 +51,7 @@ private function buildCalendarDays(int $year, int $month, int $daysInMonth, Coll
'date' => null, 'date' => null,
'isToday' => false, 'isToday' => false,
'scheduledDishes' => collect(), 'scheduledDishes' => collect(),
'isEmpty' => true, 'isEmpty' => true
]; ];
} }
} }

View file

@ -31,7 +31,7 @@ public function generate(Planner $planner): void
$users->each(function (User $user) use ($date, $planner, $scheduleRepository, $userDishRepository) { $users->each(function (User $user) use ($date, $planner, $scheduleRepository, $userDishRepository) {
$schedule = $scheduleRepository->findOrCreate($planner, $date); $schedule = $scheduleRepository->findOrCreate($planner, $date);
(new CreateScheduledUserDishAction)->execute( (new CreateScheduledUserDishAction())->execute(
planner: $planner, planner: $planner,
schedule: $schedule, schedule: $schedule,
userDish: $userDishRepository->getRandomForDate($user, $date) userDish: $userDishRepository->getRandomForDate($user, $date)

View file

@ -16,7 +16,7 @@ class CreateScheduledUserDishAction
public function execute(Planner $planner, Schedule $schedule, UserDish $userDish): ScheduledUserDish public function execute(Planner $planner, Schedule $schedule, UserDish $userDish): ScheduledUserDish
{ {
if ($userDish->dish->planner_id !== $planner->id || $userDish->user->planner_id !== $planner->id) { if ($userDish->dish->planner_id !== $planner->id || $userDish->user->planner_id !== $planner->id) {
throw new InvalidPlannerException; throw new InvalidPlannerException();
} }
return ScheduledUserDish::create([ return ScheduledUserDish::create([

View file

@ -36,7 +36,7 @@ public function create(CreateScheduleRequest $request): JsonResponse
$schedule = resolve(ScheduleRepository::class)->findOrCreate($planner, $date); $schedule = resolve(ScheduleRepository::class)->findOrCreate($planner, $date);
try { try {
$scheduledUserDish = (new CreateScheduledUserDishAction)->execute( $scheduledUserDish = (new CreateScheduledUserDishAction())->execute(
planner: $planner, planner: $planner,
schedule: $schedule, schedule: $schedule,
userDish: $userDish, userDish: $userDish,
@ -46,7 +46,7 @@ public function create(CreateScheduleRequest $request): JsonResponse
} }
return $this->success([ return $this->success([
'scheduled_user_dish' => new ScheduledUserDishResource($scheduledUserDish), 'scheduled_user_dish' => new ScheduledUserDishResource($scheduledUserDish)
]); ]);
} }
@ -63,7 +63,7 @@ public function update(UpdateScheduledUserDishRequest $request, ScheduledUserDis
{ {
Gate::authorize('update', $scheduledUserDish); Gate::authorize('update', $scheduledUserDish);
(new UpdateScheduledUserDishAction)->execute( (new UpdateScheduledUserDishAction())->execute(
scheduledUserDish: $scheduledUserDish, scheduledUserDish: $scheduledUserDish,
userDish: UserDish::find($request->user_dish_id), userDish: UserDish::find($request->user_dish_id),
isSkipped: $request->is_skipped ?? null, isSkipped: $request->is_skipped ?? null,
@ -78,7 +78,7 @@ public function delete(ScheduledUserDish $scheduledUserDish): JsonResponse
{ {
Gate::authorize('delete', $scheduledUserDish); Gate::authorize('delete', $scheduledUserDish);
(new DeleteScheduledUserDishAction)->execute($scheduledUserDish); (new DeleteScheduledUserDishAction())->execute($scheduledUserDish);
return $this->success(null); return $this->success(null);
} }

View file

@ -4,6 +4,7 @@
use App\Models\Planner; use App\Models\Planner;
use App\Models\ScheduledUserDish; use App\Models\ScheduledUserDish;
use DishPlanner\UserDish\Policies\UserDishPolicy;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;
class ScheduledUserDishPolicy class ScheduledUserDishPolicy

View file

@ -2,6 +2,7 @@
namespace DishPlanner\User\Actions; namespace DishPlanner\User\Actions;
use App\Models\Planner;
use App\Models\User; use App\Models\User;
class DeleteUserAction class DeleteUserAction

View file

@ -2,6 +2,7 @@
namespace DishPlanner\User\Actions; namespace DishPlanner\User\Actions;
use App\Models\Planner;
use App\Models\User; use App\Models\User;
class UpdateUserAction class UpdateUserAction

View file

@ -33,7 +33,7 @@ public function create(CreateUserRequest $request): JsonResponse
$requestData = $request->validated(); $requestData = $request->validated();
$user = (new CreateUserAction) $user = (new CreateUserAction())
->execute($planner, Arr::get($requestData, 'name')); ->execute($planner, Arr::get($requestData, 'name'));
return $this->success(['user' => new UserResource($user)]); return $this->success(['user' => new UserResource($user)]);
@ -43,7 +43,7 @@ public function update(UpdateUserRequest $request, User $user): JsonResponse
{ {
Gate::authorize('update', $user); Gate::authorize('update', $user);
$user = (new UpdateUserAction) $user = (new UpdateUserAction())
->execute($user, Arr::get($request->validated(), 'name')); ->execute($user, Arr::get($request->validated(), 'name'));
return $this->success(['user' => new UserResource($user)]); return $this->success(['user' => new UserResource($user)]);
@ -53,7 +53,7 @@ public function delete(User $user): JsonResponse
{ {
Gate::authorize('delete', $user); Gate::authorize('delete', $user);
(new DeleteUserAction)->execute($user); (new DeleteUserAction())->execute($user);
return $this->success(null, 201); return $this->success(null, 201);
} }

View file

@ -17,8 +17,8 @@ class CreateFixedRecurrenceAction
*/ */
public function execute(UserDish $userDish, string $recurrenceType, int $value): void public function execute(UserDish $userDish, string $recurrenceType, int $value): void
{ {
if (! in_array($recurrenceType, self::FIXED_RECURRENCES)) { if (!in_array($recurrenceType, self::FIXED_RECURRENCES)) {
throw new InvalidRecurrenceTypeException; throw new InvalidRecurrenceTypeException();
} }
$recurrence = $recurrenceType::create([ $recurrence = $recurrenceType::create([

View file

@ -15,7 +15,7 @@ class CreateMinimumRecurrenceAction
public function execute(UserDish $userDish, string $recurrenceType, int $recurrenceValue): void public function execute(UserDish $userDish, string $recurrenceType, int $recurrenceValue): void
{ {
if ($recurrenceType !== MinimumRecurrence::class) { if ($recurrenceType !== MinimumRecurrence::class) {
throw new InvalidRecurrenceTypeException; throw new InvalidRecurrenceTypeException();
} }
$existingRecurrenceForDay = $userDish $existingRecurrenceForDay = $userDish

View file

@ -40,11 +40,11 @@ private function addRecurrences(UserDish $userDish, array $data): void
} }
if ($recurrenceType === WeeklyRecurrence::class) { if ($recurrenceType === WeeklyRecurrence::class) {
(new CreateFixedRecurrenceAction)->execute($userDish, $recurrenceType, $recurrenceValue); (new CreateFixedRecurrenceAction())->execute($userDish, $recurrenceType, $recurrenceValue);
} elseif ($recurrenceType === MinimumRecurrence::class) { } elseif ($recurrenceType === MinimumRecurrence::class) {
(new CreateMinimumRecurrenceAction)->execute($userDish, $recurrenceType, $recurrenceValue); (new CreateMinimumRecurrenceAction())->execute($userDish, $recurrenceType, $recurrenceValue);
} else { } else {
throw new InvalidRecurrenceTypeException; throw new InvalidRecurrenceTypeException();
} }
} }
} }

View file

@ -14,7 +14,7 @@ class DeleteFixedRecurrenceAction
public function execute(RecurrenceInterface $recurrence): void public function execute(RecurrenceInterface $recurrence): void
{ {
if (! $recurrence instanceof WeeklyRecurrence) { if (! $recurrence instanceof WeeklyRecurrence) {
throw new InvalidRecurrenceTypeException; throw new InvalidRecurrenceTypeException();
} }
$recurrence->delete(); $recurrence->delete();

View file

@ -15,7 +15,7 @@ class DeleteMinimumRecurrenceAction
public function execute(RecurrenceInterface $recurrence): void public function execute(RecurrenceInterface $recurrence): void
{ {
if (! $recurrence instanceof MinimumRecurrence) { if (! $recurrence instanceof MinimumRecurrence) {
throw new InvalidRecurrenceTypeException; throw new InvalidRecurrenceTypeException();
} }
UserDishRecurrence::query() UserDishRecurrence::query()

View file

@ -32,9 +32,9 @@ public function execute(UserDish $userDish, Collection $recurrences): UserDish
} }
match ($recurrenceType) { match ($recurrenceType) {
WeeklyRecurrence::class => (new CreateFixedRecurrenceAction)->execute($userDish, $recurrenceType, $recurrenceValue), WeeklyRecurrence::class => (new CreateFixedRecurrenceAction())->execute($userDish, $recurrenceType, $recurrenceValue),
MinimumRecurrence::class => (new CreateMinimumRecurrenceAction)->execute($userDish, $recurrenceType, $recurrenceValue), MinimumRecurrence::class => (new CreateMinimumRecurrenceAction())->execute($userDish, $recurrenceType, $recurrenceValue),
default => throw new InvalidRecurrenceTypeException, default => throw new InvalidRecurrenceTypeException(),
}; };
}); });

View file

@ -15,7 +15,7 @@ class UpdateFixedRecurrenceAction
public function execute(RecurrenceInterface $recurrence, array $data): RecurrenceInterface public function execute(RecurrenceInterface $recurrence, array $data): RecurrenceInterface
{ {
if (! $recurrence instanceof WeeklyRecurrence) { if (! $recurrence instanceof WeeklyRecurrence) {
throw new InvalidRecurrenceTypeException; throw new InvalidRecurrenceTypeException();
} }
$weekday = Arr::get($data, 'recurrence_data.weekday'); $weekday = Arr::get($data, 'recurrence_data.weekday');

View file

@ -15,7 +15,7 @@ class UpdateMinimumRecurrenceAction
public function execute(RecurrenceInterface $recurrence, array $data): RecurrenceInterface public function execute(RecurrenceInterface $recurrence, array $data): RecurrenceInterface
{ {
if (! $recurrence instanceof MinimumRecurrence) { if (! $recurrence instanceof MinimumRecurrence) {
throw new InvalidRecurrenceTypeException; throw new InvalidRecurrenceTypeException();
} }
$days = Arr::get($data, 'recurrence_data.days'); $days = Arr::get($data, 'recurrence_data.days');

View file

@ -20,7 +20,7 @@ public function __invoke(Request $request)
$userDishes = $userDishRepository->getAllForPlanner($planner); $userDishes = $userDishRepository->getAllForPlanner($planner);
return $this->success([ return $this->success([
'user_dishes' => UserDishResource::collection($userDishes)->collection->toArray(), 'user_dishes' => UserDishResource::collection($userDishes)->collection->toArray()
]); ]);
} }
} }

View file

@ -48,7 +48,7 @@ public function show(User $user, Dish $dish): JsonResponse
*/ */
public function store(CreateUserDishRequest $request, User $user, Dish $dish): JsonResponse public function store(CreateUserDishRequest $request, User $user, Dish $dish): JsonResponse
{ {
$userDish = (new CreateUserDishAction)->execute($dish, $user, $request->validated()); $userDish = (new CreateUserDishAction())->execute($dish, $user, $request->validated());
return $this->success([ return $this->success([
'user_dish' => new UserDishResource($userDish), 'user_dish' => new UserDishResource($userDish),
@ -57,7 +57,7 @@ public function store(CreateUserDishRequest $request, User $user, Dish $dish): J
public function destroy(User $user, Dish $dish): JsonResponse public function destroy(User $user, Dish $dish): JsonResponse
{ {
(new DeleteUserDishAction)->execute($user, $dish); (new DeleteUserDishAction())->execute($user, $dish);
return $this->success(null); return $this->success(null);
} }

View file

@ -35,7 +35,7 @@ public function store(StoreUserDishRecurrenceRequest $request, User $user, Dish
$recurrences = collect($request->validated()); $recurrences = collect($request->validated());
(new SyncRecurrencesForUserDishAction)->execute($userDish, $recurrences); (new SyncRecurrencesForUserDishAction())->execute($userDish, $recurrences);
return $this->success([ return $this->success([
'user_dish' => new UserDishResource($userDish->refresh()), 'user_dish' => new UserDishResource($userDish->refresh()),
@ -51,9 +51,9 @@ public function update(UpdateUserDishFixedRecurrenceRequest $request, UserDish $
$recurrence = $recurrenceClass::findOrFail($recurrenceId); $recurrence = $recurrenceClass::findOrFail($recurrenceId);
if ($recurrence instanceof WeeklyRecurrence) { if ($recurrence instanceof WeeklyRecurrence) {
(new UpdateFixedRecurrenceAction)->execute($recurrence, $request->validated()); (new UpdateFixedRecurrenceAction())->execute($recurrence, $request->validated());
} elseif ($recurrenceClass === MinimumRecurrence::class) { } elseif ($recurrenceClass === MinimumRecurrence::class) {
(new UpdateMinimumRecurrenceAction)->execute($recurrence, $request->validated()); (new UpdateMinimumRecurrenceAction())->execute($recurrence, $request->validated());
} else { } else {
return $this->error('invalid recurrence type'); return $this->error('invalid recurrence type');
} }
@ -72,9 +72,9 @@ public function destroy(UserDish $userDish, string $recurrenceType, int $recurre
$recurrence = $recurrenceClass::findOrFail($recurrenceId); $recurrence = $recurrenceClass::findOrFail($recurrenceId);
if ($recurrence instanceof WeeklyRecurrence) { if ($recurrence instanceof WeeklyRecurrence) {
(new DeleteFixedRecurrenceAction)->execute($recurrence); (new DeleteFixedRecurrenceAction())->execute($recurrence);
} elseif ($recurrenceClass === MinimumRecurrence::class) { } elseif ($recurrenceClass === MinimumRecurrence::class) {
(new DeleteMinimumRecurrenceAction)->execute($recurrence); (new DeleteMinimumRecurrenceAction())->execute($recurrence);
} else { } else {
return $this->error('invalid recurrence type'); return $this->error('invalid recurrence type');
} }

View file

@ -2,4 +2,5 @@
namespace DishPlanner\UserDish\Interfaces; namespace DishPlanner\UserDish\Interfaces;
interface FixedRecurrenceInterface {} interface FixedRecurrenceInterface
{}

View file

@ -2,4 +2,5 @@
namespace DishPlanner\UserDish\Interfaces; namespace DishPlanner\UserDish\Interfaces;
interface RecurrenceInterface {} interface RecurrenceInterface
{}

View file

@ -12,6 +12,7 @@
use App\Models\WeeklyRecurrence; use App\Models\WeeklyRecurrence;
use Carbon\Carbon; use Carbon\Carbon;
use Carbon\CarbonPeriod; use Carbon\CarbonPeriod;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Collection as SupportCollection; use Illuminate\Support\Collection as SupportCollection;
@ -69,7 +70,7 @@ public function findInterferingUserDishes(User $user, Carbon $date): Collection
->get() ->get()
->flatMap(fn (Schedule $schedule) => $schedule->scheduledUserDishes) ->flatMap(fn (Schedule $schedule) => $schedule->scheduledUserDishes)
->filter(fn (ScheduledUserDish $scheduledUserDish) => $scheduledUserDish->userDish->user_id === $user->id) ->filter(fn (ScheduledUserDish $scheduledUserDish) => $scheduledUserDish->userDish->user_id === $user->id)
->filter(fn (ScheduledUserDish $scheduledUserDish) => $scheduledUserDish->userDish->recurrences->contains('recurrence_type', MinimumRecurrence::class)) ->filter(fn(ScheduledUserDish $scheduledUserDish) => $scheduledUserDish->userDish->recurrences->contains('recurrence_type', MinimumRecurrence::class))
->filter(function (ScheduledUserDish $scheduledUserDish) use ($date) { ->filter(function (ScheduledUserDish $scheduledUserDish) use ($date) {
$minimum = $scheduledUserDish->userDish $minimum = $scheduledUserDish->userDish
->recurrences ->recurrences

View file

@ -19,7 +19,7 @@ public function rules(): array
MinimumRecurrence::class, MinimumRecurrence::class,
WeeklyRecurrence::class, WeeklyRecurrence::class,
]), ]),
'required_with:*.recurrence_value', 'required_with:*.recurrence_value'
], ],
'*.value' => ['sometimes', 'integer', 'required_with:*.recurrence_type'], '*.value' => ['sometimes', 'integer', 'required_with:*.recurrence_type'],
]; ];

View file

@ -14,14 +14,14 @@ public function rules(): array
'recurrence_type' => [ 'recurrence_type' => [
'required', 'required',
'string', 'string',
'in:'.implode(',', [ 'in:' . implode(',', [
MinimumRecurrence::class, MinimumRecurrence::class,
WeeklyRecurrence::class, WeeklyRecurrence::class,
]), ]),
], ],
'recurrence_data' => 'required|array', 'recurrence_data' => 'required|array',
'recurrence_data.days' => 'required_if:recurrence_type,'.MinimumRecurrence::class.'|integer|min:1', 'recurrence_data.days' => 'required_if:recurrence_type,' . MinimumRecurrence::class . '|integer|min:1',
'recurrence_data.weekday' => 'required_if:recurrence_type,'.WeeklyRecurrence::class.'|integer|between:0,6', 'recurrence_data.weekday' => 'required_if:recurrence_type,' . WeeklyRecurrence::class . '|integer|between:0,6',
]; ];
} }

View file

@ -2,17 +2,15 @@
namespace Tests\Browser\Auth; namespace Tests\Browser\Auth;
use App\Models\Planner;
use Illuminate\Support\Facades\Hash;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\DuskTestCase; use Tests\DuskTestCase;
use App\Models\Planner;
use Illuminate\Support\Facades\Hash;
class LoginTest extends DuskTestCase class LoginTest extends DuskTestCase
{ {
protected static $testPlanner = null; protected static $testPlanner = null;
protected static $testEmail = null; protected static $testEmail = null;
protected static $testPassword = 'password'; protected static $testPassword = 'password';
protected function ensureTestPlannerExists(): void protected function ensureTestPlannerExists(): void
@ -28,7 +26,7 @@ protected function ensureTestPlannerExists(): void
} }
} }
public function test_successful_login(): void public function testSuccessfulLogin(): void
{ {
$this->ensureTestPlannerExists(); $this->ensureTestPlannerExists();
@ -46,7 +44,7 @@ public function test_successful_login(): void
}); });
} }
public function test_login_with_wrong_credentials(): void public function testLoginWithWrongCredentials(): void
{ {
$this->ensureTestPlannerExists(); $this->ensureTestPlannerExists();
@ -65,7 +63,7 @@ public function test_login_with_wrong_credentials(): void
}); });
} }
public function test_login_form_required_fields(): void public function testLoginFormRequiredFields(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$browser->driver->manage()->deleteAllCookies(); $browser->driver->manage()->deleteAllCookies();

View file

@ -3,17 +3,16 @@
namespace Tests\Browser\Dishes; namespace Tests\Browser\Dishes;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use Tests\Browser\Pages\DishesPage;
use Tests\Browser\Components\DishModal; use Tests\Browser\Components\DishModal;
use Tests\Browser\LoginHelpers; use Tests\Browser\LoginHelpers;
use Tests\Browser\Pages\DishesPage;
use Tests\DuskTestCase;
class CreateDishFormValidationTest extends DuskTestCase class CreateDishFormValidationTest extends DuskTestCase
{ {
use LoginHelpers; use LoginHelpers;
protected static $createDishFormValidationTestPlanner = null; protected static $createDishFormValidationTestPlanner = null;
protected static $createDishFormValidationTestEmail = null; protected static $createDishFormValidationTestEmail = null;
protected function setUp(): void protected function setUp(): void
@ -32,7 +31,7 @@ protected function tearDown(): void
parent::tearDown(); parent::tearDown();
} }
public function test_create_dish_form_validation(): void public function testCreateDishFormValidation(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToDishes($browser); $this->loginAndGoToDishes($browser);

View file

@ -3,17 +3,16 @@
namespace Tests\Browser\Dishes; namespace Tests\Browser\Dishes;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use Tests\Browser\Pages\DishesPage;
use Tests\Browser\Components\DishModal; use Tests\Browser\Components\DishModal;
use Tests\Browser\LoginHelpers; use Tests\Browser\LoginHelpers;
use Tests\Browser\Pages\DishesPage;
use Tests\DuskTestCase;
class CreateDishSuccessTest extends DuskTestCase class CreateDishSuccessTest extends DuskTestCase
{ {
use LoginHelpers; use LoginHelpers;
protected static $createDishSuccessTestPlanner = null; protected static $createDishSuccessTestPlanner = null;
protected static $createDishSuccessTestEmail = null; protected static $createDishSuccessTestEmail = null;
protected function setUp(): void protected function setUp(): void
@ -32,10 +31,10 @@ protected function tearDown(): void
parent::tearDown(); parent::tearDown();
} }
public function test_can_create_dish_successfully(): void public function testCanCreateDishSuccessfully(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$dishName = 'Test Dish '.uniqid(); $dishName = 'Test Dish ' . uniqid();
$this->loginAndGoToDishes($browser); $this->loginAndGoToDishes($browser);

View file

@ -3,16 +3,16 @@
namespace Tests\Browser\Dishes; namespace Tests\Browser\Dishes;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\Browser\LoginHelpers;
use Tests\Browser\Pages\DishesPage;
use Tests\DuskTestCase; use Tests\DuskTestCase;
use Tests\Browser\Pages\DishesPage;
use Tests\Browser\Components\DishModal;
use Tests\Browser\LoginHelpers;
class CreateDishTest extends DuskTestCase class CreateDishTest extends DuskTestCase
{ {
use LoginHelpers; use LoginHelpers;
protected static $createDishTestPlanner = null; protected static $createDishTestPlanner = null;
protected static $createDishTestEmail = null; protected static $createDishTestEmail = null;
protected function setUp(): void protected function setUp(): void
@ -31,7 +31,7 @@ protected function tearDown(): void
parent::tearDown(); parent::tearDown();
} }
public function test_can_access_dishes_page(): void public function testCanAccessDishesPage(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToDishes($browser); $this->loginAndGoToDishes($browser);

View file

@ -2,17 +2,16 @@
namespace Tests\Browser\Dishes; namespace Tests\Browser\Dishes;
use App\Models\Planner;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\Browser\LoginHelpers;
use Tests\DuskTestCase; use Tests\DuskTestCase;
use Tests\Browser\LoginHelpers;
use App\Models\Planner;
class DeleteDishTest extends DuskTestCase class DeleteDishTest extends DuskTestCase
{ {
use LoginHelpers; use LoginHelpers;
protected static $deleteDishTestPlanner = null; protected static $deleteDishTestPlanner = null;
protected static $deleteDishTestEmail = null; protected static $deleteDishTestEmail = null;
protected function setUp(): void protected function setUp(): void
@ -31,7 +30,7 @@ protected function tearDown(): void
parent::tearDown(); parent::tearDown();
} }
public function test_can_access_delete_feature(): void public function testCanAccessDeleteFeature(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToDishes($browser) $this->loginAndGoToDishes($browser)

View file

@ -3,15 +3,14 @@
namespace Tests\Browser\Dishes; namespace Tests\Browser\Dishes;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\Browser\LoginHelpers;
use Tests\DuskTestCase; use Tests\DuskTestCase;
use Tests\Browser\LoginHelpers;
class DishDeletionSafetyTest extends DuskTestCase class DishDeletionSafetyTest extends DuskTestCase
{ {
use LoginHelpers; use LoginHelpers;
protected static $dishDeletionSafetyTestPlanner = null; protected static $dishDeletionSafetyTestPlanner = null;
protected static $dishDeletionSafetyTestEmail = null; protected static $dishDeletionSafetyTestEmail = null;
protected function setUp(): void protected function setUp(): void
@ -30,7 +29,7 @@ protected function tearDown(): void
parent::tearDown(); parent::tearDown();
} }
public function test_deletion_safety_features(): void public function testDeletionSafetyFeatures(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToDishes($browser); $this->loginAndGoToDishes($browser);

View file

@ -2,17 +2,16 @@
namespace Tests\Browser\Dishes; namespace Tests\Browser\Dishes;
use App\Models\Planner;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\Browser\LoginHelpers;
use Tests\DuskTestCase; use Tests\DuskTestCase;
use Tests\Browser\LoginHelpers;
use App\Models\Planner;
class EditDishTest extends DuskTestCase class EditDishTest extends DuskTestCase
{ {
use LoginHelpers; use LoginHelpers;
protected static $editDishTestPlanner = null; protected static $editDishTestPlanner = null;
protected static $editDishTestEmail = null; protected static $editDishTestEmail = null;
protected function setUp(): void protected function setUp(): void
@ -31,7 +30,7 @@ protected function tearDown(): void
parent::tearDown(); parent::tearDown();
} }
public function test_can_access_edit_feature(): void public function testCanAccessEditFeature(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToDishes($browser) $this->loginAndGoToDishes($browser)
@ -44,7 +43,7 @@ public function test_can_access_edit_feature(): void
}); });
} }
public function test_edit_modal_components(): void public function testEditModalComponents(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToDishes($browser) $this->loginAndGoToDishes($browser)
@ -53,7 +52,7 @@ public function test_edit_modal_components(): void
}); });
} }
public function test_dishes_page_structure(): void public function testDishesPageStructure(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToDishes($browser) $this->loginAndGoToDishes($browser)

View file

@ -2,29 +2,25 @@
namespace Tests\Browser; namespace Tests\Browser;
use App\Models\Planner;
use Illuminate\Support\Facades\Hash;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\DuskTestCase; use Tests\DuskTestCase;
trait LoginHelpers trait LoginHelpers
{ {
protected static $testPlanner = null; protected static $testPlanner = null;
protected static $testEmail = null; protected static $testEmail = null;
protected static $testPassword = 'password'; protected static $testPassword = 'password';
protected function ensureTestPlannerExists(): void protected function ensureTestPlannerExists(): void
{ {
// Always create a fresh planner for each test class to avoid session conflicts // Always create a fresh planner for each test class to avoid session conflicts
if (self::$testPlanner === null || ! self::$testPlanner->exists) { if (self::$testPlanner === null || !self::$testPlanner->exists) {
// Generate unique email for this test run // Generate unique email for this test run
self::$testEmail = fake()->unique()->safeEmail(); self::$testEmail = fake()->unique()->safeEmail();
self::$testPlanner = Planner::factory()->create([ self::$testPlanner = \App\Models\Planner::factory()->create([
'email' => self::$testEmail, 'email' => self::$testEmail,
'password' => Hash::make(self::$testPassword), 'password' => \Illuminate\Support\Facades\Hash::make(self::$testPassword),
]); ]);
} }
} }
@ -45,7 +41,7 @@ protected function loginAndNavigate(Browser $browser, string $page = '/dashboard
->press('Sign In') ->press('Sign In')
->waitForLocation('/dashboard', DuskTestCase::TIMEOUT_MEDIUM) // Wait for successful login redirect ->waitForLocation('/dashboard', DuskTestCase::TIMEOUT_MEDIUM) // Wait for successful login redirect
->pause(DuskTestCase::PAUSE_SHORT) // Brief pause for any initialization ->pause(DuskTestCase::PAUSE_SHORT) // Brief pause for any initialization
->visit('http://dishplanner_app:8000'.$page) ->visit('http://dishplanner_app:8000' . $page)
->pause(DuskTestCase::PAUSE_MEDIUM); // Let Livewire components initialize ->pause(DuskTestCase::PAUSE_MEDIUM); // Let Livewire components initialize
} }

View file

@ -84,7 +84,7 @@ public function selectUser(Browser $browser, string $userName): void
$browser->check("input[type='checkbox'][value]", $userName); $browser->check("input[type='checkbox'][value]", $userName);
} }
public function assertSuccessMessage(Browser $browser, ?string $message = null): void public function assertSuccessMessage(Browser $browser, string $message = null): void
{ {
if ($message) { if ($message) {
$browser->assertSee($message); $browser->assertSee($message);

View file

@ -2,9 +2,9 @@
namespace Tests\Browser; namespace Tests\Browser;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\DuskTestCase; use Tests\DuskTestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class RedirectTest extends DuskTestCase class RedirectTest extends DuskTestCase
{ {
@ -13,7 +13,7 @@ class RedirectTest extends DuskTestCase
/** /**
* Test that unauthenticated users are redirected to login * Test that unauthenticated users are redirected to login
*/ */
public function test_unauthenticated_redirects_to_login() public function testUnauthenticatedRedirectsToLogin()
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$browser->visit('http://dishplanner_app:8000/dashboard') $browser->visit('http://dishplanner_app:8000/dashboard')
@ -25,7 +25,7 @@ public function test_unauthenticated_redirects_to_login()
/** /**
* Test that login page loads correctly * Test that login page loads correctly
*/ */
public function test_login_page_loads() public function testLoginPageLoads()
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$browser->visit('http://dishplanner_app:8000/login') $browser->visit('http://dishplanner_app:8000/login')

View file

@ -7,19 +7,15 @@
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\Browser\Pages\SchedulePage;
use Tests\DuskTestCase; use Tests\DuskTestCase;
use Tests\Browser\Pages\SchedulePage;
class GenerateScheduleTest extends DuskTestCase class GenerateScheduleTest extends DuskTestCase
{ {
protected static $planner = null; protected static $planner = null;
protected static $email = null; protected static $email = null;
protected static $password = 'password'; protected static $password = 'password';
protected static $user = null; protected static $user = null;
protected static $dish = null; protected static $dish = null;
protected function setUp(): void protected function setUp(): void
@ -68,7 +64,7 @@ protected function loginAsPlanner(Browser $browser): Browser
->pause(DuskTestCase::PAUSE_MEDIUM); ->pause(DuskTestCase::PAUSE_MEDIUM);
} }
public function test_can_generate_schedule_with_user_and_dish(): void public function testCanGenerateScheduleWithUserAndDish(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAsPlanner($browser); $this->loginAsPlanner($browser);
@ -82,7 +78,7 @@ public function test_can_generate_schedule_with_user_and_dish(): void
}); });
} }
public function test_generated_schedule_shows_dish_on_calendar(): void public function testGeneratedScheduleShowsDishOnCalendar(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAsPlanner($browser); $this->loginAsPlanner($browser);
@ -95,7 +91,7 @@ public function test_generated_schedule_shows_dish_on_calendar(): void
}); });
} }
public function test_can_clear_month_schedule(): void public function testCanClearMonthSchedule(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAsPlanner($browser); $this->loginAsPlanner($browser);
@ -113,7 +109,7 @@ public function test_can_clear_month_schedule(): void
}); });
} }
public function test_user_selection_affects_generation(): void public function testUserSelectionAffectsGeneration(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAsPlanner($browser); $this->loginAsPlanner($browser);
@ -122,7 +118,7 @@ public function test_user_selection_affects_generation(): void
// Verify the user checkbox is present // Verify the user checkbox is present
->assertSee('Test User') ->assertSee('Test User')
// User should be selected by default // User should be selected by default
->assertChecked("input[value='".self::$user->id."']"); ->assertChecked("input[value='" . self::$user->id . "']");
}); });
} }
} }

View file

@ -3,16 +3,15 @@
namespace Tests\Browser\Schedule; namespace Tests\Browser\Schedule;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\Browser\LoginHelpers;
use Tests\Browser\Pages\SchedulePage;
use Tests\DuskTestCase; use Tests\DuskTestCase;
use Tests\Browser\Pages\SchedulePage;
use Tests\Browser\LoginHelpers;
class SchedulePageTest extends DuskTestCase class SchedulePageTest extends DuskTestCase
{ {
use LoginHelpers; use LoginHelpers;
protected static $schedulePageTestPlanner = null; protected static $schedulePageTestPlanner = null;
protected static $schedulePageTestEmail = null; protected static $schedulePageTestEmail = null;
protected function setUp(): void protected function setUp(): void
@ -29,7 +28,7 @@ protected function tearDown(): void
parent::tearDown(); parent::tearDown();
} }
public function test_can_access_schedule_page(): void public function testCanAccessSchedulePage(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToSchedule($browser); $this->loginAndGoToSchedule($browser);
@ -40,7 +39,7 @@ public function test_can_access_schedule_page(): void
}); });
} }
public function test_schedule_page_has_month_navigation(): void public function testSchedulePageHasMonthNavigation(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToSchedule($browser); $this->loginAndGoToSchedule($browser);
@ -52,7 +51,7 @@ public function test_schedule_page_has_month_navigation(): void
}); });
} }
public function test_can_navigate_to_next_month(): void public function testCanNavigateToNextMonth(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToSchedule($browser); $this->loginAndGoToSchedule($browser);
@ -65,7 +64,7 @@ public function test_can_navigate_to_next_month(): void
}); });
} }
public function test_can_navigate_to_previous_month(): void public function testCanNavigateToPreviousMonth(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToSchedule($browser); $this->loginAndGoToSchedule($browser);
@ -78,7 +77,7 @@ public function test_can_navigate_to_previous_month(): void
}); });
} }
public function test_schedule_generator_shows_user_selection(): void public function testScheduleGeneratorShowsUserSelection(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToSchedule($browser); $this->loginAndGoToSchedule($browser);
@ -90,7 +89,7 @@ public function test_schedule_generator_shows_user_selection(): void
}); });
} }
public function test_calendar_displays_days_of_week(): void public function testCalendarDisplaysDaysOfWeek(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToSchedule($browser); $this->loginAndGoToSchedule($browser);

View file

@ -3,16 +3,15 @@
namespace Tests\Browser\Users; namespace Tests\Browser\Users;
use Laravel\Dusk\Browser; use Laravel\Dusk\Browser;
use Tests\Browser\LoginHelpers;
use Tests\Browser\Pages\UsersPage;
use Tests\DuskTestCase; use Tests\DuskTestCase;
use Tests\Browser\Pages\UsersPage;
use Tests\Browser\LoginHelpers;
class CreateUserTest extends DuskTestCase class CreateUserTest extends DuskTestCase
{ {
use LoginHelpers; use LoginHelpers;
protected static $createUserTestPlanner = null; protected static $createUserTestPlanner = null;
protected static $createUserTestEmail = null; protected static $createUserTestEmail = null;
protected function setUp(): void protected function setUp(): void
@ -31,7 +30,7 @@ protected function tearDown(): void
parent::tearDown(); parent::tearDown();
} }
public function test_can_access_users_page(): void public function testCanAccessUsersPage(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToUsers($browser); $this->loginAndGoToUsers($browser);
@ -42,7 +41,7 @@ public function test_can_access_users_page(): void
}); });
} }
public function test_can_open_create_user_modal(): void public function testCanOpenCreateUserModal(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToUsers($browser); $this->loginAndGoToUsers($browser);
@ -56,7 +55,7 @@ public function test_can_open_create_user_modal(): void
}); });
} }
public function test_create_user_form_validation(): void public function testCreateUserFormValidation(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToUsers($browser); $this->loginAndGoToUsers($browser);
@ -69,10 +68,10 @@ public function test_create_user_form_validation(): void
}); });
} }
public function test_can_create_user(): void public function testCanCreateUser(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$userName = 'TestCreate_'.uniqid(); $userName = 'TestCreate_' . uniqid();
$this->loginAndGoToUsers($browser); $this->loginAndGoToUsers($browser);
@ -86,7 +85,7 @@ public function test_can_create_user(): void
}); });
} }
public function test_can_cancel_user_creation(): void public function testCanCancelUserCreation(): void
{ {
$this->browse(function (Browser $browser) { $this->browse(function (Browser $browser) {
$this->loginAndGoToUsers($browser); $this->loginAndGoToUsers($browser);

View file

@ -5,6 +5,7 @@
use Facebook\WebDriver\Chrome\ChromeOptions; use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities; use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\RemoteWebDriver;
use Illuminate\Support\Collection;
use Laravel\Dusk\TestCase as BaseTestCase; use Laravel\Dusk\TestCase as BaseTestCase;
use PHPUnit\Framework\Attributes\BeforeClass; use PHPUnit\Framework\Attributes\BeforeClass;
@ -12,11 +13,8 @@ abstract class DuskTestCase extends BaseTestCase
{ {
// Timeout constants for consistent timing across all Dusk tests // Timeout constants for consistent timing across all Dusk tests
public const TIMEOUT_SHORT = 2; // 2 seconds max for most operations public const TIMEOUT_SHORT = 2; // 2 seconds max for most operations
public const TIMEOUT_MEDIUM = 3; // 3 seconds for slower operations public const TIMEOUT_MEDIUM = 3; // 3 seconds for slower operations
public const PAUSE_SHORT = 500; // 0.5 seconds for quick pauses public const PAUSE_SHORT = 500; // 0.5 seconds for quick pauses
public const PAUSE_MEDIUM = 1000; // 1 second for medium pauses public const PAUSE_MEDIUM = 1000; // 1 second for medium pauses
/** /**

View file

@ -2,10 +2,10 @@
namespace Tests\Feature; namespace Tests\Feature;
use App\Models\Planner;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken; use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase; use Tests\TestCase;
use App\Models\Planner;
use Illuminate\Foundation\Testing\RefreshDatabase;
class AuthenticationTest extends TestCase class AuthenticationTest extends TestCase
{ {
@ -61,6 +61,10 @@ public function test_session_is_created_on_login_page(): void
// Check if CSRF token is generated // Check if CSRF token is generated
$this->assertNotNull(csrf_token()); $this->assertNotNull(csrf_token());
// Check session driver
$sessionDriver = config('session.driver');
$this->assertNotEquals('array', $sessionDriver, 'Session driver should not be array for authentication');
$response->assertStatus(200); $response->assertStatus(200);
$response->assertSessionHasNoErrors(); $response->assertSessionHasNoErrors();
} }

View file

@ -3,6 +3,7 @@
namespace Tests\Feature\Dish; namespace Tests\Feature\Dish;
use App\Models\Dish; use App\Models\Dish;
use App\Models\Planner;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Testing\Fluent\AssertableJson; use Illuminate\Testing\Fluent\AssertableJson;

View file

@ -64,6 +64,7 @@ public function test_it_deletes_user_dishes_when_deleting_a_dish(): void
$this->assertDatabaseEmpty(UserDish::class); $this->assertDatabaseEmpty(UserDish::class);
} }
public function test_planner_cannot_delete_dish_from_other_planner(): void public function test_planner_cannot_delete_dish_from_other_planner(): void
{ {
$planner = $this->planner; $planner = $this->planner;

View file

@ -2,9 +2,9 @@
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase;
use App\Models\Planner; use App\Models\Planner;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class RegistrationTest extends TestCase class RegistrationTest extends TestCase
{ {

View file

@ -3,11 +3,12 @@
namespace Tests\Feature\Schedule; namespace Tests\Feature\Schedule;
use App\Models\Dish; use App\Models\Dish;
use App\Models\Planner;
use App\Models\UserDish;
use App\Models\UserDishRecurrence;
use App\Models\Schedule; use App\Models\Schedule;
use App\Models\ScheduledUserDish; use App\Models\ScheduledUserDish;
use App\Models\User; use App\Models\User;
use App\Models\UserDish;
use App\Models\UserDishRecurrence;
use App\Models\WeeklyRecurrence; use App\Models\WeeklyRecurrence;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
@ -114,7 +115,6 @@ public function test_fresh_schedule_adheres_to_fixed_recurrences(): void
$this->assertContains($targetUserDish->id, $targetScheduledUserDishes); $this->assertContains($targetUserDish->id, $targetScheduledUserDishes);
} }
public function test_schedule_can_be_overwritten(): void public function test_schedule_can_be_overwritten(): void
{ {
$planner = $this->planner; $planner = $this->planner;
@ -132,7 +132,8 @@ public function test_schedule_can_be_overwritten(): void
}); });
// Assert that every user has `UserDish` records // Assert that every user has `UserDish` records
$users->each(fn (User $user) => $this->assertNotEmpty($user->refresh()->userDishes) $users->each(fn (User $user) =>
$this->assertNotEmpty($user->refresh()->userDishes)
); );
$scheduleDay = Schedule::factory() $scheduleDay = Schedule::factory()
@ -171,7 +172,7 @@ public function test_schedule_can_be_overwritten(): void
$this->assertDatabaseCount(Schedule::class, 14); $this->assertDatabaseCount(Schedule::class, 14);
$freshScheduleDay = Schedule::query()->whereDate('date', $scheduleDay->date)->first(); $freshScheduleDay = Schedule::query()->where('date', $scheduleDay->date)->first();
$this->assertNotEquals( $this->assertNotEquals(
$originalUserDishes, $originalUserDishes,
$freshScheduleDay->scheduledUserDishes->map(fn (ScheduledUserDish $scheduledUserDish) => [ $freshScheduleDay->scheduledUserDishes->map(fn (ScheduledUserDish $scheduledUserDish) => [
@ -234,6 +235,7 @@ public function test_fixed_recurrence_takes_precedence_during_overwrite(): void
$this->assertDatabaseCount(Schedule::class, 1); $this->assertDatabaseCount(Schedule::class, 1);
$this->assertDatabaseCount(ScheduledUserDish::class, 2); $this->assertDatabaseCount(ScheduledUserDish::class, 2);
$this $this
->actingAs($planner) ->actingAs($planner)
->post(route('api.schedule.generate'), [ ->post(route('api.schedule.generate'), [

Some files were not shown because too many files have changed in this diff Show more