JSONTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace League\CLImate\Tests;
  3. class JSONTest extends TestBase
  4. {
  5. /** @test */
  6. public function it_can_output_an_object_as_json()
  7. {
  8. $should_be = json_encode((object) [
  9. 'cell1' => 'Cell 1',
  10. 'cell2' => 'Cell 2',
  11. 'cell3' => 'Cell 3',
  12. 'cell4' => 'Cell 4',
  13. ], JSON_PRETTY_PRINT);
  14. $this->shouldWrite("\e[m" . $should_be . "\e[0m");
  15. $this->shouldHavePersisted();
  16. $this->cli->json((object) [
  17. 'cell1' => 'Cell 1',
  18. 'cell2' => 'Cell 2',
  19. 'cell3' => 'Cell 3',
  20. 'cell4' => 'Cell 4',
  21. ]);
  22. }
  23. /**
  24. * We do this test specifically because json escapes the tags,
  25. * we want to make sure we're taking care of that
  26. *
  27. * @test */
  28. public function it_can_output_json_with_tags()
  29. {
  30. $should_be = json_encode((object) [
  31. 'cell1' => 'Cell 1',
  32. 'cell2' => 'Cell 2',
  33. 'cell3' => 'Cell 3',
  34. 'cell4' => 'Cell 4',
  35. ], JSON_PRETTY_PRINT);
  36. $should_be = str_replace('Cell 4', "\e[5mCell 4\e[0m", $should_be);
  37. $this->shouldWrite("\e[m" . $should_be . "\e[0m");
  38. $this->shouldHavePersisted();
  39. $this->cli->json((object) [
  40. 'cell1' => 'Cell 1',
  41. 'cell2' => 'Cell 2',
  42. 'cell3' => 'Cell 3',
  43. 'cell4' => '<blink>Cell 4</blink>',
  44. ]);
  45. }
  46. }