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()

Covers the following target responsibilities.

  • Interpret stdin as options as per REST API.
  • Successfully execute specified command.
  • JSON object has expected contents (including errors).
  • JSON object is wrapped in expected delimiters.

File

tests/backendTest.php, line 81

Namespace

Unish

Class

backendCase
We choose to test the backend system in two parts.

Code

function testTarget() {
  $stdin = json_encode(array('filter' => 'sql'));
  $exec = sprintf('%s version --backend 2>%s', UNISH_DRUSH, self::escapeshellarg($this->bit_bucket()));
  $this->execute($exec, self::EXIT_SUCCESS, NULL, NULL, $stdin);
  $parsed = $this->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 `version` was called and that stdin options were respected.
  $this->assertStringStartsWith(' Drush Version ', $parsed['output']);
  $this->assertEquals('Starting Drush preflight.', $parsed['log'][1]['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 = $this->parse_backend_output($this->getOutput());
  $this->assertEquals(1, $parsed['error_status']);
  $this->assertArrayHasKey('DRUSH_COMMAND_INSUFFICIENT_BOOTSTRAP', $parsed['error_log']);
}