You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zhishifufei_php/vendor/mtdowling/jmespath.php/tests/FnDispatcherTest.php

43 lines
1006 B

9 months ago
<?php
namespace JmesPath\Tests;
use JmesPath\fnDispatcher;
use PHPUnit\Framework\TestCase;
class fnDispatcherTest extends TestCase
{
public function testConvertsToString()
{
$fn = new FnDispatcher();
$this->assertEquals('foo', $fn('to_string', ['foo']));
$this->assertEquals('1', $fn('to_string', [1]));
$this->assertEquals('["foo"]', $fn('to_string', [['foo']]));
$std = new \stdClass();
$std->foo = 'bar';
$this->assertEquals('{"foo":"bar"}', $fn('to_string', [$std]));
$this->assertEquals('foo', $fn('to_string', [new _TestStringClass()]));
$this->assertEquals('"foo"', $fn('to_string', [new _TestJsonStringClass()]));
}
}
class _TestStringClass
{
public function __toString()
{
return 'foo';
}
}
class _TestJsonStringClass implements \JsonSerializable
{
public function __toString()
{
return 'no!';
}
public function jsonSerialize()
{
return 'foo';
}
}