-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·680 lines (576 loc) · 31.7 KB
/
Copy pathMakefile
File metadata and controls
executable file
·680 lines (576 loc) · 31.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
# Load environment variables from .env.test
include .env.test
# Parameters
PROJECT = user-service
GIT_AUTHOR = Kravalg
LOAD_TEST_CONFIG = tests/Load/config.prod.json
LOAD_TEST_COMPOSE_PROJECT ?= $(PROJECT)-load-tests
LOAD_TEST_API_PORT ?= 18081
LOAD_TEST_MAILCATCHER_SMTP_PORT ?= 1125
LOAD_TEST_MAILCATCHER_HTTP_PORT ?= 1180
MEMORY_SOAK_ROUNDS ?= 6
MEMORY_SOAK_WARMUP_ROUNDS ?= 2
MEMORY_SOAK_SETTLE_SECONDS ?= 5
WORKER_MEMORY_STEP_TOLERANCE_KB ?= 2048
WORKER_MEMORY_TOTAL_GROWTH_TOLERANCE_KB ?= 12288
MEMORY_SOAK_SCENARIOS ?=
# Executables: local only
SYMFONY_BIN = symfony
DOCKER = docker
DOCKER_COMPOSE = docker compose
DOCKER_COMPOSE_LOAD_TEST = LOAD_TEST_API_PORT=$(LOAD_TEST_API_PORT) LOAD_TEST_MAILCATCHER_SMTP_PORT=$(LOAD_TEST_MAILCATCHER_SMTP_PORT) LOAD_TEST_MAILCATCHER_HTTP_PORT=$(LOAD_TEST_MAILCATCHER_HTTP_PORT) $(DOCKER_COMPOSE) -p $(LOAD_TEST_COMPOSE_PROJECT) -f docker-compose.load-tests.yml
DOCKER_COMPOSE_SCHEMATHESIS = $(DOCKER_COMPOSE) -f docker-compose.yml -f docker-compose.schemathesis.yml
# Pinned Schemathesis image to avoid CI drift
SCHEMATHESIS_IMAGE = schemathesis/schemathesis:4.9.5
SCHEMATHESIS_API_PORT ?= 8081
SCHEMATHESIS_BASE_URL ?= http://localhost:$(SCHEMATHESIS_API_PORT)
SCHEMATHESIS_CLIENT_ID ?= dc0bc6323f16fecd4224a3860ca894c5
SCHEMATHESIS_CLIENT_SECRET ?= 8897b24436ac63e457fbd7d0bd5b678686c0cb214ef92fa9e8464fc7
SCHEMATHESIS_AUTH = $(SCHEMATHESIS_CLIENT_ID):$(SCHEMATHESIS_CLIENT_SECRET)
# Executables
EXEC_PHP = $(DOCKER_COMPOSE) exec php
EXEC_PHP_SCHEMATHESIS = $(DOCKER_COMPOSE_SCHEMATHESIS) exec php
COMPOSER = $(EXEC_PHP) composer
GIT = git
EXEC_PHP_TEST_ENV = $(DOCKER_COMPOSE) exec -e APP_ENV=test php
EXEC_PHP_TEST_ENV_NOTTY = $(DOCKER_COMPOSE) exec -T -e APP_ENV=test php
EXEC_PHP_TEST_ENV_NODEBUG = $(DOCKER_COMPOSE) exec -e APP_ENV=test -e APP_DEBUG=0 php
EXEC_PHP_LOAD_TEST_ENV = $(DOCKER_COMPOSE_LOAD_TEST) exec -e APP_ENV=load_test php
EXEC_PHP_LOAD_TEST_ENV_NODEBUG = $(DOCKER_COMPOSE_LOAD_TEST) exec -e APP_ENV=load_test -e APP_DEBUG=0 php
# Alias
SYMFONY = $(EXEC_PHP) bin/console
SYMFONY_TEST_ENV = $(EXEC_PHP_TEST_ENV) bin/console
SYMFONY_TEST_ENV_NODEBUG = $(EXEC_PHP_TEST_ENV_NODEBUG) bin/console
SYMFONY_LOAD_TEST_ENV = $(EXEC_PHP_LOAD_TEST_ENV) bin/console
SYMFONY_LOAD_TEST_ENV_NODEBUG = $(EXEC_PHP_LOAD_TEST_ENV_NODEBUG) bin/console
# Executables: vendors
BEHAT = php -d memory_limit=-1 ./vendor/bin/behat --stop-on-failure -n features
BEHAT_ENV = env APP_DEBUG=0
PHPUNIT = ./vendor/bin/phpunit
PSALM = ./vendor/bin/psalm
PHP_CS_FIXER = ./vendor/bin/php-cs-fixer
DEPTRAC = ./vendor/bin/deptrac
INFECTION = ./vendor/bin/infection
INFECTION_THREADS ?= 4
INFECTION_COVERAGE_DIR = /tmp/infection
# Misc
.DEFAULT_GOAL = help
.RECIPEPREFIX +=
.PHONY: $(filter-out vendor node_modules,$(MAKECMDGOALS))
.PHONY: start all clean test
all: ci
clean: purge
test: all-tests
# Conditional execution based on CI environment variable
EXEC_ENV ?= $(EXEC_PHP_TEST_ENV)
ifeq ($(CI),1)
EXEC_ENV =
endif
# Variables for environment and commands
FIXER_ENV = PHP_CS_FIXER_IGNORE_ENV=1
PHP_CS_FIXER_CMD = php ./vendor/bin/php-cs-fixer fix $(git ls-files -om --exclude-standard) --allow-risky=yes --config .php-cs-fixer.dist.php
COVERAGE_CMD = php -d memory_limit=-1 ./vendor/bin/phpunit --coverage-text
MEMORY_COVERAGE_CMD = php -d memory_limit=-1 ./vendor/bin/phpunit --configuration=phpunit.memory.xml.dist --coverage-text
GITHUB_HOST ?= github.com
FORMAT ?= markdown
BMALPH_PLATFORM ?= codex
BMALPH_DRY_RUN ?= false
define DOCKER_EXEC_WITH_ENV
$(DOCKER_COMPOSE) exec -e $(1) php $(2)
endef
# Conditional execution based on CI environment variable
ifeq ($(CI),1)
RUN_PHP_CS_FIXER = $(FIXER_ENV) $(PHP_CS_FIXER_CMD)
RUN_TESTS_COVERAGE = XDEBUG_MODE=coverage $(COVERAGE_CMD)
else
RUN_PHP_CS_FIXER = $(call DOCKER_EXEC_WITH_ENV,$(FIXER_ENV),$(PHP_CS_FIXER_CMD))
RUN_TESTS_COVERAGE = $(call DOCKER_EXEC_WITH_ENV,APP_ENV=test -e XDEBUG_MODE=coverage,$(COVERAGE_CMD))
endif
RUN_MEMORY_TESTS_COVERAGE = $(call DOCKER_EXEC_WITH_ENV,APP_ENV=test -e XDEBUG_MODE=coverage,$(MEMORY_COVERAGE_CMD))
#Input
CLIENT_NAME ?= default_value
export SYMFONY
help:
@printf "\033[33mUsage:\033[0m\n make [target] [arg=\"val\"...]\n\n\033[33mTargets:\033[0m\n"
@grep -h -E '^[-a-zA-Z0-9_\.\/]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-15s\033[0m %s\n", $$1, $$2}'
bmalph-install: ## Install and verify BMALPH for BMALPH_PLATFORM=codex|claude-code
bash scripts/local-coder/install-bmalph.sh --platform "$(BMALPH_PLATFORM)"
bmalph-codex: ## Install and verify BMALPH for Codex
@$(MAKE) bmalph-install BMALPH_PLATFORM=codex
bmalph-claude: ## Install and verify BMALPH for Claude Code
@$(MAKE) bmalph-install BMALPH_PLATFORM=claude-code
bmalph-init: ## Initialize BMALPH for current project; set BMALPH_DRY_RUN=true to preview safely
bash scripts/local-coder/install-bmalph.sh --platform "$(BMALPH_PLATFORM)" --init $(if $(filter true TRUE 1 yes YES,$(BMALPH_DRY_RUN)),--dry-run,)
bmalph-setup: ## Install and initialize BMALPH for current project; defaults to BMALPH_PLATFORM=codex
@$(MAKE) bmalph-init BMALPH_PLATFORM="$(BMALPH_PLATFORM)" BMALPH_DRY_RUN="$(BMALPH_DRY_RUN)"
ai-review-loop: ## Run local AI code review + fix loop (Codex default)
./scripts/ai-review-loop.sh
bmad-fr-nfr-review-gate: ## Run BMAD spec-driven FR/NFR review gate; set BMAD_REVIEW_SPEC_PATH=specs/my-bundle
@if [ -z "$${BMAD_REVIEW_SPEC_PATH:-}" ] && [ -z "$${AI_REVIEW_SPEC_PATH:-}" ]; then \
echo "Error: BMAD_REVIEW_SPEC_PATH or AI_REVIEW_SPEC_PATH is required, for example specs/my-bundle"; \
exit 1; \
fi
@./scripts/bmad-fr-nfr-review-gate.sh \
--spec "$${BMAD_REVIEW_SPEC_PATH:-$${AI_REVIEW_SPEC_PATH}}" \
$${BMAD_REVIEW_MANUAL_EVIDENCE:+--manual-evidence "$${BMAD_REVIEW_MANUAL_EVIDENCE}"} \
$${BMAD_REVIEW_PR:+--pr "$${BMAD_REVIEW_PR}"} \
$${BMAD_REVIEW_BASE:+--base "$${BMAD_REVIEW_BASE}"} \
$${BMAD_REVIEW_MAX_ITER:+--max-iter "$${BMAD_REVIEW_MAX_ITER}"} \
$${BMAD_REVIEW_VERIFY_CMD:+--verify-cmd "$${BMAD_REVIEW_VERIFY_CMD}"} \
$${BMAD_REVIEW_LOG_DIR:+--log-dir "$${BMAD_REVIEW_LOG_DIR}"} \
$${BMAD_REVIEW_IMPACT_CONTEXT:+--impact-context "$${BMAD_REVIEW_IMPACT_CONTEXT}"} \
$${BMAD_REVIEW_AGENTS:+--agents "$${BMAD_REVIEW_AGENTS}"}
bats: ## Run tests for bash commands
bats tests/CLI/bats/
phpcsfixer: ## A tool to automatically fix PHP Coding Standards issues
$(RUN_PHP_CS_FIXER)
composer-validate: ## The validate command validates a given composer.json and composer.lock
$(COMPOSER) validate
check-requirements: ## Checks requirements for running Symfony and gives useful recommendations to optimize PHP for Symfony.
$(EXEC_ENV) $(SYMFONY_BIN) check:requirements
check-security: ## Checks security issues in project dependencies. Without arguments, it looks for a "composer.lock" file in the current directory. Pass it explicitly to check a specific "composer.lock" file.
$(EXEC_ENV) $(SYMFONY_BIN) security:check
check-jwt-key-permissions: ## Verify JWT key permissions are correct (AC: NFR-61, RC-03 fix)
@echo "🔐 Checking JWT key permissions..."
@PRIVATE_PERMS=$$(stat -c %a config/jwt/private.pem 2>/dev/null || stat -f %A config/jwt/private.pem 2>/dev/null || echo "ERROR"); \
PUBLIC_PERMS=$$(stat -c %a config/jwt/public.pem 2>/dev/null || stat -f %A config/jwt/public.pem 2>/dev/null || echo "ERROR"); \
if [ "$$PRIVATE_PERMS" != "600" ]; then \
echo "❌ CRITICAL: private.pem has permissions $$PRIVATE_PERMS (expected 600)"; \
echo " Run: chmod 600 config/jwt/private.pem"; \
exit 1; \
fi; \
if [ "$$PUBLIC_PERMS" != "644" ]; then \
echo "❌ ERROR: public.pem has permissions $$PUBLIC_PERMS (expected 644)"; \
echo " Run: chmod 644 config/jwt/public.pem"; \
exit 1; \
fi; \
echo "✅ JWT key permissions are correct (private: 600, public: 644)"
psalm: ## A static analysis tool for finding errors in PHP applications
$(EXEC_ENV) $(PSALM)
psalm-security: ## Psalm security analysis
$(EXEC_ENV) $(PSALM) --taint-analysis
psalm-security-report: ## Psalm security analysis with SARIF output
$(EXEC_ENV) $(PSALM) --taint-analysis --report=results.sarif
phpmd: ## Instant PHP MD quality checks, static analysis, and complexity insights
$(EXEC_ENV) ./vendor/bin/phpmd src ansi codesize,design,cleancode --exclude vendor
$(EXEC_ENV) ./vendor/bin/phpmd tests ansi phpmd.tests.xml --exclude vendor,tests/CLI/bats/php
phpinsights: phpmd ## Instant PHP quality checks, static analysis, and complexity insights
$(EXEC_ENV) ./vendor/bin/phpinsights --no-interaction --flush-cache --fix --ansi --disable-security-check
$(EXEC_ENV) ./vendor/bin/phpinsights analyse tests --no-interaction --flush-cache --fix --disable-security-check --config-path=phpinsights-tests.php
unit-tests: ## Run unit tests
@echo "Running unit tests with coverage requirement of 100%..."
@$(RUN_TESTS_COVERAGE) --testsuite=Unit 2>&1 | tee /tmp/phpunit_output.txt
@if grep -Eq "FAILURES!|ERRORS!" /tmp/phpunit_output.txt; then \
echo "❌ TEST FAILURE: Some unit tests failed"; \
exit 1; \
fi
@coverage=$$(sed 's/\x1b\[[0-9;]*m//g' /tmp/phpunit_output.txt | grep "^ Lines:" | awk '{print $$2}' | sed 's/%//' | head -1); \
if [ -n "$$coverage" ]; then \
if [ $$(echo "$$coverage < 100" | bc -l) -eq 1 ]; then \
echo "❌ COVERAGE FAILURE: Line coverage is $$coverage%, but 100% is required. Please cover all lines of code and achieve the 100% code coverage"; \
exit 1; \
else \
echo "✅ COVERAGE SUCCESS: Line coverage is $$coverage%"; \
fi; \
else \
echo "❌ ERROR: Could not parse coverage from output"; \
exit 1; \
fi
deptrac: ## Check directory structure
$(EXEC_ENV) $(DEPTRAC) analyse --config-file=deptrac.yaml --report-uncovered --fail-on-uncovered
deptrac-debug: ## Find files unassigned for Deptrac
$(EXEC_ENV) $(DEPTRAC) debug:unassigned --config-file=deptrac.yaml
behat: setup-test-db clear-test-expression-language-caches ## A php framework for autotesting business expectations
APP_ENV=test APP_DEBUG=0 $(DOCKER_COMPOSE) up --detach --wait php database redis mailer localstack
$(EXEC_ENV) $(BEHAT_ENV) $(BEHAT)
integration-tests: setup-test-db ## Run integration tests
$(RUN_TESTS_COVERAGE) --testsuite=Integration
memory-tests: setup-test-db ## Run memory leak tests with 100% suite coverage and endpoint inventory enforcement
@echo "Running memory leak tests with strict inventory and coverage requirements..."
@bash -c 'set -o pipefail; $(RUN_MEMORY_TESTS_COVERAGE) 2>&1 | tee /tmp/phpunit_memory_output.txt'; \
status=$$?; \
if [ $$status -ne 0 ]; then \
echo "❌ TEST FAILURE: Some memory leak tests failed"; \
exit $$status; \
fi
@coverage=$$(sed 's/\x1b\[[0-9;]*m//g' /tmp/phpunit_memory_output.txt | grep "^ Lines:" | awk '{print $$2}' | sed 's/%//' | head -1); \
if [ -n "$$coverage" ]; then \
if [ $$(echo "$$coverage < 100" | bc -l) -eq 1 ]; then \
echo "❌ COVERAGE FAILURE: Memory suite line coverage is $$coverage%, but 100% is required. Please cover all memory test lines and keep endpoint inventory complete"; \
exit 1; \
else \
echo "✅ COVERAGE SUCCESS: Memory suite line coverage is $$coverage%"; \
fi; \
else \
echo "❌ ERROR: Could not parse memory suite coverage from output"; \
exit 1; \
fi
cache-performance-tests: setup-test-db ## Run cache performance integration tests
$(EXEC_ENV) $(PHPUNIT) tests/Integration/User/Infrastructure/Repository/CachePerformanceTest.php --testdox
tests-with-coverage: ## Run tests with coverage
$(RUN_TESTS_COVERAGE) --coverage-clover /coverage/coverage.xml
setup-test-db: ## Create database for testing purposes
$(SYMFONY_TEST_ENV) c:c
$(SYMFONY_TEST_ENV_NODEBUG) c:c
@echo "Recreating MongoDB schema for testing..."
@$(SYMFONY_TEST_ENV) doctrine:mongodb:schema:drop 2>&1 || true
$(SYMFONY_TEST_ENV) doctrine:mongodb:schema:create
@echo "Ensuring JWT keypair exists for test environment..."
$(SYMFONY_TEST_ENV) lexik:jwt:generate-keypair --skip-if-exists
@echo "Seeding test OAuth client..."
$(SYMFONY_TEST_ENV) app:seed-test-oauth-client
@echo "✅ Test database ready"
clear-test-expression-language-caches:
$(SYMFONY_TEST_ENV) cache:pool:clear cache.validator_expression_language
$(SYMFONY_TEST_ENV) cache:pool:clear cache.security_expression_language
$(SYMFONY_TEST_ENV) cache:pool:clear cache.security_is_granted_attribute_expression_language
$(SYMFONY_TEST_ENV) cache:pool:clear cache.security_is_csrf_token_valid_attribute_expression_language
setup-load-test-db: ## Create database for load testing purposes
$(SYMFONY_LOAD_TEST_ENV) c:c
$(SYMFONY_LOAD_TEST_ENV_NODEBUG) c:c
@echo "Recreating MongoDB schema for load testing..."
@$(SYMFONY_LOAD_TEST_ENV) doctrine:mongodb:schema:drop 2>&1 || true
$(SYMFONY_LOAD_TEST_ENV) doctrine:mongodb:schema:create
@echo "Ensuring JWT keypair exists for load-test environment..."
$(SYMFONY_LOAD_TEST_ENV) lexik:jwt:generate-keypair --skip-if-exists
@echo "Seeding test OAuth client..."
$(SYMFONY_LOAD_TEST_ENV) app:seed-test-oauth-client
@echo "✅ Load-test database ready"
all-tests: unit-tests integration-tests behat ## Run unit, integration and e2e tests
LOAD_TEST_PREPARE_OAUTH_CLIENT = SYMFONY="$(DOCKER_COMPOSE_LOAD_TEST) exec -T php bin/console" tests/Load/load-tests-prepare-oauth-client.sh "$$(jq -r '.endpoints.oauth.clientName' $(LOAD_TEST_CONFIG))" "$$(jq -r '.endpoints.oauth.clientID' $(LOAD_TEST_CONFIG))" "$$(jq -r '.endpoints.oauth.clientSecret' $(LOAD_TEST_CONFIG))" "$$(jq -r '.endpoints.oauth.clientRedirectUri' $(LOAD_TEST_CONFIG))"
smoke-load-tests: build-k6-docker ## Run load tests with minimal load
$(DOCKER_COMPOSE_LOAD_TEST) up --detach --wait php database redis mailer localstack
$(LOAD_TEST_PREPARE_OAUTH_CLIENT)
tests/Load/run-smoke-load-tests.sh
average-load-tests: build-k6-docker ## Run load tests with average load
$(DOCKER_COMPOSE_LOAD_TEST) up --detach --wait php database redis mailer localstack
$(LOAD_TEST_PREPARE_OAUTH_CLIENT)
tests/Load/run-average-load-tests.sh
stress-load-tests: build-k6-docker ## Run load tests with high load
$(DOCKER_COMPOSE_LOAD_TEST) up --detach --wait php database redis mailer localstack
$(LOAD_TEST_PREPARE_OAUTH_CLIENT)
tests/Load/run-stress-load-tests.sh
spike-load-tests: build-k6-docker ## Run load tests with a spike of extreme load
$(DOCKER_COMPOSE_LOAD_TEST) up --detach --wait php database redis mailer localstack
$(LOAD_TEST_PREPARE_OAUTH_CLIENT)
tests/Load/run-spike-load-tests.sh
load-tests: build-k6-docker ## Run load tests
$(DOCKER_COMPOSE_LOAD_TEST) up --detach --wait php database redis mailer localstack
$(LOAD_TEST_PREPARE_OAUTH_CLIENT)
tests/Load/run-load-tests.sh
memory-load-soak-tests: build-k6-docker ## Run repeated worker-mode smoke load tests and fail on leak signals
$(DOCKER_COMPOSE_LOAD_TEST) up --detach --wait php database redis mailer localstack
$(MAKE) setup-load-test-db
$(LOAD_TEST_PREPARE_OAUTH_CLIENT)
$(DOCKER_COMPOSE_LOAD_TEST) restart php
$(DOCKER_COMPOSE_LOAD_TEST) up --detach --wait php
MEMORY_SOAK_ROUNDS=$(MEMORY_SOAK_ROUNDS) MEMORY_SOAK_WARMUP_ROUNDS=$(MEMORY_SOAK_WARMUP_ROUNDS) MEMORY_SOAK_SETTLE_SECONDS=$(MEMORY_SOAK_SETTLE_SECONDS) WORKER_MEMORY_STEP_TOLERANCE_KB=$(WORKER_MEMORY_STEP_TOLERANCE_KB) WORKER_MEMORY_TOTAL_GROWTH_TOLERANCE_KB=$(WORKER_MEMORY_TOTAL_GROWTH_TOLERANCE_KB) MEMORY_SOAK_SCENARIOS="$(MEMORY_SOAK_SCENARIOS)" tests/Load/run-worker-memory-soak.sh
memory-load-soak-tests-full: build-k6-docker ## Run exhaustive worker-mode smoke load tests across every load scenario
$(DOCKER_COMPOSE_LOAD_TEST) up --detach --wait php database redis mailer localstack
$(MAKE) setup-load-test-db
$(LOAD_TEST_PREPARE_OAUTH_CLIENT)
$(DOCKER_COMPOSE_LOAD_TEST) restart php
$(DOCKER_COMPOSE_LOAD_TEST) up --detach --wait php
MEMORY_SOAK_ROUNDS=$(MEMORY_SOAK_ROUNDS) MEMORY_SOAK_WARMUP_ROUNDS=$(MEMORY_SOAK_WARMUP_ROUNDS) MEMORY_SOAK_SETTLE_SECONDS=$(MEMORY_SOAK_SETTLE_SECONDS) WORKER_MEMORY_STEP_TOLERANCE_KB=$(WORKER_MEMORY_STEP_TOLERANCE_KB) WORKER_MEMORY_TOTAL_GROWTH_TOLERANCE_KB=$(WORKER_MEMORY_TOTAL_GROWTH_TOLERANCE_KB) MEMORY_SOAK_SCENARIOS="$$(./tests/Load/get-worker-memory-soak-scenarios.sh | paste -sd, -)" tests/Load/run-worker-memory-soak.sh
execute-load-tests-script: build-k6-docker ## Execute single load test scenario.
$(DOCKER_COMPOSE_LOAD_TEST) up --detach --wait php database redis mailer localstack
$(LOAD_TEST_PREPARE_OAUTH_CLIENT)
tests/Load/execute-load-test.sh $(scenario) $(or $(runSmoke),true) $(or $(runAverage),true) $(or $(runStress),true) $(or $(runSpike),true)
cache-performance-load-tests: build-k6-docker ## Run cache performance K6 load tests
$(DOCKER_COMPOSE_LOAD_TEST) up --detach --wait php database redis mailer localstack
tests/Load/execute-load-test.sh cachePerformance true false false false
build-k6-docker:
$(DOCKER) build -t k6 -f ./tests/Load/Dockerfile .
build-spectral-docker:
$(DOCKER) build -t user-service-spectral -f ./docker/spectral/Dockerfile .
infection: ## Run mutations test.
$(EXEC_PHP_TEST_ENV_NOTTY) sh -lc 'set -eu; \
export XDEBUG_MODE=coverage; \
rm -rf $(INFECTION_COVERAGE_DIR); \
mkdir -p $(INFECTION_COVERAGE_DIR)/coverage-xml; \
php -d memory_limit=-1 ./vendor/bin/phpunit --testsuite=Unit --coverage-xml=$(INFECTION_COVERAGE_DIR)/coverage-xml --log-junit=$(INFECTION_COVERAGE_DIR)/junit.xml --order-by=defects,random; \
php -d memory_limit=-1 $(INFECTION) --configuration=infection.json5 --coverage=$(INFECTION_COVERAGE_DIR) --skip-initial-tests --test-framework-options="--testsuite=Unit" --show-mutations --log-verbosity=all -j$(INFECTION_THREADS) --min-msi=100 --min-covered-msi=100 --with-uncovered'
create-oauth-client: ## Run mutation testing
$(EXEC_PHP) sh -c 'bin/console league:oauth2-server:create-client $(clientName)'
cache-clear: ## Clears and warms up the application cache for a given environment and debug mode
$(SYMFONY) c:c
install: composer.lock ## Install vendors according to the current composer.lock file
@$(COMPOSER) install --no-progress --prefer-dist --optimize-autoloader
update: ## Update vendors according to the current composer.json file
@$(COMPOSER) update --no-progress --prefer-dist --optimize-autoloader
cache-warmup: ## Warmup the Symfony cache
@$(SYMFONY) cache:warmup
purge: ## Purge cache and logs
@rm -rf var/cache/* var/logs/*
up: ## Start the docker hub (PHP, caddy)
$(DOCKER_COMPOSE) up --detach
build: ## Builds the images (PHP, caddy)
$(DOCKER_COMPOSE) build --pull --no-cache
down: ## Stop the docker hub
$(DOCKER_COMPOSE) down --remove-orphans
sh: ## Log to the docker container
@echo "Connecting to user-service PHP container..."
@$(EXEC_PHP) sh
logs: ## Show all logs
@$(DOCKER_COMPOSE) logs
new-logs: ## Show live logs
@$(DOCKER_COMPOSE) logs --tail=0 --follow
start: ## Start docker
$(DOCKER_COMPOSE) up --detach --wait php database redis mailer localstack
$(MAKE) build-k6-docker
$(MAKE) build-spectral-docker
start-memory-tests: ## Start only services required for memory leak tests
$(DOCKER_COMPOSE) up --detach --wait php database redis mailer localstack
ps: ## Check docker containers
$(DOCKER_COMPOSE) ps
stop: ## Stop docker and the Symfony binary server
$(DOCKER_COMPOSE) stop
commands: ## List all Symfony commands
@$(SYMFONY) list
doctrine-migrations-migrate: ## Apply database migrations (MongoDB ODM uses schema management instead)
@echo "Note: MongoDB ODM does not use traditional migrations."
@echo "Schema is managed via doctrine:mongodb:schema:create/update commands."
@echo "For test database setup, use: make setup-test-db"
doctrine-migrations-generate: ## Generate migration file (MongoDB ODM uses schema management instead)
@echo "Note: MongoDB ODM does not use traditional migrations."
@echo "Schema changes are managed automatically via Doctrine ODM mappings."
@echo "To update schema: make setup-test-db (for tests) or manually run doctrine:mongodb:schema:update"
load-fixtures: ## Build the DB, control the schema validity, load fixtures and check the migration status
@echo "Clearing MongoDB metadata cache..."
@$(SYMFONY) doctrine:mongodb:cache:clear-metadata
@echo "Recreating MongoDB schema..."
@$(SYMFONY) doctrine:mongodb:schema:drop 2>&1 || true
@$(SYMFONY) doctrine:mongodb:schema:create
@echo "Loading fixtures..."
@$(SYMFONY) doctrine:mongodb:fixtures:load --no-interaction
@echo "✅ Fixtures loaded successfully"
reset-db: ## Recreate the database schema for ephemeral test runs
@echo "Clearing MongoDB metadata cache..."
@$(SYMFONY) doctrine:mongodb:cache:clear-metadata 2>&1 || true
@echo "Recreating MongoDB schema..."
@$(SYMFONY) doctrine:mongodb:schema:drop 2>&1 || true
@$(SYMFONY) doctrine:mongodb:schema:create
@echo "Seeding Schemathesis test data..."
@$(SYMFONY) app:seed-schemathesis-data
@echo "✅ Database reset complete"
coverage-html: ## Create the code coverage report with PHPUnit
$(DOCKER_COMPOSE) exec -e XDEBUG_MODE=coverage php php -d memory_limit=-1 vendor/bin/phpunit --coverage-html=coverage/html
coverage-xml: ## Create the code coverage report with PHPUnit
$(DOCKER_COMPOSE) exec -e XDEBUG_MODE=coverage php php -d memory_limit=-1 vendor/bin/phpunit --coverage-clover coverage/coverage.xml
generate-openapi-spec:
$(EXEC_PHP) php bin/console api:openapi:export --yaml --output=.github/openapi-spec/spec.yaml
@if command -v npx >/dev/null 2>&1; then \
if [ ! -w .github/openapi-spec/spec.yaml ] && command -v sudo >/dev/null 2>&1; then \
sudo -n chown "$$(id -u):$$(id -g)" .github/openapi-spec/spec.yaml 2>/dev/null || true; \
fi; \
if [ -w .github/openapi-spec/spec.yaml ]; then \
npx --yes prettier@3.5.3 --write --ignore-path /dev/null .github/openapi-spec/spec.yaml; \
else \
echo "Skipping OpenAPI spec formatting because .github/openapi-spec/spec.yaml is not writable"; \
fi; \
else \
echo "Skipping OpenAPI spec formatting because 'npx' is not available; install Node.js to keep spec formatting consistent"; \
fi
validate-openapi-spec: generate-openapi-spec build-spectral-docker ## Generate and lint the OpenAPI spec with Spectral
./scripts/validate-openapi-spec.sh
validate-configuration: ## Validate configuration structure and detect locked file modifications
./scripts/validate-configuration.sh
openapi-diff: generate-openapi-spec ## Compare the generated OpenAPI spec against the base reference using OpenAPI Diff
./scripts/openapi-diff.sh $(or $(base_ref),origin/main)
schemathesis-validate: reset-db generate-openapi-spec ## Validate the running API against the OpenAPI spec with Schemathesis
SCHEMATHESIS_IMAGE=$(SCHEMATHESIS_IMAGE) SCHEMATHESIS_API_PORT=$(SCHEMATHESIS_API_PORT) SCHEMATHESIS_BASE_URL=$(SCHEMATHESIS_BASE_URL) ./scripts/schemathesis-validate.sh
generate-graphql-spec:
$(EXEC_PHP) php bin/console api:graphql:export --output=.github/graphql-spec/spec
start-prod-loadtest: ## Start production environment with load testing capabilities
$(DOCKER_COMPOSE) -f docker-compose.loadtest.yml up --detach
stop-prod-loadtest: ## Stop production load testing environment
$(DOCKER_COMPOSE) -f docker-compose.loadtest.yml down --remove-orphans
ci: ci-preflight ## Run comprehensive CI checks with stable resource usage (excludes bats and load tests)
@echo "🚀 Running static checks in parallel..."
@$(MAKE) -j2 --output-sync=target ci-static-analysis ci-deptrac
@echo "🧪 Running tests and API validation..."
@$(MAKE) ci-tests-and-openapi
@echo "🧬 Running mutation testing..."
@$(MAKE) ci-mutation
@echo ""
@echo "✅ CI checks successfully passed!"
ci-preflight: ## Run mutating checks sequentially (code style, quality)
@echo "🎨 Preflight: fixing code style and running quality checks..."
@$(MAKE) phpcsfixer
@$(MAKE) phpinsights
ci-static-analysis:
@$(MAKE) composer-validate
@$(MAKE) check-requirements
@$(MAKE) check-security
@$(MAKE) validate-configuration
@$(MAKE) check-jwt-key-permissions
@$(MAKE) psalm
@$(MAKE) psalm-security
ci-deptrac:
@$(MAKE) deptrac
ci-mutation:
@$(MAKE) infection
ci-tests-and-openapi:
@$(MAKE) setup-test-db
@$(MAKE) unit-tests
@$(MAKE) integration-tests
@$(MAKE) behat
@$(MAKE) generate-openapi-spec
@$(MAKE) openapi-diff
@$(MAKE) validate-openapi-spec
@$(MAKE) schemathesis-validate
ci-sequential: ## Run CI checks sequentially (fallback if parallel execution has issues)
@echo "🚀 Running comprehensive CI checks (sequential mode)..."
@failed_checks=""; \
echo "1️⃣ Validating composer.json and composer.lock..."; \
if ! make composer-validate; then failed_checks="$$failed_checks\n❌ composer validation"; fi; \
echo "2️⃣ Checking Symfony requirements..."; \
if ! make check-requirements; then failed_checks="$$failed_checks\n❌ Symfony requirements check"; fi; \
echo "3️⃣ Running security analysis..."; \
if ! make check-security; then failed_checks="$$failed_checks\n❌ security analysis"; fi; \
echo "4️⃣ Validating locked configuration files..."; \
if ! make validate-configuration; then failed_checks="$$failed_checks\n❌ configuration validation"; fi; \
echo "5️⃣ Fixing code style with PHP CS Fixer..."; \
if ! make phpcsfixer; then failed_checks="$$failed_checks\n❌ PHP CS Fixer"; fi; \
echo "6️⃣ Running static analysis with Psalm..."; \
if ! make psalm; then failed_checks="$$failed_checks\n❌ Psalm static analysis"; fi; \
echo "7️⃣ Running security taint analysis..."; \
if ! make psalm-security; then failed_checks="$$failed_checks\n❌ Psalm security analysis"; fi; \
echo "8️⃣ Running code quality analysis with PHPMD..."; \
if ! make phpmd; then failed_checks="$$failed_checks\n❌ PHPMD quality analysis"; fi; \
echo "9️⃣ Running code quality analysis with PHPInsights..."; \
if ! make phpinsights; then failed_checks="$$failed_checks\n❌ PHPInsights quality analysis"; fi; \
echo "🔟 Validating architecture with Deptrac..."; \
if ! make deptrac; then failed_checks="$$failed_checks\n❌ Deptrac architecture validation"; fi; \
echo "1️⃣1️⃣ Running complete test suite (unit, integration, e2e)..."; \
if ! make unit-tests; then failed_checks="$$failed_checks\n❌ unit tests"; fi; \
if ! make integration-tests; then failed_checks="$$failed_checks\n❌ integration tests"; fi; \
if ! make behat; then failed_checks="$$failed_checks\n❌ Behat e2e tests"; fi; \
echo "1️⃣2️⃣ Running mutation testing with Infection..."; \
if ! make infection; then failed_checks="$$failed_checks\n❌ mutation testing"; fi; \
echo "1️⃣3️⃣ Checking OpenAPI backward compatibility..."; \
if ! make openapi-diff; then failed_checks="$$failed_checks\n❌ OpenAPI diff"; fi; \
echo "1️⃣4️⃣ Validating OpenAPI specification..."; \
if ! make validate-openapi-spec; then failed_checks="$$failed_checks\n❌ OpenAPI Spectral validation"; fi; \
echo "1️⃣5️⃣ Running Schemathesis validation..."; \
if ! make schemathesis-validate; then failed_checks="$$failed_checks\n❌ Schemathesis validation"; fi; \
if [ -n "$$failed_checks" ]; then \
echo ""; \
echo "💥 CI checks completed with failures:"; \
printf "$$failed_checks\n"; \
echo ""; \
echo "❌ CI checks failed! Please fix the above issues."; \
exit 1; \
else \
echo "✅ CI checks successfully passed!"; \
fi
pr-comments: ## Retrieve ALL unresolved comments (including outdated) for current PR (markdown format)
@if ! command -v gh >/dev/null 2>&1; then \
echo "Error: GitHub CLI (gh) is required but not installed."; \
echo "Visit: https://cli.github.com/ for installation instructions"; \
exit 1; \
fi
@if ! command -v jq >/dev/null 2>&1; then \
echo "Error: jq is required but not installed."; \
echo "Install via package manager (e.g., apt-get install jq, brew install jq)"; \
exit 1; \
fi
ifdef PR
@echo "Retrieving unresolved comments (including outdated) for PR #$(PR)..."
@GITHUB_HOST="$(GITHUB_HOST)" INCLUDE_OUTDATED="true" \
./scripts/get-pr-comments.sh "$(PR)" "$${FORMAT:-markdown}"
else
@echo "Auto-detecting PR from current git branch..."
@GITHUB_HOST="$(GITHUB_HOST)" INCLUDE_OUTDATED="true" \
./scripts/get-pr-comments.sh "$${FORMAT:-markdown}"
endif
pr-comments-current: ## Retrieve only NON-OUTDATED unresolved comments (markdown format)
@if ! command -v gh >/dev/null 2>&1; then \
echo "Error: GitHub CLI (gh) is required but not installed."; \
echo "Visit: https://cli.github.com/ for installation instructions"; \
exit 1; \
fi
@if ! command -v jq >/dev/null 2>&1; then \
echo "Error: jq is required but not installed."; \
echo "Install via package manager (e.g., apt-get install jq, brew install jq)"; \
exit 1; \
fi
ifdef PR
@echo "Retrieving current (non-outdated) unresolved comments for PR #$(PR)..."
@GITHUB_HOST="$(GITHUB_HOST)" INCLUDE_OUTDATED="false" \
./scripts/get-pr-comments.sh "$(PR)" "$${FORMAT:-markdown}"
else
@echo "Auto-detecting PR from current git branch..."
@GITHUB_HOST="$(GITHUB_HOST)" INCLUDE_OUTDATED="false" \
./scripts/get-pr-comments.sh "$${FORMAT:-markdown}"
endif
pr-comments-all: ## Retrieve ALL unresolved comments (with pagination) for a GitHub Pull Request
@if ! command -v gh >/dev/null 2>&1; then \
echo "Error: GitHub CLI (gh) is required but not installed."; \
echo "Visit: https://cli.github.com/ for installation instructions"; \
exit 1; \
fi
@if ! command -v jq >/dev/null 2>&1; then \
echo "Error: jq is required but not installed."; \
echo "Install via package manager (e.g., apt-get install jq, brew install jq)"; \
exit 1; \
fi
ifdef PR
@echo "Retrieving ALL unresolved comments for PR #$(PR)..."
@GITHUB_HOST="$(GITHUB_HOST)" INCLUDE_OUTDATED="$${INCLUDE_OUTDATED:-false}" VERBOSE="$${VERBOSE:-false}" \
./scripts/get-pr-comments.sh "$(PR)" "$${FORMAT:-text}"
else
@GITHUB_HOST="$(GITHUB_HOST)" INCLUDE_OUTDATED="$${INCLUDE_OUTDATED:-false}" VERBOSE="$${VERBOSE:-false}" \
./scripts/get-pr-comments.sh "$${FORMAT:-text}"
endif
pr-comments-to-file: ## Fetch ALL unresolved PR comments and save to pr-comments-errors.txt
@if ! command -v gh >/dev/null 2>&1; then \
echo "Error: GitHub CLI (gh) is required but not installed."; \
echo "Visit: https://cli.github.com/ for installation instructions"; \
exit 1; \
fi
@if ! command -v jq >/dev/null 2>&1; then \
echo "Error: jq is required but not installed."; \
echo "Install via package manager (e.g., apt-get install jq, brew install jq)"; \
exit 1; \
fi
@output_file="$${OUTPUT_FILE:-pr-comments-errors.txt}"; \
if [ -f "$$output_file" ]; then \
echo "⚠️ File $$output_file already exists. Creating backup..."; \
mv "$$output_file" "$$output_file.backup.$$(date +%Y%m%d_%H%M%S)"; \
fi; \
{ \
echo "========================================"; \
echo "PR Comments and Errors Report"; \
echo "Generated: $$(date '+%Y-%m-%d %H:%M:%S')"; \
echo "========================================"; \
echo ""; \
} > "$$output_file"; \
if [ -n "$(PR)" ]; then \
if ! GITHUB_HOST="$(GITHUB_HOST)" INCLUDE_OUTDATED="$${INCLUDE_OUTDATED:-true}" VERBOSE="false" \
./scripts/get-pr-comments.sh "$(PR)" "text" >> "$$output_file" 2>&1; then \
echo "⚠️ Warning: Failed to fetch PR comments, check error output above" >> "$$output_file"; \
echo "❌ Failed to fetch PR comments for PR #$(PR)"; \
fi; \
else \
if ! GITHUB_HOST="$(GITHUB_HOST)" INCLUDE_OUTDATED="$${INCLUDE_OUTDATED:-true}" VERBOSE="false" \
./scripts/get-pr-comments.sh "text" >> "$$output_file" 2>&1; then \
echo "⚠️ Warning: Failed to fetch PR comments, check error output above" >> "$$output_file"; \
echo "❌ Failed to fetch PR comments from current branch"; \
fi; \
fi; \
comment_count=$$(grep -c "^Comment ID:" "$$output_file" || echo "0"); \
echo "" >> "$$output_file"; \
echo "========================================" >> "$$output_file"; \
echo "Report Summary:" >> "$$output_file"; \
echo "Total Comments Found: $$comment_count" >> "$$output_file"; \
echo "Report saved to: $$output_file" >> "$$output_file"; \
echo "========================================" >> "$$output_file"; \
if [ "$$comment_count" -gt 0 ]; then \
echo "✅ Report successfully saved to: $$output_file"; \
echo "📊 Total comments found: $$comment_count"; \
cat "$$output_file"; \
else \
echo "ℹ️ No unresolved comments found"; \
echo "📄 Report saved to: $$output_file"; \
fi