-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
DeclareEqualNormalizeFixerTest.php
127 lines (118 loc) · 3.79 KB
/
DeclareEqualNormalizeFixerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
declare(strict_types=1);
/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <fabien@symfony.com>
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace PhpCsFixer\Tests\Fixer\LanguageConstruct;
use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
/**
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* @internal
*
* @covers \PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer
*/
final class DeclareEqualNormalizeFixerTest extends AbstractFixerTestCase
{
/**
* @dataProvider provideFixCases
*/
public function testFix(string $expected, ?string $input, array $config): void
{
$this->fixer->configure($config);
$this->doTest($expected, $input);
}
public function provideFixCases(): array
{
return [
'minimal case remove whitespace (default config)' => [
'<?php declare(ticks=1);',
'<?php declare(ticks= 1);',
[],
],
'minimal case remove whitespace (no space config)' => [
'<?php declare(ticks=1);',
'<?php declare(ticks = 1);',
['space' => 'none'],
],
'minimal case add whitespace' => [
'<?php declare(ticks = 1);',
'<?php declare(ticks=1);',
['space' => 'single'],
],
'to much whitespace case add whitespace' => [
'<?php declare(ticks = 1);',
"<?php declare(ticks\n\t = 1);",
['space' => 'single'],
],
'repeating case remove whitespace (default config)' => [
'<?php declare(ticks=1);declare(ticks=1)?>',
'<?php declare(ticks= 1);declare(ticks= 1)?>',
[],
],
'repeating case add whitespace' => [
'<?php declare ( ticks = 1 );declare( ticks = 1) ?>',
'<?php declare ( ticks=1 );declare( ticks =1) ?>',
['space' => 'single'],
],
'minimal case add whitespace comments, single' => [
'<?php declare(ticks#
= #
1#
);',
'<?php declare(ticks#
=#
1#
);',
['space' => 'single'],
],
'minimal case add whitespace comments, none' => [
'<?php declare(ticks#
=#
1#
);',
null,
['space' => 'none'],
],
'declare having multiple directives, single' => [
'<?php declare(strict_types=1, ticks=1);',
'<?php declare(strict_types = 1, ticks = 1);',
[],
],
'declare having multiple directives, none' => [
'<?php declare(strict_types = 1, ticks = 1);',
'<?php declare(strict_types=1, ticks=1);',
['space' => 'single'],
],
];
}
/**
* @dataProvider provideInvalidConfigCases
*/
public function testInvalidConfig(array $config, string $expectedMessage): void
{
$this->expectException(InvalidFixerConfigurationException::class);
$this->expectExceptionMessage(sprintf('[declare_equal_normalize] Invalid configuration: %s', $expectedMessage));
$this->fixer->configure($config);
}
public function provideInvalidConfigCases(): array
{
return [
[
[1, 2],
'The options "0", "1" do not exist.',
],
[
['space' => 'tab'],
'The option "space" with value "tab" is invalid.',
],
];
}
}