InflectShellTest.php 2.1 KB

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