1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\QueuedJobs\Tests\QueuedJobsTest; |
4
|
|
|
|
5
|
|
|
use Monolog\Logger; |
6
|
|
|
use SilverStripe\Dev\TestOnly; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Test logger for recording messages |
10
|
|
|
*/ |
11
|
|
|
class QueuedJobsTest_RecordingLogger extends Logger implements TestOnly |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var QueuedJobsTest_Handler |
15
|
|
|
*/ |
16
|
|
|
protected $testHandler = null; |
17
|
|
|
|
18
|
|
|
public function __construct($name = 'testlogger', array $handlers = array(), array $processors = array()) |
19
|
|
|
{ |
20
|
|
|
parent::__construct($name, $handlers, $processors); |
21
|
|
|
|
22
|
|
|
$this->testHandler = new QueuedJobsTest_Handler(); |
23
|
|
|
$this->pushHandler($this->testHandler); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
public function getMessages() |
30
|
|
|
{ |
31
|
|
|
return $this->testHandler->getMessages(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Clear all messages |
36
|
|
|
*/ |
37
|
|
|
public function clear() |
38
|
|
|
{ |
39
|
|
|
$this->testHandler->clear(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get messages with the given filter |
44
|
|
|
* |
45
|
|
|
* @param string $containing |
46
|
|
|
* @return array Filtered array |
47
|
|
|
*/ |
48
|
|
|
public function filterMessages($containing) |
49
|
|
|
{ |
50
|
|
|
return array_values(array_filter( |
51
|
|
|
$this->getMessages(), |
52
|
|
|
function ($content) use ($containing) { |
53
|
|
|
return stripos($content, $containing) !== false; |
54
|
|
|
} |
55
|
|
|
)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Count all messages containing the given substring |
60
|
|
|
* |
61
|
|
|
* @param string $containing Message to filter by |
62
|
|
|
* @return int |
63
|
|
|
*/ |
64
|
|
|
public function countMessages($containing = null) |
65
|
|
|
{ |
66
|
|
|
if ($containing) { |
|
|
|
|
67
|
|
|
$messages = $this->filterMessages($containing); |
68
|
|
|
} else { |
69
|
|
|
$messages = $this->getMessages(); |
70
|
|
|
} |
71
|
|
|
return count($messages); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: