From efcac02755c473970c28b46a36f3f04ac67bed1c Mon Sep 17 00:00:00 2001 From: = Date: Tue, 6 Oct 2015 14:29:32 +0200 Subject: [PATCH] Variable name for PHP compilation for null values changed. To avoid conflicts with compiled NullValue QTI expressions. --- src/qtism/data/storage/php/marshalling/Utils.php | 3 ++- .../storage/php/marshalling/PhpMarshallingContextTest.php | 8 ++++---- .../storage/php/marshalling/PhpMarshallingUtilsTest.php | 6 +++--- .../storage/php/marshalling/PhpScalarMarshallerTest.php | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/qtism/data/storage/php/marshalling/Utils.php b/src/qtism/data/storage/php/marshalling/Utils.php index 40e06f305..55be40fa4 100644 --- a/src/qtism/data/storage/php/marshalling/Utils.php +++ b/src/qtism/data/storage/php/marshalling/Utils.php @@ -80,7 +80,8 @@ public static function variableName($value, $occurence = 0) } // null value? elseif (is_null($value) === true) { - return 'nullvalue_' . $occurence; + // To avoid conflict with NullValue QTI expression object!!! + return 'scalarnullvalue_' . $occurence; } else { $msg = "Cannot handle the given value."; throw new InvalidArgumentException($msg); diff --git a/test/qtismtest/data/storage/php/marshalling/PhpMarshallingContextTest.php b/test/qtismtest/data/storage/php/marshalling/PhpMarshallingContextTest.php index d214ebebc..c7817cfbd 100644 --- a/test/qtismtest/data/storage/php/marshalling/PhpMarshallingContextTest.php +++ b/test/qtismtest/data/storage/php/marshalling/PhpMarshallingContextTest.php @@ -102,9 +102,9 @@ public function testGenerateVariableName() { $this->assertEquals('integer_0', $ctx->generateVariableName(0)); $this->assertEquals('integer_1', $ctx->generateVariableName(-10)); - $this->assertEquals('nullvalue_0', $ctx->generateVariableName(null)); - $this->assertEquals('nullvalue_1', $ctx->generateVariableName(null)); - $this->assertEquals('nullvalue_2', $ctx->generateVariableName(null)); + $this->assertEquals('scalarnullvalue_0', $ctx->generateVariableName(null)); + $this->assertEquals('scalarnullvalue_1', $ctx->generateVariableName(null)); + $this->assertEquals('scalarnullvalue_2', $ctx->generateVariableName(null)); $this->assertEquals('boolean_0', $ctx->generateVariableName(true)); $this->assertEquals('boolean_1', $ctx->generateVariableName(false)); $this->assertEquals('double_0', $ctx->generateVariableName(20.3)); @@ -119,4 +119,4 @@ public function testGenerateVariableName() { $this->assertEquals('point_1', $ctx->generateVariableName(new Point(0, 1))); $this->assertEquals('coords_2', $ctx->generateVariableName(new Coords(Shape::CIRCLE, array(5, 5, 3)))); } -} \ No newline at end of file +} diff --git a/test/qtismtest/data/storage/php/marshalling/PhpMarshallingUtilsTest.php b/test/qtismtest/data/storage/php/marshalling/PhpMarshallingUtilsTest.php index 799ba2a4d..1ed18c5c6 100644 --- a/test/qtismtest/data/storage/php/marshalling/PhpMarshallingUtilsTest.php +++ b/test/qtismtest/data/storage/php/marshalling/PhpMarshallingUtilsTest.php @@ -20,8 +20,8 @@ public function testVariableName($value, $occurence, $expected) { public function variableNameDataProvider() { return array( - array(null, 0, 'nullvalue_0'), - array(null, 1, 'nullvalue_1'), + array(null, 0, 'scalarnullvalue_0'), + array(null, 1, 'scalarnullvalue_1'), array('string!', 0, 'string_0'), array('string!', 2, 'string_2'), array(-23, 0, 'integer_0'), @@ -36,4 +36,4 @@ public function variableNameDataProvider() { array(array(), 7, 'array_7') ); } -} \ No newline at end of file +} diff --git a/test/qtismtest/data/storage/php/marshalling/PhpScalarMarshallerTest.php b/test/qtismtest/data/storage/php/marshalling/PhpScalarMarshallerTest.php index 9b5e67724..a53c7eaae 100644 --- a/test/qtismtest/data/storage/php/marshalling/PhpScalarMarshallerTest.php +++ b/test/qtismtest/data/storage/php/marshalling/PhpScalarMarshallerTest.php @@ -29,7 +29,7 @@ public function testMarshallWrongDataType() { public function marshallDataProvider() { return array( - array("\$nullvalue_0 = null;\n", null), + array("\$scalarnullvalue_0 = null;\n", null), array("\$integer_0 = 10;\n", 10), array("\$double_0 = 10.44;\n", 10.44), array("\$string_0 = \"\";\n", ''), @@ -41,4 +41,4 @@ public function marshallDataProvider() { array("\$string_0 = \"Hello \\\\ there!\";\n", "Hello \\ there!"), ); } -} \ No newline at end of file +}