1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\Tests\v3\edm\EntityContainer; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType; |
6
|
|
|
use AlgoWeb\ODataMetadata\Tests\TestCase; |
7
|
|
|
use Mockery as m; |
8
|
|
|
|
9
|
|
|
class EntitySetAnonymousTypeTest extends TestCase |
10
|
|
|
{ |
11
|
|
View Code Duplication |
public function testSetBadName() |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
$expected = "Name must be a valid TSimpleIdentifier"; |
14
|
|
|
$actual = null; |
15
|
|
|
|
16
|
|
|
$foo = new EntitySetAnonymousType(); |
17
|
|
|
$name = " _ "; |
18
|
|
|
|
19
|
|
|
try { |
20
|
|
|
$foo->setName($name); |
21
|
|
|
} catch (\InvalidArgumentException $e) { |
22
|
|
|
$actual = $e->getMessage(); |
23
|
|
|
} |
24
|
|
|
$this->assertEquals($expected, $actual); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
public function testSetBadEntityType() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$expected = "Entity type must be a valid TQualifiedName"; |
30
|
|
|
$actual = null; |
31
|
|
|
|
32
|
|
|
$foo = new EntitySetAnonymousType(); |
33
|
|
|
$name = " _ "; |
34
|
|
|
|
35
|
|
|
try { |
36
|
|
|
$foo->setEntityType($name); |
37
|
|
|
} catch (\InvalidArgumentException $e) { |
38
|
|
|
$actual = $e->getMessage(); |
39
|
|
|
} |
40
|
|
|
$this->assertEquals($expected, $actual); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function testSetBadGetterAccess() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$expected = "Getter access must be a valid TAccess"; |
46
|
|
|
$actual = null; |
47
|
|
|
|
48
|
|
|
$foo = new EntitySetAnonymousType(); |
49
|
|
|
$name = " _ "; |
50
|
|
|
|
51
|
|
|
try { |
52
|
|
|
$foo->setGetterAccess($name); |
53
|
|
|
} catch (\InvalidArgumentException $e) { |
54
|
|
|
$actual = $e->getMessage(); |
55
|
|
|
} |
56
|
|
|
$this->assertEquals($expected, $actual); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
View Code Duplication |
public function testIsTEntitySetAttributesOKBadName() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$expectedStarts = "Name must be a valid TSimpleIdentifier"; |
62
|
|
|
$expectedEnds = "AlgoWeb_ODataMetadata_MetadataV3_edm_EntityContainer_EntitySetAnonymousType"; |
63
|
|
|
$actual = null; |
64
|
|
|
|
65
|
|
|
$foo = m::mock(EntitySetAnonymousType::class)->makePartial(); |
66
|
|
|
$foo->shouldReceive('isTSimpleIdentifierValid')->andReturn(true, false)->twice(); |
67
|
|
|
|
68
|
|
|
$foo->setName(" _ "); |
69
|
|
|
|
70
|
|
|
$this->assertFalse($foo->isTEntitySetAttributesOK($actual)); |
71
|
|
|
$this->assertStringStartsWith($expectedStarts, $actual); |
72
|
|
|
$this->assertStringEndsWith($expectedEnds, $actual); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
View Code Duplication |
public function testIsTEntitySetAttributesOKBadEntityType() |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
$expectedStarts = "Entity type must be a valid TQualifiedName"; |
78
|
|
|
$expectedEnds = "AlgoWeb_ODataMetadata_MetadataV3_edm_EntityContainer_EntitySetAnonymousType"; |
79
|
|
|
$actual = null; |
80
|
|
|
|
81
|
|
|
$foo = m::mock(EntitySetAnonymousType::class)->makePartial(); |
82
|
|
|
$foo->shouldReceive('isTQualifiedNameValid')->andReturn(true, false)->twice(); |
83
|
|
|
|
84
|
|
|
$foo->setEntityType(" _ "); |
85
|
|
|
|
86
|
|
|
$this->assertFalse($foo->isTEntitySetAttributesOK($actual)); |
87
|
|
|
$this->assertStringStartsWith($expectedStarts, $actual); |
88
|
|
|
$this->assertStringEndsWith($expectedEnds, $actual); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
View Code Duplication |
public function testIsTEntitySetAttributesOKBadGetterAccess() |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
$expectedStarts = "Getter access must be a valid TAccess"; |
94
|
|
|
$expectedEnds = "AlgoWeb_ODataMetadata_MetadataV3_edm_EntityContainer_EntitySetAnonymousType"; |
95
|
|
|
$actual = null; |
96
|
|
|
|
97
|
|
|
$foo = m::mock(EntitySetAnonymousType::class)->makePartial(); |
98
|
|
|
$foo->shouldReceive('isTAccessOk')->andReturn(true, false)->twice(); |
99
|
|
|
|
100
|
|
|
$foo->setGetterAccess(" _ "); |
101
|
|
|
|
102
|
|
|
$this->assertFalse($foo->isTEntitySetAttributesOK($actual)); |
103
|
|
|
$this->assertStringStartsWith($expectedStarts, $actual); |
104
|
|
|
$this->assertStringEndsWith($expectedEnds, $actual); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
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.