@@ -22,6 +22,13 @@ trait WatchdogTrait {
22
22
*/
23
23
protected $ watchdogScenarioStartTime ;
24
24
25
+ /**
26
+ * Array of watchdog message types.
27
+ *
28
+ * @var array
29
+ */
30
+ protected $ watchdogMessageTypes = [];
31
+
25
32
/**
26
33
* Store current time.
27
34
*
@@ -34,6 +41,34 @@ public function watchdogSetScenarioStartTime(BeforeScenarioScope $scope) {
34
41
}
35
42
36
43
$ this ->watchdogScenarioStartTime = time ();
44
+
45
+ $ this ->watchdogMessageTypes = $ this ->watchdogParseMessageTypes ($ scope ->getScenario ()->getTags ());
46
+ }
47
+
48
+ /**
49
+ * Parse scenario tags into message types.
50
+ *
51
+ * @code
52
+ * @watchdog:my_module_type @watchdog:my_other_module_type
53
+ * @endcode
54
+ *
55
+ * @param array $tags
56
+ * Array of scenario tags.
57
+ * @param string $prefix
58
+ * Optional tag prefix to filter by.
59
+ *
60
+ * @return array
61
+ * Array of message types. 'php' is always added to the list.
62
+ */
63
+ protected function watchdogParseMessageTypes (array $ tags = [], $ prefix = 'watchdog: ' ) {
64
+ $ types = [];
65
+ foreach ($ tags as $ tag ) {
66
+ if (strpos ($ tag , $ prefix ) === 0 && strlen ($ tag ) > strlen ($ prefix )) {
67
+ $ types [] = substr ($ tag , strlen ($ prefix ));
68
+ }
69
+ }
70
+
71
+ return array_unique (array_merge ($ types , ['php ' ]));
37
72
}
38
73
39
74
/**
@@ -65,7 +100,7 @@ public function watchdogAssertErrors(AfterScenarioScope $scope) {
65
100
// of the scenario.
66
101
$ entries = $ database ->select ('watchdog ' , 'w ' )
67
102
->fields ('w ' )
68
- ->condition ('w.type ' , ' php ' , '= ' )
103
+ ->condition ('w.type ' , $ this -> watchdogMessageTypes , 'IN ' )
69
104
->condition ('w.timestamp ' , $ this ->watchdogScenarioStartTime , '>= ' )
70
105
->execute ()
71
106
->fetchAll ();
0 commit comments