Skip to content

Commit 4109c18

Browse files
committed
feat: use Doctrine DBAL to query a SQLite database
1 parent be38112 commit 4109c18

17 files changed

+1252
-111
lines changed

.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ APP_SECRET=3bUhVCRkHJfT2ZJTqBnvkclRFT1zy1ig
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
@@ -30,9 +30,14 @@ go-dev: ## Switch to the development environment
3030
warmup: ## Warmup the dev cache for the static analysis
3131
@bin/console c:w --env=dev
3232

33-
purge: ## Purge all Symfony cache and logs
33+
purge: ## Purge all Symfony variable data
3434
@rm -rf ./var/cache/* ./var/logs/* ./var/coverage/*
3535

36+
load-fixtures: ## Reset migrations and load the database fixtures
37+
@rm -rf ./var/data.db
38+
@bin/console d:m:m --env=dev --no-interaction
39+
@bin/console a:l --env=dev --no-interaction
40+
3641

3742
## —— Tests ✅ —————————————————————————————————————————————————————————————————
3843
test: ## Run all PHPUnit tests
@@ -41,7 +46,7 @@ test: ## Run all PHPUnit tests
4146
coverage: ## Generate the HTML PHPUnit code coverage report (stored in var/coverage)
4247
coverage: purge
4348
@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
44-
@php bin/coverage-checker.php var/coverage/clover.xml 100
49+
@php bin/coverage-checker.php var/coverage/clover.xml 84
4550

4651
cov-report: var/coverage/index.html ## Open the PHPUnit code coverage report (var/coverage/index.html)
4752
@open var/coverage/index.html

castor.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ function purge(): void
8989
success(exit_code('rm -rf ./var/cache/* ./var/logs/* ./var/coverage/*', quiet: false));
9090
}
9191

92+
#[AsTask(namespace: 'app', description: 'Load the database fixtures', aliases: ['load-fixtures'])]
93+
function loadFixures(): void
94+
{
95+
title('app:load-fixtures');
96+
io()->note('Resetting db...');
97+
success(exit_code('rm -f ./var/data.db', quiet: false));
98+
io()->note('Running db migrations...');
99+
success(exit_code('bin/console d:m:m --no-interaction', quiet: false));
100+
io()->note('Load fixtures...');
101+
success(exit_code('bin/console a:l --no-interaction', quiet: false));
102+
}
103+
92104
#[AsTask(name: 'all', namespace: 'test', description: 'Run all PHPUnit tests', aliases: ['test'])]
93105
function test_all(): int
94106
{
@@ -113,7 +125,7 @@ function coverage(): int
113125
return $ec;
114126
}
115127

116-
return success(exit_code('php bin/coverage-checker.php var/coverage/clover.xml 100', quiet: false));
128+
return success(exit_code('php bin/coverage-checker.php var/coverage/clover.xml 84', quiet: false));
117129
}
118130

119131
#[AsTask(namespace: 'test', description: 'Open the PHPUnit code coverage report (var/coverage/index.html)', aliases: ['cov-report'])]
@@ -250,6 +262,7 @@ function ci(): void
250262
{
251263
title('ci:all');
252264
purge();
265+
loadFixures();
253266
io()->section('Coverage');
254267
coverage();
255268
io()->section('Codings standards');

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"ext-libxml": "*",
2222
"ext-simplexml": "*",
2323
"ext-xml": "*",
24+
"doctrine/dbal": "^3",
25+
"doctrine/doctrine-bundle": "^2.13",
26+
"doctrine/doctrine-migrations-bundle": "^3.3",
2427
"league/commonmark": "^2.4",
2528
"symfony/asset": "~7.1.0",
2629
"symfony/asset-mapper": "~7.1.0",

0 commit comments

Comments
 (0)