11
11
12
12
namespace Sensio \Bundle \GeneratorBundle \Tests \Manipulator ;
13
13
14
+ use Symfony \Component \Process \Process ;
14
15
use Symfony \Component \Process \ProcessBuilder ;
15
16
use Symfony \Component \Process \PhpExecutableFinder ;
16
17
use Sensio \Bundle \GeneratorBundle \Tests \Generator \GeneratorTest ;
@@ -45,14 +46,33 @@ public function testAddToArray($kernelOriginFilePath)
45
46
$ phpFinder = new PhpExecutableFinder ();
46
47
$ phpExecutable = $ phpFinder ->find ();
47
48
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
+ }
49
71
50
- $ pb = new ProcessBuilder ();
51
- $ process = $ pb ->add ($ phpExecutable )->add ('-l ' )->add ($ fullpath )->getProcess ();
52
72
$ process ->run ();
53
73
54
74
$ 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 ' );
56
76
}
57
77
58
78
/**
@@ -66,10 +86,9 @@ public function kernelStubFilenamesProvider()
66
86
'With bundles array contains comma ' => array (__DIR__ .'/Stubs/ContainsCommaKernelStub.php ' ),
67
87
'With bundles added w/o trailing comma ' => array (__DIR__ .'/Stubs/ContainsBundlesKernelStub.php ' ),
68
88
'With some extra code and bad formatted ' => array (__DIR__ .'/Stubs/ContainsExtraCodeKernelStub.php ' ),
69
-
70
89
);
71
90
72
- if (PHP_VERSION_ID >= 50400 ){
91
+ if (PHP_VERSION_ID >= 50400 ) {
73
92
$ stubs = array_merge ($ stubs , array (
74
93
'With empty bundles array, short array syntax ' => array (__DIR__ .'/Stubs/EmptyBundlesShortArraySyntaxKernelStub.php ' ),
75
94
'With empty multiline bundles array, short array syntax ' => array (__DIR__ .'/Stubs/EmptyBundlesMultilineShortArraySyntaxKernelStub.php ' ),
0 commit comments