StyleTest.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. namespace League\CLImate\Tests;
  3. class StyleTest extends TestBase
  4. {
  5. /**
  6. * @test
  7. * @doesNotPerformAssertions
  8. */
  9. public function it_can_use_a_foreground_color_method()
  10. {
  11. $this->shouldWrite("\e[31mThis would go out to the console.\e[0m");
  12. $this->shouldHavePersisted();
  13. $this->cli->red('This would go out to the console.');
  14. }
  15. /**
  16. * @test
  17. * @doesNotPerformAssertions
  18. */
  19. public function it_resets_itself_after_styled_output()
  20. {
  21. $this->shouldWrite("\e[31mThis would go out to the console.\e[0m");
  22. $this->shouldWrite("\e[mThis is plain.\e[0m");
  23. $this->shouldHavePersisted(2);
  24. $this->cli->red('This would go out to the console.');
  25. $this->cli->out('This is plain.');
  26. }
  27. /**
  28. * @test
  29. * @doesNotPerformAssertions
  30. */
  31. public function it_can_use_a_background_color_method()
  32. {
  33. $this->shouldWrite("\e[41mThis would go out to the console.\e[0m");
  34. $this->shouldHavePersisted();
  35. $this->cli->backgroundRed('This would go out to the console.');
  36. }
  37. /**
  38. * @test
  39. * @doesNotPerformAssertions
  40. */
  41. public function it_can_use_a_background_color_method_chained()
  42. {
  43. $this->shouldWrite("\e[41mThis would go out to the console.\e[0m");
  44. $this->shouldHavePersisted();
  45. $this->cli->backgroundRed()->out('This would go out to the console.');
  46. }
  47. /**
  48. * @test
  49. * @doesNotPerformAssertions
  50. */
  51. public function it_can_apply_a_format()
  52. {
  53. $this->shouldWrite("\e[5mThis would go out to the console.\e[0m");
  54. $this->shouldHavePersisted();
  55. $this->cli->blink('This would go out to the console.');
  56. }
  57. /**
  58. * @test
  59. * @doesNotPerformAssertions
  60. */
  61. public function it_can_apply_multiple_formats()
  62. {
  63. $this->shouldWrite("\e[4;5mThis would go out to the console.\e[0m");
  64. $this->shouldHavePersisted();
  65. $this->cli->underline()->blink('This would go out to the console.');
  66. }
  67. /**
  68. * @test
  69. * @doesNotPerformAssertions
  70. */
  71. public function it_can_chain_a_foreground_color_method()
  72. {
  73. $this->shouldWrite("\e[31mThis would go out to the console.\e[0m");
  74. $this->shouldHavePersisted();
  75. $this->cli->red()->out('This would go out to the console.');
  76. }
  77. /**
  78. * @test
  79. * @doesNotPerformAssertions
  80. */
  81. public function it_can_use_a_background_color_and_foreground_color_method()
  82. {
  83. $this->shouldWrite("\e[31;41mThis would go out to the console.\e[0m");
  84. $this->shouldHavePersisted();
  85. $this->cli->backgroundRed()->red('This would go out to the console.');
  86. }
  87. /**
  88. * @test
  89. * @doesNotPerformAssertions
  90. */
  91. public function it_can_use_a_background_color_and_foreground_color_and_format_method()
  92. {
  93. $this->shouldWrite("\e[5;31;41mThis would go out to the console.\e[0m");
  94. $this->shouldHavePersisted();
  95. $this->cli->backgroundRed()->blink()->red('This would go out to the console.');
  96. }
  97. /**
  98. * @test
  99. * @doesNotPerformAssertions
  100. */
  101. public function it_can_parse_foreground_color_tags()
  102. {
  103. $this->shouldWrite("\e[mThis \e[31mwould\e[0m go out to the console.\e[0m");
  104. $this->shouldHavePersisted();
  105. $this->cli->out('This <red>would</red> go out to the console.');
  106. }
  107. /**
  108. * @test
  109. * @doesNotPerformAssertions
  110. */
  111. public function it_can_parse_background_color_tags()
  112. {
  113. $this->shouldWrite("\e[mThis \e[41mwould\e[0m go out to the console.\e[0m");
  114. $this->shouldHavePersisted();
  115. $this->cli->out('This <background_red>would</background_red> go out to the console.');
  116. }
  117. /**
  118. * @test
  119. * @doesNotPerformAssertions
  120. */
  121. public function it_can_parse_formatting_tags()
  122. {
  123. $this->shouldWrite("\e[mThis \e[5mwould\e[0m go out to the console.\e[0m");
  124. $this->shouldHavePersisted();
  125. $this->cli->out('This <blink>would</blink> go out to the console.');
  126. }
  127. /**
  128. * @test
  129. * @doesNotPerformAssertions
  130. */
  131. public function it_can_parse_nested_tags()
  132. {
  133. $this->shouldWrite("\e[mThis \e[31m\e[5mwould\e[0;31m (still red)\e[0m go out to the console.\e[0m");
  134. $this->shouldHavePersisted();
  135. $this->cli->out('This <red><blink>would</blink> (still red)</red> go out to the console.');
  136. }
  137. /**
  138. * @test
  139. * @doesNotPerformAssertions
  140. */
  141. public function it_can_parse_tags_and_return_to_current_style()
  142. {
  143. $this->shouldWrite("\e[31mThis \e[5mwould\e[0;31m go out to the console.\e[0m");
  144. $this->shouldHavePersisted();
  145. $this->cli->red('This <blink>would</blink> go out to the console.');
  146. }
  147. /**
  148. * @test
  149. * @doesNotPerformAssertions
  150. */
  151. public function it_can_add_a_color_and_use_it()
  152. {
  153. $this->shouldWrite("\e[900mThis is the new color.\e[0m");
  154. $this->shouldHavePersisted();
  155. $this->cli->style->addColor('new_custom_color', 900);
  156. $this->cli->newCustomColor('This is the new color.');
  157. }
  158. /**
  159. * @test
  160. * @doesNotPerformAssertions
  161. */
  162. public function it_can_add_a_color_and_use_it_as_a_tag()
  163. {
  164. $this->shouldWrite("\e[mThis \e[900mis\e[0m the new color.\e[0m");
  165. $this->shouldHavePersisted();
  166. $this->cli->style->addColor('new_custom_color', 900);
  167. $this->cli->out('This <new_custom_color>is</new_custom_color> the new color.');
  168. }
  169. /**
  170. * @test
  171. * @doesNotPerformAssertions
  172. */
  173. public function it_can_add_a_color_and_use_it_as_a_background()
  174. {
  175. $this->shouldWrite("\e[910mThis is the new color.\e[0m");
  176. $this->shouldHavePersisted();
  177. $this->cli->style->addColor('new_custom_color', 900);
  178. $this->cli->backgroundNewCustomColor()->out('This is the new color.');
  179. }
  180. /**
  181. * @test
  182. * @doesNotPerformAssertions
  183. */
  184. public function it_can_use_a_color_command()
  185. {
  186. $this->shouldWrite("\e[91mThis would go out to the console.\e[0m");
  187. $this->shouldHavePersisted();
  188. $this->cli->error('This would go out to the console.');
  189. }
  190. /**
  191. * @test
  192. * @doesNotPerformAssertions
  193. */
  194. public function it_can_chain_a_color_command()
  195. {
  196. $this->shouldWrite("\e[91mThis would go out to the console.\e[0m");
  197. $this->shouldHavePersisted();
  198. $this->cli->error()->out('This would go out to the console.');
  199. }
  200. /**
  201. * @test
  202. * @doesNotPerformAssertions
  203. */
  204. public function it_can_use_add_a_command_via_a_string()
  205. {
  206. $this->shouldWrite("\e[94mThis would go out to the console.\e[0m");
  207. $this->shouldHavePersisted();
  208. $this->cli->style->addCommand('holler', 'light_blue');
  209. $this->cli->holler('This would go out to the console.');
  210. }
  211. /**
  212. * @test
  213. * @doesNotPerformAssertions
  214. */
  215. public function it_can_use_a_string_command_as_a_tag()
  216. {
  217. $this->shouldWrite("\e[mThis would go \e[94mout\e[0m to the console.\e[0m");
  218. $this->shouldHavePersisted();
  219. $this->cli->style->addCommand('holler', 'light_blue');
  220. $this->cli->out('This would go <holler>out</holler> to the console.');
  221. }
  222. /**
  223. * @test
  224. * @doesNotPerformAssertions
  225. */
  226. public function it_can_use_add_a_command_via_an_array()
  227. {
  228. $this->shouldWrite("\e[1;4;41;94mThis would go out to the console.\e[0m");
  229. $this->shouldHavePersisted();
  230. $command = ['light_blue', 'background_red', 'bold', 'underline'];
  231. $this->cli->style->addCommand('holler', $command);
  232. $this->cli->holler('This would go out to the console.');
  233. }
  234. /**
  235. * @test
  236. * @doesNotPerformAssertions
  237. */
  238. public function it_can_use_an_array_command_as_a_tag()
  239. {
  240. $this->shouldWrite("\e[mThis would go \e[1;4;41;94mout\e[0m to the console.\e[0m");
  241. $this->shouldHavePersisted();
  242. $command = ['light_blue', 'background_red', 'bold', 'underline'];
  243. $this->cli->style->addCommand('holler', $command);
  244. $this->cli->out('This would go <holler>out</holler> to the console.');
  245. }
  246. }