PaddingTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace League\CLImate\Tests;
  3. class PaddingTest extends TestBase
  4. {
  5. /** @test */
  6. public function it_can_wrap_a_line()
  7. {
  8. $max_width = $this->util->width();
  9. $padding = $this->cli->padding();
  10. $content = str_repeat('a', $max_width * 2);
  11. $content = substr($content, 0, ($max_width * 2) - 5);
  12. $this->output->shouldReceive('sameLine');
  13. $this->shouldWrite("\e[m" . substr($content, 0, $max_width) . "\e[0m");
  14. $this->shouldWrite("\e[m" . substr($content, $max_width) . ".....\e[0m");
  15. $this->shouldWrite("\e[m result\e[0m");
  16. $padding->label($content)->result('result');
  17. }
  18. /** @test */
  19. public function it_can_chain()
  20. {
  21. $padding = $this->cli->padding(10);
  22. $this->output->shouldReceive('sameLine');
  23. $this->shouldWrite("\e[mPad me....\e[0m");
  24. $this->shouldWrite("\e[m extra\e[0m");
  25. $padding->label('Pad me')->result('extra');
  26. }
  27. /** @test */
  28. public function it_can_pad_with_multiple_characters()
  29. {
  30. $padding = $this->cli->padding(10)->char('.-');
  31. $this->output->shouldReceive('sameLine');
  32. $this->shouldWrite("\e[mPad me.-.-\e[0m");
  33. $this->shouldWrite("\e[m extra\e[0m");
  34. $padding->label('Pad me')->result('extra');
  35. }
  36. /** @test */
  37. public function it_can_pad_with_multiple_characters_odd()
  38. {
  39. $padding = $this->cli->padding(10)->char('.-');
  40. $this->output->shouldReceive('sameLine');
  41. $this->shouldWrite("\e[mPad odd.-.\e[0m");
  42. $this->shouldWrite("\e[m extra\e[0m");
  43. $padding->label('Pad odd')->result('extra');
  44. }
  45. /** @test */
  46. public function it_can_pad_with_multibyte_characters()
  47. {
  48. $padding = $this->cli->padding(10);
  49. $this->output->shouldReceive("sameLine");
  50. $this->shouldWrite("\e[mЛорем.....\e[0m");
  51. $this->shouldWrite("\e[m END\e[0m");
  52. $padding->label("Лорем")->result("END");
  53. }
  54. /** @test */
  55. public function it_can_wrap_a_multibyte_line()
  56. {
  57. $max_width = $this->util->width();
  58. $padding = $this->cli->padding();
  59. $content = "Лорем" . str_repeat('a', $max_width * 2);
  60. $content = mb_substr($content, 0, ($max_width * 2) - 5);
  61. $this->output->shouldReceive('sameLine');
  62. $this->shouldWrite("\e[m" . mb_substr($content, 0, $max_width) . "\e[0m");
  63. $this->shouldWrite("\e[m" . mb_substr($content, $max_width) . ".....\e[0m");
  64. $this->shouldWrite("\e[m result\e[0m");
  65. $padding->label($content)->result('result');
  66. }
  67. /** @test */
  68. public function it_can_add_newline_without_result()
  69. {
  70. $padding = $this->cli->padding(10);
  71. $this->output->shouldReceive('sameLine');
  72. $this->shouldWrite('Pad me....');
  73. $this->shouldWrite('');
  74. $padding->label('Pad me')->br();
  75. }
  76. }