<?php

namespace KupShop\DevelopmentBundle\Util\Tests;

use Monolog\Handler\TestHandler;
use Symfony\Bridge\Monolog\Logger;

trait LoggerTestTrait
{
    public function getLogger()
    {
        /** @var Logger $logger */
        $logger = $this->get('logger');
        $testHandler = new TestHandler('DEBUG');
        $logger->pushHandler($testHandler);
    }

    public function getTestHandler()
    {
        $logger = $this->get('logger');
        $testHandler = null;
        foreach ($logger->getHandlers() as $handler) {
            if ($handler instanceof TestHandler) {
                $testHandler = $handler;
            }
        }

        return $testHandler;
    }
}
