Skip to content

Commit

Permalink
feat: castor 0.15 upgrade and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
COil committed Apr 24, 2024
1 parent 9f3841b commit 92b3d70
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 48 deletions.
90 changes: 47 additions & 43 deletions castor.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

Check warning on line 1 in castor.php

View workflow job for this annotation

GitHub Actions / symfony-lint

Found violation(s) of type: no_extra_blank_lines

Check warning on line 1 in castor.php

View workflow job for this annotation

GitHub Actions / symfony-lint

Found violation(s) of type: ordered_imports

Check warning on line 1 in castor.php

View workflow job for this annotation

GitHub Actions / symfony-lint

Found violation(s) of type: blank_line_between_import_groups

// Until the 1.x Castor version the API may be unstable
// it script was tested with Castor 0.10.0
// it script was tested with Castor 0.15.0

declare(strict_types=1);

use Castor\Attribute\AsTask;
use Symfony\Component\Console\Command\Command;

use function Castor\get_command;
use function Castor\exit_code;
use function Castor\task;
use function Castor\io;
use function Castor\run;

Expand All @@ -22,9 +23,13 @@ function title(string $title, ?Command $command = null): void
io()->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
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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();
Expand All @@ -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();
Expand 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();
Expand All @@ -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'));
}
5 changes: 0 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
</testsuite>
</testsuites>

<coverage>
<report>
<clover outputFile="var/coverage/clover.xml"/>
</report>
</coverage>
<!-- Run `composer require symfony/panther` before enabling this extension -->
<!--
<extensions>
Expand Down

0 comments on commit 92b3d70

Please sign in to comment.