TreeCompilerTest.php 651 B

1234567891011121314151617181920212223
  1. <?php
  2. namespace JmesPath\Tests\Tree;
  3. use JmesPath\TreeCompiler;
  4. /**
  5. * @covers JmesPath\Tree\TreeCompiler
  6. */
  7. class TreeCompilerTest extends \PHPUnit_Framework_TestCase
  8. {
  9. public function testCreatesSourceCode()
  10. {
  11. $t = new TreeCompiler();
  12. $source = $t->visit(
  13. ['type' => 'field', 'value' => 'foo'],
  14. 'testing',
  15. 'foo'
  16. );
  17. $this->assertContains('<?php', $source);
  18. $this->assertContains('$value = isset($value->{\'foo\'}) ? $value->{\'foo\'} : null;', $source);
  19. $this->assertContains('$value = isset($value[\'foo\']) ? $value[\'foo\'] : null;', $source);
  20. }
  21. }