@@ -127,19 +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.
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.
132
135
*
133
136
* @return bool
134
137
* @throws \Exception
135
138
*/
136
- private function match (callable $ matcher , string $ notFoundMessage ): bool
137
- {
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 {
138
146
if ($ this ->getError ()) {
139
147
return false ;
140
148
}
141
149
142
- if ($ this ->logReader ->readUntil ($ matcher , $ notFoundMessage )) {
150
+ if ($ this ->logReader ->readUntil (
151
+ $ matcher ,
152
+ $ notFoundMessage ,
153
+ $ checkAllLogs ,
154
+ $ timeoutSeconds ,
155
+ $ timeoutMicroseconds
156
+ )) {
143
157
$ this ->popError ();
144
158
145
159
return true ;
@@ -434,7 +448,8 @@ class LogTool
434
448
* @return bool
435
449
* @throws \Exception
436
450
*/
437
- public function expectReloadingLogsLines (): bool {
451
+ public function expectReloadingLogsLines (): bool
452
+ {
438
453
return (
439
454
$ this ->expectNotice ('error log file re-opened ' ) &&
440
455
$ this ->expectNotice ('access log file re-opened ' )
@@ -570,10 +585,14 @@ class LogTool
570
585
/**
571
586
* Expect log entry.
572
587
*
573
- * @param string $type Entry type like NOTICE, WARNING, DEBUG and so on.
574
- * @param string $expectedMessage Message to search for
575
- * @param string|null $pool Pool that is used and prefixes the message.
576
- * @param string $ignoreErrorFor Ignore error for supplied string in the message.
588
+ * @param string $type Entry type like NOTICE, WARNING, DEBUG and so on.
589
+ * @param string $expectedMessage Message to search for
590
+ * @param string|null $pool Pool that is used and prefixes the message.
591
+ * @param string $ignoreErrorFor Ignore error for supplied string in the message.
592
+ * @param bool $checkAllLogs Whether to also check past logs.
593
+ * @param bool $invert Whether the log entry is not expected rather than expected.
594
+ * @param int|null $timeoutSeconds Timeout in seconds for reading of all messages.
595
+ * @param int|null $timeoutMicroseconds Additional timeout in microseconds for reading of all messages.
577
596
*
578
597
* @return bool
579
598
* @throws \Exception
@@ -582,16 +601,29 @@ class LogTool
582
601
string $ type ,
583
602
string $ expectedMessage ,
584
603
string $ pool = null ,
585
- string $ ignoreErrorFor = self ::DEBUG
604
+ string $ ignoreErrorFor = self ::DEBUG ,
605
+ bool $ checkAllLogs = false ,
606
+ bool $ invert = false ,
607
+ int $ timeoutSeconds = null ,
608
+ int $ timeoutMicroseconds = null
586
609
): bool {
587
610
if ($ this ->getError ()) {
588
611
return false ;
589
612
}
590
613
591
- return $ this ->match (
614
+ $ matchResult = $ this ->match (
592
615
$ this ->getEntryMatcher ($ type , $ expectedMessage , $ pool , $ ignoreErrorFor ),
593
- "The $ type does not match expected message "
616
+ $ invert ? null : "The $ type does not match expected message " ,
617
+ $ checkAllLogs ,
618
+ $ timeoutSeconds ,
619
+ $ timeoutMicroseconds
594
620
);
621
+
622
+ if ($ matchResult && $ invert ) {
623
+ return $ this ->error ("The $ type matches unexpected message " );
624
+ }
625
+
626
+ return $ matchResult ;
595
627
}
596
628
597
629
/**
@@ -667,14 +699,23 @@ class LogTool
667
699
/**
668
700
* Expect pattern in the log line.
669
701
*
670
- * @param string $pattern
702
+ * @param string $pattern Pattern to use.
703
+ * @param bool $invert Whether to expect pattern not to match.
704
+ * @param bool $checkAllLogs Whether to also check past logs.
705
+ * @param int|null $timeoutSeconds Timeout in seconds for reading of all messages.
706
+ * @param int|null $timeoutMicroseconds Additional timeout in microseconds for reading of all messages.
671
707
*
672
708
* @return bool
673
709
* @throws \Exception
674
710
*/
675
- public function expectPattern (string $ pattern ): bool
676
- {
677
- return $ this ->match (
711
+ public function expectPattern (
712
+ string $ pattern ,
713
+ bool $ invert = false ,
714
+ bool $ checkAllLogs = false ,
715
+ int $ timeoutSeconds = null ,
716
+ int $ timeoutMicroseconds = null ,
717
+ ): bool {
718
+ $ matchResult = $ this ->match (
678
719
function ($ line ) use ($ pattern ) {
679
720
if (preg_match ($ pattern , $ line ) === 1 ) {
680
721
$ this ->traceMatch ("Pattern expectation " , $ pattern , $ line );
@@ -684,8 +725,17 @@ class LogTool
684
725
685
726
return false ;
686
727
},
687
- 'The search pattern not found '
728
+ $ invert ? null : 'The search pattern not found ' ,
729
+ $ checkAllLogs ,
730
+ $ timeoutSeconds ,
731
+ $ timeoutMicroseconds
688
732
);
733
+
734
+ if ($ invert && $ matchResult ) {
735
+ return $ this ->logReader ->printError ('The search pattern found - PATTERN: ' . $ pattern );
736
+ }
737
+
738
+ return $ matchResult ;
689
739
}
690
740
691
741
/**
0 commit comments