Passed
Pull Request — master (#1)
by Alex
08:35
created

ErrorLogHandlerFactoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 2
b 0
f 0
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testInvokeWillReturnValidErrorLogHandler() 0 11 1
A testImplementsFactoryInterface() 0 5 1
A setUp() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArpTest\LaminasMonolog\Factory\Handler;
6
7
use Arp\LaminasFactory\FactoryInterface;
8
use Arp\LaminasMonolog\Factory\Handler\ErrorLogHandlerFactory;
9
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
10
use Monolog\Handler\ErrorLogHandler;
11
use Monolog\Logger;
12
use PHPUnit\Framework\MockObject\MockObject;
13
use PHPUnit\Framework\TestCase;
14
use Psr\Container\ContainerInterface;
15
16
/**
17
 * @covers \Arp\LaminasMonolog\Factory\Handler\ErrorLogHandlerFactory
18
 *
19
 * @author  Alex Patterson <[email protected]>
20
 * @package ArpTest\LaminasMonolog\Factory\Handler
21
 */
22
final class ErrorLogHandlerFactoryTest extends TestCase
23
{
24
    /**
25
     * @var ContainerInterface&MockObject
26
     */
27
    private ContainerInterface $container;
28
29
    /**
30
     * Prepare the test case dependencies
31
     */
32
    public function setUp(): void
33
    {
34
        $this->container = $this->createMock(ContainerInterface::class);
35
    }
36
37
    /**
38
     * Assert that the factory implements FactoryInterface
39
     */
40
    public function testImplementsFactoryInterface(): void
41
    {
42
        $factory = new ErrorLogHandlerFactory();
43
44
        $this->assertInstanceOf(FactoryInterface::class, $factory);
45
    }
46
47
    /**
48
     * Assert that calls to __invoke() will return a configured ErrorLogHandler instance
49
     *
50
     * @throws ServiceNotCreatedException
51
     */
52
    public function testInvokeWillReturnValidErrorLogHandler(): void
53
    {
54
        $factory = new ErrorLogHandlerFactory();
55
56
        $options = [
57
            'level' => Logger::DEBUG,
58
        ];
59
60
        $this->assertInstanceOf(
61
            ErrorLogHandler::class,
62
            $factory($this->container, ErrorLogHandler::class, $options)
63
        );
64
    }
65
}
66