Skip to content

Commit 8bed61b

Browse files
committed
Add tests for exceptions
1 parent 8fd6a05 commit 8bed61b

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

src/Parser/Exception/NotASniffPath.php

+6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
namespace App\Parser\Exception;
55

66
use DomainException;
7+
use Throwable;
78

89
class NotASniffPath extends DomainException
910
{
11+
private function __construct($message = "", $code = 0, Throwable $previous = null)
12+
{
13+
parent::__construct($message, $code, $previous);
14+
}
15+
1016
public static function fromPath(string $path): self
1117
{
1218
return new self(

src/Parser/Exception/NotAViolationPath.php

+6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
namespace App\Parser\Exception;
55

66
use DomainException;
7+
use Throwable;
78

89
class NotAViolationPath extends DomainException
910
{
11+
private function __construct($message = "", $code = 0, Throwable $previous = null)
12+
{
13+
parent::__construct($message, $code, $previous);
14+
}
15+
1016
public static function fromPath(string $path): self
1117
{
1218
return new self(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Tests\Parser\Exception;
5+
6+
use App\Parser\Exception\NotASniffPath;
7+
use PHPUnit\Framework\TestCase;
8+
9+
/** @covers \App\Parser\Exception\NotASniffPath */
10+
class NotASniffPathTest extends TestCase
11+
{
12+
/** @test */
13+
public function fromPath()
14+
{
15+
self::assertStringContainsString(
16+
'The file path provided does not follow the convention for a sniff class.',
17+
NotASniffPath::fromPath('INVALID/PATH')->getMessage()
18+
);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Tests\Parser\Exception;
5+
6+
use App\Parser\Exception\NotAViolationPath;
7+
use PHPUnit\Framework\TestCase;
8+
9+
/** @covers \App\Parser\Exception\NotAViolationPath */
10+
class NotAViolationPathTest extends TestCase
11+
{
12+
/** @test */
13+
public function fromPath()
14+
{
15+
self::assertStringContainsString(
16+
'The file path provided does not follow the convention for violation documentation.',
17+
NotAViolationPath::fromPath('INVALID/PATH')->getMessage()
18+
);
19+
}
20+
}

0 commit comments

Comments
 (0)