Completed
Branch master (95b3ba)
by Ryan
28:02 queued 13:03
created

ConfigurationTest::testCustomContainer()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2017 Ryan Parman <http://ryanparman.com>.
4
 * Copyright (c) 2017 Contributors.
5
 *
6
 * http://opensource.org/licenses/Apache2.0
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimplePie\Test\Unit;
12
13
use Monolog\Handler\TestHandler;
14
use Monolog\Logger;
15
use Psr\Log\LoggerInterface;
16
use SimplePie\Configuration;
17
use SimplePie\Container;
18
use SimplePie\HandlerStack;
19
use SimplePie\HandlerStackInterface;
20
use SimplePie\Middleware\Xml\Atom;
21
22
class ConfigurationTest extends AbstractTestCase
23
{
24
    public function testDefaultContainer(): void
25
    {
26
        Configuration::setContainer();
27
28
        $this->assertTrue(Configuration::getLogger() instanceof LoggerInterface);
29
        $this->assertTrue(Configuration::getMiddlewareStack() instanceof HandlerStackInterface);
30
        $this->assertSame(4792582, Configuration::getLibxml());
31
    }
32
33
    public function testCustomContainer(): void
34
    {
35
        $container = new Container();
36
37
        $container['simplepie.logger'] = function (Container $c) {
38
            $logger = new Logger('Testing');
39
            $logger->pushHandler(new TestHandler());
40
41
            return $logger;
42
        };
43
44
        $container['simplepie.libxml'] = function (Container $c) {
45
            return LIBXML_NOCDATA;
46
        };
47
48
        $container['simplepie.middleware'] = function (Container $c) {
49
            return (new HandlerStack())->append(new Atom());
50
        };
51
52
        Configuration::setContainer($container);
53
54
        $this->assertTrue(Configuration::getLogger() instanceof LoggerInterface);
55
        $this->assertTrue(Configuration::getMiddlewareStack() instanceof HandlerStackInterface);
56
        $this->assertSame(16384, Configuration::getLibxml());
57
    }
58
59
    /**
60
     * @expectedException \SimplePie\Exception\ConfigurationException
61
     * @expectedExceptionMessage The configured logger MUST be compatible with `Psr\Log\LoggerInterface`. Received `string` instead.
62
     */
63
    public function testCustomLogger(): void
64
    {
65
        $container = new Container();
66
67
        $container['simplepie.logger'] = function (Container $c) {
68
            return 'b0rk';
69
        };
70
71
        Configuration::setContainer($container);
72
    }
73
74
    /**
75
     * @expectedException \SimplePie\Exception\ConfigurationException
76
     * @expectedExceptionMessage The configured libxml options MUST be bitwise LIBXML_* constants, which result in an integer value. Received `string` instead.
77
     */
78
    public function testCustomLibxml(): void
79
    {
80
        $container = new Container();
81
82
        $container['simplepie.libxml'] = function (Container $c) {
83
            return 'b0rk';
84
        };
85
86
        Configuration::setContainer($container);
87
    }
88
89
    /**
90
     * @expectedException \SimplePie\Exception\ConfigurationException
91
     * @expectedExceptionMessage The configured middleware handler stack MUST be compatible with `SimplePie\HandlerStackInterface`. Received `string` instead.
92
     */
93
    public function testCustomMiddleware(): void
94
    {
95
        $container = new Container();
96
97
        $container['simplepie.middleware'] = function (Container $c) {
98
            return 'b0rk';
99
        };
100
101
        Configuration::setContainer($container);
102
    }
103
}
104