Completed
Push — master ( a7941f...9cc640 )
by Damian
11s
created

MultiDomainTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 4
dl 0
loc 95
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 17 1
A testGetDomain() 0 5 1
A testGetAllDomains() 0 9 2
A getAllDomainsProvider() 0 7 1
A testGetPrimaryDomain() 0 6 1
A testDomainForUrl() 0 6 1
A testDomainForUrlDefaultsToPrimaryDomain() 0 4 1
A tearDown() 0 5 1
1
<?php
2
3
class MultiDomainTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    /**
6
     * Set up some test domain configuration
7
     *
8
     * {@inheritDoc}
9
     */
10
    public function setUp()
11
    {
12
        parent::setUp();
13
        Config::nest();
14
15
        Config::inst()->remove('MultiDomain', 'domains');
16
        Config::inst()->update('MultiDomain', 'domains', array(
17
            'primary' => array(
18
                'hostname' => 'foo.bar',
19
                'resolves_to' => 'bar.baz'
20
            ),
21
            'secondary' => array(
22
                'hostname' => 'localhost',
23
                'resolves_to' => 'local.dev'
24
            )
25
        ));
26
    }
27
28
    /**
29
     * Test that a MultiDomainDomain can be returned from the configured domains
30
     */
31
    public function testGetDomain()
32
    {
33
        $this->assertNull(MultiDomain::get_domain('does-not-exist'));
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<MultiDomainTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
        $this->assertInstanceOf(MultiDomainDomain::class, MultiDomain::get_domain('primary'));
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<MultiDomainTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
    }
36
37
    /**
38
     * Test that all domains can be returned, with or without the primary domain
39
     *
40
     * @dataProvider getAllDomainsProvider
41
     * @param bool $withPrimary
42
     */
43
    public function testGetAllDomains($withPrimary)
44
    {
45
        $result = MultiDomain::get_all_domains($withPrimary);
46
        $this->assertInternalType('array', $result);
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<MultiDomainTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
        $this->assertNotEmpty($result);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<MultiDomainTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
49
        $expectedCount = $withPrimary ? 2 : 1;
50
        $this->assertCount($expectedCount, $result);
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<MultiDomainTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
    }
52
53
    /**
54
     * @return array[]
55
     */
56
    public function getAllDomainsProvider()
57
    {
58
        return array(
59
            array(true),
60
            array(false)
61
        );
62
    }
63
64
    /**
65
     * Test that the primary domain can be returned
66
     */
67
    public function testGetPrimaryDomain()
68
    {
69
        $result = MultiDomain::get_primary_domain();
70
        $this->assertInstanceOf(MultiDomainDomain::class, $result);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<MultiDomainTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
        $this->assertTrue($result->isPrimary());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<MultiDomainTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
    }
73
74
    /**
75
     * Test that the correct domain can be returned by a provided URL
76
     */
77
    public function testDomainForUrl()
78
    {
79
        $result = MultiDomain::domain_for_url('foo.bar/my-page');
80
        $this->assertInstanceOf(MultiDomainDomain::class, $result);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<MultiDomainTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
81
        $this->assertSame('primary', $result->getKey());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<MultiDomainTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
    }
83
84
    /**
85
     * Test that if a URL doesn't match any domain then the primary domain is returned
86
     */
87
    public function testDomainForUrlDefaultsToPrimaryDomain()
88
    {
89
        $this->assertTrue(MultiDomain::domain_for_url('does-not-exist.com')->isPrimary());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<MultiDomainTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
    }
91
92
    public function tearDown()
93
    {
94
        Config::unnest();
95
        parent::tearDown();
96
    }
97
}
98