function backendCase::testTarget

8.0.x backendTest.php backendCase::testTarget()
6.x backendTest.php backendCase::testTarget()
7.x backendTest.php backendCase::testTarget()
4.x backendTest.php backendCase::testTarget()
5.x backendTest.php backendCase::testTarget()
master backendTest.php backendCase::testTarget()

File

tests/backendTest.php, line 76

Class

backendCase

Code

function testTarget() {
  $stdin = json_encode(array('filter' => 'sql'));
  $exec = sprintf('echo %s | %s version --backend', self::escapeshellarg($stdin), UNISH_DRUSH);
  $this->execute($exec);
  $parsed = parse_backend_output($this->getOutput());
  $this->assertTrue((bool) $parsed, 'Successfully parsed backend output');
  $this->assertArrayHasKey('log', $parsed);
  $this->assertArrayHasKey('output', $parsed);
  $this->assertArrayHasKey('object', $parsed);
  $this->assertEquals(self::EXIT_SUCCESS, $parsed['error_status']);
  // This assertion shows that `help` was called and that stdin options were respected.
  $this->assertStringStartsWith('drush ', $parsed['output']);
  $this->assertEquals('Bootstrap to phase 0.', $parsed['log'][0]['message']);

  // Check error propogation by requesting an invalid command (missing Drupal site).
  $this->drush('core-cron', array(), array('backend' => NULL), NULL, NULL, self::EXIT_ERROR);
  $parsed = parse_backend_output($this->getOutput());
  $this->assertEquals(1, $parsed['error_status']);
  $this->assertArrayHasKey('DRUSH_NO_DRUPAL_ROOT', $parsed['error_log']);
}