Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9abae0

Browse files
committed
Merge branch '2.2' into 2.4
# Conflicts: # src/Linter/ProcessLinter.php # tests/Linter/ProcessLinterTest.php
2 parents b1b52d9 + 5cf5bfb commit f9abae0

5 files changed

Lines changed: 127 additions & 60 deletions

File tree

src/Linter/ProcessLinter.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\Component\Filesystem\Exception\IOException;
1717
use Symfony\Component\Process\PhpExecutableFinder;
1818
use Symfony\Component\Process\Process;
19-
use Symfony\Component\Process\ProcessBuilder;
2019

2120
/**
2221
* Handle PHP code linting using separated process of `php -l _file_`.
@@ -28,23 +27,21 @@
2827
final class ProcessLinter implements LinterInterface
2928
{
3029
/**
31-
* Temporary file for code linting.
32-
*
33-
* @var null|string
30+
* @var FileRemoval
3431
*/
35-
private $temporaryFile;
32+
private $fileRemoval;
3633

3734
/**
38-
* Path of PHP executable.
39-
*
40-
* @var string
35+
* @var ProcessLinterProcessBuilder
4136
*/
42-
private $executable;
37+
private $processBuilder;
4338

4439
/**
45-
* @var FileRemoval
40+
* Temporary file for code linting.
41+
*
42+
* @var null|string
4643
*/
47-
private $fileRemoval;
44+
private $temporaryFile;
4845

4946
/**
5047
* @param null|string $executable PHP executable, null for autodetection
@@ -73,7 +70,7 @@ public function __construct($executable = null)
7370
}
7471
}
7572

76-
$this->executable = $executable;
73+
$this->processBuilder = new ProcessLinterProcessBuilder($executable);
7774

7875
$this->fileRemoval = new FileRemoval();
7976
}
@@ -121,7 +118,7 @@ private function createProcessForFile($path)
121118
return $this->createProcessForSource(file_get_contents($path));
122119
}
123120

124-
$process = $this->prepareProcess($path);
121+
$process = $this->processBuilder->build($path);
125122
$process->setTimeout(null);
126123
$process->start();
127124

@@ -148,14 +145,4 @@ private function createProcessForSource($source)
148145

149146
return $this->createProcessForFile($this->temporaryFile);
150147
}
151-
152-
/**
153-
* @param string $path
154-
*
155-
* @return Process
156-
*/
157-
private function prepareProcess($path)
158-
{
159-
return ProcessBuilder::create(['-l', $path])->setPrefix($this->executable)->getProcess();
160-
}
161148
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of PHP CS Fixer.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
* Dariusz Rumiński <[email protected]>
8+
*
9+
* This source file is subject to the MIT license that is bundled
10+
* with this source code in the file LICENSE.
11+
*/
12+
13+
namespace PhpCsFixer\Linter;
14+
15+
use Symfony\Component\Process\Process;
16+
use Symfony\Component\Process\ProcessBuilder;
17+
18+
/**
19+
* @author Dariusz Rumiński <[email protected]>
20+
*
21+
* @internal
22+
*/
23+
final class ProcessLinterProcessBuilder
24+
{
25+
/**
26+
* @var string
27+
*/
28+
private $executable;
29+
30+
/**
31+
* @param string $executable PHP executable
32+
*/
33+
public function __construct($executable)
34+
{
35+
$this->executable = $executable;
36+
}
37+
38+
/**
39+
* @param string $path
40+
*
41+
* @return Process
42+
*/
43+
public function build($path)
44+
{
45+
return ProcessBuilder::create(['-l', $path])->setPrefix($this->executable)->getProcess();
46+
}
47+
}

tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
namespace PhpCsFixer\Tests\Fixer\PhpUnit;
1414

15-
use PhpCsFixer\Test\AccessibleObject;
1615
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
1716

1817
/**
@@ -64,7 +63,12 @@ public function testFix($expected, $input = null)
6463

6564
public function provideTestFixCases()
6665
{
67-
$methodsMap = AccessibleObject::create($this->createFixer())->assertionMap;
66+
$methodsMap = [
67+
'assertAttributeEquals' => 'assertAttributeSame',
68+
'assertAttributeNotEquals' => 'assertAttributeNotSame',
69+
'assertEquals' => 'assertSame',
70+
'assertNotEquals' => 'assertNotSame',
71+
];
6872

6973
$cases = [
7074
['<?php $self->foo();'],
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/*
4+
* This file is part of PHP CS Fixer.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
* Dariusz Rumiński <[email protected]>
8+
*
9+
* This source file is subject to the MIT license that is bundled
10+
* with this source code in the file LICENSE.
11+
*/
12+
13+
namespace PhpCsFixer\Tests\Linter;
14+
15+
use PhpCsFixer\Linter\ProcessLinterProcessBuilder;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* @author Dariusz Rumiński <[email protected]>
20+
*
21+
* @internal
22+
*
23+
* @covers \PhpCsFixer\Linter\ProcessLinterProcessBuilder
24+
*/
25+
final class ProcessLinterProcessBuilderTest extends TestCase
26+
{
27+
/**
28+
* @param string $executable
29+
* @param string $file
30+
* @param string $expected
31+
*
32+
* @testWith ["php", "foo.php", "'php' '-l' 'foo.php'"]
33+
* ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "'C:\\Program Files\\php\\php.exe' '-l' 'foo bar\\baz.php'"]
34+
* @requires OS Linux|Darwin
35+
*/
36+
public function testPrepareCommandOnPhpOnLinuxOrMac($executable, $file, $expected)
37+
{
38+
$builder = new ProcessLinterProcessBuilder($executable);
39+
40+
$this->assertSame(
41+
$expected,
42+
$builder->build($file)->getCommandLine()
43+
);
44+
}
45+
46+
/**
47+
* @param string $executable
48+
* @param string $file
49+
* @param string $expected
50+
*
51+
* @testWith ["php", "foo.php", "php -l foo.php"]
52+
* ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
53+
* @requires OS ^Win
54+
*/
55+
public function testPrepareCommandOnPhpOnWindows($executable, $file, $expected)
56+
{
57+
$builder = new ProcessLinterProcessBuilder($executable);
58+
59+
$this->assertSame(
60+
$expected,
61+
$builder->build($file)->getCommandLine()
62+
);
63+
}
64+
}

tests/Linter/ProcessLinterTest.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
namespace PhpCsFixer\Tests\Linter;
1414

1515
use PhpCsFixer\Linter\ProcessLinter;
16-
use PhpCsFixer\Test\AccessibleObject;
1716

1817
/**
1918
* @author Dariusz Rumiński <[email protected]>
@@ -30,40 +29,6 @@ public function testIsAsync()
3029
$this->assertTrue($this->createLinter()->isAsync());
3130
}
3231

33-
/**
34-
* @param string $executable
35-
* @param string $file
36-
* @param string $expected
37-
*
38-
* @testWith ["php", "foo.php", "'php' '-l' 'foo.php'"]
39-
* ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "'C:\\Program Files\\php\\php.exe' '-l' 'foo bar\\baz.php'"]
40-
* @requires OS Linux|Darwin
41-
*/
42-
public function testPrepareCommandOnPhpOnLinuxOrMac($executable, $file, $expected)
43-
{
44-
$this->assertSame(
45-
$expected,
46-
AccessibleObject::create(new ProcessLinter($executable))->prepareProcess($file)->getCommandLine()
47-
);
48-
}
49-
50-
/**
51-
* @param string $executable
52-
* @param string $file
53-
* @param string $expected
54-
*
55-
* @testWith ["php", "foo.php", "php -l foo.php"]
56-
* ["C:\\Program Files\\php\\php.exe", "foo bar\\baz.php", "\"C:\\Program Files\\php\\php.exe\" -l \"foo bar\\baz.php\""]
57-
* @requires OS ^Win
58-
*/
59-
public function testPrepareCommandOnPhpOnWindows($executable, $file, $expected)
60-
{
61-
$this->assertSame(
62-
$expected,
63-
AccessibleObject::create(new ProcessLinter($executable))->prepareProcess($file)->getCommandLine()
64-
);
65-
}
66-
6732
/**
6833
* {@inheritdoc}
6934
*/

0 commit comments

Comments
 (0)