Completed
Push — master ( 06c1ce...67d37c )
by Jeroen
06:20
created

Tests/unit/Helper/DomainConfigurationTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminBundle\Tests\Helper;
4
5
use Kunstmaan\AdminBundle\Helper\DomainConfiguration;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\RequestStack;
10
11
class DomainConfigurationTest extends TestCase
12
{
13
    /**
14
     * @var DomainConfiguration
15
     */
16
    protected $object;
17
18
    /**
19
     * @var ContainerInterface
20
     */
21
    protected $container;
22
23
    public function testGetHost()
24
    {
25
        $object = $this->getSingleLanguageDomainConfiguration();
26
        $this->assertEquals('domain.tld', $object->getHost());
27
    }
28
29
    public function testGetHosts()
30
    {
31
        $object = $this->getSingleLanguageDomainConfiguration();
32
        $this->assertEquals(array('domain.tld'), $object->getHosts());
33
    }
34
35
    public function testGetDefaultLocale()
36
    {
37
        $object = $this->getSingleLanguageDomainConfiguration();
38
        $this->assertEquals('en', $object->getDefaultLocale());
39
    }
40
41
    public function testGetExtraData()
42
    {
43
        $object = $this->getSingleLanguageDomainConfiguration();
44
        $this->assertEquals(array(), $object->getExtraData());
45
    }
46
47
    public function testGetRootNode()
48
    {
49
        $object = $this->getSingleLanguageDomainConfiguration();
50
        $this->assertNull($object->getRootNode());
51
    }
52
53
    public function testIsMultiDomainHost()
54
    {
55
        $object = $this->getSingleLanguageDomainConfiguration();
56
        $this->assertFalse($object->isMultiDomainHost());
57
    }
58
59
    public function testIsMultiLanguageWithSingleLanguage()
60
    {
61
        $object = $this->getSingleLanguageDomainConfiguration();
62
        $this->assertFalse($object->isMultiLanguage());
63
    }
64
65
    public function testIsMultiLanguageWithMultiLanguage()
66
    {
67
        $object = $this->getMultiLanguageDomainConfiguration();
68
        $this->assertTrue($object->isMultiLanguage());
69
    }
70
71
    public function testGetFrontendLocalesWithSingleLanguage()
72
    {
73
        $object = $this->getSingleLanguageDomainConfiguration();
74
        $this->assertEquals(array('en'), $object->getFrontendLocales());
75
    }
76
77
    public function testGetFrontendLocalesWithMultiLanguage()
78
    {
79
        $object = $this->getMultiLanguageDomainConfiguration();
80
        $this->assertEquals(array('nl', 'fr', 'en'), $object->getFrontendLocales());
81
    }
82
83
    public function testGetBackendLocalesWithSingleLanguage()
84
    {
85
        $object = $this->getSingleLanguageDomainConfiguration();
86
        $this->assertEquals(array('en'), $object->getBackendLocales());
87
    }
88
89
    public function testGetBackendLocalesWithMultiLanguage()
90
    {
91
        $object = $this->getMultiLanguageDomainConfiguration();
92
        $this->assertEquals(array('nl', 'fr', 'en'), $object->getBackendLocales());
93
    }
94
95 View Code Duplication
    private function getRequestStack()
96
    {
97
        $requestStack = $this->createMock(RequestStack::class);
98
        $requestStack->expects($this->any())->method('getMasterRequest')->willReturn(Request::create('http://domain.tld/'));
99
100
        return $requestStack;
101
    }
102
103
    private function getSingleLanguageDomainConfiguration()
104
    {
105
        return new DomainConfiguration($this->getRequestStack(), false, 'en', 'en');
0 ignored issues
show
false is of type boolean, but the function expects a object<Symfony\Component...rInterface>|string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
106
    }
107
108
    private function getMultiLanguageDomainConfiguration()
109
    {
110
        return new DomainConfiguration($this->getRequestStack(), true, 'nl', 'nl|fr|en');
0 ignored issues
show
true is of type boolean, but the function expects a object<Symfony\Component...rInterface>|string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
111
    }
112
}
113