-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractParserTest.php
More file actions
58 lines (49 loc) · 1.64 KB
/
AbstractParserTest.php
File metadata and controls
58 lines (49 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace Fabiang\Dateparser;
use DateTime;
use Fabiang\Dateparser\Exception\LoadDefinitionException;
use org\bovigo\vfs\vfsStream;
use Override;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use function chmod;
use function file_put_contents;
#[CoversClass(AbstractParser::class)]
final class AbstractParserTest extends TestCase
{
public function testLoadFileMissing()
{
$this->expectException(LoadDefinitionException::class);
$this->expectExceptionMessageMatches('/^Unable to load definition file/');
$underTest = new class extends AbstractParser {
#[Override]
public function parse(string $string): DateTime
{
$this->load('UNKNOWN');
}
};
$underTest->parse('unrelevant');
}
public function testLoadNotReadable()
{
$this->expectException(LoadDefinitionException::class);
$this->expectExceptionMessageMatches('/^Definition file \'.*NOT_READABLE.php\' is not readable/');
$underTest = new class extends AbstractParser {
public function __construct()
{
$path = vfsStream::setup();
$file = $path->url() . '/NOT_READABLE.php';
file_put_contents($file, '<?php return [];');
chmod($file, 0000);
parent::__construct($path->url());
}
#[Override]
public function parse(string $string): DateTime
{
$this->load('NOT_READABLE');
}
};
$underTest->parse('unrelevant');
}
}