1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Tests\Unit\Process; |
6
|
|
|
|
7
|
|
|
use Paraunit\Configuration\PHPUnitConfig; |
8
|
|
|
use Paraunit\Configuration\TempFilenameFactory; |
9
|
|
|
use Paraunit\Process\AbstractParaunitProcess; |
10
|
|
|
use Paraunit\Process\CommandLine; |
11
|
|
|
use Paraunit\Process\ProcessBuilderFactory; |
12
|
|
|
use Tests\BaseUnitTestCase; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class ProcessBuilderFactoryTest |
16
|
|
|
* @package Tests\Unit\Process |
17
|
|
|
*/ |
18
|
|
|
class ProcessBuilderFactoryTest extends BaseUnitTestCase |
19
|
|
|
{ |
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
if (! \class_exists('Symfony\Component\Process\ProcessBuilder')) { |
23
|
|
|
$this->markTestSkipped('This test is legacy, will not work under Symfony 4'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
parent::setUp(); // TODO: Change the autogenerated stub |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @group legacy |
31
|
|
|
* @expectedDeprecation The Symfony\Component\Process\ProcessBuilder class is deprecated since version 3.4 and will be removed in 4.0. Use the Process class instead |
32
|
|
|
*/ |
33
|
|
View Code Duplication |
public function testCreateProcess() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$phpUnitConfig = $this->prophesize(PHPUnitConfig::class); |
36
|
|
|
$cliCommand = $this->prophesize(CommandLine::class); |
37
|
|
|
$cliCommand->getExecutable()->willReturn(['sapi', 'executable']); |
38
|
|
|
$cliCommand |
39
|
|
|
->getOptions($phpUnitConfig->reveal()) |
40
|
|
|
->shouldBeCalled() |
41
|
|
|
->willReturn(['--configuration=config.xml']); |
42
|
|
|
$cliCommand |
43
|
|
|
->getSpecificOptions('TestTest.php') |
44
|
|
|
->shouldBeCalled() |
45
|
|
|
->willReturn(['--specific=value-for-TestTest.php']); |
46
|
|
|
$cliCommand |
47
|
|
|
->getSpecificOptions('TestTest2.php') |
48
|
|
|
->shouldBeCalled() |
49
|
|
|
->willReturn(['--specific=value-for-TestTest2.php']); |
50
|
|
|
|
51
|
|
|
$tempFilenameFactory = $this->prophesize(TempFilenameFactory::class); |
52
|
|
|
$tempFilenameFactory->getPathForLog() |
53
|
|
|
->willReturn('/path/for/log/'); |
54
|
|
|
|
55
|
|
|
$factory = new ProcessBuilderFactory( |
56
|
|
|
$cliCommand->reveal(), |
57
|
|
|
$phpUnitConfig->reveal(), |
58
|
|
|
$tempFilenameFactory->reveal() |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
$processBuilder = $factory->create('TestTest.php'); |
62
|
|
|
|
63
|
|
|
$this->assertInstanceOf(AbstractParaunitProcess::class, $processBuilder); |
64
|
|
|
$commandLine = $processBuilder->getCommandLine(); |
65
|
|
|
$this->assertContains('TestTest.php', $commandLine); |
66
|
|
|
$this->assertContains('--specific=value-for-TestTest.php', $commandLine); |
67
|
|
|
|
68
|
|
|
$processBuilder = $factory->create('TestTest2.php'); |
69
|
|
|
|
70
|
|
|
$this->assertInstanceOf(AbstractParaunitProcess::class, $processBuilder); |
71
|
|
|
$commandLine = $processBuilder->getCommandLine(); |
72
|
|
|
$this->assertContains('TestTest2.php', $commandLine); |
73
|
|
|
$this->assertContains('--specific=value-for-TestTest2.php', $commandLine); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.