InflectShellTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Tools\Test\TestCase\Shell;
  3. use Tools\Shell\InflectShell;
  4. use Cake\Console\ConsoleIo;
  5. use Cake\Console\ConsoleOutput;
  6. use Cake\Console\Shell;
  7. use Cake\Core\Plugin;
  8. use Cake\TestSuite\TestCase;
  9. /**
  10. * Class TestCompletionStringOutput
  11. *
  12. */
  13. class TestInflectOutput extends ConsoleOutput {
  14. public $output = '';
  15. protected function _write($message) {
  16. $this->output .= $message;
  17. }
  18. }
  19. /**
  20. */
  21. class InflectShellTest extends TestCase {
  22. /**
  23. * setUp method
  24. *
  25. * @return void
  26. */
  27. public function setUp() {
  28. parent::setUp();
  29. $this->out = new TestInflectOutput();
  30. $io = new ConsoleIo($this->out);
  31. $this->Shell = $this->getMock(
  32. 'Tools\Shell\InflectShell',
  33. ['in', 'err', '_stop'],
  34. [$io]
  35. );
  36. }
  37. /**
  38. * tearDown
  39. *
  40. * @return void
  41. */
  42. public function tearDown() {
  43. parent::tearDown();
  44. unset($this->Shell);
  45. }
  46. /**
  47. * test that the startup method supresses the shell header
  48. *
  49. * @return void
  50. */
  51. public function testMain() {
  52. $this->Shell->expects($this->any())->method('in')
  53. ->will($this->returnValue('FooBar'));
  54. $this->Shell->runCommand(['pluralize']);
  55. $output = $this->out->output;
  56. $expected = 'FooBars';
  57. $this->assertContains($expected, $output);
  58. $this->Shell->runCommand(['underscore']);
  59. $output = $this->out->output;
  60. $expected = 'foo_bar';
  61. $this->assertContains($expected, $output);
  62. $this->Shell->runCommand(['dasherize']);
  63. $output = $this->out->output;
  64. $expected = 'foo-bar';
  65. $this->assertContains($expected, $output);
  66. $this->Shell->runCommand(['slug']);
  67. $output = $this->out->output;
  68. $expected = 'foo-bar';
  69. $this->assertContains($expected, $output);
  70. $this->Shell->runCommand(['tableize']);
  71. $output = $this->out->output;
  72. $expected = 'foo_bar';
  73. $this->assertContains($expected, $output);
  74. }
  75. }