generated from strangebuzz/MicroSymfony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
castor.php
152 lines (132 loc) · 3.98 KB
/
castor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
// Until the 1.x Castor version the API may be unstable
// it script was tested with Castor 0.8.0
declare(strict_types=1);
use Castor\Attribute\AsTask;
use Symfony\Component\Console\Command\Command;
use function Castor\get_command;
use function Castor\io;
use function Castor\run;
// use function Castor\parallel;
/**
* Don't display the description when using a parent command context.
*/
function title(string $title, Command $command = null): void
{
io()->title($title.($command !== null ? ': '.$command->getDescription() : ''));
}
function success(): void
{
io()->success('Done!');
}
#[AsTask(namespace: 'symfony', description: 'Serve the application with the Symfony binary', )]
function start(): void
{
title(__FUNCTION__, get_command());
run('symfony serve --daemon', quiet: false);
success();
}
#[AsTask(namespace: 'symfony', description: 'Stop the web server')]
function stop(): void
{
title(__FUNCTION__, get_command());
run('symfony server:stop', quiet: false);
success();
}
#[AsTask(name: 'all', namespace: 'test', description: 'Run all PHPUnit tests')]
function test(): void
{
title(__FUNCTION__, get_command());
run('vendor/bin/simple-phpunit', quiet: false);
io()->writeln('');
success();
}
#[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/simple-phpunit --coverage-html=var/coverage',
environment: [
'XDEBUG_MODE' => 'coverage',
],
quiet: false
);
run('php bin/coverage-checker.php var/coverage/clover.xml 100', quiet: false);
success();
}
#[AsTask(namespace: 'test', description: 'Open the PHPUnit code coverage report (var/coverage/index.html)')]
function cov_report(): void
{
title(__FUNCTION__, get_command());
run('open var/coverage/index.html', quiet: true);
success();
}
#[AsTask(namespace: 'cs', description: 'Run PHPStan')]
function stan(): void
{
title(__FUNCTION__, get_command());
run('vendor/bin/phpstan analyse -c phpstan.neon --memory-limit 1G -vvv --xdebug', quiet: false);
success();
}
#[AsTask(namespace: 'cs', description: 'Fix PHP files with php-cs-fixer (ignore PHP 8.2 warning)')]
function fix_php(): void
{
title(__FUNCTION__, get_command());
run('vendor/bin/php-cs-fixer fix --allow-risky=yes',
environment: [
'PHP_CS_FIXER_IGNORE_ENV' => 1,
],
quiet: false
);
success();
}
#[AsTask(name: 'all', namespace: 'cs', description: 'Run all CS checks')]
function cs_all(): void
{
title(__FUNCTION__, get_command());
fix_php();
stan();
}
#[AsTask(name: 'container', namespace: 'lint', description: 'Lint the Symfony DI container')]
function lint_container(): void
{
title(__FUNCTION__, get_command());
run('bin/console lint:container', quiet: false);
success();
}
#[AsTask(name: 'twig', namespace: 'lint', description: 'Lint Twig files')]
function lint_twig(): void
{
title(__FUNCTION__, get_command());
run('bin/console lint:twig templates/', quiet: false);
success();
}
#[AsTask(name: 'yaml', namespace: 'lint', description: 'Lint Yaml files')]
function lint_yaml(): void
{
title(__FUNCTION__, get_command());
run('bin/console lint:yaml --parse-tags config/', quiet: false);
success();
}
#[AsTask(name: 'all', namespace: 'lint', description: 'Run all lints')]
function lint_all(): void
{
title(__FUNCTION__, get_command());
lint_container();
lint_twig();
lint_yaml();
// if you want to speed up the process, you can run these commands in parallel
// parallel(
// fn() => lint_container(null),
// fn() => lint_twig(),
// fn() => lint_yaml(),
// );
}
#[AsTask(name: 'all', namespace: 'ci', description: 'Run CI locally')]
function ci(): void
{
title(__FUNCTION__, get_command());
test();
cs_all();
lint_all();
}