WhitespaceShellTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Tools\Test\TestCase\Console\Command;
  3. use Tools\Console\Command\WhitespaceShell;
  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 TestWhitespaceOutput extends ConsoleOutput {
  14. public $output = '';
  15. protected function _write($message) {
  16. $this->output .= $message;
  17. }
  18. }
  19. /**
  20. */
  21. class WhitespaceShellTest extends TestCase {
  22. /**
  23. * setUp method
  24. *
  25. * @return void
  26. */
  27. public function setUp() {
  28. parent::setUp();
  29. $this->out = new TestWhitespaceOutput();
  30. $io = new ConsoleIo($this->out);
  31. $this->Shell = $this->getMock(
  32. 'Tools\Console\Command\WhitespaceShell',
  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 testClean() {
  52. $this->Shell->expects($this->any())->method('in')
  53. ->will($this->returnValue('y'));
  54. $content = PHP_EOL . ' <?php echo $foo;' . PHP_EOL . '?> ' . PHP_EOL . PHP_EOL;
  55. file_put_contents(TMP . 'Foo.php', $content);
  56. $this->Shell->runCommand(['clean', TMP]);
  57. $output = $this->out->output;
  58. $this->assertTextContains('Found 1 files.', $output);
  59. $this->assertTextContains('found 1 leading, 1 trailing ws', $output);
  60. $this->assertTextContains('fixed 1 leading, 1 trailing ws', $output);
  61. $output = file_get_contents(TMP . 'Foo.php');
  62. $expected = '<?php echo $foo;' . PHP_EOL . '?>';
  63. unlink(TMP . 'Foo.php');
  64. $this->assertEquals($expected, $output);
  65. }
  66. }