These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace OpenOrchestra\FunctionalTests\Mapping\Metadata\Driver; |
||
4 | |||
5 | use Metadata\PropertyMetadata; |
||
6 | use Metadata\ClassMetadata; |
||
7 | use Metadata\Driver\DriverInterface; |
||
8 | use OpenOrchestra\Mapping\Metadata\MergeableClassMetadataFactory; |
||
9 | use OpenOrchestra\Mapping\Metadata\PropertySearchMetadataFactory; |
||
10 | use OpenOrchestra\FunctionalTests\Mapping\Metadata\Driver\FakeClass\FakeClassMetadata; |
||
11 | use OpenOrchestra\FunctionalTests\Mapping\Metadata\Driver\FakeClass\FakeClassWithOutMetadata; |
||
12 | use ReflectionObject; |
||
13 | |||
14 | /** |
||
15 | * Class AbstractDriverTest |
||
16 | */ |
||
17 | abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase |
||
18 | { |
||
19 | /** |
||
20 | * @var DriverInterface |
||
21 | */ |
||
22 | protected $driver; |
||
23 | protected $propertySearchMetadataFactory; |
||
24 | protected $mergeableClassMetadataFactory; |
||
25 | |||
26 | public function setUp() |
||
27 | { |
||
28 | $this->propertySearchMetadataFactory = new PropertySearchMetadataFactory(); |
||
29 | $this->mergeableClassMetadataFactory = new MergeableClassMetadataFactory(); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Test LoadMetadataForClass with out search metadata |
||
34 | */ |
||
35 | public function testLoadMetadaForClassWithOutMetadata() |
||
36 | { |
||
37 | $class = new \ReflectionClass(new FakeClassWithOutMetadata()); |
||
38 | $metadata = $this->driver->loadMetadataForClass($class); |
||
39 | $this->assertNull($metadata); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Test LoadMetadataForClass |
||
44 | */ |
||
45 | public function testLoadMetadataForClass() |
||
46 | { |
||
47 | $class = new \ReflectionClass(new FakeClassMetadata()); |
||
48 | $metadata = $this->driver->loadMetadataForClass($class); |
||
49 | $this->assertMetadata($metadata); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param ClassMetadata $metadata |
||
54 | */ |
||
55 | protected function assertMetadata(ClassMetadata $metadata) |
||
56 | { |
||
57 | $this->assertInstanceOf('Metadata\ClassMetadata', $metadata); |
||
58 | $propertiesMetadata = $metadata->propertyMetadata; |
||
59 | $this->assertArrayHasKey('fakeProperty1', $propertiesMetadata); |
||
60 | $this->assertArrayHasKey('fakeProperty2', $propertiesMetadata); |
||
61 | $propertyMetadataFakeProperty1 = $propertiesMetadata['fakeProperty1']->propertySearchMetadata[0]; |
||
62 | $this->assertPropertyMetadata($propertyMetadataFakeProperty1, 'fake_property1', 'fakeType', 'fakeProperty1'); |
||
63 | |||
64 | $this->assertCount(2, $propertiesMetadata['fakeProperty2']->propertySearchMetadata); |
||
65 | $propertyMetadataFakeProperty2 = $propertiesMetadata['fakeProperty2']->propertySearchMetadata[0]; |
||
66 | $this->assertPropertyMetadata($propertyMetadataFakeProperty2, array("fake_property2", "fake_property_multi"), 'string', 'fakeProperty2'); |
||
67 | $propertyMetadataFakeProperty2Other = $propertiesMetadata['fakeProperty2']->propertySearchMetadata[1]; |
||
68 | $this->assertPropertyMetadata($propertyMetadataFakeProperty2Other, "fake_property3", 'string', 'fakeProperty2'); |
||
69 | |||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @param PropertyMetadata $property |
||
74 | * @param array|string $key |
||
75 | * @param string $type |
||
76 | * @param string $field |
||
77 | */ |
||
78 | protected function assertPropertyMetadata($property, $key, $type, $field) |
||
79 | { |
||
80 | $this->assertEquals($property->key, $key); |
||
0 ignored issues
–
show
|
|||
81 | $this->assertEquals($property->type, $type); |
||
0 ignored issues
–
show
The property
type does not seem to exist in Metadata\PropertyMetadata .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.
Loading history...
|
|||
82 | $this->assertEquals($property->field, $field); |
||
0 ignored issues
–
show
The property
field does not seem to exist in Metadata\PropertyMetadata .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.
Loading history...
|
|||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Clean up |
||
87 | */ |
||
88 | View Code Duplication | protected function tearDown() |
|
89 | { |
||
90 | $refl = new ReflectionObject($this); |
||
91 | foreach ($refl->getProperties() as $prop) { |
||
92 | if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) { |
||
93 | $prop->setAccessible(true); |
||
94 | $prop->setValue($this, null); |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.