-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactoryTest.php
More file actions
59 lines (50 loc) · 1.56 KB
/
FactoryTest.php
File metadata and controls
59 lines (50 loc) · 1.56 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
59
<?php declare(strict_types=1);
namespace Tests\FileParser;
use PHPUnit\Framework\TestCase;
/**
* 测试 php-file-parser\FileParser\Factory
*
* @author fdipzone
*/
final class FactoryTest extends TestCase
{
/**
* @covers \FileParser\Factory::make
*/
public function testMake()
{
// 创建 XML 解析器对象
$parser = \FileParser\Factory::make(\FileParser\Type::XML);
$this->assertEquals('FileParser\XmlParser', get_class($parser));
// 创建 XML 解析器对象(单例)
$parser2 = \FileParser\Factory::make(\FileParser\Type::XML);
// 检查是否单例
$this->assertTrue($parser==$parser2);
}
/**
* @covers \FileParser\Factory::make
*/
public function testMakeException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('file parser factory: type not_exists_type not exists');
\FileParser\Factory::make('not_exists_type');
}
/**
* @covers \FileParser\Factory::getParserClass
*/
public function testGetParserClass()
{
$class = \FileParser\Factory::getParserClass(\FileParser\Type::XML);
$this->assertEquals('\FileParser\XmlParser', $class);
}
/**
* @covers \FileParser\Factory::getParserClass
*/
public function testGetParserClassException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('file parser factory: type not_exists_type not exists');
\FileParser\Factory::getParserClass('not_exists_type');
}
}