Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added getData() method to Basho\Riak\Search\Doc #118

Merged
merged 4 commits into from Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Riak/Search/Doc.php
Expand Up @@ -44,13 +44,34 @@ public function __construct(\stdClass $data)
$this->data = $data;
}

/**
* Returns bucket location
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would actually be the location of an object not the bucket.

*
* @return Location
*/
public function getLocation()
{
return new Location($this->_yz_rk, new Bucket($this->_yz_rb, $this->_yz_rt));
}

/**
* Returns a single value from Solr result document
*
* @param string $name
* @return mixed
*/
public function __get($name)
{
return $this->data->{$name};
}

/**
* Returns all values as array from Solr result document
*
* @return array
*/
public function getData()
{
return (array)$this->data;
}
}
55 changes: 55 additions & 0 deletions tests/unit/Riak/Search/DocTest.php
@@ -0,0 +1,55 @@
<?php

namespace Basho\Tests\Riak\Search;

use Basho\Riak\Search\Doc;
use PHPUnit_Framework_TestCase as TestCase;

/**
* Search result document test
*
* @author Michael Mayer <michael@lastzero.net>
*/
class DocTest extends TestCase
{
/**
* @var Doc
*/
protected $doc;

public function setUp()
{
$data = new \stdClass();
$data->_yz_id = '1*tests*test*5*39';
$data->_yz_rk = '5';
$data->_yz_rt = 'tests';
$data->_yz_rb = 'test';
$data->foo = 'bar';
$data->_status = 200;
$this->doc = new Doc($data);
}

public function testGetLocation()
{
$result = $this->doc->getLocation();
$this->assertInstanceOf('\Basho\Riak\Location', $result);
$this->assertInstanceOf('\Basho\Riak\Bucket', $result->getBucket());
$this->assertEquals('tests', $result->getBucket()->getType());
$this->assertEquals('test', $result->getBucket()->getName());
$this->assertEquals('5', $result->getKey());
}

public function testGetData()
{
$result = $this->doc->getData();
$this->assertInternalType('array', $result);
$this->assertEquals('bar', $result['foo']);
$this->assertEquals(200, $result['_status']);
}

public function testMagicGetter()
{
$this->assertEquals('bar', $this->doc->foo);
$this->assertEquals(200, $this->doc->_status);
}
}