Skip to content

Commit eb54ffa

Browse files
authored
Merge pull request #68 from lion-packages/refactoring
Component refactoring
2 parents 25ba82b + 24e0131 commit eb54ffa

19 files changed

+461
-261
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"monolog/monolog": "^3.3",
5858
"nesbot/carbon": "^2.66",
5959
"predis/predis": "^2.2",
60-
"symfony/console": "^6.3"
60+
"symfony/console": "^6.3",
61+
"symfony/process": "^7.0"
6162
},
6263
"require-dev": {
6364
"lion/test": "^2.0",

composer.lock

Lines changed: 62 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<bootstrap class="RobinIngelbrecht\PHPUnitPrettyPrint\PhpUnitExtension">
4040
<parameter name="enableByDefault" value="true" />
4141
<parameter name="displayProfiling" value="true" />
42-
<parameter name="useCompactMode" value="false" />
42+
<parameter name="useCompactMode" value="true" />
4343
</bootstrap>
4444
</extensions>
4545

src/LionBundle/Commands/Lion/New/CommandsCommand.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class CommandsCommand extends Command
3535
*/
3636
private Store $store;
3737

38-
/**
38+
/**
3939
* @required
4040
* */
4141
public function setClassFactory(ClassFactory $classFactory): CommandsCommand
@@ -60,13 +60,13 @@ public function setStore(Store $store): CommandsCommand
6060
*
6161
* @return void
6262
*/
63-
protected function configure(): void
63+
protected function configure(): void
6464
{
65-
$this
65+
$this
6666
->setName('new:command')
6767
->setDescription('Command required for the creation of new Commands')
6868
->addArgument('new-command', InputArgument::OPTIONAL, 'Command name', 'ExampleCommand');
69-
}
69+
}
7070

7171
/**
7272
* Executes the current command
@@ -87,7 +87,7 @@ protected function configure(): void
8787
*
8888
* @see setCode()
8989
*/
90-
protected function execute(InputInterface $input, OutputInterface $output): int
90+
protected function execute(InputInterface $input, OutputInterface $output): int
9191
{
9292
$command = $input->getArgument('new-command');
9393

@@ -176,12 +176,12 @@ protected function interact(InputInterface \$input, OutputInterface \$output): v
176176
}
177177
178178
/**
179-
* Executes the current command.
179+
* Executes the current command
180180
*
181181
* This method is not abstract because you can use this class
182182
* as a concrete class. In this case, instead of defining the
183183
* execute() method, you set the code to execute by passing
184-
* a Closure to the setCode() method.
184+
* a Closure to the setCode() method
185185
*
186186
* @param InputInterface \$input [InputInterface is the interface implemented
187187
* by all input classes]
@@ -211,5 +211,5 @@ protected function execute(InputInterface \$input, OutputInterface \$output): in
211211
$output->writeln($this->successOutput("\t>> COMMAND: the '{$namespace}\\{$class}' command has been generated"));
212212

213213
return Command::SUCCESS;
214-
}
214+
}
215215
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Lion\Bundle\Commands\Lion\Npm;
6+
7+
use Lion\Bundle\Helpers\Commands\ProcessCommand;
8+
use Lion\Bundle\Helpers\Commands\Selection\MenuCommand;
9+
use Lion\Command\Command;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Output\OutputInterface;
12+
13+
/**
14+
* Run the local vite environment for development
15+
*
16+
* @package Lion\Bundle\Commands\Lion\Npm
17+
*/
18+
class NpmRunDevCommand extends MenuCommand
19+
{
20+
/**
21+
* Configures the current command
22+
*
23+
* @return void
24+
*/
25+
protected function configure(): void
26+
{
27+
$this
28+
->setName('npm:dev')
29+
->setDescription('Starts the Vite development server');
30+
}
31+
32+
/**
33+
* Executes the current command
34+
*
35+
* This method is not abstract because you can use this class
36+
* as a concrete class. In this case, instead of defining the
37+
* execute() method, you set the code to execute by passing
38+
* a Closure to the setCode() method
39+
*
40+
* @param InputInterface $input [InputInterface is the interface implemented
41+
* by all input classes]
42+
* @param OutputInterface $output [OutputInterface is the interface
43+
* implemented by all Output classes]
44+
*
45+
* @return int 0 if everything went fine, or an exit code
46+
*
47+
* @throws LogicException When this abstract method is not implemented
48+
*
49+
* @see setCode()
50+
*/
51+
protected function execute(InputInterface $input, OutputInterface $output): int
52+
{
53+
$project = $this->selectedProject($input, $output);
54+
55+
ProcessCommand::run("cd ./vite/{$project} && npm run dev");
56+
57+
return Command::SUCCESS;
58+
}
59+
}

src/LionBundle/Commands/Lion/RunTestCommand.php

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,21 @@
55
namespace Lion\Bundle\Commands\Lion;
66

77
use Lion\Command\Command;
8-
use Lion\Command\Kernel;
9-
use Lion\Helpers\Arr;
8+
use Symfony\Component\Console\Application;
109
use Symfony\Component\Console\Input\InputInterface;
1110
use Symfony\Component\Console\Input\InputOption;
1211
use Symfony\Component\Console\Output\OutputInterface;
12+
use Symfony\Component\Process\Exception\ProcessFailedException;
13+
use Symfony\Component\Process\PhpExecutableFinder;
14+
use Symfony\Component\Process\Process;
1315

1416
/**
1517
* Run the tests defined with PHPunit
1618
*
17-
* @property Kernel $kernel [Kernel class object]
18-
* @property Arr $arr [Arr class object]
19-
*
2019
* @package Lion\Bundle\Commands\Lion
2120
*/
2221
class RunTestCommand extends Command
2322
{
24-
/**
25-
* [Kernel class object]
26-
*
27-
* @var Kernel $kernel
28-
*/
29-
private Kernel $kernel;
30-
31-
/**
32-
* [Arr class object]
33-
*
34-
* @var Arr $arr
35-
*/
36-
private Arr $arr;
37-
38-
/**
39-
* @required
40-
* */
41-
public function setKernel(Kernel $kernel): RunTestCommand
42-
{
43-
$this->kernel = $kernel;
44-
45-
return $this;
46-
}
47-
48-
/**
49-
* @required
50-
* */
51-
public function setArr(Arr $arr): RunTestCommand
52-
{
53-
$this->arr = $arr;
54-
55-
return $this;
56-
}
57-
5823
/**
5924
* Configures the current command
6025
*
@@ -64,10 +29,12 @@ protected function configure(): void
6429
{
6530
$this
6631
->setName('test')
67-
->setDescription('Command to create run unit tests')
68-
->addOption('class', 'c', InputOption::VALUE_OPTIONAL, 'Do you want to run a specific class?', false)
69-
->addOption('method', 'm', InputOption::VALUE_OPTIONAL, 'Do you want to filter a specific method?', false)
70-
->addOption('suite', 's', InputOption::VALUE_OPTIONAL, 'Do you want to run a specific suite?', 'All-Test');
32+
->setDescription('Runs the PHPUnit tests')
33+
->setHelp('This command allows you to run PHPUnit tests via the Symfony Console command')
34+
->addOption('class', 'c', InputOption::VALUE_OPTIONAL, 'The class to test')
35+
->addOption('method', 'm', InputOption::VALUE_OPTIONAL, 'The method to test')
36+
->addOption('suite', 's', InputOption::VALUE_OPTIONAL, 'The test suite to run')
37+
->addOption('report', 'r', InputOption::VALUE_OPTIONAL, 'The test suite with coverage report', 'none');
7138
}
7239

7340
/**
@@ -91,34 +58,45 @@ protected function configure(): void
9158
*/
9259
protected function execute(InputInterface $input, OutputInterface $output): int
9360
{
94-
$result = '';
61+
$application = new Application();
9562

96-
$class = $input->getOption('class');
63+
$application->setAutoExit(false);
9764

98-
$method = $input->getOption('method');
65+
$phpBinaryPath = (new PhpExecutableFinder())->find();
9966

100-
$suite = $input->getOption('suite');
67+
$commandString = "{$phpBinaryPath} ./vendor/bin/phpunit";
10168

102-
$output->writeln($this->successOutput("\t>> Running unit tests...\n\t>> "));
69+
if ($input->getOption('suite')) {
70+
$commandString .= ' --testsuite ' . $input->getOption('suite');
71+
}
10372

104-
$path = 'php vendor/bin/phpunit';
73+
if ($input->getOption('class')) {
74+
$commandString .= ' ./tests/' . $input->getOption('class') . '.php';
75+
}
10576

106-
if (!$class && !$method) {
107-
$result = $this->kernel->execute("{$path} --testsuite {$suite}", false);
77+
if ($input->getOption('method')) {
78+
$commandString .= ' --filter ' . $input->getOption('method');
10879
}
10980

110-
if ($class && !$method) {
111-
$result = $this->kernel->execute("{$path} tests/{$class}.php --testsuite {$suite}", false);
81+
if ('none' != $input->getOption('report')) {
82+
$commandString .= ' --coverage-clover tests/build/logs/clover.xml --coverage-html tests/build/coverage';
11283
}
11384

114-
if ($class && $method) {
115-
$result = $this->kernel->execute(
116-
"{$path} tests/{$class}.php --filter {$method} --testsuite {$suite}",
117-
false
118-
);
85+
$process = new Process(explode(' ', $commandString));
86+
87+
$process->setTimeout(null);
88+
89+
if (Process::isTtySupported()) {
90+
$process->setTty(true);
11991
}
12092

121-
$output->writeln($this->warningOutput("\t>> " . $this->arr->of($result)->join("\n\t>> ")));
93+
$process->run(function ($type, $buffer): void {
94+
echo $buffer;
95+
});
96+
97+
if (!$process->isSuccessful()) {
98+
throw new ProcessFailedException($process);
99+
}
122100

123101
return Command::SUCCESS;
124102
}

src/LionBundle/Commands/Lion/Schedule/ListScheduleCommand.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
175175
(new Table($output))
176176
->setHeaderTitle('<info> SCHEDULED TASKS </info>')
177177
->setHeaders(['CRON', 'COMMAND', 'OPTIONS', 'LOG'])
178-
->setFooterTitle(
179-
$size > 1
180-
? "<info> Showing [{$size}] available scheduled tasks </info>"
181-
: ($size === 1
182-
? '<info> Showing a scheduled task </info>'
183-
: '<info> No scheduled tasks available </info>'
184-
)
185-
)
178+
->setFooterTitle("<info> Showing [{$size}] available scheduled tasks </info>")
186179
->setRows($rows)
187180
->render();
188181

0 commit comments

Comments
 (0)