Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copilot instructions for this repository

Preferred behavior for running backend tests and quality checks:

- Always run backend tests and QA inside the docker-compose "app" service so environment, PHP extensions and dependencies match the container.
- Prefer using the Makefile targets which already invoke the app service. Examples:
- make test # runs phpunit inside the app container
- make quality # runs composer qa inside the app container

If running commands directly inside the container, run non-interactively (no -it) to avoid TTY allocation issues:

- docker compose exec -T app bin/phpunit
- docker compose exec -T app composer qa
- docker compose exec -T app vendor/bin/phpstan analyse --memory-limit=1G
- docker compose exec -T app vendor/bin/php-cs-fixer fix
- docker compose exec -T app vendor/bin/deptrac analyse --report-uncovered

Guidelines for Copilot CLI usage in this repo:

- When asked to run tests or QA, prefer the Makefile targets (make test, make quality) executed in the repository root.
- If running inside a container is required, always target the "app" service and use `-T` for exec to run non-interactively.
- When proposing automation or CI commands, include explicit container commands using the "app" service so they work in the project's docker-compose setup.

These instructions ensure consistent, reproducible test and QA runs by using the project's containerized environment.
46 changes: 46 additions & 0 deletions backend/tests/Unit/SplitFairly/ExpenseTrackerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace App\Tests\Unit\SplitFairly;

use App\SplitFairly\CurrentUserInterface;
use App\SplitFairly\Event;
use App\SplitFairly\EventStoreInterface;
use App\SplitFairly\Expense;
use App\SplitFairly\ExpenseTracker;
use App\SplitFairly\NormalizerInterface;
use App\SplitFairly\Price;
use PHPUnit\Framework\TestCase;

final class ExpenseTrackerTest extends TestCase
{
public function test_tracks_expense_and_persists_event(): void
{
$price = new Price(value: 10.50, currency: 'EUR');
$expense = new Expense(price: $price, what: 'Coffee', type: 'Groceries', location: 'Starbucks');

$currentUser = $this->createMock(CurrentUserInterface::class);
$currentUser->method('getUuid')->willReturn('user-123');

$normalizedPayload = ['price' => (string) $price, 'what' => 'Coffee', 'type' => 'Groceries', 'location' => 'Starbucks'];
$normalizer = $this->createMock(NormalizerInterface::class);
$normalizer->expects($this->once())->method('toArray')->with($expense, ['id'])->willReturn($normalizedPayload);

$eventStore = $this->createMock(EventStoreInterface::class);
$eventStore->expects($this->once())->method('persist')->with(
$this->callback(function (Event $event) use ($expense, $normalizedPayload): bool {
return 'user-123' === $event->createdBy
&& 'Expense' === $event->subjectType
&& $event->subjectId === $expense->getId()->toRfc4122()
&& 'tracked' === $event->eventType
&& $event->payload === $normalizedPayload;
}),
false
);

$tracker = new ExpenseTracker($eventStore, $normalizer, $currentUser);

$tracker->track($expense);
}
}
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Limit Codecov reports to the SplitFairly namespace
coverage:
status:
project:
default:
target: 0
precision: 2
round: down
reports:
- name: SplitFairly
paths:
- backend/src/SplitFairly
# Only show this report on the Codecov UI
# see https://docs.codecov.com/docs/codecov-yaml#section-reports
5 changes: 5 additions & 0 deletions dashboard/assets/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ services:
icon: "fa-brands fa-github"
url: "https://github.com/makomweb/split-fairly"
target: "_blank"
- name: "Code coverage"
subtitle: "PHPUnit coverage"
icon: "fa-solid fa-clipboard-check"
url: "http://localhost:8000/coverage/index.html"
target: "_blank"
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ services:
volumes:
- ./dashboard/assets:/www/assets
- ./backend/report:/www/public/report
- ./backend/coverage:/www/public/coverage
- ./backend/coverage:/www/coverage
ports:
- "8000:8080"
user: "1000:1001"
Expand Down