protected $state;
/**
* {@inheritdoc}
*/
protected function setUp(): void
{ parent::
setUp();
// Construct a state object used for testing logger assertions.
$this->state =
new State(new KeyValueMemoryFactory());
// Create a mock logger to set a flag in the resulting state.
$logger =
$this->
prophesize('Drupal\Core\Logger\LoggerChannelInterface'
);
// Safely ignore the cron success message.
$logger->
info('Cron run completed.'
)->
shouldBeCalled();
// Set a flag to track when a message is logged by adding a callback
// function for each logging method.
foreach (get_class_methods(LoggerInterface::
class) as $logger_method) { $logger->
{$logger_method}(Argument::
cetera())->
will(function D
) { \Drupal::
state()->
set('cron_test.message_logged', TRUE
);
});
}