Skip to content

Commit

Permalink
Add override Standard method
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Apr 27, 2024
1 parent 8b843a1 commit c6e6efc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Ruleset/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,16 @@ public function addStandard(StandardInterface $standard): self

return $this;
}

/**
* @return $this
*/
public function overrideStandard(StandardInterface $standard): self
{
foreach ($standard->getRules() as $rule) {
$this->overrideRule($rule);
}

return $this;
}
}
22 changes: 22 additions & 0 deletions tests/Ruleset/RulesetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ public function testAddAndRemoveRule(): void
static::assertCount(1, $ruleset->getRules());
}

public function testAddStandard(): void
{
$ruleset = new Ruleset();
$rule1 = new SingleQuoteRule(true);
$rule2 = new SingleQuoteRule(false);

$standard1 = self::createStub(StandardInterface::class);
$standard1->method('getRules')->willReturn([$rule1]);

$standard2 = self::createStub(StandardInterface::class);
$standard2->method('getRules')->willReturn([$rule2]);

$ruleset->addStandard($standard1);
static::assertCount(1, $ruleset->getRules());

$ruleset->addStandard($standard2);
static::assertCount(2, $ruleset->getRules());

$ruleset->overrideStandard($standard2);
static::assertSame([$rule2], $ruleset->getRules());
}

public function testAllowNonFixableRules(): void
{
$ruleset = new Ruleset();
Expand Down

0 comments on commit c6e6efc

Please sign in to comment.