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

DataTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 66
rs 10
c 2
b 0
f 0
1
<?php
2
3
namespace NerdsAndCompany\Schematic\Models;
4
5
use Symfony\Component\Yaml\Yaml;
6
use Codeception\Test\Unit;
7
8
/**
9
 * Class DataTest.
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 DataTest extends Unit
18
{
19
    /**
20
     * @return string
21
     */
22
    private function getSchemaTestFile()
23
    {
24
        return file_get_contents(__DIR__.'/../../_data/test_schema.yml');
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    private function getOverrideTestFile()
31
    {
32
        return file_get_contents(__DIR__.'/../../_data/test_override.yml');
33
    }
34
35
    /**
36
     * @return Data
37
     */
38
    private function generateDataModel()
39
    {
40
        putenv('SCHEMATIC_S3_BUCKET=override_bucket_name');
41
        $schema = $this->getSchemaTestFile();
42
        $override = $this->getOverrideTestFile();
43
44
        return Data::fromYaml($schema, $override);
45
    }
46
47
    public function testRegularOverride()
48
    {
49
        $result = $this->generateDataModel();
50
        $this->assertEquals('override_key', $result['volumes']['uploads']['attributes']['keyId']);
51
    }
52
53
    public function testEnvironmentOverride()
54
    {
55
        $result = $this->generateDataModel();
56
        $this->assertEquals('override_bucket_name', $result['volumes']['uploads']['attributes']['bucket']);
57
    }
58
59
    public function testErrorWhenEnvironmentVariableNotSet()
60
    {
61
        // unset environment variable
62
        putenv('SCHEMATIC_S3_BUCKET');
63
        $this->setExpectedException('Exception');
64
        $schema = $this->getSchemaTestFile();
65
        $override = $this->getOverrideTestFile();
66
        Data::fromYaml($schema, $override);
67
    }
68
69
    public function testToYamlIsValidYaml()
70
    {
71
        $dataModel = $this->generateDataModel();
72
        $yaml = Data::toYaml($dataModel);
73
        $this->assertInternalType('array', Yaml::parse($yaml));
74
    }
75
76
    public function testToYamlContainsCorrectText()
77
    {
78
        $dataModel = $this->generateDataModel();
79
        $yaml = Data::toYaml($dataModel);
80
        $this->assertContains('override_bucket_name', $yaml);
81
    }
82
}
83