Passed
Push — master ( cd9417...6e4265 )
by Gabriel
03:32 queued 12s
created

SectionDetectorTest::test_detectFromSubdomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 14
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
namespace Nip\Mvc\Tests\Sections;
4
5
use Mockery;
6
use Nip\Config\Config;
7
use Nip\Container\Container;
8
use Nip\Mvc\Sections\SectionDetector;
9
use Nip\Mvc\Sections\SectionsManager;
10
use Nip\Mvc\Tests\AbstractTest;
11
12
/**
13
 * Class SectionDetectorTest
14
 * @package Nip\Mvc\Tests\Sections
15
 */
16
class SectionDetectorTest extends AbstractTest
17
{
18
    public function test_detectFromSubdomain()
19
    {
20
        $this->prepareConfig();
21
        $manager = new SectionsManager();
22
        $sections = $manager->getSections();
23
24
        /** @var Mockery\Mock|SectionDetector $detector */
25
        $detector = Mockery::mock(SectionDetector::class)->makePartial()->shouldAllowMockingProtectedMethods();
26
        $detector->shouldReceive('detectFromConstant')->andReturn(false);
27
        $detector->shouldReceive('getCurrentSubdomain')->andReturn('sec2');
28
29
        $detected = $detector->detect($sections);
30
        self::assertSame(1, $detected);
31
        self::assertSame('sec2', $sections[$detected]->getSubdomain());
32
    }
33
34
    /**
35
     * @param string $file
36
     */
37
    protected function prepareConfig($file = 'basic')
38
    {
39
        $data = require TEST_FIXTURE_PATH . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $file . '.php';
40
        $config = new Config(['mvc' => $data]);
41
        Container::getInstance()->set('config', $config);
42
    }
43
}
44