InflectShellTest.php 2.0 KB

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