1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TheCodingMachine\TDBM\Utils\Annotation; |
5
|
|
|
|
6
|
|
|
use Doctrine\Common\Annotations\AnnotationException; |
7
|
|
|
use TheCodingMachine\TDBM\TDBMException; |
8
|
|
|
|
9
|
|
|
class AnnotationParserTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
public function testParse() |
12
|
|
|
{ |
13
|
|
|
$parser = new AnnotationParser([ |
14
|
|
|
'UUID' => UUID::class, |
15
|
|
|
'Autoincrement' => Autoincrement::class |
16
|
|
|
]); |
17
|
|
|
$annotations = $parser->parse('@UUID', ''); |
18
|
|
|
|
19
|
|
|
$annotation = $annotations->findAnnotation(UUID::class); |
20
|
|
|
$this->assertInstanceOf(UUID::class, $annotation); |
21
|
|
|
|
22
|
|
|
$annotationsArray = $annotations->getAnnotations(); |
23
|
|
|
$this->assertCount(1, $annotationsArray); |
24
|
|
|
$this->assertSame($annotation, $annotationsArray[0]); |
25
|
|
|
|
26
|
|
|
$annotation = $annotations->findAnnotation('not_exist'); |
27
|
|
|
$this->assertNull($annotation); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testException() |
31
|
|
|
{ |
32
|
|
|
$parser = new AnnotationParser([ |
33
|
|
|
'UUID' => UUID::class, |
34
|
|
|
'Autoincrement' => Autoincrement::class |
35
|
|
|
]); |
36
|
|
|
$annotations = $parser->parse("@UUID\n@UUID", ''); |
37
|
|
|
|
38
|
|
|
$this->expectException(TDBMException::class); |
39
|
|
|
$annotations->findAnnotation(UUID::class); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testParseParameters() |
43
|
|
|
{ |
44
|
|
|
$parser = new AnnotationParser([ |
45
|
|
|
'UUID' => UUID::class, |
46
|
|
|
'Autoincrement' => Autoincrement::class |
47
|
|
|
]); |
48
|
|
|
$annotations = $parser->parse('@UUID("v4")', ''); |
49
|
|
|
|
50
|
|
|
$annotation = $annotations->findAnnotation(UUID::class); |
51
|
|
|
$this->assertSame('v4', $annotation->value); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testParseOldUUID() |
55
|
|
|
{ |
56
|
|
|
$parser = new AnnotationParser([ |
57
|
|
|
'UUID' => UUID::class, |
58
|
|
|
]); |
59
|
|
|
// First generation UUID did not use the Doctrine syntax. |
60
|
|
|
$annotations = $parser->parse('@UUID v4', ''); |
61
|
|
|
|
62
|
|
|
$annotation = $annotations->findAnnotation(UUID::class); |
63
|
|
|
$this->assertSame('v4', $annotation->value); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|