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

orchestral / dusk-updater / 13355377128

16 Feb 2025 01:14PM UTC coverage: 56.977% (-2.8%) from 59.794%
13355377128

push

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

40 of 76 new or added lines in 2 files covered. (52.63%)

18 existing lines in 2 files now uncovered.

98 of 172 relevant lines covered (56.98%)

1.65 hits per line

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

0.0
/src/DetectCommand.php
1
<?php
2

3
namespace Orchestra\DuskUpdater;
4

5
use Composer\Semver\Comparator;
6
use Orchestra\DuskUpdaterApi\ChromeVersionFinder;
7
use Orchestra\DuskUpdaterApi\OperatingSystem;
8
use Symfony\Component\Console\Attribute\AsCommand;
9
use Symfony\Component\Console\Input\ArrayInput;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13

14
use function Laravel\Prompts\confirm;
15
use function Laravel\Prompts\intro;
16
use function Laravel\Prompts\table;
17
use function Laravel\Prompts\warning;
18

19
/**
20
 * @copyright Originally created by Jonas Staudenmeir: https://github.com/staudenmeir/dusk-updater
21
 */
22
#[AsCommand(name: 'detect', description: 'Detect the installed Chrome/Chromium version')]
23
class DetectCommand extends Command
24
{
25
    /** {@inheritDoc} */
26
    #[\Override]
27
    protected function configure(): void
28
    {
UNCOV
29
        $this->addOption('chrome-dir', null, InputOption::VALUE_OPTIONAL, 'Detect the installed Chrome/Chromium version, optionally in a custom path')
×
UNCOV
30
            ->addOption('auto-update', null, InputOption::VALUE_NONE, 'Auto update ChromeDriver binary if outdated');
×
31

UNCOV
32
        parent::configure();
×
33
    }
34

35
    /** {@inheritDoc} */
36
    #[\Override]
37
    protected function execute(InputInterface $input, OutputInterface $output): int
38
    {
39
        $finder = new ChromeVersionFinder;
×
40

UNCOV
41
        $chromeDirectory = $input->getOption('chrome-dir');
×
42
        $driverDirectory = $input->getOption('install-dir');
×
UNCOV
43
        $autoUpdate = $input->getOption('auto-update');
×
44

45
        $currentOS = OperatingSystem::id();
×
46

47
        $chromeVersions = $finder->installedChromeVersion($currentOS, $chromeDirectory);
×
48
        $driverVersions = $finder->installedChromeDriverVersion($currentOS, (string) $driverDirectory);
×
49

50
        $updated = Comparator::equalTo(
×
UNCOV
51
            isset($driverVersions['semver']) ? $driverVersions['semver'] : '',
×
52
            isset($chromeVersions['semver']) ? $chromeVersions['semver'] : ''
×
UNCOV
53
        );
×
54

55
        intro(\sprintf('Running PHP %s on Platform [%s]', PHP_VERSION, $currentOS));
×
56

57
        table(['Tool', 'Version'], [
×
UNCOV
58
            ['Chrome/Chromium', $chromeVersions['semver'] ?? '<fg=yellow>✖ N/A</>'],
×
59
            ['ChromeDriver', $driverVersions['semver'] ?? '<fg=yellow>✖ N/A</>'],
×
60
        ]);
×
61

UNCOV
62
        if (! $updated) {
×
UNCOV
63
            if (! $autoUpdate) {
×
64
                warning('ChromeDriver is outdated!');
×
65
            }
66

UNCOV
67
            if ($autoUpdate || confirm('Do you want to update ChromeDriver?')) {
×
UNCOV
68
                $this->updateChromeDriver($input, $output, $driverDirectory, $chromeVersions['major']);
×
69
            }
70
        }
71

UNCOV
72
        return self::SUCCESS;
×
73
    }
74

75
    /**
76
     * Update ChromeDriver.
77
     */
78
    protected function updateChromeDriver(InputInterface $input, OutputInterface $output, string $directory, int $version): int
79
    {
80
        /** @var \Symfony\Component\Console\Application $console */
UNCOV
81
        $console = $this->getApplication();
×
82

83
        $command = $console->find('update');
×
84

85
        $arguments = array_merge([
×
86
            'command' => 'update',
×
87
            'version' => $version,
×
88
            '--install-dir' => $directory,
×
89
        ], array_filter([
×
UNCOV
90
            '--proxy' => $input->getOption('proxy'),
×
91
            '--ssl-no-verify' => $input->getOption('ssl-no-verify'),
×
UNCOV
92
        ]));
×
93

UNCOV
94
        return $command->run(new ArrayInput($arguments), $output);
×
95
    }
96
}
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