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 42

Class

backendCase

Code

function testTarget() {
  $stdin = json_encode(array('filter' => 'sql'));
  $exec = sprintf('echo %s | %s help --backend', self::escapeshellarg($stdin), self::escapeshellarg(UNISH_DRUSH));
  $this->execute($exec);
  $parsed = $this->parse($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('SQL commands', $parsed['output']);
  $this->assertEquals('Bootstrap to phase 0.', $parsed['log'][0]['message']);

  // Check error propogation by requesting an invalid command (missing Drupal site).
  $exec = sprintf('%s core-cron --backend 2>/dev/null', self::escapeshellarg(UNISH_DRUSH));
  $this->execute($exec, self::EXIT_ERROR);
  $parsed = $this->parse($this->getOutput());
  $this->assertEquals(1, $parsed['error_status']);
  $this->assertArrayHasKey('DRUSH_NO_DRUPAL_ROOT', $parsed['error_log']);
}