Skip to content

Commit ed1c375

Browse files
committed
Add test for ternary operator with objects
1 parent 8a0cefa commit ed1c375

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/render.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,21 @@ public function __get($name)
127127
$this->assertTrue($result->__toBoolean());
128128
}
129129

130+
public function testTernary()
131+
{
132+
$jsPhpize = new JsPhpize();
133+
134+
$result = $jsPhpize->renderCode('return val === 42 ? {"answer": "42"} : {"ko": "failed"}', [
135+
'val' => 42,
136+
]);
137+
$this->assertSame(['answer' => '42'], $result);
138+
139+
$result = $jsPhpize->renderCode('return val === 42 ? {"answer": "42"} : {"ko": "failed"}', [
140+
'val' => 1,
141+
]);
142+
$this->assertSame(['ko' => 'failed'], $result);
143+
}
144+
130145
public function testDollarVariablePrefix()
131146
{
132147
$jsPhpize = new JsPhpize([

0 commit comments

Comments
 (0)