8000 Fix deprecation notice in test (ProcessBuilder) · sensiolabs/SensioGeneratorBundle@5fe7d3e · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 6, 2020. It is now read-only.

Commit 5fe7d3e

Browse files
guilliamxavierfabpot
authored andcommitted
Fix deprecation notice in test (ProcessBuilder)
1 parent 535417a commit 5fe7d3e

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

Tests/Manipulator/KernelManipulatorTest.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Sensio\Bundle\GeneratorBundle\Tests\Manipulator;
1313

14+
use Symfony\Component\Process\Process;
1415
use Symfony\Component\Process\ProcessBuilder;
1516
use Symfony\Component\Process\PhpExecutableFinder;
1617
use Sensio\Bundle\GeneratorBundle\Tests\Generator\GeneratorTest;
@@ -45,14 +46,33 @@ public function testAddToArray($kernelOriginFilePath)
4546
$phpFinder = new PhpExecutableFinder();
4647
$phpExecutable = $phpFinder->find();
4748

48-
$this->assertNotSame(false, $phpExecutable, 'Php executable binary found');
49+
$this->assertNotFalse($phpExecutable, 'Php executable binary found');
50+
51+
$arguments = array($phpExecutable, '-l', $fullpath);
52+
53+
// ProcessBuilder is deprecated in symfony/process version 3.4,
54+
// but Process doesn't accept an array of arguments in versions <3.3,
55+
// in which ProcessUtils::escapeArgument() is not marked as deprecated
56+
$useProcess = true;
57+
if (method_exists('Symfony\Component\Process\ProcessUtils', 'escapeArgument')) {
58+
$r = new \ReflectionMethod('Symfony\Component\Process\ProcessUtils', 'escapeArgument');
59+
if ($r->isPublic() && false === strpos($r->getDocComment(), '@deprecated')) {
60+
$useProcess = false;
61+
}
62+
}
63+
if ($useProcess) {
64+
$process = new Process($arguments);
65+
// preserve the BC with symfony <3.3
66+
$process->setCommandLine($process->getCommandLine());
67+
} else {
68+
$pb = new ProcessBuilder($arguments);
69+
$process = $pb->getProcess();
70+
}
4971

50-
$pb = new ProcessBuilder();
51-
$process = $pb->add($phpExecutable)->add('-l')->add($fullpath)->getProcess();
5272
$process->run();
5373

5474
$result = strpos($process->getOutput(), 'No syntax errors detected');
55-
$this->assertNotSame(false, $result, 'Manipulator should not provoke syntax errors');
75+
$this->assertNotFalse($result, 'Manipulator should not provoke syntax errors');
5676
}
5777

5878
/**
@@ -66,10 +86,9 @@ public function kernelStubFilenamesProvider()
6686
'With bundles array contains comma' => array(__DIR__.'/Stubs/ContainsCommaKernelStub.php'),
6787
'With bundles added w/o trailing comma' => array(__DIR__.'/Stubs/ContainsBundlesKernelStub.php'),
6888
'With some extra code and bad formatted' => array(__DIR__.'/Stubs/ContainsExtraCodeKernelStub.php'),
69-
7089
);
7190

72-
if(PHP_VERSION_ID >= 50400){
91+
if (PHP_VERSION_ID >= 50400) {
7392
$stubs = array_merge($stubs, array(
7493
'With empty bundles array, short array syntax' => array(__DIR__.'/Stubs/EmptyBundlesShortArraySyntaxKernelStub.php'),
7594
'With empty multiline bundles array, short array syntax' => array(__DIR__.'/Stubs/EmptyBundlesMultilineShortArraySyntaxKernelStub.php'),

0 commit comments

Comments
 (0)
0