@@ -127,20 +127,33 @@ class LogTool
127
127
/**
128
128
* Match the matcher checking the log lines using the callback.
129
129
*
130
- * @param callable $matcher Callback checking whether the log line matches the expected message.
131
- * @param string $notFoundMessage Error message to show if the message is not found.
132
- * @param bool $checkAllLogs Whether to also check past logs.
130
+ * @param callable $matcher Callback checking whether the log line matches the expected message.
131
+ * @param string|null $notFoundMessage Error message to show if the message is not found.
132
+ * @param bool $checkAllLogs Whether to also check past logs.
133
+ * @param int|null $timeoutSeconds Timeout in seconds for reading of all messages.
134
+ * @param int|null $timeoutMicroseconds Additional timeout in microseconds for reading of all messages.
133
135
*
134
136
* @return bool
135
137
* @throws \Exception
136
138
*/
137
- private function match (callable $ matcher , string $ notFoundMessage , bool $ checkAllLogs = false ): bool
138
- {
139
+ private function match (
140
+ callable $ matcher ,
141
+ string $ notFoundMessage = null ,
142
+ bool $ checkAllLogs = false ,
143
+ int $ timeoutSeconds = null ,
144
+ int $ timeoutMicroseconds = null
145
+ ): bool {
139
146
if ($ this ->getError ()) {
140
147
return false ;
141
148
}
142
149
143
- if ($ this ->logReader ->readUntil ($ matcher , $ notFoundMessage , $ checkAllLogs )) {
150
+ if ($ this ->logReader ->readUntil (
151
+ $ matcher ,
152
+ $ notFoundMessage ,
153
+ $ checkAllLogs ,
154
+ $ timeoutSeconds ,
155
+ $ timeoutMicroseconds
156
+ )) {
144
157
$ this ->popError ();
145
158
146
159
return true ;
@@ -576,11 +589,14 @@ class LogTool
576
589
/**
577
590
* Expect log entry.
578
591
*
579
- * @param string $type Entry type like NOTICE, WARNING, DEBUG and so on.
580
- * @param string $expectedMessage Message to search for
581
- * @param string|null $pool Pool that is used and prefixes the message.
582
- * @param string $ignoreErrorFor Ignore error for supplied string in the message.
583
- * @param bool $checkAllLogs Whether to also check past logs.
592
+ * @param string $type Entry type like NOTICE, WARNING, DEBUG and so on.
593
+ * @param string $expectedMessage Message to search for
594
+ * @param string|null $pool Pool that is used and prefixes the message.
595
+ * @param string $ignoreErrorFor Ignore error for supplied string in the message.
596
+ * @param bool $checkAllLogs Whether to also check past logs.
597
+ * @param bool $invert Whether the log entry is not expected rather than expected.
598
+ * @param int|null $timeoutSeconds Timeout in seconds for reading of all messages.
599
+ * @param int|null $timeoutMicroseconds Additional timeout in microseconds for reading of all messages.
584
600
*
585
601
* @return bool
586
602
* @throws \Exception
@@ -590,17 +606,28 @@ class LogTool
590
606
string $ expectedMessage ,
591
607
string $ pool = null ,
592
608
string $ ignoreErrorFor = self ::DEBUG ,
593
- bool $ checkAllLogs = false
609
+ bool $ checkAllLogs = false ,
610
+ bool $ invert = false ,
611
+ int $ timeoutSeconds = null ,
612
+ int $ timeoutMicroseconds = null
594
613
): bool {
595
614
if ($ this ->getError ()) {
596
615
return false ;
597
616
}
598
617
599
- return $ this ->match (
618
+ $ matchResult = $ this ->match (
600
619
$ this ->getEntryMatcher ($ type , $ expectedMessage , $ pool , $ ignoreErrorFor ),
601
- "The $ type does not match expected message " ,
602
- $ checkAllLogs
620
+ $ invert ? null : "The $ type does not match expected message " ,
621
+ $ checkAllLogs ,
622
+ $ timeoutSeconds ,
623
+ $ timeoutMicroseconds
603
624
);
625
+
626
+ if ($ matchResult && $ invert ) {
627
+ return $ this ->error ("The $ type matches unexpected message " );
628
+ }
629
+
630
+ return $ matchResult ;
604
631
}
605
632
606
633
/**
@@ -676,14 +703,23 @@ class LogTool
676
703
/**
677
704
* Expect pattern in the log line.
678
705
*
679
- * @param string $pattern
706
+ * @param string $pattern Pattern to use.
707
+ * @param bool $invert Whether to expect pattern not to match.
708
+ * @param bool $checkAllLogs Whether to also check past logs.
709
+ * @param int|null $timeoutSeconds Timeout in seconds for reading of all messages.
710
+ * @param int|null $timeoutMicroseconds Additional timeout in microseconds for reading of all messages.
680
711
*
681
712
* @return bool
682
713
* @throws \Exception
683
714
*/
684
- public function expectPattern (string $ pattern ): bool
685
- {
686
- return $ this ->match (
715
+ public function expectPattern (
716
+ string $ pattern ,
717
+ bool $ invert = false ,
718
+ bool $ checkAllLogs = false ,
719
+ int $ timeoutSeconds = null ,
720
+ int $ timeoutMicroseconds = null ,
721
+ ): bool {
722
+ $ matchResult = $ this ->match (
687
723
function ($ line ) use ($ pattern ) {
688
724
if (preg_match ($ pattern , $ line ) === 1 ) {
689
725
$ this ->traceMatch ("Pattern expectation " , $ pattern , $ line );
@@ -693,8 +729,17 @@ class LogTool
693
729
694
730
return false ;
695
731
},
696
- 'The search pattern not found '
732
+ $ invert ? null : 'The search pattern not found ' ,
733
+ $ checkAllLogs ,
734
+ $ timeoutSeconds ,
735
+ $ timeoutMicroseconds
697
736
);
737
+
738
+ if ($ invert && $ matchResult ) {
739
+ return $ this ->logReader ->printError ('The search pattern found - PATTERN: ' . $ pattern );
740
+ }
741
+
742
+ return $ matchResult ;
698
743
}
699
744
700
745
/**
0 commit comments