Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/Everyman/Neo4j/Query/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,27 @@ public function offsetExists($offset)

public function offsetGet($offset)
{
$offsetInt = $offset;

if (!is_integer($offset)) {
$offset = array_search($offset, $this->columns);
$offsetInt = array_search($offset, $this->columns);

if ($offsetInt === false) {
trigger_error("Undefined offset: {$offset}", E_USER_NOTICE);
return null;
}
}

if (!isset($this->data[$offset])) {
$raw = $this->raw[$offset];
if (!isset($this->data[$offsetInt])) {
$raw = $this->raw[$offsetInt];
$data = $this->client->getEntityMapper()->getEntityFor($raw);
if (is_array($data)) {
$data = new Row($this->client, array_keys($raw), array_values($raw));
}
$this->data[$offset] = $data;
$this->data[$offsetInt] = $data;
}

return $this->data[$offset];
return $this->data[$offsetInt];
}

public function offsetSet($offset, $value)
Expand Down
25 changes: 24 additions & 1 deletion tests/unit/lib/Everyman/Neo4j/Query/RowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ public function setUp()
{
$this->client = new Client($this->getMock('Everyman\Neo4j\Transport', array(), array(), '', false));
}


public function tearDown()
{
// just in case if testArrayAccessNonExistedValue fails and not set back $enabled to default value
\PHPUnit_Framework_Error_Notice::$enabled = true;
}

public function testCount()
{
$columns = array('name','age');
Expand Down Expand Up @@ -71,6 +77,23 @@ public function testArrayAccess()
$this->assertEquals(false, isset($row[3]));
}

public function testArrayAccessNonExistedValue()
{
$columns = array('name');
$data = array('Brenda');

$row = new Row($this->client, $columns, $data);

// First check if we have null value

\PHPUnit_Framework_Error_Notice::$enabled = false;
$this->assertSame(null, $row['age']);
\PHPUnit_Framework_Error_Notice::$enabled = true;

$this->setExpectedException('PHPUnit_Framework_Error_Notice');
$this->assertSame(null, $row['age']);
}

public function testArrayAccess_Set_ThrowsException()
{
$columns = array('name','age');
Expand Down