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

SectionDetectorTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 13
dl 0
loc 26
rs 10
c 2
b 1
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_detectFromSubdomain() 0 14 1
A prepareConfig() 0 5 1
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