2017-04-21 03:18:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\FullTextSearch\Tests\SolrReindexTest;
|
|
|
|
|
|
|
|
use Monolog\Logger;
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
use SilverStripe\FullTextSearch\Tests\SolrReindexTest\SolrReindexTest_Handler;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test logger for recording messages
|
|
|
|
*/
|
|
|
|
class SolrReindexTest_RecordingLogger extends Logger implements TestOnly
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var SolrReindexTest_Handler
|
|
|
|
*/
|
|
|
|
protected $testHandler = null;
|
|
|
|
|
|
|
|
public function __construct($name = 'testlogger', array $handlers = array(), array $processors = array())
|
|
|
|
{
|
|
|
|
parent::__construct($name, $handlers, $processors);
|
|
|
|
|
|
|
|
$this->testHandler = new SolrReindexTest_Handler();
|
|
|
|
$this->pushHandler($this->testHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getMessages()
|
|
|
|
{
|
|
|
|
return $this->testHandler->getMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all messages
|
|
|
|
*/
|
|
|
|
public function clear()
|
|
|
|
{
|
|
|
|
$this->testHandler->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get messages with the given filter
|
|
|
|
*
|
|
|
|
* @param string $containing
|
|
|
|
* @return array Filtered array
|
|
|
|
*/
|
|
|
|
public function filterMessages($containing)
|
|
|
|
{
|
|
|
|
return array_values(array_filter(
|
2022-04-13 01:24:03 +02:00
|
|
|
$this->getMessages() ?? [],
|
2017-04-21 03:18:37 +02:00
|
|
|
function ($content) use ($containing) {
|
2022-04-13 01:24:03 +02:00
|
|
|
return stripos($content ?? '', $containing ?? '') !== false;
|
2017-04-21 03:18:37 +02:00
|
|
|
}
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Count all messages containing the given substring
|
|
|
|
*
|
|
|
|
* @param string $containing Message to filter by
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function countMessages($containing = null)
|
|
|
|
{
|
|
|
|
if ($containing) {
|
|
|
|
$messages = $this->filterMessages($containing);
|
|
|
|
} else {
|
|
|
|
$messages = $this->getMessages();
|
|
|
|
}
|
2022-04-13 01:24:03 +02:00
|
|
|
return count($messages ?? []);
|
2017-04-21 03:18:37 +02:00
|
|
|
}
|
|
|
|
}
|