Skip to content

Commit 191aece

Browse files
SpacePossumsebastianbergmann
authored andcommitted
fix test on sf5 process package
1 parent 81601e2 commit 191aece

File tree

4 files changed

+50
-42
lines changed

4 files changed

+50
-42
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^7.5 || ^8.0",
22-
"symfony/process": "^2 || ^3.3 || ^4 || ^5"
22+
"symfony/process": "^4 || ^5"
2323
},
2424
"autoload": {
2525
"classmap": [

tests/Output/Integration/StrictUnifiedDiffOutputBuilderIntegrationTest.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,15 @@ public function testIntegrationDiffOutputBuilderVersusDiffCommand(string $diff,
198198
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
199199
$this->assertNotFalse(\file_put_contents($this->fileTo, $to));
200200

201-
$p = new Process(\sprintf('diff -u %s %s', \escapeshellarg($this->fileFrom), \escapeshellarg($this->fileTo)));
202-
$p->run();
201+
$p = Process::fromShellCommandline('diff -u $from $to');
202+
$p->run(
203+
null,
204+
[
205+
'from' => $this->fileFrom,
206+
'to' => $this->fileTo,
207+
]
208+
);
209+
203210
$this->assertSame(1, $p->getExitCode()); // note: Process assumes exit code 0 for `isSuccessful`, however `diff` uses the exit code `1` for success with diff
204211

205212
$output = $p->getOutput();
@@ -227,13 +234,14 @@ private function doIntegrationTestGitApply(string $diff, string $from, string $t
227234
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
228235
$this->assertNotFalse(\file_put_contents($this->filePatch, $diff));
229236

230-
$p = new Process(\sprintf(
231-
'git --git-dir %s apply --check -v --unsafe-paths --ignore-whitespace %s',
232-
\escapeshellarg($this->dir),
233-
\escapeshellarg($this->filePatch)
234-
));
235-
236-
$p->run();
237+
$p = Process::fromShellCommandline('git --git-dir $dir apply --check -v --unsafe-paths --ignore-whitespace $patch');
238+
$p->run(
239+
null,
240+
[
241+
'dir' => $this->dir,
242+
'patch' => $this->filePatch,
243+
]
244+
);
237245

238246
$this->assertProcessSuccessful($p);
239247
}
@@ -248,21 +256,21 @@ private function doIntegrationTestPatch(string $diff, string $from, string $to):
248256
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
249257
$this->assertNotFalse(\file_put_contents($this->filePatch, $diff));
250258

251-
$command = \sprintf(
252-
'patch -u --verbose --posix %s < %s',
253-
\escapeshellarg($this->fileFrom),
254-
\escapeshellarg($this->filePatch)
259+
$p = Process::fromShellCommandline('patch -u --verbose --posix $from < $patch');
260+
$p->run(
261+
null,
262+
[
263+
'from' => $this->fileFrom,
264+
'patch' => $this->filePatch,
265+
]
255266
);
256267

257-
$p = new Process($command);
258-
$p->run();
259-
260268
$this->assertProcessSuccessful($p);
261269

262270
$this->assertStringEqualsFile(
263271
$this->fileFrom,
264272
$to,
265-
\sprintf('Patch command "%s".', $command)
273+
\sprintf('Patch command "%s".', $p->getCommandLine())
266274
);
267275
}
268276

tests/Output/Integration/UnifiedDiffOutputBuilderIntegrationTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,21 @@ private function doIntegrationTestPatch(string $diff, string $from, string $to):
9191
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
9292
$this->assertNotFalse(\file_put_contents($this->filePatch, $diff));
9393

94-
$command = \sprintf(
95-
'patch -u --verbose --posix %s < %s', // --posix
96-
\escapeshellarg($this->fileFrom),
97-
\escapeshellarg($this->filePatch)
94+
$p = Process::fromShellCommandline('patch -u --verbose --posix $from < $patch'); // --posix
95+
$p->run(
96+
null,
97+
[
98+
'from' => $this->fileFrom,
99+
'patch' => $this->filePatch,
100+
]
98101
);
99102

100-
$p = new Process($command);
101-
$p->run();
102-
103103
$this->assertProcessSuccessful($p);
104104

105105
$this->assertStringEqualsFile(
106106
$this->fileFrom,
107107
$to,
108-
\sprintf('Patch command "%s".', $command)
108+
\sprintf('Patch command "%s".', $p->getCommandLine())
109109
);
110110
}
111111

@@ -119,15 +119,15 @@ private function doIntegrationTestGitApply(string $diff, string $from, string $t
119119
$this->assertNotFalse(\file_put_contents($this->fileFrom, $from));
120120
$this->assertNotFalse(\file_put_contents($this->filePatch, $diff));
121121

122-
$command = \sprintf(
123-
'git --git-dir %s apply --check -v --unsafe-paths --ignore-whitespace %s',
124-
\escapeshellarg($this->dir),
125-
\escapeshellarg($this->filePatch)
122+
$p = Process::fromShellCommandline('git --git-dir $dir apply --check -v --unsafe-paths --ignore-whitespace $patch');
123+
$p->run(
124+
null,
125+
[
126+
'dir' => $this->dir,
127+
'patch' => $this->filePatch,
128+
]
126129
);
127130

128-
$p = new Process($command);
129-
$p->run();
130-
131131
$this->assertProcessSuccessful($p);
132132
}
133133

tests/Utils/UnifiedDiffAssertTraitIntegrationTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ protected function tearDown(): void
4444
*/
4545
public function testValidPatches(string $fileFrom, string $fileTo): void
4646
{
47-
$command = \sprintf(
48-
'diff -u %s %s > %s',
49-
\escapeshellarg(\realpath($fileFrom)),
50-
\escapeshellarg(\realpath($fileTo)),
51-
\escapeshellarg($this->filePatch)
47+
$p = Process::fromShellCommandline('diff -u $from $to > $patch');
48+
$p->run(
49+
null,
50+
[
51+
'from' => \realpath($fileFrom),
52+
'to' => \realpath($fileTo),
53+
'patch' => $this->filePatch,
54+
]
5255
);
5356

54-
$p = new Process($command);
55-
$p->run();
56-
5757
$exitCode = $p->getExitCode();
5858

5959
if (0 === $exitCode) {
@@ -68,7 +68,7 @@ public function testValidPatches(string $fileFrom, string $fileTo): void
6868
$exitCode,
6969
\sprintf(
7070
"Command exec. was not successful:\n\"%s\"\nOutput:\n\"%s\"\nStdErr:\n\"%s\"\nExit code %d.\n",
71-
$command,
71+
$p->getCommandLine(),
7272
$p->getOutput(),
7373
$p->getErrorOutput(),
7474
$p->getExitCode()

0 commit comments

Comments
 (0)