Skip to content

Commit 3bdf888

Browse files
committed
(chore): added 14 tests
1 parent 3020645 commit 3bdf888

File tree

5 files changed

+108
-6
lines changed

5 files changed

+108
-6
lines changed

src/Config.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function mergeRules(array $rules): self
9797
}
9898

9999
/**
100-
* Recursively unset matching rules
100+
* Unset matching rules
101101
*
102102
* @param array<int, string> $rulesKeys
103103
*/
@@ -109,4 +109,12 @@ public function removeRules(array $rulesKeys): self
109109

110110
return $this;
111111
}
112+
113+
/**
114+
* Removes rule name
115+
*/
116+
public function removeRule(string $ruleKey): self
117+
{
118+
return $this->removeRules([$ruleKey]);
119+
}
112120
}

tests/Feature/ConfigTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Finder;
6+
use Yard\PhpCsFixerRules\Config;
7+
use Yard\PhpCsFixerRules\Interfaces\ConfigInterface;
8+
9+
it('can create config', function () {
10+
$config = Config::create(Finder::create());
11+
12+
expect($config)->toBeInstanceOf(ConfigInterface::class);
13+
});
14+
15+
it('sets rules on create', function () {
16+
$config = Config::create(Finder::create());
17+
18+
expect($config->getRules())->not->toBeEmpty();
19+
});
20+
21+
it('sets line ending on create', function () {
22+
$config = Config::create(Finder::create());
23+
24+
expect($config->getLineEnding())->not->toBeEmpty();
25+
});
26+
27+
it('sets risky allowed on create', function () {
28+
$config = Config::create(Finder::create());
29+
30+
expect($config->getRiskyAllowed())->not->toBeEmpty();
31+
});

tests/Feature/ExampleTest.php

Lines changed: 0 additions & 5 deletions
This file was deleted.
File renamed without changes.

tests/Unit/ConfigRulesRemoveTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Finder;
6+
use Yard\PhpCsFixerRules\Config;
7+
8+
it('can remove rules', function () {
9+
$config = Config::create(Finder::create());
10+
11+
$config->setRules([ // reset rules list
12+
'@PSR2' => true,
13+
'indentation_type' => true,
14+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
15+
])->removeRules([
16+
"@PSR2", "ordered_imports",
17+
]);
18+
19+
expect($config->getRules())->toBe([
20+
'indentation_type' => true,
21+
]);
22+
});
23+
24+
it('can handle an request to remove nothing', function () {
25+
$config = Config::create(Finder::create());
26+
27+
$config->setRules([ // reset rules list
28+
'@PSR2' => true,
29+
'indentation_type' => true,
30+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
31+
])->removeRules([]);
32+
33+
expect($config->getRules())->toBe([
34+
'@PSR2' => true,
35+
'indentation_type' => true,
36+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
37+
]);
38+
});
39+
40+
it('can remove one rule', function () {
41+
$config = Config::create(Finder::create());
42+
43+
$config->setRules([ // reset rules list
44+
'@PSR2' => true,
45+
'indentation_type' => true,
46+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
47+
])->removeRule("@PSR2");
48+
49+
expect($config->getRules())->toBe([
50+
'indentation_type' => true,
51+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
52+
]);
53+
});
54+
55+
it('can remove a list with one rule', function () {
56+
$config = Config::create(Finder::create());
57+
58+
$config->setRules([ // reset rules list
59+
'@PSR2' => true,
60+
'indentation_type' => true,
61+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
62+
])->removeRules(["@PSR2"]);
63+
64+
expect($config->getRules())->toBe([
65+
'indentation_type' => true,
66+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
67+
]);
68+
});

0 commit comments

Comments
 (0)