Completed
Pull Request — master (#13)
by Alejandro
04:35
created

provideDebugs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace AcelayaTest\ExpressiveErrorHandler\ErrorHandler\Factory;
5
6
use Acelaya\ExpressiveErrorHandler\ErrorHandler\Factory\PlainTextResponseGeneratorFactory;
7
use PHPUnit\Framework\TestCase;
8
use Zend\ServiceManager\ServiceManager;
9
use Zend\Stratigility\Middleware\ErrorResponseGenerator;
10
11
class PlainTextResponseGeneratorFactoryTest extends TestCase
12
{
13
    /**
14
     * @var PlainTextResponseGeneratorFactory
15
     */
16
    protected $factory;
17
18
    public function setUp()
19
    {
20
        $this->factory = new PlainTextResponseGeneratorFactory();
21
    }
22
23
    /**
24
     * @test
25
     * @dataProvider provideDebugs
26
     * @param array $config
27
     * @param bool $expectedIsDev
28
     */
29
    public function serviceIsCreated(array $config, bool $expectedIsDev)
30
    {
31
        $instance = $this->factory->__invoke(new ServiceManager(['services' => [
32
            'config' => $config,
33
        ]]));
34
35
        $ref = new \ReflectionObject($instance);
36
        $isDev = $ref->getProperty('isDevelopmentMode');
37
        $isDev->setAccessible(true);
38
39
        $this->assertInstanceOf(ErrorResponseGenerator::class, $instance);
40
        $this->assertEquals($expectedIsDev, $isDev->getValue($instance));
41
    }
42
43
    public function provideDebugs(): array
44
    {
45
        return [
46
            [[], false],
47
            [['debug' => true], true],
48
            [['debug' => false], false],
49
        ];
50
    }
51
}
52