From 92b3d70162bad64be4faf978040e1296e77f3b92 Mon Sep 17 00:00:00 2001 From: COil Date: Fri, 19 Apr 2024 07:41:39 +0200 Subject: [PATCH] feat: castor 0.15 upgrade and cleanup --- castor.php | 90 +++++++++++++++++++++++++----------------------- phpunit.xml.dist | 5 --- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/castor.php b/castor.php index 142528f..020a1af 100644 --- a/castor.php +++ b/castor.php @@ -1,14 +1,15 @@ title($title.($command !== null ? ': '.$command->getDescription() : '')); } -function success(): void +function success(int $exitCode): void { - io()->success('Done!'); + if ($exitCode === 0) { + io()->success('Done!'); + } else { + io()->warning(sprintf('Failure (exit code %d returned).', $exitCode)); + } } function aborted(): void @@ -35,27 +40,27 @@ function aborted(): void #[AsTask(namespace: 'symfony', description: 'Serve the application with the Symfony binary', )] function start(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); run('symfony serve --daemon', quiet: false); - success(); + success(0); } #[AsTask(namespace: 'symfony', description: 'Stop the web server')] function stop(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); run('symfony server:stop', quiet: false); - success(); + success(0); } #[AsTask(namespace: 'symfony', description: 'Switch to the production environment')] function go_prod(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); if (io()->confirm('Are you sure you want to switch to the production environment? This will overwrite your .env.local file', false)) { run('cp .env.local.dist .env.local', quiet: false); run('bin/console asset-map:compile', quiet: false); - success(); + success(0); return; } @@ -66,11 +71,11 @@ function go_prod(): void #[AsTask(namespace: 'symfony', description: 'Switch to the development environment')] function go_dev(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); if (io()->confirm('Are you sure you want to switch to the development environment? This will delete your .env.local file', false)) { run('rm -f .env.local', quiet: false); run('rm -rf ./public/assets/*', quiet: false); - success(); + success(0); return; } @@ -81,111 +86,111 @@ function go_dev(): void #[AsTask(namespace: 'symfony', description: 'Purge all Symfony cache and logs')] function purge(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); run('rm -rf ./var/cache/* ./var/logs/* ./var/coverage/*', quiet: false); - success(); + success(0); } #[AsTask(name: 'all', namespace: 'test', description: 'Run all PHPUnit tests')] function test(): void { - title(__FUNCTION__, get_command()); - run('vendor/bin/phpunit', quiet: false); + title(__FUNCTION__, task()); + $ec = exit_code(__DIR__.'/vendor/bin/phpunit'); io()->writeln(''); - success(); + success($ec); } #[AsTask(namespace: 'test', description: 'Generate the HTML PHPUnit code coverage report (stored in var/coverage)')] function coverage(): void { - title(__FUNCTION__, get_command()); - run('php -d xdebug.enable=1 -d memory_limit=-1 vendor/bin/phpunit --coverage-html=var/coverage', + title(__FUNCTION__, task()); + run('php -d xdebug.enable=1 -d memory_limit=-1 vendor/bin/phpunit --coverage-html=var/coverage --coverage-clover=var/coverage/clover.xml', environment: [ 'XDEBUG_MODE' => 'coverage', ], quiet: false ); - run('php bin/coverage-checker.php var/coverage/clover.xml 100', quiet: false); - success(); + $ec = exit_code('php bin/coverage-checker.php var/coverage/clover.xml 100', quiet: false); + success($ec); } #[AsTask(namespace: 'test', description: 'Open the PHPUnit code coverage report (var/coverage/index.html)')] function cov_report(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); run('open var/coverage/index.html', quiet: true); - success(); + success(0); } #[AsTask(namespace: 'cs', description: 'Run PHPStan')] function stan(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); run('vendor/bin/phpstan analyse -c phpstan.neon --memory-limit 1G -vvv', quiet: false); - success(); + success(0); } #[AsTask(namespace: 'cs', description: 'Fix PHP files with php-cs-fixer (ignore PHP 8.2 warning)')] function fix_php(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); run('vendor/bin/php-cs-fixer fix --allow-risky=yes', environment: [ 'PHP_CS_FIXER_IGNORE_ENV' => 1, ], quiet: false ); - success(); + success(0); } #[AsTask(namespace: 'cs', description: 'Lint PHP files with php-cs-fixer (report only)')] function lint_php(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); run('vendor/bin/php-cs-fixer fix --allow-risky=yes --dry-run', environment: [ 'PHP_CS_FIXER_IGNORE_ENV' => 1, ], quiet: false ); - success(); + success(0); } #[AsTask(name: 'all', namespace: 'cs', description: 'Run all CS checks')] function cs_all(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); fix_php(); stan(); } #[AsTask(name: 'container', namespace: 'lint', description: 'Lint the Symfony DI container')] function lint_container(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); run('bin/console lint:container', quiet: false); - success(); + success(0); } #[AsTask(name: 'twig', namespace: 'lint', description: 'Lint Twig files')] function lint_twig(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); run('bin/console lint:twig templates/', quiet: false); - success(); + success(0); } #[AsTask(name: 'yaml', namespace: 'lint', description: 'Lint Yaml files')] function lint_yaml(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); run('bin/console lint:yaml --parse-tags config/', quiet: false); - success(); + success(0); } #[AsTask(name: 'all', namespace: 'lint', description: 'Run all lints')] function lint_all(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); lint_php(); lint_container(); lint_twig(); @@ -203,7 +208,7 @@ function lint_all(): void #[AsTask(name: 'all', namespace: 'ci', description: 'Run CI locally')] function ci(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); test(); cs_all(); lint_all(); @@ -212,7 +217,7 @@ function ci(): void #[AsTask(name: 'versions', namespace: 'helpers', description: 'Output current stack versions')] function versions(): void { - title(__FUNCTION__, get_command()); + title(__FUNCTION__, task()); io()->note('PHP'); run('php -v', quiet: false); io()->newLine(); @@ -236,13 +241,12 @@ function versions(): void run('vendor/bin/php-cs-fixer --version', quiet: false); io()->newLine(); - success(); + success(0); } #[AsTask(name: 'check-requirements', namespace: 'helpers', description: 'Checks requirements for running Symfony')] function check_requirements(): void { - title(__FUNCTION__, get_command()); - run('vendor/bin/requirements-checker', quiet: false); - success(); + title(__FUNCTION__, task()); + success(exit_code('vendor/bin/requirements-checker')); } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c3edc78..c6edcb5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -26,11 +26,6 @@ - - - - -