Completed
Push — master ( ae47f3...33ec04 )
by Bob Olde
11s
created

SiteDataTypeTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 59
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A _before() 0 4 1
A testGetMapperHandle() 0 6 1
A testGetRecords() 0 12 1
A getMockSite() 0 4 1
1
<?php
2
3
namespace NerdsAndCompany\Schematic\DataTypes;
4
5
use Craft;
6
use craft\models\Site;
7
use Codeception\Test\Unit;
8
9
/**
10
 * Class SiteDataTypeTest.
11
 *
12
 * @author    Nerds & Company
13
 * @copyright Copyright (c) 2015-2017, Nerds & Company
14
 * @license   MIT
15
 *
16
 * @see      http://www.nerds.company
17
 */
18
class SiteDataTypeTest extends Unit
19
{
20
    /**
21
     * @var SiteDataType
22
     */
23
    private $dataType;
24
25
    /**
26
     * Set the dataType.
27
     *
28
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
29
     */
30
    protected function _before()
31
    {
32
        $this->dataType = new SiteDataType();
33
    }
34
35
    //==============================================================================================================
36
    //=================================================  TESTS  ====================================================
37
    //==============================================================================================================
38
39
    /**
40
     * Get mapper handle test.
41
     */
42
    public function testGetMapperHandle()
43
    {
44
        $result = $this->dataType->getMapperHandle();
45
46
        $this->assertSame('modelMapper', $result);
47
    }
48
49
    /**
50
     * Get records test.
51
     */
52
    public function testGetRecords()
53
    {
54
        $records = [$this->getMockSite()];
55
56
        Craft::$app->sites->expects($this->exactly(1))
57
                          ->method('getAllSites')
58
                          ->willReturn($records);
59
60
        $result = $this->dataType->getRecords();
61
62
        $this->assertSame($records, $result);
63
    }
64
65
    //==============================================================================================================
66
    //================================================  HELPERS  ===================================================
67
    //==============================================================================================================
68
69
    /**
70
     * @return Mock|Site
71
     */
72
    private function getMockSite()
73
    {
74
        return $this->getMockBuilder(Site::class)->getMock();
75
    }
76
}
77