1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Cubiche/Metadata component. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) Cubiche |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Cubiche\Core\Metadata\Tests\Units\Driver; |
13
|
|
|
|
14
|
|
|
use Cubiche\Core\Metadata\ClassMetadata; |
15
|
|
|
use Cubiche\Core\Metadata\Driver\DriverInterface; |
16
|
|
|
use Cubiche\Core\Metadata\Exception\MappingException; |
17
|
|
|
use Cubiche\Core\Metadata\Tests\Fixtures\Address; |
18
|
|
|
use Cubiche\Core\Metadata\Tests\Fixtures\User; |
19
|
|
|
use Cubiche\Core\Metadata\Tests\Units\TestCase; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* DriverTestCase class. |
23
|
|
|
* |
24
|
|
|
* Generated by TestGenerator on 2017-05-16 at 13:17:21. |
25
|
|
|
*/ |
26
|
|
|
abstract class DriverTestCase extends TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @return DriverInterface |
30
|
|
|
*/ |
31
|
|
|
abstract protected function createDriver(); |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Test loadMetadataForClass method. |
35
|
|
|
*/ |
36
|
|
|
public function testLoadMetadataForClass() |
37
|
|
|
{ |
38
|
|
|
$this |
39
|
|
|
->given($driver = $this->createDriver()) |
40
|
|
|
->then() |
41
|
|
|
->exception(function () use ($driver) { |
42
|
|
|
$driver->loadMetadataForClass('Cubiche\Core\Metadata\Tests\Fixtures\Post'); |
43
|
|
|
})->isInstanceOf(MappingException::class) |
44
|
|
|
->exception(function () use ($driver) { |
45
|
|
|
$driver->loadMetadataForClass('Cubiche\Core\Metadata\Tests\Fixtures\Blog'); |
46
|
|
|
})->isInstanceOf(MappingException::class) |
47
|
|
|
; |
48
|
|
|
|
49
|
|
|
$this |
50
|
|
|
->given($driver = $this->createDriver()) |
51
|
|
|
->when($classMetadata = $driver->loadMetadataForClass(User::class)) |
52
|
|
|
->then() |
53
|
|
|
->object($classMetadata) |
54
|
|
|
->isInstanceOf(ClassMetadata::class) |
55
|
|
|
->array($classMetadata->propertiesMetadata()) |
56
|
|
|
->hasSize(7) |
57
|
|
|
->hasKey('id') |
58
|
|
|
->hasKey('name') |
59
|
|
|
->hasKey('username') |
60
|
|
|
->hasKey('age') |
61
|
|
|
->hasKey('email') |
62
|
|
|
->hasKey('addresses') |
63
|
|
|
->hasKey('friends') |
64
|
|
|
->object($propertyMetadata = $classMetadata->propertyMetadata('id')) |
65
|
|
|
->isNotNull() |
66
|
|
|
->boolean($propertyMetadata->getMetadata('identifier')) |
67
|
|
|
->isTrue() |
68
|
|
|
->string($propertyMetadata->getMetadata('name')) |
69
|
|
|
->isEqualTo('_id') |
70
|
|
|
->string($classMetadata->propertyMetadata('name')->getMetadata('name')) |
71
|
|
|
->isEqualTo('fullName') |
72
|
|
|
->string($classMetadata->propertyMetadata('addresses')->getMetadata('type')) |
73
|
|
|
->isEqualTo('ArraySet') |
74
|
|
|
->string($classMetadata->propertyMetadata('addresses')->getMetadata('of')) |
75
|
|
|
->isEqualTo('Cubiche\Core\Metadata\Tests\Fixtures\Address') |
76
|
|
|
->and() |
77
|
|
|
->when($classMetadata = $driver->loadMetadataForClass(User::class)) |
78
|
|
|
->then() |
79
|
|
|
->object($classMetadata) |
80
|
|
|
->isInstanceOf(ClassMetadata::class) |
81
|
|
|
; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Test getAllClassNames method. |
86
|
|
|
*/ |
87
|
|
View Code Duplication |
public function testGetAllClassNames() |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
$this |
90
|
|
|
->given($driver = $this->createDriver()) |
91
|
|
|
->when($classNames = $driver->getAllClassNames()) |
92
|
|
|
->then() |
93
|
|
|
->array($classNames) |
94
|
|
|
->contains(User::class) |
95
|
|
|
->contains(Address::class) |
96
|
|
|
; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.