Skip to content

Commit

Permalink
feat: use Doctrine DBAL to query a SQLite database
Browse files Browse the repository at this point in the history
  • Loading branch information
COil committed Oct 11, 2024
1 parent 4d15cac commit c538040
Show file tree
Hide file tree
Showing 18 changed files with 1,330 additions and 139 deletions.
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ APP_SECRET=3bUhVCRkHJfT2ZJTqBnvkclRFT1zy1ig
# To test the production environment, run "make go-prod" or "castor symfony:go-prod"

# To come back to the development environment, run "make go-dev" or "castor symfony:go-dev"

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
###< doctrine/doctrine-bundle ###
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ go-dev: ## Switch to the development environment
warmup: ## Warmup the dev cache for the static analysis
@bin/console c:w --env=dev

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

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


## —— Tests ✅ —————————————————————————————————————————————————————————————————
test: ## Run all PHPUnit tests
@vendor/bin/phpunit

coverage: ## Generate the HTML PHPUnit code coverage report (stored in var/coverage)
coverage: purge
coverage: purge load-fixtures
@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
@php bin/coverage-checker.php var/coverage/clover.xml $(COVERAGE_THRESHOLD)

Expand Down
15 changes: 15 additions & 0 deletions castor.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,23 @@ function purge(): void
success(exit_code('rm -rf ./var/cache/* ./var/logs/* ./var/coverage/*'));
}

#[AsTask(namespace: 'app', description: 'Load the database fixtures', aliases: ['load-fixtures'])]
function loadFixures(): void
{
title('app:load-fixtures');
io()->note('Resetting db...');
success(exit_code('rm -f ./var/data.db'));
io()->note('Running db migrations...');
success(exit_code('bin/console doctrine:migration:migrate --no-interaction'));
io()->note('Load fixtures...');
success(exit_code('bin/console app:load-fixtures --no-interaction'));
}

#[AsTask(name: 'all', namespace: 'test', description: 'Run all PHPUnit tests', aliases: ['test'])]
function test_all(): int
{
title('test:all');
loadFixures();
$ec = exit_code(__DIR__.'/vendor/bin/phpunit');
io()->writeln('');

Expand All @@ -107,6 +120,7 @@ function test_all(): int
function coverage(): int
{
title('test:coverage');
loadFixures();
$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',
context: context()->withEnvironment(['XDEBUG_MODE' => 'coverage'])
);
Expand Down Expand Up @@ -238,6 +252,7 @@ function ci(): void
{
title('ci:all');
purge();
loadFixures();
io()->section('Coverage');
coverage();
io()->section('Codings standards');
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"ext-libxml": "*",
"ext-simplexml": "*",
"ext-xml": "*",
"doctrine/dbal": "^4.0",
"doctrine/doctrine-bundle": "^2.13",
"doctrine/doctrine-migrations-bundle": "^3.3",
"league/commonmark": "^2.4",
"symfony/asset": "~7.1.0",
"symfony/asset-mapper": "~7.1.0",
Expand Down
Loading

0 comments on commit c538040

Please sign in to comment.