/
ClassParserTest.php
49 lines (39 loc) · 1.59 KB
/
ClassParserTest.php
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
<?php declare(strict_types=1);
namespace Lmc\Utils\Annotations;
use Lmc\Steward\Exception\RuntimeException;
use Lmc\Steward\Utils\Annotations\ClassParser;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\SplFileInfo;
/**
* @covers \Lmc\Steward\Exception\RuntimeException
* @covers \Lmc\Steward\Utils\Annotations\ClassParser
*/
class ClassParserTest extends TestCase
{
public function testShouldGetClassNameFromFile(): void
{
$file = $this->createFileInfo('ClassNoDocBlock.php');
$className = ClassParser::readClassNameFromFile($file);
$this->assertSame('Lmc\Steward\Utils\Annotations\Fixtures\ClassNoDocBlock', $className);
}
public function testShouldThrowExceptionForMultipleClassesInOneFile(): void
{
$file = $this->createFileInfo('MultipleClassesInFile.php');
$this->expectException(RuntimeException::class);
$this->expectExceptionMessageRegExp(
'/^File ".+MultipleClassesInFile.php" contains definition of 2 classes\./'
);
ClassParser::readClassNameFromFile($file);
}
public function testShouldThrowExceptionForNoClassInOneFile(): void
{
$file = $this->createFileInfo('NoClassInFile.php');
$this->expectException(RuntimeException::class);
$this->expectExceptionMessageRegExp('/^No class found in file ".+NoClassInFile.php"/');
ClassParser::readClassNameFromFile($file);
}
private function createFileInfo(string $fileName): SplFileInfo
{
return new SplFileInfo(__DIR__ . '/Fixtures/' . $fileName, 'Fixtures/', 'Fixtures/' . $fileName);
}
}