Skip to content

Commit

Permalink
fix: A little hack preventing an error processing [null]
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondrej Vana committed Oct 21, 2015
1 parent 9542889 commit d42faa2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Keboola/Json/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static function create(Logger $logger, array $definitions = [], $analyzeR
public function process(array $data, $type = "root", $parentId = null)
{
// The analyzer wouldn't set the $struct and parse fails!
if (empty($data) && !$this->struct->hasDefinitions($type)) {
if ((empty($data) || $data == [null]) && !$this->struct->hasDefinitions($type)) {
throw new NoDataException("Empty data set received for {$type}", [
"data" => $data,
"type" => $type,
Expand Down
25 changes: 10 additions & 15 deletions tests/Keboola/Json/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,21 +764,16 @@ public function testEmptyData()
$parser->process([]);
}

// /**
// * @expectedException \Keboola\Json\Exception\NoDataException
// * @expectedExceptionMessage Empty data set received for root
// */
// public function testNullData()
// {
// $parser = $this->getParser();
//
// $parser->process([null]);
// ini_set('xdebug.var_display_max_depth', -1);
// ini_set('xdebug.var_display_max_children', -1);
// ini_set('xdebug.var_display_max_data', -1);
// var_dump($parser);
// $parser->getCsvFiles();
// }
/**
* @expectedException \Keboola\Json\Exception\NoDataException
* @expectedExceptionMessage Empty data set received for root
*/
public function testNullData()
{
$parser = $this->getParser();

$parser->process([null]);
}

public function testArrayOfNull()
{
Expand Down
1 change: 0 additions & 1 deletion tests/Keboola/Json/StructTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

require_once 'tests/ParserTestCase.php';


class StructTest extends ParserTestCase
{
public function testTypeIsScalar()
Expand Down

0 comments on commit d42faa2

Please sign in to comment.