ColumnTest.php 5.4 KB

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