Skip to content

Commit 915386a

Browse files
committed
feat: use Doctrine DBAL to query a SQLite database
1 parent 77795d9 commit 915386a

File tree

19 files changed

+1796
-255
lines changed

19 files changed

+1796
-255
lines changed

.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ APP_SECRET=
2323
# To test the production environment, run "make go-prod" or "castor symfony:go-prod"
2424

2525
# To come back to the development environment, run "make go-dev" or "castor symfony:go-dev"
26+
27+
###> doctrine/doctrine-bundle ###
28+
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
29+
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
30+
#
31+
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
32+
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4"
33+
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
34+
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
35+
###< doctrine/doctrine-bundle ###

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ go-dev: ## Switch to the development environment
3737
warmup: ## Warmup the dev cache for the static analysis
3838
@bin/console c:w --env=dev
3939

40-
purge: ## Purge all Symfony cache and logs
40+
purge: ## Purge all Symfony variable data
4141
@rm -rf ./var/cache/* ./var/logs/* ./var/coverage/*
4242

43+
load-fixtures: ## Reset migrations and load the database fixtures
44+
@rm -f ./var/data.db
45+
@bin/console doctrine:migration:migrate --env=dev --no-interaction
46+
@bin/console app:load-fixtures --env=dev --no-interaction
47+
4348

4449
## —— Tests ✅ —————————————————————————————————————————————————————————————————
4550
test: ## Run tests with optional suite, filter and options (to debug use "make test options=--debug")
@@ -69,7 +74,7 @@ test-unit: testsuite=unit
6974
test-unit: test
7075

7176
coverage: ## Generate the HTML PHPUnit code coverage report (stored in var/coverage)
72-
coverage: purge
77+
coverage: purge load-fixtures
7378
@XDEBUG_MODE=coverage php -d xdebug.enable=1 -d memory_limit=-1 vendor/bin/phpunit --coverage-html=var/coverage --coverage-clover=var/coverage/clover.xml
7479
@php bin/coverage-checker.php var/coverage/clover.xml $(COVERAGE_THRESHOLD)
7580

castor.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ function purge(): void
9696
success(exit_code('rm -rf ./var/cache/* ./var/logs/* ./var/coverage/*'));
9797
}
9898

99+
#[AsTask(namespace: 'app', description: 'Load the database fixtures', aliases: ['load-fixtures'])]
100+
function loadFixures(): void
101+
{
102+
title('app:load-fixtures');
103+
io()->note('Resetting db...');
104+
success(exit_code('rm -f ./var/data.db'));
105+
io()->note('Running db migrations...');
106+
success(exit_code('bin/console doctrine:migration:migrate --no-interaction'));
107+
io()->note('Load fixtures...');
108+
success(exit_code('bin/console app:load-fixtures --no-interaction'));
109+
}
110+
99111
const PHP_UNIT_CMD = '/vendor/bin/phpunit --testsuite=%s --filter=%s %s';
100112
const PHP_UNIT_SUITES = ['api', 'e2e', 'functional', 'integration', 'unit'];
101113

@@ -111,6 +123,8 @@ function getParameters(): array
111123
function test_all(): int
112124
{
113125
title('test:all');
126+
loadFixures();
127+
$ec = exit_code(__DIR__.'/vendor/bin/phpunit');
114128
[$filter, $options] = getParameters();
115129
$ec = exit_code(__DIR__.sprintf(PHP_UNIT_CMD, implode(',', PHP_UNIT_SUITES), $filter, $options));
116130
io()->writeln('');
@@ -177,6 +191,7 @@ function test_unit(
177191
function coverage(): int
178192
{
179193
title('test:coverage');
194+
loadFixures();
180195
$ec = exit_code('php -d xdebug.enable=1 -d memory_limit=-1 vendor/bin/phpunit --coverage-html=var/coverage --coverage-clover=var/coverage/clover.xml',
181196
context: context()->withEnvironment(['XDEBUG_MODE' => 'coverage'])
182197
);
@@ -308,6 +323,7 @@ function ci(): void
308323
{
309324
title('ci:all');
310325
purge();
326+
loadFixures();
311327
io()->section('Coverage');
312328
coverage();
313329
io()->section('Lints');

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
"ext-mbstring": "*",
2323
"ext-simplexml": "*",
2424
"ext-xml": "*",
25+
"doctrine/dbal": "^4.0",
26+
"doctrine/doctrine-bundle": "^2.13",
27+
"doctrine/doctrine-migrations-bundle": "^3.3",
28+
"doctrine/orm": "^3.3",
2529
"league/commonmark": "^2.4",
2630
"runtime/frankenphp-symfony": "^0.2.0",
2731
"symfony/asset": "~7.2.0",

0 commit comments

Comments
 (0)