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 97ab75f
Show file tree
Hide file tree
Showing 17 changed files with 1,284 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 ###
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ help: ## Outputs this help screen
.PHONY: version-php version-composer version-symfony version-phpunit version-phpstan version-php-cs-fixer check-requirements

# You can modify the coverage threshold here
COVERAGE_THRESHOLD = 100
COVERAGE_THRESHOLD = 80

## —— Symfony binary 💻 ————————————————————————————————————————————————————————
start: ## Serve the application with the Symfony binary
Expand Down Expand Up @@ -36,6 +36,11 @@ warmup: ## Warmup the dev cache for the static analysis
purge: ## Purge all Symfony cache and logs
@rm -rf ./var/cache/* ./var/logs/* ./var/coverage/*

load-fixtures: ## Reset migrations and load the database fixtures
@rm -f ./var/data.db
@bin/console d:m:m --env=dev --no-interaction
@bin/console a:l --env=dev --no-interaction


## —— Tests ✅ —————————————————————————————————————————————————————————————————
test: ## Run all PHPUnit tests
Expand Down
18 changes: 17 additions & 1 deletion castor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// use function Castor\parallel;

// You can modify the coverage threshold here
const COVERAGE_THRESHOLD = 100;
const COVERAGE_THRESHOLD = 80;

function title(string $name): void
{
Expand Down 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', quiet: false));
io()->note('Running db migrations...');
success(exit_code('bin/console d:m:m --no-interaction', quiet: false));
io()->note('Load fixtures...');
success(exit_code('bin/console a:l --no-interaction', quiet: false));
}

#[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,8 @@ function test_all(): int
function coverage(): int
{
title('test:coverage');
io()->note('Load fixtures...');
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 +253,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 97ab75f

Please sign in to comment.