Skip to content

Commit 13654bd

Browse files
Merge pull request #118 from lastzero/develop
Added getData() method to Basho\Riak\Search\Doc
2 parents 7862900 + a7da4f2 commit 13654bd

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/Riak/Search/Doc.php

+21
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,34 @@ public function __construct(\stdClass $data)
4444
$this->data = $data;
4545
}
4646

47+
/**
48+
* Returns object location
49+
*
50+
* @return Location
51+
*/
4752
public function getLocation()
4853
{
4954
return new Location($this->_yz_rk, new Bucket($this->_yz_rb, $this->_yz_rt));
5055
}
5156

57+
/**
58+
* Returns a single value from Solr result document
59+
*
60+
* @param string $name
61+
* @return mixed
62+
*/
5263
public function __get($name)
5364
{
5465
return $this->data->{$name};
5566
}
67+
68+
/**
69+
* Returns all values as array from Solr result document
70+
*
71+
* @return array
72+
*/
73+
public function getData()
74+
{
75+
return (array)$this->data;
76+
}
5677
}

tests/unit/Riak/Search/DocTest.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Basho\Tests\Riak\Search;
4+
5+
use Basho\Riak\Search\Doc;
6+
use PHPUnit_Framework_TestCase as TestCase;
7+
8+
/**
9+
* Search result document test
10+
*
11+
* @author Michael Mayer <[email protected]>
12+
*/
13+
class DocTest extends TestCase
14+
{
15+
/**
16+
* @var Doc
17+
*/
18+
protected $doc;
19+
20+
public function setUp()
21+
{
22+
$data = new \stdClass();
23+
$data->_yz_id = '1*tests*test*5*39';
24+
$data->_yz_rk = '5';
25+
$data->_yz_rt = 'tests';
26+
$data->_yz_rb = 'test';
27+
$data->foo = 'bar';
28+
$data->_status = 200;
29+
$this->doc = new Doc($data);
30+
}
31+
32+
public function testGetLocation()
33+
{
34+
$result = $this->doc->getLocation();
35+
$this->assertInstanceOf('\Basho\Riak\Location', $result);
36+
$this->assertInstanceOf('\Basho\Riak\Bucket', $result->getBucket());
37+
$this->assertEquals('tests', $result->getBucket()->getType());
38+
$this->assertEquals('test', $result->getBucket()->getName());
39+
$this->assertEquals('5', $result->getKey());
40+
}
41+
42+
public function testGetData()
43+
{
44+
$result = $this->doc->getData();
45+
$this->assertInternalType('array', $result);
46+
$this->assertEquals('bar', $result['foo']);
47+
$this->assertEquals(200, $result['_status']);
48+
}
49+
50+
public function testMagicGetter()
51+
{
52+
$this->assertEquals('bar', $this->doc->foo);
53+
$this->assertEquals(200, $this->doc->_status);
54+
}
55+
}

0 commit comments

Comments
 (0)