Completed
Push — master ( afadea...e6376f )
by Tomáš
03:06 queued 03:01
created

FixerFactoryTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 56
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testResolveFixerLevels() 0 10 2
A provideCreateData() 0 12 1
A createConfigurationResolver() 0 6 1
A getAllFixers() 0 6 1
1
<?php
2
3
namespace Symplify\MultiCodingStandard\Tests\PhpCsFixer\Factory;
4
5
use PHPUnit\Framework\TestCase;
6
use Symfony\CS\ConfigurationResolver;
7
use Symfony\CS\Fixer;
8
use Symfony\CS\FixerInterface;
9
use Symplify\MultiCodingStandard\PhpCsFixer\Factory\FixerFactory;
10
11
final class FixerFactoryTest extends TestCase
12
{
13
    /**
14
     * @var FixerFactory
15
     */
16
    private $fixerFactory;
17
18
    protected function setUp()
19
    {
20
        $this->fixerFactory = new FixerFactory($this->createConfigurationResolver());
21
    }
22
23
    /**
24
     * @dataProvider provideCreateData
25
     */
26
    public function testResolveFixerLevels(array $fixerLevels, array $fixers, array $excludedFixers, int $expectedFixerCount)
27
    {
28
        $fixers = $this->fixerFactory->createFromLevelsFixersAndExcludedFixers($fixerLevels, $fixers, $excludedFixers);
29
        $this->assertCount($expectedFixerCount, $fixers);
30
31
        if (count($fixers)) {
32
            $fixer = $fixers[0];
33
            $this->assertInstanceOf(FixerInterface::class, $fixer);
34
        }
35
    }
36
37
    public function provideCreateData() : array
38
    {
39
        return [
40
            [[], [], [], 0],
41
            [[], ['array_element_no_space_before_comma'], [], 1],
42
            [['psr1'], [], [], 3],
43
            [['psr2'], [], [], 24],
44
            [['psr2'], [], ['visibility'],  23],
45
            [['psr1', 'psr2'], [], [], 27],
46
            [['psr1', 'psr2'], [], ['visibility'], 26]
47
        ];
48
    }
49
50
    private function createConfigurationResolver() : ConfigurationResolver
51
    {
52
        $configurationResolver = new ConfigurationResolver();
53
        $configurationResolver->setAllFixers($this->getAllFixers());
54
        return $configurationResolver;
55
    }
56
57
    /**
58
     * @return FixerInterface[]
59
     */
60
    private function getAllFixers() : array
61
    {
62
        $fixer = new Fixer();
63
        $fixer->registerBuiltInFixers();
64
        return $fixer->getFixers();
65
    }
66
}
67