TreeCompilerTest.php 664 B

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