Skip to content

Commit 280a643

Browse files
committed
[DEV-3393] Add new methods to fetch metadata.
1 parent e683418 commit 280a643

2 files changed

Lines changed: 126 additions & 19 deletions

File tree

src/Document/Document.php

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Document
3737
*
3838
* @var string
3939
*/
40-
private $_id = '';
40+
private $_id = "";
4141

4242
/**
4343
* Document key/value store
@@ -89,9 +89,62 @@ public function getId()
8989
*/
9090
public function getProgramId()
9191
{
92-
$program_id = &$this->_meta[ 'programId' ];
92+
return $this->_getMetaByName( "programId" );
93+
}
94+
95+
96+
/**
97+
* Get agent identifier
98+
*
99+
* @return string agent id or empty string if unknown
100+
*/
101+
public function getAgentId()
102+
{
103+
return $this->_getMetaByName( "agentId" );
104+
}
105+
106+
107+
/**
108+
* Get agent entity identifier (i.e. the user id)
109+
*
110+
* @return string agent entity id or empty string if unknown
111+
*/
112+
public function getAgentEntityId()
113+
{
114+
return $this->_getMetaByName( "agentEntityId" );
115+
}
116+
117+
118+
/**
119+
* Get the initial rated date.
120+
*
121+
* @return int A unix timestamp for the initial rating date
122+
*/
123+
public function getInitialRatedDate()
124+
{
125+
return $this->_getMetaByName( "initialRatedDate" );
126+
}
127+
93128

94-
return (string)$program_id;
129+
/**
130+
* Get the start date.
131+
*
132+
* @return int A unix timestamp for the start date
133+
*/
134+
public function getStartDate()
135+
{
136+
return $this->_getMetaByName( "startDate" );
137+
}
138+
139+
140+
/**
141+
* Get agent name
142+
*
143+
* @return string agent name or empty string if unknown
144+
*/
145+
public function getAgentName()
146+
{
147+
return $this->_getMetaByName( "agentName" );
95148
}
96149

97150

@@ -104,4 +157,18 @@ public function getBucket()
104157
{
105158
return $this->_bucket;
106159
}
160+
161+
162+
/**
163+
* Get metadata by key name
164+
*
165+
* @param String The name of the key holding the data.
166+
*
167+
* @return string metadata or empty string if unknown
168+
*/
169+
private function _getMetaByName( $name )
170+
{
171+
$data = &$this->_meta[ $name ];
172+
return (string)$data;
173+
}
107174
}

test/Document/DocumentTest.php

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class DocumentTest
3131
protected function getDummyBucket()
3232
{
3333
return $this->getMockBuilder(
34-
'Lovullo\Liza\Bucket\Bucket'
34+
"Lovullo\Liza\Bucket\Bucket"
3535
)
36-
->setMethods( array( 'getDataByName', 'hasData' ) )
36+
->setMethods( array( "getDataByName", "hasData" ) )
3737
->getMock();
3838
}
3939

@@ -46,7 +46,7 @@ protected function createSut( $id, $bucket, $meta = [] )
4646

4747
public function testReturnsDocumentId()
4848
{
49-
$id = '123456';
49+
$id = "123456";
5050

5151
$this->assertEquals(
5252
$id,
@@ -58,45 +58,85 @@ public function testReturnsDocumentId()
5858
public function testIdReturnedAsAString()
5959
{
6060
$this->assertSame(
61-
'1234',
61+
"1234",
6262
$this->createSut( 1234, $this->getDummyBucket() )->getId()
6363
);
6464
}
6565

6666

67-
public function programIdDataProvider()
67+
public function testReturnsBucket()
68+
{
69+
$bucket = $this->getDummyBucket();
70+
71+
$this->assertSame(
72+
$bucket,
73+
$this->createSut( "foo", $bucket )->getBucket()
74+
);
75+
}
76+
77+
78+
public function gettersDataProvider()
6879
{
6980
return [
70-
[ [ 'programId' => 'fooprog' ], 'fooprog' ],
71-
[ [ 'programId' => '' ], '' ],
72-
[ [], '' ],
81+
[ [ "agentId" => "fooagentid" ], "fooagentid" ],
82+
[ [ "agentId" => "" ], "" ],
83+
[ [ "agentName" => "fooagentname" ], "fooagentname" ],
84+
[ [ "agentName" => "" ], "" ],
85+
[ [ "programId" => "fooprog" ], "fooprog" ],
86+
[ [ "programId" => "" ], "" ],
87+
[ [ "agentEntityId" => "fooaei" ], "fooaei" ],
88+
[ [ "agentEntityId" => "" ], "" ],
89+
[ [ "initialRatedDate" => "fooird" ], "fooird" ],
90+
[ [ "initialRatedDate" => "" ], "" ],
91+
[ [ "startDate" => "foosd" ], "foosd" ],
92+
[ [ "startDate" => "" ], "" ],
7393
];
7494
}
7595

7696

7797
/**
78-
* @dataProvider programIdDataProvider
98+
* @dataProvider gettersDataProvider
7999
*/
80-
public function testProgramIdReturnedAsString( array $meta, $expected )
100+
public function testGetters( array $meta, $expected )
81101
{
102+
$methodName = "get" . ucfirst( array_keys( $meta )[0] );
103+
82104
$this->assertEquals(
83105
$expected,
84106
$this->createSut(
85107
1234,
86108
$this->getDummyBucket(),
87109
$meta
88-
)->getProgramId()
110+
)->$methodName()
89111
);
90112
}
91113

92114

93-
public function testReturnsBucket()
115+
public function emptyGettersDataProvider()
94116
{
95-
$bucket = $this->getDummyBucket();
117+
return [
118+
[ "getProgramId" ],
119+
[ "getAgentId" ],
120+
[ "getAgentName" ],
121+
[ "getAgentEntityId" ],
122+
[ "getInitialRatedDate" ],
123+
[ "getStartDate" ],
124+
];
125+
}
96126

97-
$this->assertSame(
98-
$bucket,
99-
$this->createSut( 'foo', $bucket )->getBucket()
127+
128+
/**
129+
* @dataProvider emptyGettersDataProvider
130+
*/
131+
public function testEmptyGetters( $methodName )
132+
{
133+
$this->assertEquals(
134+
"",
135+
$this->createSut(
136+
1234,
137+
$this->getDummyBucket(),
138+
[]
139+
)->$methodName()
100140
);
101141
}
102142
}

0 commit comments

Comments
 (0)