Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

FnDispatcherTest.php 1006B

il y a 2 ans
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace JmesPath\Tests;
  3. use JmesPath\fnDispatcher;
  4. use PHPUnit\Framework\TestCase;
  5. class fnDispatcherTest extends TestCase
  6. {
  7. public function testConvertsToString()
  8. {
  9. $fn = new FnDispatcher();
  10. $this->assertEquals('foo', $fn('to_string', ['foo']));
  11. $this->assertEquals('1', $fn('to_string', [1]));
  12. $this->assertEquals('["foo"]', $fn('to_string', [['foo']]));
  13. $std = new \stdClass();
  14. $std->foo = 'bar';
  15. $this->assertEquals('{"foo":"bar"}', $fn('to_string', [$std]));
  16. $this->assertEquals('foo', $fn('to_string', [new _TestStringClass()]));
  17. $this->assertEquals('"foo"', $fn('to_string', [new _TestJsonStringClass()]));
  18. }
  19. }
  20. class _TestStringClass
  21. {
  22. public function __toString()
  23. {
  24. return 'foo';
  25. }
  26. }
  27. class _TestJsonStringClass implements \JsonSerializable
  28. {
  29. public function __toString()
  30. {
  31. return 'no!';
  32. }
  33. public function jsonSerialize()
  34. {
  35. return 'foo';
  36. }
  37. }