From d42faa258be89bd8cb2695b4b70b103d8cfccf23 Mon Sep 17 00:00:00 2001 From: Ondrej Vana Date: Wed, 21 Oct 2015 16:55:49 -0700 Subject: [PATCH] fix: A little hack preventing an error processing [null] --- src/Keboola/Json/Parser.php | 2 +- tests/Keboola/Json/ParserTest.php | 25 ++++++++++--------------- tests/Keboola/Json/StructTest.php | 1 - 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/Keboola/Json/Parser.php b/src/Keboola/Json/Parser.php index ce355db..d030fe7 100755 --- a/src/Keboola/Json/Parser.php +++ b/src/Keboola/Json/Parser.php @@ -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, diff --git a/tests/Keboola/Json/ParserTest.php b/tests/Keboola/Json/ParserTest.php index 6ab9040..97f689b 100755 --- a/tests/Keboola/Json/ParserTest.php +++ b/tests/Keboola/Json/ParserTest.php @@ -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() { diff --git a/tests/Keboola/Json/StructTest.php b/tests/Keboola/Json/StructTest.php index 692bb98..ef468a3 100755 --- a/tests/Keboola/Json/StructTest.php +++ b/tests/Keboola/Json/StructTest.php @@ -6,7 +6,6 @@ require_once 'tests/ParserTestCase.php'; - class StructTest extends ParserTestCase { public function testTypeIsScalar()