|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Papper\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Papper\TypeMap; |
|
6
|
|
|
|
|
7
|
|
|
class TypeMapTest extends TestCaseBase |
|
8
|
|
|
{ |
|
9
|
|
|
public function testGetUnmappedProperty() |
|
10
|
|
|
{ |
|
11
|
|
|
// arrange |
|
12
|
|
|
$mappedPropertyMap = self::createMappedProperty(); |
|
13
|
|
|
$unmappedPropertyMap = self::createUnmappedProperty(); |
|
14
|
|
|
|
|
15
|
|
|
$typeMap = new TypeMap('SomeType', 'AnotherType', \Mockery::mock('Papper\ObjectCreatorInterface')); |
|
16
|
|
|
$typeMap->addPropertyMap($mappedPropertyMap); |
|
17
|
|
|
$typeMap->addPropertyMap($unmappedPropertyMap); |
|
18
|
|
|
// act |
|
19
|
|
|
$unmappedProperties = $typeMap->getUnmappedPropertyMaps(); |
|
20
|
|
|
// assert |
|
21
|
|
|
$this->assertCount(1, $unmappedProperties); |
|
22
|
|
|
$this->assertSame($unmappedPropertyMap, $unmappedProperties['unmapped']); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testValidationWithUnmappedPropertiesShouldPass() |
|
26
|
|
|
{ |
|
27
|
|
|
// arrange |
|
28
|
|
|
$typeMap = new TypeMap('SomeType', 'AnotherType', \Mockery::mock('Papper\ObjectCreatorInterface')); |
|
29
|
|
|
$typeMap->addPropertyMap(self::createMappedProperty()); |
|
30
|
|
|
// act |
|
31
|
|
|
$typeMap->validate(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testValidationWithUnmappedPropertiesShouldThrowException() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->setExpectedException('Papper\ValidationException'); |
|
37
|
|
|
// arrange |
|
38
|
|
|
$typeMap = new TypeMap('SomeType', 'AnotherType', \Mockery::mock('Papper\ObjectCreatorInterface')); |
|
39
|
|
|
$typeMap->addPropertyMap(self::createMappedProperty()); |
|
40
|
|
|
$typeMap->addPropertyMap(self::createUnmappedProperty()); |
|
41
|
|
|
// act |
|
42
|
|
|
$typeMap->validate(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
private static function createMappedProperty() |
|
46
|
|
|
{ |
|
47
|
|
|
$mock = \Mockery::mock('Papper\PropertyMap'); |
|
48
|
|
|
$mock->shouldReceive('getMemberName')->andReturn('mapped'); |
|
49
|
|
|
$mock->shouldReceive('isMapped')->andReturn(true); |
|
50
|
|
|
return $mock; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
private static function createUnmappedProperty() |
|
54
|
|
|
{ |
|
55
|
|
|
$mock = \Mockery::mock('Papper\PropertyMap'); |
|
56
|
|
|
$mock->shouldReceive('getMemberName')->andReturn('unmapped'); |
|
57
|
|
|
$mock->shouldReceive('isMapped')->andReturn(false); |
|
58
|
|
|
return $mock; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|