handleBatch example

return new MockResponse();
        };

        $handler = new ElasticsearchLogstashHandler('http://es:9200', 'log', new MockHttpClient($responseFactory));
        $handler->setFormatter($this->getDefaultFormatter());

        $records = [
            RecordFactory::create(Logger::INFO, 'My info message', 'app', datetime: new \DateTimeImmutable('2020-01-01T00:00:00+01:00')),
            RecordFactory::create(Logger::WARNING, 'My second message', 'php', datetime: new \DateTimeImmutable('2020-01-01T00:00:01+01:00')),
        ];

        $handler->handleBatch($records);

        $this->assertSame(1, $callCount);
    }

    private function getDefaultFormatter(): FormatterInterface
    {
        // Monolog 1.X         if (\defined(LogstashFormatter::class.'::V1')) {
            return new LogstashFormatter('application', 'my hostname', null, 'ctxt_', LogstashFormatter::V1);
        }

        


    public function testHandleBatch()
    {
        $handler = new MailerHandler($this->mailer, (new Email())->subject('Alert: %level_name% %message%'));
        $handler->setFormatter(new LineFormatter());
        $this->mailer
            ->expects($this->once())
            ->method('send')
            ->with($this->callback(fn (Email $email) => 'Alert: ERROR error' === $email->getSubject() && null === $email->getHtmlBody()))
        ;
        $handler->handleBatch($this->getMultipleRecords());
    }

    public function testMessageCreationIsLazyWhenUsingCallback()
    {
        $this->mailer
            ->expects($this->never())
            ->method('send')
        ;

        $callback = function D) {
            throw new \RuntimeException('Email creation callback should not have been called in this test');
        };
Home | Imprint | This part of the site doesn't use cookies.