Skip to content

Commit 89fe19a

Browse files
committed
Merge pull request #184 from adrienbrault/gh-183
Fix ExpressionEvaluator::evaluate with non strings, fixed #183
2 parents b09e669 + ffa1027 commit 89fe19a

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

src/Hateoas/Expression/ExpressionEvaluator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function setContextVariable($name, $value)
5050
*/
5151
public function evaluate($expression, $data)
5252
{
53-
if (is_bool($expression)) {
53+
if (!is_string($expression)) {
5454
return $expression;
5555
}
5656

tests/Hateoas/Tests/Expression/ExpressionEvaluatorTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ public function testRegisterFunction()
117117
->isEqualTo('Hello, toto!')
118118
;
119119
}
120+
121+
/**
122+
* @dataProvider getTestEvaluateNonStringData
123+
*/
124+
public function testEvaluateNonString($value)
125+
{
126+
$expressionEvaluator = new ExpressionEvaluator(new ExpressionLanguage());
127+
128+
$this
129+
->variable($expressionEvaluator->evaluate($value, array()))
130+
->isIdenticalTo($value)
131+
;
132+
}
133+
134+
public function getTestEvaluateNonStringData()
135+
{
136+
return array(
137+
array(true),
138+
array(1.0),
139+
array(new \StdClass),
140+
array(array('foo' => 'bar')),
141+
);
142+
}
120143
}
121144

122145
class HelloExpressionFunction implements ExpressionFunctionInterface

tests/Hateoas/Tests/Fixtures/AdrienBrault.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getWindowsComputer()
5656
public function getRelations()
5757
{
5858
return array(
59-
new Relation('dynamic-relation', 'awesome!!!'),
59+
new Relation('dynamic-relation', 'awesome!!!', array('wowowow')),
6060
);
6161
}
6262
}

tests/Hateoas/Tests/Serializer/JsonHalSerializerTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ public function testSerializeAdrienBrault()
190190
},
191191
"broken-computer": {
192192
"name": "Windows Computer"
193-
}
193+
},
194+
"dynamic-relation": [
195+
"wowowow"
196+
]
194197
}
195198
}
196199
JSON

tests/Hateoas/Tests/Serializer/XmlHalSerializerTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function testSerializeAdrienBrault()
3131
<resource rel="broken-computer">
3232
<name><![CDATA[Windows Computer]]></name>
3333
</resource>
34+
<resource rel="dynamic-relation"><![CDATA[wowowow]]></resource>
3435
</result>
3536
3637
XML

tests/Hateoas/Tests/Serializer/XmlSerializerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public function testSerializeAdrienBrault()
9595
<computer rel="broken-computer">
9696
<name><![CDATA[Windows Computer]]></name>
9797
</computer>
98+
<entry rel="dynamic-relation">
99+
<entry><![CDATA[wowowow]]></entry>
100+
</entry>
98101
</result>
99102
100103
XML

0 commit comments

Comments
 (0)