Completed
Push — source-fix-test ( e3b467...5068b6 )
by Bart
05:55 queued 04:24
created

EmailSettingsMapperTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 83
rs 10
1
<?php
2
3
namespace NerdsAndCompany\Schematic\Mappers;
4
5
use Craft;
6
use Codeception\Test\Unit;
7
8
/**
9
 * Class EmailSettingsMapperTest.
10
 *
11
 * @author    Nerds & Company
12
 * @copyright Copyright (c) 2015-2018, Nerds & Company
13
 * @license   MIT
14
 *
15
 * @see      http://www.nerds.company
16
 */
17
class EmailSettingsMapperTest extends Unit
18
{
19
    /**
20
     * @var EmailSettingsMapper
21
     */
22
    private $mapper;
23
24
    /**
25
     * Set the mapper.
26
     *
27
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
28
     * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
29
     */
30
    protected function _before()
31
    {
32
        $this->mapper = new EmailSettingsMapper();
33
    }
34
35
    //==============================================================================================================
36
    //=================================================  TESTS  ====================================================
37
    //==============================================================================================================
38
39
    /**
40
     * Test EmailSettings service export.
41
     */
42
    public function testEmailSettingsServiceExport()
43
    {
44
        $this->setMockServicesForExport();
45
46
        $definition = $this->getEmailSettingsDefinition();
47
        $result = $this->mapper->export();
48
49
        $this->assertSame($definition, $result);
50
    }
51
52
    /**
53
     * Test EmailSettings service import.
54
     */
55
    public function testEmailSettingsServiceImport()
56
    {
57
        $definition = $this->getEmailSettingsDefinition();
58
        $import = $this->mapper->import($definition);
59
60
        $this->assertSame([], $import);
61
    }
62
63
    //==============================================================================================================
64
    //================================================  HELPERS  ===================================================
65
    //==============================================================================================================
66
67
    /**
68
     * Email settings definition.
69
     *
70
     * @return array
71
     */
72
    private function getEmailSettingsDefinition()
73
    {
74
        return [
75
            'settings' => [
76
                'fromEmail' => '[email protected]',
77
                'fromName' => 'Schematic',
78
                'template' => null,
79
            ],
80
        ];
81
    }
82
83
    /**
84
     * Set mock services for export.
85
     */
86
    private function setMockServicesForExport()
87
    {
88
        $settings = [
89
            'fromEmail' => '[email protected]',
90
            'fromName' => 'Schematic',
91
            'template' => null,
92
        ];
93
94
        Craft::$app->systemSettings->expects($this->exactly(1))
95
                                   ->method('getSettings')
96
                                   ->with('email')
97
                                   ->willReturn($settings);
98
    }
99
}
100