Skip to content

Commit 691b7d7

Browse files
committed
Exception for missing solution file
1 parent d2cc6cb commit 691b7d7

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpSchool\PhpWorkshop\Exception;
6+
7+
/**
8+
* Represents the situation where an exercise requires compares a user generated file with
9+
* one provided with the solution but it does not exist
10+
*/
11+
class SolutionFileDoesNotExistException extends RuntimeException
12+
{
13+
/**
14+
* Static constructor to create an instance from the expected filename.
15+
*/
16+
public static function fromExpectedFile(string $expectedFile): self
17+
{
18+
return new self(sprintf('File: "%s" does not exist in solution folder', $expectedFile));
19+
}
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace PhpSchool\PhpWorkshopTest\Exception;
4+
5+
use PhpSchool\PhpWorkshop\Exception\SolutionFileDoesNotExistException;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class SolutionFileDoesNotExistExceptionTest extends TestCase
9+
{
10+
public function testException(): void
11+
{
12+
$e = SolutionFileDoesNotExistException::fromExpectedFile('some-file.csv');
13+
$this->assertEquals('File: "some-file.csv" does not exist in solution folder', $e->getMessage());
14+
}
15+
}

0 commit comments

Comments
 (0)