StyleTest.php 8.1 KB

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