EnvTest.php 878 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace JmesPath\Tests;
  3. use JmesPath\Env;
  4. use JmesPath\CompilerRuntime;
  5. use PHPUnit\Framework\TestCase;
  6. class EnvTest extends TestCase
  7. {
  8. public function testSearchesInput()
  9. {
  10. $data = ['foo' => 123];
  11. $this->assertEquals(123, Env::search('foo', $data));
  12. $this->assertEquals(123, Env::search('foo', $data));
  13. }
  14. public function testSearchesWithFunction()
  15. {
  16. $data = ['foo' => 123];
  17. $this->assertEquals(123, \JmesPath\search('foo', $data));
  18. }
  19. public function testCleansCompileDir()
  20. {
  21. $dir = sys_get_temp_dir();
  22. $runtime = new CompilerRuntime($dir);
  23. $runtime('@ | @ | @[0][0][0]', []);
  24. $this->assertNotEmpty(glob($dir . '/jmespath_*.php'));
  25. $this->assertGreaterThan(0, Env::cleanCompileDir());
  26. $this->assertEmpty(glob($dir . '/jmespath_*.php'));
  27. }
  28. }