初始化代码

This commit is contained in:
2025-12-22 14:34:25 +08:00
parent c2c5ae2fdd
commit a77dbc743f
1510 changed files with 213008 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
<?php
namespace JmesPath\Tests\Tree;
use JmesPath\AstRuntime;
use JmesPath\TreeInterpreter;
use PHPUnit\Framework\TestCase;
/**
* @covers JmesPath\Tree\TreeInterpreter
*/
class TreeInterpreterTest extends TestCase
{
public function testReturnsNullWhenMergingNonArray()
{
$t = new TreeInterpreter();
$this->assertNull($t->visit([
'type' => 'flatten',
'children' => [
['type' => 'literal', 'value' => 1],
['type' => 'literal', 'value' => 1]
]
], [], [
'runtime' => new AstRuntime()
]));
}
public function testWorksWithArrayObjectAsObject()
{
$runtime = new AstRuntime();
$this->assertEquals('baz', $runtime('foo.bar', new \ArrayObject([
'foo' => new \ArrayObject(['bar' => 'baz'])
])));
}
public function testWorksWithArrayObjectAsArray()
{
$runtime = new AstRuntime();
$this->assertEquals('baz', $runtime('foo[0].bar', new \ArrayObject([
'foo' => new \ArrayObject([new \ArrayObject(['bar' => 'baz'])])
])));
}
public function testWorksWithArrayProjections()
{
$runtime = new AstRuntime();
$this->assertEquals(
['baz'],
$runtime('foo[*].bar', new \ArrayObject([
'foo' => new \ArrayObject([
new \ArrayObject([
'bar' => 'baz'
])
])
]))
);
}
public function testWorksWithObjectProjections()
{
$runtime = new AstRuntime();
$this->assertEquals(
['baz'],
$runtime('foo.*.bar', new \ArrayObject([
'foo' => new \ArrayObject([
'abc' => new \ArrayObject([
'bar' => 'baz'
])
])
]))
);
}
}