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

orchestral / dusk-updater / 13355156842

16 Feb 2025 12:49PM UTC coverage: 59.794% (+14.2%) from 45.604%
13355156842

push

github

crynobone
Merge branch '2.x' into 3.x

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

36 of 40 new or added lines in 5 files covered. (90.0%)

1 existing line in 1 file now uncovered.

58 of 97 relevant lines covered (59.79%)

1.69 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
use Symfony\Component\Console\Style\SymfonyStyle;
14

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

28
        parent::configure();
×
29
    }
30

31
    /** {@inheritDoc */
32
    #[\Override]
33
    protected function execute(InputInterface $input, OutputInterface $output): int
34
    {
NEW
35
        $finder = new ChromeVersionFinder;
×
UNCOV
36
        $io = new SymfonyStyle($input, $output);
×
37

38
        $chromeDirectory = $input->getOption('chrome-dir');
×
39
        $driverDirectory = $input->getOption('install-dir');
×
40
        $autoUpdate = $input->getOption('auto-update');
×
41

42
        $currentOS = OperatingSystem::id();
×
43

NEW
44
        $chromeVersions = $finder->installedChromeVersion($currentOS, $chromeDirectory);
×
NEW
45
        $driverVersions = $finder->installedChromeDriverVersion($currentOS, (string) $driverDirectory);
×
46

47
        $updated = Comparator::equalTo(
×
48
            isset($driverVersions['semver']) ? $driverVersions['semver'] : '',
×
49
            isset($chromeVersions['semver']) ? $chromeVersions['semver'] : ''
×
50
        );
×
51

52
        $io->block(\sprintf('Running PHP %s on Platform [%s]', PHP_VERSION, $currentOS));
×
53

54
        $io->table(['Tool', 'Version'], [
×
55
            ['Chrome/Chromium', $chromeVersions['semver'] ?? '<fg=yellow>✖ N/A</>'],
×
56
            ['ChromeDriver', $driverVersions['semver'] ?? '<fg=yellow>✖ N/A</>'],
×
57
        ]);
×
58

59
        if (! $updated) {
×
60
            if (! $autoUpdate) {
×
61
                $io->caution('ChromeDriver is outdated!');
×
62
            }
63

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

69
        return self::SUCCESS;
×
70
    }
71

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

80
        $command = $console->find('update');
×
81

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

91
        return $command->run(new ArrayInput($arguments), $output);
×
92
    }
93
}
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