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

orchestral / sidekick / 18183807442

02 Oct 2025 04:57AM UTC coverage: 91.848% (-0.8%) from 92.697%
18183807442

push

github

web-flow
Allows `Orchestra\Sidekick\is_testbench_cli()` to detect running via Testbench Dusk CLI (#56)

* Allows `Orchestra\Sidekick\is_testbench_cli()` to detect running via
Testbench Dusk CLI

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

* wip

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

* wip

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

* wip

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

* wip

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

* wip

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

* wip

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

---------

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

6 of 7 new or added lines in 1 file covered. (85.71%)

5 existing lines in 2 files now uncovered.

169 of 184 relevant lines covered (91.85%)

5.89 hits per line

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

87.18
/src/functions.php
1
<?php
2

3
namespace Orchestra\Sidekick;
4

5
use Closure;
6
use Illuminate\Foundation\Application;
7
use Illuminate\Support\Arr;
8
use PHPUnit\Runner\Version;
9
use RuntimeException;
10

11
if (! \function_exists('Orchestra\Sidekick\join_paths')) {
12
    /**
13
     * Join the given paths together.
14
     *
15
     * @api
16
     */
17
    function join_paths(?string $basePath, string ...$paths): string
18
    {
19
        foreach ($paths as $index => $path) {
18✔
20
            if (empty($path) && $path !== '0') {
18✔
21
                unset($paths[$index]);
18✔
22
            } else {
23
                $paths[$index] = DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR);
18✔
24
            }
25
        }
26

27
        return $basePath.implode('', $paths);
18✔
28
    }
29
}
30

31
if (! \function_exists('Orchestra\Sidekick\once')) {
32
    /**
33
     * Run callback only once.
34
     *
35
     * @api
36
     *
37
     * @param  mixed  $callback
38
     * @return \Closure():mixed
39
     */
40
    function once($callback): Closure
41
    {
42
        $response = new UndefinedValue;
22✔
43

44
        return function () use ($callback, &$response) {
22✔
45
            if ($response instanceof UndefinedValue) {
22✔
46
                $response = value($callback) ?? null;
22✔
47
            }
48

49
            return $response;
22✔
50
        };
22✔
51
    }
52
}
53

54
if (! \function_exists('Orchestra\Sidekick\is_safe_callable')) {
55
    /**
56
     * Determine if the value is a callable and not a string matching an available function name.
57
     *
58
     * @api
59
     */
60
    function is_safe_callable(mixed $value): bool
61
    {
62
        if ($value instanceof Closure) {
6✔
63
            return true;
1✔
64
        }
65

66
        if (! \is_callable($value)) {
5✔
67
            return false;
2✔
68
        }
69

70
        if (\is_array($value)) {
3✔
71
            $isList = \function_exists('array_is_list')
1✔
72
                ? array_is_list($value)
1✔
73
                : ! Arr::isAssoc($value);
×
74

75
            return \count($value) === 2 && $isList && method_exists(...$value);
1✔
76
        }
77

78
        return ! \is_string($value);
2✔
79
    }
80
}
81

82
if (! \function_exists('Orchestra\Sidekick\is_symlink')) {
83
    /**
84
     * Determine if the path is a symlink for both Unix and Windows environments.
85
     *
86
     * @api
87
     */
88
    function is_symlink(string $path): bool
89
    {
90
        if (windows_os() && is_dir($path) && readlink($path) !== $path) {
1✔
91
            return true;
×
92
        } elseif (is_link($path)) {
1✔
93
            return true;
×
94
        }
95

96
        return false;
1✔
97
    }
98
}
99

100
if (! \function_exists('Orchestra\Sidekick\is_testbench_cli')) {
101
    /**
102
     * Determine if command executed via Testbench CLI.
103
     *
104
     * @api
105
     */
106
    function is_testbench_cli(?bool $dusk = null): bool
107
    {
108
        $usingTestbench = \defined('TESTBENCH_CORE');
1✔
109
        $usingTestbenchDusk = \defined('TESTBENCH_DUSK');
1✔
110

111
        return match ($dusk) {
1✔
NEW
112
            false => $usingTestbench === true && $usingTestbenchDusk === false,
×
113
            true => $usingTestbench === true && $usingTestbenchDusk === true,
1✔
114
            default => $usingTestbench === true,
1✔
115
        };
1✔
116
    }
117
}
118

119
if (! \function_exists('Orchestra\Sidekick\transform_relative_path')) {
120
    /**
121
     * Transform relative path.
122
     *
123
     * @api
124
     */
125
    function transform_relative_path(string $path, string $workingPath): string
126
    {
127
        return str_starts_with($path, './')
1✔
128
            ? rtrim($workingPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.mb_substr($path, 2)
1✔
129
            : $path;
1✔
130
    }
131
}
132

133
if (! \function_exists('Orchestra\Sidekick\working_path')) {
134
    /**
135
     * Get the working path.
136
     *
137
     * @api
138
     *
139
     * @no-named-arguments
140
     *
141
     * @param  array<int, string|null>|string  ...$path
142
     */
143
    function working_path(array|string $path = ''): string
144
    {
145
        return is_testbench_cli() && \function_exists('Orchestra\Testbench\package_path')
1✔
146
            ? \Orchestra\Testbench\package_path($path)
×
147
            : base_path(join_paths(...Arr::wrap(\func_num_args() > 1 ? \func_get_args() : $path)));
1✔
148
    }
149
}
150

151
if (! \function_exists('Orchestra\Sidekick\laravel_version_compare')) {
152
    /**
153
     * Laravel version compare.
154
     *
155
     * @api
156
     *
157
     * @template TOperator of string|null
158
     *
159
     * @phpstan-param  TOperator  $operator
160
     *
161
     * @phpstan-return (TOperator is null ? int : bool)
162
     *
163
     * @codeCoverageIgnore
164
     */
165
    function laravel_version_compare(string $version, ?string $operator = null): int|bool
166
    {
167
        if (! class_exists(Application::class)) {
168
            throw new RuntimeException('Unable to verify Laravel Framework version');
169
        }
170

171
        /** @var string $laravel */
172
        $laravel = transform(
173
            Application::VERSION,
174
            fn (string $version) => match ($version) {
175
                '13.x-dev' => '13.0.0',
176
                default => $version,
177
            }
178
        );
179

180
        if (\is_null($operator)) {
181
            return version_compare($laravel, $version);
182
        }
183

184
        return version_compare($laravel, $version, $operator);
185
    }
186
}
187

188
if (! \function_exists('Orchestra\Sidekick\phpunit_version_compare')) {
189
    /**
190
     * PHPUnit version compare.
191
     *
192
     * @api
193
     *
194
     * @template TOperator of string|null
195
     *
196
     * @phpstan-param  TOperator  $operator
197
     *
198
     * @phpstan-return (TOperator is null ? int : bool)
199
     *
200
     * @throws \RuntimeException
201
     *
202
     * @codeCoverageIgnore
203
     */
204
    function phpunit_version_compare(string $version, ?string $operator = null): int|bool
205
    {
206
        if (! class_exists(Version::class)) {
207
            throw new RuntimeException('Unable to verify PHPUnit version');
208
        }
209

210
        /** @var string $phpunit */
211
        $phpunit = transform(
212
            Version::id(),
213
            fn (string $version) => match (true) {
214
                str_starts_with($version, '12.4-') => '12.4.0',
215
                default => $version,
216
            }
217
        );
218

219
        if (\is_null($operator)) {
220
            return version_compare($phpunit, $version);
221
        }
222

223
        return version_compare($phpunit, $version, $operator);
224
    }
225
}
226

227
if (! \function_exists('Orchestra\Sidekick\php_binary')) {
228
    /**
229
     * Determine the PHP Binary.
230
     *
231
     * @api
232
     *
233
     * @codeCoverageIgnore
234
     */
235
    function php_binary(): string
236
    {
237
        return (new PhpExecutableFinder)->find(false) ?: 'php';
238
    }
239
}
240

241
if (! \function_exists('Orchestra\Sidekick\windows_os')) {
242
    /**
243
     * Determine whether the current environment is Windows-based.
244
     *
245
     * @api
246
     *
247
     * @codeCoverageIgnore
248
     */
249
    function windows_os(): bool
250
    {
251
        return PHP_OS_FAMILY === 'Windows';
252
    }
253
}
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

© 2025 Coveralls, Inc