Test Failed
Pull Request — master (#132)
by Alessandro
03:15
created

ParallelConfigurationTest::testBuildContainer()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 55

Duplication

Lines 4
Ratio 7.27 %

Importance

Changes 0
Metric Value
dl 4
loc 55
rs 8.9818
c 0
b 0
f 0
cc 3
nc 4
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Unit\Configuration;
6
7
use Paraunit\Configuration\ParallelConfiguration;
8
use Paraunit\Configuration\PHPDbgBinFile;
9
use Paraunit\Configuration\PHPUnitConfig;
10
use Paraunit\Coverage\CoverageFetcher;
11
use Paraunit\File\Cleaner;
12
use Paraunit\Parser\JSON\LogParser;
13
use Paraunit\Printer\CoveragePrinter;
14
use Paraunit\Printer\DebugPrinter;
15
use Paraunit\Printer\ProcessPrinter;
16
use Paraunit\Process\ProcessFactoryInterface;
17
use Paraunit\Runner\Runner;
18
use Paraunit\TestResult\TestResultFactory;
19
use Prophecy\Argument;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Output\OutputInterface;
22
use Symfony\Component\DependencyInjection\ContainerBuilder;
23
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
24
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
25
use Tests\BaseUnitTestCase;
26
27
/**
28
 * Class ParaunitTest
29
 * @package Tests\Unit\Configuration
30
 */
31
class ParallelConfigurationTest extends BaseUnitTestCase
32
{
33
    public function testBuildContainer()
34
    {
35
        $paraunit = new ParallelConfiguration(true);
36
        $input = $this->prophesize(InputInterface::class);
37
        $output = $this->prophesize(OutputInterface::class);
38
        $input->getArgument('stringFilter')
39
            ->willReturn('text');
40
        $input->getOption('parallel')
41
            ->willReturn(10);
42
        $input->getOption('testsuite')
43
            ->willReturn('testsuite');
44
        $input->getOption('configuration')
45
            ->willReturn($this->getConfigForStubs());
46
        $input->getOption(Argument::cetera())
47
            ->willReturn(null);
48
49
        $container = $paraunit->buildContainer($input->reveal(), $output->reveal());
50
51
        $this->assertInstanceOf(ContainerBuilder::class, $container);
52
53
        $requiredParameters = [
54
            'paraunit.max_process_count' => 10,
55
            'paraunit.testsuite' => 'testsuite',
56
            'paraunit.string_filter' => 'text',
57
            'paraunit.phpunit_config_filename' => $this->getConfigForStubs(),
58
        ];
59
60 View Code Duplication
        foreach ($requiredParameters as $parameterName => $expectedValue) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
61
            $this->assertTrue($container->hasParameter($parameterName), 'Parameter missing: ' . $parameterName);
62
            $this->assertEquals($expectedValue, $container->getParameter($parameterName));
63
        }
64
65
        $requiredDefinitions = [
66
            OutputInterface::class,
67
            Cleaner::class,
68
            LogParser::class,
69
            ProcessPrinter::class,
70
            ProcessFactoryInterface::class,
71
            Runner::class,
72
            EventDispatcherInterface::class,
73
            TestResultFactory::class,
74
            'paraunit.test_result.pass_container',
75
            'paraunit.test_result.pass_format',
76
            PHPUnitConfig::class,
77
        ];
78
79
        $servicesIds = $container->getServiceIds();
80
        $this->assertNotContains(PHPDbgBinFile::class, $servicesIds);
81
        $this->assertNotContains(CoverageFetcher::class, $servicesIds);
82
        $this->assertNotContains(CoveragePrinter::class, $servicesIds);
83
84
        foreach ($requiredDefinitions as $definitionName) {
85
            $this->getService($container, $definitionName); // test instantiation, to prevent misconfigurations
86
        }
87
    }
88
89
    public function testBuildContainerWithDebug()
90
    {
91
        $paraunit = new ParallelConfiguration(true);
92
        $input = $this->prophesize(InputInterface::class);
93
        $output = $this->prophesize(OutputInterface::class);
94
        $input->getArgument('stringFilter')
95
            ->willReturn('text');
96
        $input->getOption('debug')
97
            ->willReturn(true);
98
        $input->getOption(Argument::cetera())
99
            ->willReturn(null);
100
101
        $container = $paraunit->buildContainer($input->reveal(), $output->reveal());
102
103
        $this->assertInstanceOf(ContainerBuilder::class, $container);
104
105
        // test instantiation, to prevent misconfigurations
106
        $service = $this->getService($container, DebugPrinter::class);
107
        $this->assertInstanceOf(DebugPrinter::class, $service);
108
        $this->assertInstanceOf(EventSubscriberInterface::class, $service);
109
    }
110
111
    private function getService(ContainerBuilder $container, string $serviceName)
112
    {
113
        return $container->get(sprintf(ParallelConfiguration::PUBLIC_ALIAS_FORMAT, $serviceName));
114
    }
115
}
116