• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 14049246919

24 Mar 2025 09:42PM UTC coverage: 79.353% (-0.04%) from 79.391%
14049246919

push

github

web-flow
feat(support): support array parameters in string manipulations (#1073)

48 of 48 new or added lines in 2 files covered. (100.0%)

735 existing lines in 126 files now uncovered.

10492 of 13222 relevant lines covered (79.35%)

90.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Tempest/CommandBus/src/MonitorAsyncCommands.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\CommandBus;
6

7
use DateTimeImmutable;
8
use Symfony\Component\Process\Process;
9
use Tempest\Console\Console;
10
use Tempest\Console\ConsoleCommand;
11
use Tempest\Console\HasConsole;
12
use Tempest\Console\Input\ConsoleArgumentBag;
13

14
use function Tempest\Support\arr;
15

16
final readonly class MonitorAsyncCommands
17
{
18
    use HasConsole;
19

20
    public function __construct(
×
21
        private CommandRepository $repository,
22
        private ConsoleArgumentBag $argumentBag,
23
        private Console $console,
UNCOV
24
    ) {}
×
25

UNCOV
26
    #[ConsoleCommand(name: 'command:monitor', description: 'Monitors and executes pending async commands')]
×
27
    public function __invoke(): void
28
    {
UNCOV
29
        $this->info('Monitoring for new commands. Press <em>Ctrl+C</em> to stop.');
×
30
        $this->writeln();
×
31

32
        /** @var \Symfony\Component\Process\Process[] $processes */
UNCOV
33
        $processes = [];
×
34

UNCOV
35
        while (true) { // @phpstan-ignore-line
×
36
            foreach ($processes as $uuid => $process) {
×
37
                if ($process->isTerminated()) {
×
38
                    if ($process->isSuccessful()) {
×
39
                        $this->console->keyValue(
×
40
                            key: "<style='fg-gray'>{$uuid}</style>",
×
41
                            value: "<style='fg-green bold'>SUCCESS</style>",
×
42
                        );
×
43
                    } else {
UNCOV
44
                        $this->console->keyValue(
×
45
                            key: "<style='fg-gray'>{$uuid}</style>",
×
46
                            value: "<style='fg-red bold'>FAILED</style>",
×
47
                        );
×
48
                    }
49

UNCOV
50
                    if ($output = trim($process->getOutput())) {
×
51
                        $this->writeln($output);
×
52
                    }
53

UNCOV
54
                    if ($errorOutput = trim($process->getErrorOutput())) {
×
55
                        $this->writeln($errorOutput);
×
56
                    }
57

UNCOV
58
                    unset($processes[$uuid]);
×
59
                }
60
            }
61

UNCOV
62
            $availableCommands = arr($this->repository->getPendingCommands())
×
63
                ->filter(fn (object $_, string $uuid) => ! array_key_exists($uuid, $processes));
×
64

UNCOV
65
            if (count($processes) === 5) {
×
66
                $this->sleep(0.5);
×
67

UNCOV
68
                continue;
×
69
            }
70

UNCOV
71
            if ($availableCommands->isEmpty()) {
×
72
                $this->sleep(0.5);
×
73

UNCOV
74
                continue;
×
75
            }
76

77
            // Start a task
UNCOV
78
            $uuid = $availableCommands->keys()->first();
×
79

UNCOV
80
            $time = new DateTimeImmutable();
×
81
            $this->console->keyValue(
×
82
                key: $uuid,
×
83
                value: "<style='fg-gray'>{$time->format('Y-m-d H:i:s')}</style>",
×
84
            );
×
85

UNCOV
86
            $process = new Process([
×
87
                $this->argumentBag->getBinaryPath(),
×
88
                $this->argumentBag->getCliName(),
×
89
                'command:handle',
×
90
                $uuid,
×
91
            ], getcwd());
×
92

UNCOV
93
            $process->start();
×
94

UNCOV
95
            $processes[$uuid] = $process;
×
96
        }
97
    }
98

UNCOV
99
    private function sleep(float $seconds): void
×
100
    {
UNCOV
101
        usleep((int) ($seconds * 1_000_000));
×
102
    }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc