drush('cc', ['drush'], $options); // drush foobar $options['include'] = "$globalIncludes"; $this->drush('foobar', [], $options); $output = $this->getOutput(); $this->assertEquals('baz', $output); // Drush foobaz $this->drush('foobaz', [], $options); $output = $this->getOutput(); $this->assertEquals('bar', $output); $options = [ 'yes' => null, 'include' => $globalIncludes, 'directory' => self::getSandbox(), ]; $original = getenv('SHELL_INTERACTIVE'); $this->setEnv(['SHELL_INTERACTIVE' => 1]); $this->drush('generate', ['foo-example'], $options); $this->setEnv(['SHELL_INTERACTIVE' => $original]); $target = Path::join($this->getSandbox(), 'foo.php'); $actual = trim(file_get_contents($target)); $this->assertEquals('Foo.', $actual); unlink($target); } public function testExecute() { $this->setUpDrupal(1, true); // Copy the 'woot' module over to the Drupal site we just set up. $this->setupModulesForTests(['woot'], Path::join(__DIR__, 'resources/modules/d8')); // Enable our module. This will also clear the commandfile cache. $this->drush('pm-enable', ['woot']); // In theory this is not necessary, but this test keeps failing. // $this->drush('cc', array('drush'), $options); // Make sure that modules can supply DCG Generators and they work. $optionsExample['answers'] = json_encode([ 'name' => 'foo', 'machine_name' => 'bar', ]); $optionsExample['directory'] = self::getSandbox(); $optionsExample['yes'] = null; $original = getenv('SHELL_INTERACTIVE'); $this->setEnv(['SHELL_INTERACTIVE' => 1]); $this->drush('generate', ['woot-example'], $optionsExample); $this->setEnv(['SHELL_INTERACTIVE' => $original]); $target = Path::join(self::getSandbox(), '/src/Commands/ExampleBarCommands.php'); $actual = trim(file_get_contents($target)); $this->assertEquals('ExampleBarCommands says Woot mightily.', $actual); // drush woot $this->drush('woot'); $output = $this->getOutput(); $this->assertEquals('Woot!', $output); // drush my-cat bet alpha --flip $this->drush('my-cat', ['bet', 'alpha'], ['flip' => null]); $output = $this->getOutput(); $this->assertEquals('alphabet', $output); // drush my-cat bet alpha --flip $this->drush('my-cat', ['bet', 'alpha'], ['flip' => null, 'ignored-modules' => 'woot'], null, null, self::EXIT_ERROR); $this->drush('try-formatters'); $output = $this->getOutput(); $expected = <<assertEquals(trim(preg_replace('#[ \n]+#', ' ', $expected)), trim(preg_replace('#[ \n]+#', ' ', $output))); $this->drush('try-formatters --format=yaml --fields=III,II', [], [], null, null, self::EXIT_SUCCESS); $output = $this->getOutput(); // TODO: If there are different versions of symfony/yaml in Drush and Drupal, // then we can get indentation errors. Ignore that in these tests; this is not // a problem with site-local Drush. $output = str_replace(' ', ' ', $output); $expected = <<assertEquals($expected, $output); $this->drush('try-formatters', [], ['format' => 'json']); $data = $this->getOutput(); $expected = <<assertEquals($expected, $data); // drush help my-cat $this->drush('help', ['my-cat']); $output = $this->getOutput(); $this->assertContains('bet alpha --flip Concatinate "alpha" and "bet".', $output); $this->assertContains('Aliases: c', $output); // drush help woot $this->drush('help', ['woot']); $output = $this->getOutput(); $this->assertContains('Woot mightily.', $output); // TODO: support console.command commands $this->drush('annotated:greet symfony'); $output = $this->getOutput(); $this->assertEquals('Hello symfony', $output); $this->drush('demo:greet symfony'); $output = $this->getOutput(); $this->assertEquals('Hello symfony', $output); $this->markTestSkipped('--help not working yet.'); // drush my-cat --help $this->drush('my-cat', [], ['help' => null]); $output = $this->getOutput(); $this->assertContains('my-cat bet alpha --flip', $output); $this->assertContains('The first parameter', $output); $this->assertContains('The other parameter', $output); $this->assertContains('Whether or not the second parameter', $output); // drush woot --help $this->drush('woot', [], ['help' => null]); $output = $this->getOutput(); $this->assertContains('Usage:', $output); $this->assertContains('woot [options]', $output); $this->assertContains('Woot mightily.', $output); // drush try-formatters --help $this->drush('try-formatters', [], ['help' => null]); $output = $this->getOutput(); $this->assertContains('Demonstrate formatters', $output); $this->assertContains('try:formatters --fields=first,third', $output); $this->assertContains('try:formatters --fields=III,II', $output); // $this->assertContains('--fields=', $output); $this->assertContains('Available fields:', $output); $this->assertContains('[default: "table"]', $output); $this->markTestSkipped('--ignored-modules not supported yet'); // TODO: Support --ignored-modules // drush woot --help with the 'woot' module ignored $this->drush('woot', [], ['help' => null, 'ignored-modules' => 'woot'], null, null, self::EXIT_ERROR); } public function setupGlobalExtensionsForTests() { $globalExtension = __DIR__ . '/resources/global-includes'; $targetDir = Path::join(self::getSandbox(), 'global-includes'); $this->mkdir($targetDir); $this->recursiveCopy($globalExtension, $targetDir); return $targetDir; } }