function completeCase::verifyComplete

8.0.x completeTest.php completeCase::verifyComplete($command, $first, $last, $cache_hit = TRUE)
6.x completeTest.php completeCase::verifyComplete($command, $first, $last, $cache_hit = TRUE)
7.x completeTest.php completeCase::verifyComplete($command, $first, $last, $cache_hit = TRUE)
5.x completeTest.php completeCase::verifyComplete($command, $first, $last, $cache_hit = TRUE)
master completeTest.php completeCase::verifyComplete($command, $first, $last, $cache_hit = TRUE)

Helper function to call completion and make common checks.

Parameters

$command: The command line to attempt to complete.

$first: String indicating the expected first completion suggestion.

$last: String indicating the expected last completion suggestion.

bool $cache_hit: Optional parameter, if TRUE or omitted the debug log is checked to ensure a cache hit on the last cache debug log entry, if FALSE then a cache miss is checked for.

1 call to completeCase::verifyComplete()

File

tests/completeTest.php, line 132

Class

completeCase
@group base

Code

function verifyComplete($command, $first, $last, $cache_hit = TRUE) {
  // We capture debug output to a separate file, so we can check for cache
  // hits/misses.
  $debug_file = tempnam(UNISH_SANDBOX . '/complete-debug', 'complete-debug');
  // Commands should take the format:
  // drush --early=includes/complete.inc [--complete-debug] drush [@alias] [command]...
  $exec = sprintf('%s --early=includes/complete.inc --config=%s --complete-debug %s %s 2> %s', UNISH_DRUSH, UNISH_SANDBOX . '/drushrc.php', UNISH_DRUSH, $command, $debug_file);
  $this->execute($exec);
  $result = $this->getOutputAsList();
  $actual = reset($result);
  $this->assertEquals("$command: (f) $first", "$command: (f) $actual");
  $actual = end($result);
  $this->assertEquals("$command: (l) $last", "$command: (l) $actual");
  // If checking for HIT, we ensure no MISS exists, if checking for MISS we
  // ensure no HIT exists. However, we exclude the first cache report, since
  // it is expected that the command-names cache (loaded when matching
  // command names) may sometimes be a HIT even when we are testing for a MISS
  // in the actual cache we are loading to complete against.
  $check_not_exist = 'HIT';
  if ($cache_hit) {
    $check_not_exist = 'MISS';
  }
  $contents = file_get_contents($debug_file);
  $first_cache_pos = strpos($contents, 'Cache ') + 6;
  $this->assertFalse(strpos($contents, 'Cache ' . $check_not_exist . ' cid', $first_cache_pos));
  unlink($debug_file);
}