-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Reject rule sets referencing unknown layers
- Loading branch information
1 parent
5ade86b
commit b3eae34
Showing
5 changed files
with
221 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Configuration/Exception/InvalidConfigurationException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SensioLabs\Deptrac\Configuration\Exception; | ||
|
||
final class InvalidConfigurationException extends \InvalidArgumentException | ||
{ | ||
public static function fromUnknownLayerNames(string ...$layerNames): self | ||
{ | ||
natsort($layerNames); | ||
|
||
return new self(sprintf( | ||
'Configuration can not reference rule sets with unknown layer names, got "%s" as unknown.', | ||
implode('", "', $layerNames) | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/Configuration/Exception/InvalidConfigurationExceptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\SensioLabs\Deptrac\Configuration\Exception; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SensioLabs\Deptrac\Configuration\Exception\InvalidConfigurationException; | ||
|
||
/** | ||
* @covers \SensioLabs\Deptrac\Configuration\Exception\InvalidConfigurationException | ||
*/ | ||
final class InvalidConfigurationExceptionTest extends TestCase | ||
{ | ||
public function testIsInvalidArgumentException(): void | ||
{ | ||
$exception = new InvalidConfigurationException(); | ||
|
||
self::assertInstanceOf(\InvalidArgumentException::class, $exception); | ||
} | ||
|
||
public function testFromUnknownLayerNamesReturnsException(): void | ||
{ | ||
$layerNames = [ | ||
'foo', | ||
'bar', | ||
]; | ||
|
||
$exception = InvalidConfigurationException::fromUnknownLayerNames(...$layerNames); | ||
|
||
natsort($layerNames); | ||
|
||
$message = sprintf( | ||
'Configuration can not reference rule sets with unknown layer names, got "%s" as unknown.', | ||
implode('", "', $layerNames) | ||
); | ||
|
||
self::assertSame($message, $exception->getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters