forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WatchdogTest.php
48 lines (43 loc) · 2.01 KB
/
WatchdogTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Unish;
/**
* @group commands
*/
class WatchdogTest extends UnishIntegrationTestCase
{
public function testWatchdog()
{
$this->drush('pm-install', ['dblog']);
$this->drush('watchdog-delete', ['all'], ['yes' => true]);
$output = $this->getErrorOutput();
$this->assertStringContainsString('All watchdog messages have been deleted', $output);
$eval1 = "\\Drupal::logger('drush')->notice('Unish rocks.');";
$this->drush('php-eval', [$eval1]);
$this->drush('watchdog-show', [], ['count' => 50]);
$output = $this->getOutput();
$this->assertStringContainsString('Unish rocks.', $output);
// Add a new entry with a long message with the letter 'd' and verify that watchdog-show does
// not print it completely in the listing unless --full is given.
// As the output is formatted so lines may be splitted, assertStringContainsString does not work
// in this scenario. Therefore, we will count the number of times a character is present.
$message_chars = 300;
$char = '*';
$message = str_repeat($char, $message_chars);
$eval2 = "\\Drupal::logger('drush')->notice('$message');";
$this->drush('php-eval', [$eval2]);
$this->drush('watchdog-show');
$output = $this->getOutput();
$this->assertStringContainsString('Unish rocks', $output);
$this->assertGreaterThan(substr_count($output, $char), $message_chars);
$this->drush('watchdog-show', [], ['extended' => null]);
$output = $this->getOutput();
$this->assertGreaterThanOrEqual($message_chars, substr_count($output, $char));
// Tests message deletion
$this->drush('watchdog-delete', ['all'], ['yes' => true]);
$output = $this->getErrorOutput();
$this->assertStringContainsString('All watchdog messages have been deleted', $output);
$this->drush('watchdog-show');
$output = $this->getOutput();
$this->assertEquals('', $output);
}
}