ColumnsTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace League\CLImate\Tests\TerminalObject\Basic;
  3. use League\CLImate\Tests\TestBase;
  4. class ColumnsTest extends TestBase
  5. {
  6. protected function getSingleColumn()
  7. {
  8. return [
  9. 'this',
  10. ];
  11. }
  12. protected function getStandardColumns()
  13. {
  14. return [
  15. 'this',
  16. 'that',
  17. 'other',
  18. 'thing',
  19. 'this',
  20. 'too',
  21. 'and',
  22. 'also',
  23. 'this is much longer',
  24. ];
  25. }
  26. protected function getArrayOfArrayColumns()
  27. {
  28. return [
  29. ['one', 'first one', 'first third column'],
  30. ['two', 'second one', 'second third column'],
  31. ['three', 'third one', 'third third column'],
  32. ['four', 'fourth one', 'fourth third column'],
  33. ['five', 'fifth one', 'fifth third column'],
  34. ];
  35. }
  36. protected function getAssociativeColumns()
  37. {
  38. return [
  39. 'one' => 'first one',
  40. 'two' => 'second one',
  41. 'three' => 'third one',
  42. 'four' => 'fourth one',
  43. 'five' => 'fifth one',
  44. ];
  45. }
  46. /**
  47. * @test
  48. * @doesNotPerformAssertions
  49. */
  50. public function it_can_output_columns()
  51. {
  52. $this->shouldWrite("\e[mthis thing and\e[0m");
  53. $this->shouldWrite("\e[mthat this also\e[0m");
  54. $this->shouldWrite("\e[mother too this is much longer\e[0m");
  55. $this->shouldHavePersisted();
  56. $this->cli->columns($this->getStandardColumns());
  57. }
  58. /**
  59. * @test
  60. * @doesNotPerformAssertions
  61. */
  62. public function it_can_output_a_single_item_in_one_column()
  63. {
  64. $this->shouldWrite("\e[mthis\e[0m");
  65. $this->shouldHavePersisted();
  66. $this->cli->columns($this->getSingleColumn(), 1);
  67. }
  68. /**
  69. * @test
  70. * @doesNotPerformAssertions
  71. */
  72. public function it_can_output_less_items_than_columns()
  73. {
  74. $this->shouldWrite("\e[mthis\e[0m");
  75. $this->shouldHavePersisted();
  76. $this->cli->columns($this->getSingleColumn(), 2);
  77. }
  78. /**
  79. * @test
  80. * @doesNotPerformAssertions
  81. */
  82. public function it_can_output_a_specific_number_of_columns()
  83. {
  84. $this->shouldWrite("\e[mthis too\e[0m");
  85. $this->shouldWrite("\e[mthat and\e[0m");
  86. $this->shouldWrite("\e[mother also\e[0m");
  87. $this->shouldWrite("\e[mthing this is much longer\e[0m");
  88. $this->shouldWrite("\e[mthis\e[0m");
  89. $this->shouldWrite("\e[mthis\e[0m");
  90. $this->shouldWrite("\e[mthat\e[0m");
  91. $this->shouldWrite("\e[mother\e[0m");
  92. $this->shouldWrite("\e[mthing\e[0m");
  93. $this->shouldWrite("\e[mthis\e[0m");
  94. $this->shouldWrite("\e[mtoo\e[0m");
  95. $this->shouldWrite("\e[mand\e[0m");
  96. $this->shouldWrite("\e[malso\e[0m");
  97. $this->shouldWrite("\e[mthis is much longer\e[0m");
  98. $this->shouldHavePersisted(2);
  99. $this->cli->columns($this->getStandardColumns(), 2);
  100. $this->cli->columns($this->getStandardColumns(), 1);
  101. }
  102. /**
  103. * @test
  104. * @doesNotPerformAssertions
  105. */
  106. public function it_can_handle_multibyte_strings()
  107. {
  108. $this->shouldWrite("\e[mthis thing and\e[0m");
  109. $this->shouldWrite("\e[mthat this also\e[0m");
  110. $this->shouldWrite("\e[mother too this is much longerø\e[0m");
  111. $this->shouldHavePersisted();
  112. $columns = $this->getStandardColumns();
  113. $columns[8] = $columns[8] . 'ø';
  114. $this->cli->columns($columns);
  115. }
  116. /**
  117. * @test
  118. * @doesNotPerformAssertions
  119. */
  120. public function it_can_output_an_associative_array_as_columns()
  121. {
  122. $this->shouldWrite("\e[mone first one\e[0m");
  123. $this->shouldWrite("\e[mtwo second one\e[0m");
  124. $this->shouldWrite("\e[mthree third one\e[0m");
  125. $this->shouldWrite("\e[mfour fourth one\e[0m");
  126. $this->shouldWrite("\e[mfive fifth one\e[0m");
  127. $this->shouldHavePersisted();
  128. $this->cli->columns($this->getAssociativeColumns());
  129. }
  130. /**
  131. * @test
  132. * @doesNotPerformAssertions
  133. */
  134. public function it_can_output_an_array_of_arrays_as_columns()
  135. {
  136. $this->shouldWrite("\e[mone first one first third column\e[0m");
  137. $this->shouldWrite("\e[mtwo second one second third column\e[0m");
  138. $this->shouldWrite("\e[mthree third one third third column\e[0m");
  139. $this->shouldWrite("\e[mfour fourth one fourth third column\e[0m");
  140. $this->shouldWrite("\e[mfive fifth one fifth third column\e[0m");
  141. $this->shouldHavePersisted();
  142. $this->cli->columns($this->getArrayOfArrayColumns());
  143. }
  144. /**
  145. * @test
  146. * @doesNotPerformAssertions
  147. */
  148. public function it_can_output_an_uneven_array_of_arrays_as_columns()
  149. {
  150. $this->shouldWrite("\e[mone first one first third column\e[0m");
  151. $this->shouldWrite("\e[mtwo second one second third column\e[0m");
  152. $this->shouldWrite("\e[mthree third one third third column\e[0m");
  153. $this->shouldWrite("\e[mfour fourth one fourth third column also this one\e[0m");
  154. $this->shouldWrite("\e[mfive fifth one fifth third column\e[0m");
  155. $this->shouldHavePersisted();
  156. $columns = $this->getArrayOfArrayColumns();
  157. $columns[3][] = 'also this one';
  158. $this->cli->columns($columns);
  159. }
  160. }