Skip to content

Commit ddff8dc

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

19 files changed

Lines changed: 1685 additions & 1261 deletions

File tree

.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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: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/log/* ./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
);
@@ -341,6 +356,7 @@ function ci(): void
341356
{
342357
title('ci:all');
343358
purge();
359+
loadFixures();
344360
io()->section('Coverage');
345361
coverage();
346362
io()->section('Lints');

composer.json

Lines changed: 9 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",
@@ -54,7 +58,7 @@
5458
"phpstan/extension-installer": "^1.3",
5559
"phpstan/phpstan-symfony": "^2.0",
5660
"phpunit/phpunit": "^12.0",
57-
"roave/security-advisories": "dev-latest",
61+
5862
"symfony/browser-kit": "~8.0.0",
5963
"symfony/css-selector": "~8.0.0",
6064
"symfony/debug-bundle": "~8.0.0",
@@ -97,7 +101,10 @@
97101
},
98102
"platform": {
99103
},
100-
"sort-packages": true
104+
"sort-packages": true,
105+
"audit": {
106+
"block-insecure": false
107+
}
101108
},
102109
"extra": {
103110
"bamarni-bin": {

0 commit comments

Comments
 (0)