Skip to content

Commit ab123d6

Browse files
committed
feat: use Doctrine DBAL to query a SQLite database
1 parent 63c248d commit ab123d6

File tree

24 files changed

+2182
-213
lines changed

24 files changed

+2182
-213
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:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
33+
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1: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: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SHELL = sh
55
DOMAIN = microsymfony.ovh
66

77
# modify the code coverage threshold here
8-
COVERAGE_THRESHOLD = 100
8+
COVERAGE_THRESHOLD = 88
99

1010
## —— 🎶 The MicroSymfony Makefile 🎶 ——————————————————————————————————————————
1111
help: ## Outputs this help screen
@@ -40,6 +40,11 @@ warmup: ## Warmup the dev cache for the static analysis
4040
purge: ## Purge all Symfony cache and logs
4141
@rm -rf ./var/cache/* ./var/log/* ./var/coverage/*
4242

43+
load-fixtures: ## Reset migrations and load the database fixtures
44+
@rm -f ./var/data.db
45+
@bin/console doctrine:migrations:migrate --env=dev --no-interaction
46+
@bin/console foundry: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

@@ -107,11 +112,14 @@ lint-container: ## Lint the Symfony DI container
107112
lint-twig: ## Lint Twig files
108113
@bin/console lint:twig templates/
109114

115+
lint-doctrine: ## Validate Dcotirne schema
116+
@bin/console doctrine:schema:validate
117+
110118
fix: ## Run all fixers
111119
fix: fix-php fix-js-css
112120

113121
lint: ## Run all linters
114-
lint: stan lint-php lint-js-css lint-container lint-twig
122+
lint: stan lint-php lint-doctrine lint-js-css lint-container lint-twig
115123

116124
ci: ## Run CI locally
117125
ci: coverage warmup lint

castor.php

Lines changed: 15 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/log/* ./var/coverage/*'));
9797
}
9898

99+
#[AsTask(namespace: 'app', description: 'Load the database fixtures', aliases: ['load-fixtures'])]
100+
function loadFixtures(): 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:migrations: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,7 @@ function getParameters(): array
111123
function test_all(): int
112124
{
113125
title('test:all');
126+
loadFixtures();
114127
[$filter, $options] = getParameters();
115128
$ec = exit_code(__DIR__.sprintf(PHP_UNIT_CMD, implode(',', PHP_UNIT_SUITES), $filter, $options));
116129
io()->writeln('');
@@ -177,6 +190,7 @@ function test_unit(
177190
function coverage(): int
178191
{
179192
title('test:coverage');
193+
loadFixtures();
180194
$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',
181195
context: context()->withEnvironment(['XDEBUG_MODE' => 'coverage'])
182196
);
@@ -341,6 +355,7 @@ function ci(): void
341355
{
342356
title('ci:all');
343357
purge();
358+
loadFixtures();
344359
io()->section('Coverage');
345360
coverage();
346361
io()->section('Lints');

composer.json

Lines changed: 10 additions & 2 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": "^3.0",
27+
"doctrine/doctrine-migrations-bundle": "^3.3",
28+
"doctrine/orm": "^3.3",
2529
"league/commonmark": "^2.4",
2630
"symfony/asset": "~8.0.0",
2731
"symfony/asset-mapper": "~8.0.0",
@@ -61,7 +65,8 @@
6165
"symfony/maker-bundle": "^1.61",
6266
"symfony/requirements-checker": "^2.0",
6367
"symfony/stopwatch": "~8.0.0",
64-
"symfony/web-profiler-bundle": "~8.0.0"
68+
"symfony/web-profiler-bundle": "~8.0.0",
69+
"zenstruck/foundry": "^2.4"
6570
},
6671
"replace": {
6772
"symfony/polyfill-ctype": "*",
@@ -97,7 +102,10 @@
97102
},
98103
"platform": {
99104
},
100-
"sort-packages": true
105+
"sort-packages": true,
106+
"audit": {
107+
"block-insecure": false
108+
}
101109
},
102110
"extra": {
103111
"bamarni-bin": {

0 commit comments

Comments
 (0)