Skip to content

Commit c44d26d

Browse files
committed
Merge branch 'review-file'
2 parents 65efa93 + d7cef5f commit c44d26d

File tree

16 files changed

+468
-240
lines changed

16 files changed

+468
-240
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ jobs:
112112
- macos-latest
113113
php-version:
114114
- "8.3"
115+
- "8.2"
115116
include:
116-
- os: ubuntu-latest
117-
php-version: "8.2"
118117
- os: ubuntu-latest
119118
php-version: "8.1"
120119
- os: ubuntu-latest
@@ -123,6 +122,13 @@ jobs:
123122
php-version: "7.4"
124123
- os: windows-latest
125124
php-version: "7.4"
125+
exclude:
126+
# As of 2024-03-13, macos-latest + 8.3 is slooooow (5+ seconds per
127+
# process spawned?), but macos-latest + 8.2 runs normally
128+
- os: macos-latest
129+
php-version: "8.3"
130+
- os: windows-latest
131+
php-version: "8.2"
126132

127133
runs-on: ${{ matrix.os }}
128134

@@ -167,19 +173,27 @@ jobs:
167173
done
168174
169175
- name: Start Mockoon CLI
176+
id: start-mockoon
170177
shell: bash
171178
run: scripts/start-mockoon.sh
172179

173180
- name: Run PHPUnit tests and generate code coverage report
174-
run: vendor/bin/phpunit --no-coverage --coverage-clover=coverage.xml
181+
id: run-phpunit-tests
182+
shell: bash
183+
run: |
184+
vendor/bin/phpunit --no-coverage --coverage-clover=coverage.xml && status=0 || status=$?
185+
printf 'coverage_report_generated=%d\n' "$([[ -s coverage.xml ]] && echo 1 || echo 0)" >>"$GITHUB_OUTPUT"
186+
(exit $status)
187+
188+
- name: Upload code coverage report to Codecov
189+
if: ${{ !cancelled() && steps.run-phpunit-tests.outputs.coverage_report_generated == 1 }}
190+
uses: codecov/codecov-action@v4
191+
with:
192+
token: ${{ secrets.CODECOV_TOKEN }}
175193

176194
- name: Upload Mockoon CLI log files artifact
195+
if: ${{ !cancelled() && steps.start-mockoon.conclusion == 'success' }}
177196
uses: actions/upload-artifact@v4
178197
with:
179198
name: mockoon-cli-logs-${{ matrix.os }}-${{ matrix.php-version }}
180199
path: ~/.mockoon-cli/logs/*.log
181-
182-
- name: Upload code coverage report to Codecov
183-
uses: codecov/codecov-action@v4
184-
with:
185-
token: ${{ secrets.CODECOV_TOKEN }}

phpstan-baseline-7.4.neon

Lines changed: 0 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline-8.3.neon

Lines changed: 0 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Toolkit/Console/Target/StreamTarget.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ public function reopen(?string $path = null): void
175175
* Creates a new StreamTarget object backed by an open PHP stream
176176
*
177177
* @param resource $stream
178-
* @param bool $closeable If `true`, call {@see fclose()} to close `$stream`
179-
* when the target is closed.
178+
* @param bool $closeable If `true`, call {@see File::close()} to close
179+
* `$stream` when the target is closed.
180180
* @param bool|null $addTimestamp If `null`, add timestamps if `$stream` is
181181
* not `STDOUT` or `STDERR`.
182182
* @param DateTimeZone|string|null $timezone If `null`, the timezone

src/Toolkit/Container/Application.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public function __construct(
321321

322322
$this->BasePath = $basePath;
323323

324-
$this->WorkingDirectory = File::cwd();
324+
$this->WorkingDirectory = File::getCwd();
325325

326326
$this->RunningFromSource =
327327
!extension_loaded('Phar') ||
@@ -393,7 +393,7 @@ final public function getWorkingDirectory(): string
393393
*/
394394
final public function restoreWorkingDirectory()
395395
{
396-
if (File::cwd() !== $this->WorkingDirectory) {
396+
if (File::getCwd() !== $this->WorkingDirectory) {
397397
File::chdir($this->WorkingDirectory);
398398
}
399399

@@ -405,7 +405,7 @@ final public function restoreWorkingDirectory()
405405
*/
406406
final public function setWorkingDirectory(?string $directory = null)
407407
{
408-
$this->WorkingDirectory = $directory ?? File::cwd();
408+
$this->WorkingDirectory = $directory ?? File::getCwd();
409409

410410
return $this;
411411
}

src/Toolkit/Core/Process.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ final class Process
3333
*/
3434
private const TIMEOUT_PRECISION = 200000;
3535

36-
private const OPTIONS = [
36+
private const DEFAULT_OPTIONS = [
3737
'suppress_errors' => true,
3838
'bypass_shell' => true,
3939
];
4040

4141
/**
42-
* @var string[]
42+
* @var string[]|string
4343
*/
44-
private array $Command;
44+
private $Command;
4545

4646
/**
4747
* @var resource|string|null
@@ -59,6 +59,11 @@ final class Process
5959

6060
private bool $UseOutputFiles;
6161

62+
/**
63+
* @var array<string,bool>|null
64+
*/
65+
private ?array $Options = null;
66+
6267
private ?int $Sec = null;
6368

6469
private int $Usec = 0;
@@ -105,15 +110,14 @@ final class Process
105110
];
106111

107112
/**
108-
* Creates a new ProcessWrapper object
113+
* Creates a new Process object
109114
*
110-
* @param string[] $args
115+
* @param string[] $command
111116
* @param resource|string|null $input
112117
* @param array<string,string>|null $env
113118
*/
114119
public function __construct(
115-
string $command,
116-
array $args = [],
120+
array $command,
117121
$input = '',
118122
?string $cwd = null,
119123
?array $env = null,
@@ -130,7 +134,7 @@ public function __construct(
130134
// @codeCoverageIgnoreEnd
131135
}
132136

133-
$this->Command = [$command, ...$args];
137+
$this->Command = $command;
134138
$this->Input = $input;
135139
$this->Cwd = $cwd;
136140
$this->Env = $env;
@@ -143,6 +147,26 @@ public function __construct(
143147
}
144148
}
145149

150+
/**
151+
* Creates a new Process object for a shell command
152+
*
153+
* @param resource|string|null $input
154+
* @param array<string,string>|null $env
155+
*/
156+
public static function withShellCommand(
157+
string $command,
158+
$input = '',
159+
?string $cwd = null,
160+
?array $env = null,
161+
?int $timeout = null,
162+
bool $useOutputFiles = false
163+
): self {
164+
$process = new self([], $input, $cwd, $env, $timeout, $useOutputFiles);
165+
$process->Command = $command;
166+
$process->Options = array_diff_key(self::DEFAULT_OPTIONS, ['bypass_shell' => null]);
167+
return $process;
168+
}
169+
146170
public function __destruct()
147171
{
148172
if ($this->isRunning() && $this->stop()->isRunning()) {
@@ -204,7 +228,7 @@ public function run(): int
204228
$pipes,
205229
$this->Cwd,
206230
$this->Env,
207-
self::OPTIONS,
231+
$this->Options ?? self::DEFAULT_OPTIONS,
208232
),
209233
'Error running process: %s',
210234
);
@@ -266,11 +290,11 @@ public function isTerminated(): bool
266290
}
267291

268292
/**
269-
* Get the command parameters passed to proc_open() to spawn the process
293+
* Get the command passed to proc_open() to spawn the process
270294
*
271-
* @return string[]
295+
* @return string[]|string
272296
*/
273-
public function getCommand(): array
297+
public function getCommand()
274298
{
275299
return $this->Command;
276300
}

0 commit comments

Comments
 (0)