CLImateTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace League\CLImate\Tests;
  3. use League\CLImate\Tests\CustomObject\BasicObject;
  4. use League\CLImate\Tests\CustomObject\BasicObjectArgument;
  5. class CLImateTest extends TestBase
  6. {
  7. /** @test */
  8. public function it_can_echo_out_a_string()
  9. {
  10. $this->shouldWrite("\e[mThis would go out to the console.\e[0m");
  11. $this->shouldHavePersisted();
  12. $this->cli->out('This would go out to the console.');
  13. }
  14. /** @test */
  15. public function it_can_chain_the_out_method()
  16. {
  17. $this->shouldWrite("\e[mThis is a line.\e[0m");
  18. $this->shouldWrite("\e[mThis is another line.\e[0m");
  19. $this->shouldHavePersisted(2);
  20. $this->cli->out('This is a line.')->out('This is another line.');
  21. }
  22. /** @test */
  23. public function it_can_write_content_to_a_different_output()
  24. {
  25. $this->shouldWrite("\e[mThis is to the buffer.\e[0m");
  26. $this->output->shouldReceive('defaultTo')->with('out')->once();
  27. $this->output->shouldReceive('once')->with('buffer')->once();
  28. $this->shouldHavePersisted();
  29. // Just double check that this is the default output
  30. $this->cli->output->defaultTo('out');
  31. $this->cli->to('buffer')->out('This is to the buffer.');
  32. }
  33. /** @test */
  34. public function it_can_be_extended_using_a_basic_object_as_string()
  35. {
  36. $this->shouldWrite("\e[mBy Custom Object: This is something my custom object is handling.\e[0m");
  37. $this->shouldHavePersisted();
  38. $this->cli->extend('League\CLImate\Tests\CustomObject\Basic');
  39. $this->cli->basic('This is something my custom object is handling.');
  40. }
  41. /** @test */
  42. public function it_can_be_extended_using_a_basic_object()
  43. {
  44. $this->shouldWrite("\e[mThis just outputs this.\e[0m");
  45. $this->shouldHavePersisted();
  46. $this->cli->extend(new BasicObject);
  47. $this->cli->basicObject();
  48. }
  49. /** @test */
  50. public function it_can_be_extended_using_a_basic_object_with_argument_setter()
  51. {
  52. $this->shouldWrite("\e[mHey: This is the thing that will print to the console.\e[0m");
  53. $this->shouldHavePersisted();
  54. $this->cli->extend(new BasicObjectArgument);
  55. $this->cli->basicObjectArgument('This is the thing that will print to the console.');
  56. }
  57. /** @test */
  58. public function it_can_be_extended_using_a_dynamic_object()
  59. {
  60. $this->cli->extend('League\CLImate\Tests\CustomObject\Dynamic');
  61. $obj = $this->cli->dynamic();
  62. $this->assertInstanceOf('League\CLImate\Tests\CustomObject\Dynamic', $obj);
  63. }
  64. /** @test */
  65. public function it_will_yell_if_extending_and_class_doesnt_exist()
  66. {
  67. $class = 'League\CLImate\Tests\CustomObject\NowhereToBeFound';
  68. $this->setExpectedException('Exception', 'Class does not exist: ' . $class);
  69. $this->cli->extend($class);
  70. }
  71. /** @test */
  72. public function it_will_yell_if_it_doesnt_implement_proper_interfaces()
  73. {
  74. $class = 'League\CLImate\Tests\CustomObject\Dummy';
  75. $this->setExpectedException('Exception', 'Class must implement either');
  76. $this->cli->extend($class);
  77. }
  78. /** @test */
  79. public function it_will_accept_a_custom_key_for_an_extension()
  80. {
  81. $this->shouldWrite("\e[mBy Custom Object: This is something my custom object is handling.\e[0m");
  82. $this->shouldHavePersisted();
  83. $this->cli->extend('League\CLImate\Tests\CustomObject\Basic', 'myCustomMethod');
  84. $this->cli->myCustomMethod('This is something my custom object is handling.');
  85. }
  86. /** @test */
  87. public function it_will_accept_an_array_of_extensions()
  88. {
  89. $this->shouldWrite("\e[mBy Custom Object: This is something my custom object is handling.\e[0m");
  90. $this->shouldHavePersisted();
  91. $extensions = [
  92. 'League\CLImate\Tests\CustomObject\Basic',
  93. 'League\CLImate\Tests\CustomObject\Dynamic',
  94. ];
  95. $this->cli->extend($extensions);
  96. $this->cli->basic('This is something my custom object is handling.');
  97. $obj = $this->cli->dynamic();
  98. $this->assertInstanceOf('League\CLImate\Tests\CustomObject\Dynamic', $obj);
  99. }
  100. /** @test */
  101. public function it_will_accept_an_array_of_extensions_with_custom_keys()
  102. {
  103. $this->shouldWrite("\e[mBy Custom Object: This is something my custom object is handling.\e[0m");
  104. $this->shouldHavePersisted();
  105. $extensions = [
  106. 'whatever' => 'League\CLImate\Tests\CustomObject\Basic',
  107. 'something' => 'League\CLImate\Tests\CustomObject\Dynamic',
  108. ];
  109. $this->cli->extend($extensions);
  110. $this->cli->whatever('This is something my custom object is handling.');
  111. $obj = $this->cli->something();
  112. $this->assertInstanceOf('League\CLImate\Tests\CustomObject\Dynamic', $obj);
  113. }
  114. }