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

FixerFactoryTest::getAllFixers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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