Skip to content

Commit

Permalink
Variable name for PHP compilation for null values changed.
Browse files Browse the repository at this point in the history
To avoid conflicts with compiled NullValue QTI expressions.
  • Loading branch information
= committed Oct 6, 2015
1 parent de66c75 commit efcac02
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/qtism/data/storage/php/marshalling/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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))));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -36,4 +36,4 @@ public function variableNameDataProvider() {
array(array(), 7, 'array_7')
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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", ''),
Expand All @@ -41,4 +41,4 @@ public function marshallDataProvider() {
array("\$string_0 = \"Hello \\\\ there!\";\n", "Hello \\ there!"),
);
}
}
}

0 comments on commit efcac02

Please sign in to comment.