Skip to content

Commit

Permalink
ability to dump resultSet from method getData()
Browse files Browse the repository at this point in the history
  • Loading branch information
gsouf committed Nov 25, 2017
1 parent aa59e55 commit d6e1b36
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Core/Serp/BaseResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ public function getData()
$data = [];
foreach ($this->data as $k => $v) {
$datum = $this->getDataValue($k);
if (is_array($datum)) {
foreach ($datum as $subK => $subV) {
if (is_array($datum) || (is_object($datum) && $datum instanceof ResultSetInterface)) {
// make sur datum is an array
$baseDatum = $datum;
$datum = [];

foreach ($baseDatum as $subK => $subV) {
if (is_object($subV) && $subV instanceof ResultDataInterface) {
$datum[$subK] = $subV->getData();
} else {
$datum[$subK] = $subV;
}
}
} elseif (is_object($datum) && $datum instanceof ResultDataInterface) {
Expand Down
33 changes: 33 additions & 0 deletions test/suites/TDD/Core/Serp/BaseResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Serps\Test\TDD\Core;

use Serps\Core\Serp\BaseResult;
use Serps\Core\Serp\ResultSet;

/**
* @covers Serps\Core\Serp\BaseResult
Expand Down Expand Up @@ -103,6 +104,38 @@ public function testNestedInArrayGetData()
}


public function testResultsetNestedInArrayGetData()
{



$result = new BaseResult('classical', [
'foo' => 'bar',
'bar' => function () {
$resultSet = new ResultSet();
$resultSet->addItems([
new BaseResult('foo', [
'bar' => 'baz',
'foo' => 'qux'
]),
new BaseResult('foo', [
'bar' => 'far',
'foo' => 'boz'
]),
]);
return $resultSet;
}
]);
$this->assertEquals([
'foo' => 'bar',
'bar' => [
['bar' => 'baz', 'foo' => 'qux'],
['bar' => 'far', 'foo' => 'boz'],
]
], $result->getData());
}




public function testGetDataValue()
Expand Down

0 comments on commit d6e1b36

Please sign in to comment.