Completed
Push — master ( 3c5a6a...c7c355 )
by Alejandro
09:25
created

TightTest::tearDown()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 14
Code Lines 9

Duplication

Lines 10
Ratio 71.43 %

Importance

Changes 3
Bugs 2 Features 2
Metric Value
c 3
b 2
f 2
dl 10
loc 14
rs 8.8571
cc 5
eloc 9
nc 9
nop 0
1
<?php
2
3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2016 Alejandro Peña Florentín ([email protected]).
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
namespace Tight\Tests;
28
29
/**
30
 * Description of TightTest
31
 *
32
 * @author Alejandro Peña Florentín ([email protected])
33
 */
34
class TightTest extends \PHPUnit_Framework_TestCase
35
{
36
37
    public $app;
38
    public $config = [
39
        "basePath" => __DIR__,
40
        "smarty" => [
41
            "template_dir" => "./templates",
42
            "compile_dir" => "./templates_c",
43
            "config_dir" => "./configs",
44
            "cache_dir" => "./cache"
45
        ],
46
        "router" => [
47
            "mvc" => [
48
                "enable" => false,
49
                "index" => "Root",
50
            ]
51
        ],
52
        "mvc" => [
53
            "enableRouter" => false,
54
            "indexName" => "Root",
55
            "controller_dir" => "./controllers/",
56
            "model_dir" => "./models/",
57
            "view_dir" => "./views/",
58
        ],
59
        "connection" => [
60
            "user" => "root",
61
            "password" => "root",
62
            "database" => "mysql"
63
        ]
64
    ];
65
    private $directories = ["res", "controllers", "models", "views"];
66
    private $files = ["./res/values.json"];
67
68
    public function setUp() {
69
        $dirSize = count($this->directories);
70 View Code Duplication
        for ($index = 0; $index < $dirSize; $index++) {
71
            if (!is_dir($this->directories[$index])) {
72
                mkdir($this->directories[$index]);
73
            }
74
        }
75
        $fileSize = count($this->files);
76 View Code Duplication
        for ($index = 0; $index < $fileSize; $index++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
            if (!is_file($this->files[$index])) {
78
                file_put_contents($this->files[$index], "");
79
            }
80
        }
81
        $config = new \Tight\TightConfig($this->config);
82
        $this->app = new \Tight\Tight($config);
83
    }
84
85
    public function tearDown() {
86
        $fileSize = count($this->files);
87
        $dirSize = count($this->directories);
88 View Code Duplication
        for ($index = 0; $index < $fileSize; $index++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
            if (is_file($this->files[$index])) {
90
                unlink($this->files[$index]);
91
            }
92
        }
93 View Code Duplication
        for ($index = 0; $index < $dirSize; $index++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
            if (is_dir($this->directories[$index])) {
95
                rmdir($this->directories[$index]);
96
            }
97
        }
98
    }
99
100
    /**
101
     * @test
102
     */
103
    public function testTightConfig() {
104
        $expectedClass = new \Tight\TightConfig($this->config);
105
        $app = new \Tight\Tight($this->config);
106
        $this->assertEquals($expectedClass, $app->getConfig());
107
        unset($app);
108
        $app = new \Tight\Tight;
109
        $app->setConfig($this->config);
110
        $this->assertEquals($expectedClass,$app->getConfig());
111
    }
112
113
    /**
114
     * @test
115
     * @covers Tight\Tight::getRouter
116
     */
117
    public function testTightGetRouter() {
118
        $router = $this->app->getRouter();
119
        $this->assertEquals(new \Tight\Router($this->config["basePath"]), $router);
120
    }
121
122
    /**
123
     * @test
124
     */
125
    public function testTightGetSmarty() {
126
        $expected = new \Smarty;
127
        $this->assertEquals($expected->template_dir, $this->app->getSmarty()->template_dir);
128
        $this->assertEquals($expected->compile_dir, $this->app->getSmarty()->compile_dir);
129
        $this->assertEquals($expected->cache_dir, $this->app->getSmarty()->cache_dir);
130
        $this->assertEquals($expected->config_dir, $this->app->getSmarty()->config_dir);
131
    }
132
133
    /**
134
     * @test
135
     */
136
    public function testTightGetLocale() {
137
        $expected = new \Tight\Modules\Localize\Localize;
138
        $this->assertEquals($expected, $this->app->getLocale());
139
    }
140
141
}
142