8 class WatchdogCase extends CommandUnishTestCase
11 public function testWatchdog()
13 $this->setUpDrupal(1, true);
14 $this->drush('pm-enable', ['dblog']);
16 $eval1 = "\\Drupal::logger('drush')->notice('Unish rocks.');";
17 $this->drush('php-eval', [$eval1]);
18 $this->drush('watchdog-show', [], ['count' => 50]);
19 $output = $this->getOutput();
20 $this->assertContains('Unish rocks.', $output);
22 // Add a new entry with a long message with the letter 'd' and verify that watchdog-show does
23 // not print it completely in the listing unless --full is given.
24 // As the output is formatted so lines may be splitted, assertContains does not work
25 // in this scenario. Therefore, we will count the number of times a character is present.
28 $message = str_repeat($char, $message_chars);
29 $eval2 = "\\Drupal::logger('drush')->notice('$message');";
30 $this->drush('php-eval', [$eval2]);
31 $this->drush('watchdog-show');
32 $output = $this->getOutput();
33 $this->assertGreaterThan(substr_count($output, $char), $message_chars);
34 $this->drush('watchdog-show', [], ['extended' => null]);
35 $output = $this->getOutput();
36 $this->assertGreaterThanOrEqual($message_chars, substr_count($output, $char));
38 // Tests message deletion
39 $this->drush('watchdog-delete', ['all']);
40 $output = $this->getOutput();
41 $this->drush('watchdog-show');
42 $output = $this->getOutput();
43 $this->assertEmpty($output);