Skip to content

Commit 5813731

Browse files
authored
Refactor runTestsInCoroutine and kernel injection (#5848)
1 parent 6f807cf commit 5813731

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"symfony/http-foundation": "^5.4|^6.0"
3434
},
3535
"suggest": {
36-
"pestphp/pest": "For testing with Pest.(^2.0)"
36+
"pestphp/pest": "For testing with Pest.(^2.8.0)"
3737
},
3838
"extra": {
3939
"branch-alias": {

src/Plugin/Pest.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
use Pest\Kernel;
1919
use Pest\Plugins\Concerns\HandleArguments;
2020
use Pest\Support\Container;
21-
use PHPUnit\TextUI\Application;
2221
use Swoole\Coroutine;
2322
use Swoole\Timer;
24-
use Symfony\Component\Console\Output\OutputInterface;
2523

2624
/**
2725
* @property string $vendorDir
2826
*/
29-
class Pest implements HandlesArguments
27+
final class Pest implements HandlesArguments
3028
{
3129
use HandleArguments;
3230

@@ -43,22 +41,19 @@ public function handleArguments(array $arguments): array
4341
}
4442

4543
if ($this->hasArgument('--parallel', $arguments) || $this->hasArgument('-p', $arguments)) {
46-
throw new InvalidOption('The coroutine mode is not supported when running in parallel.');
44+
throw new InvalidOption('The [--coroutine] option is not supported when running in parallel.');
4745
}
4846

4947
$arguments = $this->popArgument('--coroutine', $arguments);
5048

51-
exit($this->runInCoroutine($arguments));
49+
exit($this->runTestsInCoroutine($arguments));
5250
}
5351

54-
private function runInCoroutine(array $arguments): int
52+
private function runTestsInCoroutine(array $arguments): int
5553
{
5654
$code = 0;
57-
$output = Container::getInstance()->get(OutputInterface::class);
58-
$kernel = new Kernel(
59-
new Application(),
60-
$output,
61-
);
55+
/** @var Kernel $kernel */
56+
$kernel = Container::getInstance()->get(Kernel::class);
6257

6358
Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL, 'exit_condition' => function () {
6459
return Coroutine::stats()['coroutine_num'] === 0;
@@ -79,12 +74,14 @@ private function runInCoroutine(array $arguments): int
7974
private function prepend(array $arguments): array
8075
{
8176
$prepend = null;
77+
8278
foreach ($arguments as $key => $argument) {
8379
if (str_starts_with($argument, '--prepend=')) {
8480
$prepend = explode('=', $argument, 2)[1];
8581
unset($arguments[$key]);
8682
break;
8783
}
84+
8885
if (str_starts_with($argument, '--prepend')) {
8986
if (isset($arguments[$key + 1])) {
9087
$prepend = $arguments[$key + 1];

0 commit comments

Comments
 (0)