Implements PLAN.md §8's fourth makers-table row. Read-models are
server-side projections — joined fetches, aggregates, denormalised
views — that QML reads without going through a writable
#[BridgeResource]. The maker emits:
- src/ReadModel/<Name>ReadModel.php — query service stub injecting
EntityManagerInterface; user fills query() with DQL / QueryBuilder
/ raw SQL as fits.
- src/Controller/<Name>Controller.php — single GET handler at
/api/<kebab-plural>, just normalises the read-model output to JSON.
- {qml_path}/<Name>List.qml — ReactiveListModel bound to the route,
deliberately no Mercure topic.
The "no topic" choice is the design call worth documenting: read-models
are queries, not reactive resources, and pretending otherwise would
either auto-publish stale aggregates on every entity change or require
the user to invent invalidation logic in the listener. Better: pair
the read-model with `make:bridge:event` and call refresh() from the
QML event-handler when the underlying data really changes.
Naming convention: kebab-PLURAL routes (`/api/todo-summaries`) for
consistency with REST list semantics; resource path stays singular
under `src/ReadModel/`.
Wired into services.yaml's when@dev block. Three new snapshot
baselines (TodoSummaryReadModel.php / TodoSummaryController.php /
TodoSummaryList.qml) plus runner extension. All 14 maker outputs
verify on the committed state.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
87 lines
4.1 KiB
Bash
Executable File
87 lines
4.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Maker-output snapshot test.
|
|
# Runs the three Phase-2/Phase-3 makers in a clean temp app and diffs
|
|
# the output against the baselines in this directory. Detects silent
|
|
# generator drift: any change to a maker template requires the
|
|
# corresponding baseline to be updated in the same commit.
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
|
BUNDLE="$PROJECT_ROOT/framework/php"
|
|
WORK="$(mktemp -d)"
|
|
|
|
trap 'rm -rf "$WORK"' EXIT INT TERM
|
|
|
|
# Mirror the skeleton's tracked files into the temp dir.
|
|
git -C "$PROJECT_ROOT" archive HEAD framework/skeleton/ | tar -xf - -C "$WORK"
|
|
APP="$WORK/framework/skeleton"
|
|
|
|
# Point the test app's path repo at the actual bundle dir (the
|
|
# default '../../php' would resolve relative to /tmp).
|
|
sed -i "s|\"../../php\"|\"$BUNDLE\"|" "$APP/symfony/composer.json"
|
|
rm -f "$APP/symfony/composer.lock"
|
|
( cd "$APP/symfony" && composer install --no-interaction --quiet )
|
|
|
|
fail=0
|
|
check() {
|
|
local generated="$1"
|
|
local baseline="$2"
|
|
if ! diff -q "$generated" "$baseline" >/dev/null 2>&1; then
|
|
echo "✗ snapshot mismatch: $(basename "$baseline")" >&2
|
|
diff -u "$baseline" "$generated" >&2 || true
|
|
fail=1
|
|
else
|
|
echo "✓ $(basename "$baseline")"
|
|
fi
|
|
}
|
|
|
|
clear_outputs() {
|
|
rm -f "$APP/symfony/src/Entity/Todo.php"
|
|
rm -f "$APP/symfony/src/Controller/TodoController.php"
|
|
rm -f "$APP/symfony/src/Dto/CreateTodoDto.php"
|
|
rm -f "$APP/symfony/src/Dto/UpdateTodoDto.php"
|
|
rm -f "$APP/qml/TodoList.qml"
|
|
}
|
|
|
|
# ── Mode 1: legacy (no --with-dto) ────────────────────────────────────
|
|
clear_outputs
|
|
( cd "$APP/symfony" \
|
|
&& bin/console make:bridge:resource Todo --no-interaction >/dev/null \
|
|
&& bin/console make:bridge:command MarkAllDone --no-interaction >/dev/null \
|
|
&& bin/console make:bridge:window Todo --no-interaction >/dev/null \
|
|
&& bin/console make:bridge:event TodoCompleted --no-interaction >/dev/null \
|
|
&& bin/console make:bridge:read-model TodoSummary --no-interaction >/dev/null )
|
|
|
|
check "$APP/symfony/src/Entity/Todo.php" "$SCRIPT_DIR/Todo.php"
|
|
check "$APP/symfony/src/Controller/TodoController.php" "$SCRIPT_DIR/TodoController.php"
|
|
check "$APP/qml/TodoList.qml" "$SCRIPT_DIR/TodoList.qml"
|
|
check "$APP/symfony/src/Controller/MarkAllDoneController.php" "$SCRIPT_DIR/MarkAllDoneController.php"
|
|
check "$APP/qml/TodoWindow.qml" "$SCRIPT_DIR/TodoWindow.qml"
|
|
check "$APP/symfony/src/Event/TodoCompletedEvent.php" "$SCRIPT_DIR/TodoCompletedEvent.php"
|
|
check "$APP/symfony/src/EventSubscriber/TodoCompletedSubscriber.php" "$SCRIPT_DIR/TodoCompletedSubscriber.php"
|
|
check "$APP/qml/TodoCompletedEventHandler.qml" "$SCRIPT_DIR/TodoCompletedEventHandler.qml"
|
|
check "$APP/symfony/src/ReadModel/TodoSummaryReadModel.php" "$SCRIPT_DIR/TodoSummaryReadModel.php"
|
|
check "$APP/symfony/src/Controller/TodoSummaryController.php" "$SCRIPT_DIR/TodoSummaryController.php"
|
|
check "$APP/qml/TodoSummaryList.qml" "$SCRIPT_DIR/TodoSummaryList.qml"
|
|
|
|
# ── Mode 2: --with-dto (re-runs make:bridge:resource only) ────────────
|
|
# The entity + QML output is byte-identical between modes; only the
|
|
# controller swaps and the two DTOs appear. Re-checking the unchanged
|
|
# outputs would just be noise.
|
|
clear_outputs
|
|
( cd "$APP/symfony" \
|
|
&& bin/console make:bridge:resource Todo --with-dto --no-interaction >/dev/null )
|
|
|
|
check "$APP/symfony/src/Controller/TodoController.php" "$SCRIPT_DIR/TodoControllerWithDto.php"
|
|
check "$APP/symfony/src/Dto/CreateTodoDto.php" "$SCRIPT_DIR/CreateTodoDto.php"
|
|
check "$APP/symfony/src/Dto/UpdateTodoDto.php" "$SCRIPT_DIR/UpdateTodoDto.php"
|
|
|
|
if [ "$fail" -ne 0 ]; then
|
|
echo "Snapshot test failed. If the change is intended, update the baselines under $SCRIPT_DIR/." >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "All maker outputs match snapshots (legacy + --with-dto modes)."
|