Completed
Push — do-not-scrutinize-tests ( fcf005 )
by Bart
04:15 queued 02:38
created

ElementIndexDataTypeTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
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 60
rs 10
1
<?php
2
3
namespace NerdsAndCompany\Schematic\DataTypes;
4
5
use Craft;
6
use craft\models\ElementType;
7
use Codeception\Test\Unit;
8
9
/**
10
 * Class ElementTypeDataTypeTest.
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 ElementIndexDataTypeTest extends Unit
19
{
20
    /**
21
     * @var ElementIndexDataType
22
     */
23
    private $dataType;
24
25
    /**
26
     * Set the dataType.
27
     *
28
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
29
     * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
30
     */
31
    protected function _before()
32
    {
33
        $this->dataType = new ElementIndexDataType();
34
    }
35
36
    //==============================================================================================================
37
    //=================================================  TESTS  ====================================================
38
    //==============================================================================================================
39
40
    /**
41
     * Get mapper handle test.
42
     */
43
    public function testGetMapperHandle()
44
    {
45
        $result = $this->dataType->getMapperHandle();
46
47
        $this->assertSame('elementIndexMapper', $result);
48
    }
49
50
    /**
51
     * Get records test.
52
     */
53
    public function testGetRecords()
54
    {
55
        $records = [$this->getMockElementType()];
56
57
        Craft::$app->elements->expects($this->exactly(1))
58
                             ->method('getAllElementTypes')
59
                             ->willReturn($records);
60
61
        $result = $this->dataType->getRecords();
62
63
        $this->assertSame($records, $result);
64
    }
65
66
    //==============================================================================================================
67
    //================================================  HELPERS  ===================================================
68
    //==============================================================================================================
69
70
    /**
71
     * @return Mock|ElementType
72
     */
73
    private function getMockElementType()
74
    {
75
        return $this->getMockBuilder(ElementType::class)->getMock();
76
    }
77
}
78