Completed
Pull Request — master (#3)
by
unknown
23:36 queued 15:14
created

PluginTest::testConfigFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 13 and the first side effect is on line 11.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace VojtaSvoboda\TwigExtensions\Tests;
4
5
use App;
6
use Carbon\Carbon;
7
use PluginTestCase;
8
use Twig_Environment;
9
use Config;
10
11
require_once __DIR__ . '/../vendor/autoload.php';
12
13
class PluginTest extends PluginTestCase
14
{
15
    /**
16
     * Return Twig environment
17
     * 
18
     * @return Twig_Environment
19
     */
20
    private function getTwig()
21
    {
22
        return App::make('twig.environment');
23
    }
24
25 View Code Duplication
    public function testTemplateFromStringFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
26
    {
27
        $twig = $this->getTwig();
28
29
        $template = "{% set name = 'John' %}";
30
        $template .= '{{ include(template_from_string("Hello {{ name }}")) }}';
31
32
        $twigTemplate = $twig->createTemplate($template);
33
        $this->assertEquals($twigTemplate->render([]), 'Hello John');
34
    }
35
36 View Code Duplication
    public function testTruncateFilterForFive()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
37
    {
38
        $twig = $this->getTwig();
39
40
        $template = "{{ 'Gordon Freeman' | truncate(5) }}";
41
42
        $twigTemplate = $twig->createTemplate($template);
43
        $this->assertEquals($twigTemplate->render([]), 'Gordo...');
44
    }
45
46 View Code Duplication
    public function testTruncateFilterForDefault()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
47
    {
48
        $twig = $this->getTwig();
49
50
        $template = "{{ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' | truncate }}";
51
52
        $twigTemplate = $twig->createTemplate($template);
53
        $this->assertEquals($twigTemplate->render([]), 'Lorem ipsum dolor sit amet, co...');
54
    }
55
56 View Code Duplication
    public function testTruncateFilterWithSeparator()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
57
    {
58
        $twig = $this->getTwig();
59
60
        $template = "{{ 'Gordon Freeman' | truncate(5, false, '-') }}";
61
62
        $twigTemplate = $twig->createTemplate($template);
63
        $this->assertEquals($twigTemplate->render([]), 'Gordo-');
64
    }
65
66 View Code Duplication
    public function testWordWrapFilter()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
67
    {
68
        $twig = $this->getTwig();
69
70
        $template = "{{ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' | wordwrap(10) }}";
71
72
        $twigTemplate = $twig->createTemplate($template);
73
        $this->assertEquals($twigTemplate->render([]), "Lorem ipsu\nm dolor si\nt amet, co\nnsectetur \nadipiscing\n elit");
74
    }
75
76
    public function testShuffleFilter()
77
    {
78
        $twig = $this->getTwig();
0 ignored issues
show
Unused Code introduced by
$twig is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
79
80
        $template = "{{ [1, 2, 3] | shuffle }}";
0 ignored issues
show
Unused Code introduced by
$template is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
81
82
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
83
        $twigTemplate = $twig->createTemplate($template);
84
        $twigTemplate->render([]);
85
        */
86
    }
87
88
    public function testTimeDiffFunction()
89
    {
90
        $twig = $this->getTwig();
91
92
        $now = Carbon::now()->subMinute();
93
        $template = "{{ '" . $now->format('Y-m-d H:i:s') . "' | time_diff }}";
94
95
        $twigTemplate = $twig->createTemplate($template);
96
        $this->assertEquals($twigTemplate->render([]), '1 minute ago');
97
    }
98
99 View Code Duplication
    public function testStrftimeFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
100
    {
101
        $twig = $this->getTwig();
102
103
        $template = "{{ '2016-03-24 23:05' | strftime('%d.%m.%Y %H:%M:%S') }}";
104
105
        $twigTemplate = $twig->createTemplate($template);
106
        $this->assertEquals($twigTemplate->render([]), '24.03.2016 23:05:00');
107
    }
108
109 View Code Duplication
    public function testUppercaseFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
110
    {
111
        $twig = $this->getTwig();
112
113
        $template = "{{ 'Jack' | uppercase }}";
114
115
        $twigTemplate = $twig->createTemplate($template);
116
        $this->assertEquals($twigTemplate->render([]), 'JACK');
117
    }
118
119 View Code Duplication
    public function testLowercaseFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
120
    {
121
        $twig = $this->getTwig();
122
123
        $template = "{{ 'JACK' | lowercase }}";
124
125
        $twigTemplate = $twig->createTemplate($template);
126
        $this->assertEquals($twigTemplate->render([]), 'jack');
127
    }
128
129 View Code Duplication
    public function testUcfirstFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
130
    {
131
        $twig = $this->getTwig();
132
133
        $template = "{{ 'jack' | ucfirst }}";
134
135
        $twigTemplate = $twig->createTemplate($template);
136
        $this->assertEquals($twigTemplate->render([]), 'Jack');
137
    }
138
139 View Code Duplication
    public function testLcfirstFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
140
    {
141
        $twig = $this->getTwig();
142
143
        $template = "{{ 'JACK' | lcfirst }}";
144
145
        $twigTemplate = $twig->createTemplate($template);
146
        $this->assertEquals($twigTemplate->render([]), 'jACK');
147
    }
148
149 View Code Duplication
    public function testLtrimFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
150
    {
151
        $twig = $this->getTwig();
152
153
        $template = "{{ ' jack' | ltrim }}";
154
155
        $twigTemplate = $twig->createTemplate($template);
156
        $this->assertEquals($twigTemplate->render([]), 'jack');
157
    }
158
159 View Code Duplication
    public function testRtrimFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
160
    {
161
        $twig = $this->getTwig();
162
163
        $template = "{{ 'jack ' | rtrim }}";
164
165
        $twigTemplate = $twig->createTemplate($template);
166
        $this->assertEquals($twigTemplate->render([]), 'jack');
167
    }
168
169 View Code Duplication
    public function testStrRepeatFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
170
    {
171
        $twig = $this->getTwig();
172
173
        $template = "{{ ' best' | str_repeat(3) }}";
174
175
        $twigTemplate = $twig->createTemplate($template);
176
        $this->assertEquals($twigTemplate->render([]), ' best best best');
177
    }
178
179 View Code Duplication
    public function testPluralFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
180
    {
181
        $twig = $this->getTwig();
182
183
        $template = "{{ 'mail' | plural(count) }}";
184
185
        $twigTemplate = $twig->createTemplate($template);
186
        $this->assertEquals($twigTemplate->render([]), 'mails');
187
    }
188
189 View Code Duplication
    public function testStrpadFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
190
    {
191
        $twig = $this->getTwig();
192
193
        $template = "{{ 'test' | strpad(10) }}";
194
195
        $twigTemplate = $twig->createTemplate($template);
196
        $this->assertEquals($twigTemplate->render([]), '   test   ');
197
    }
198
199 View Code Duplication
    public function testLeftpadFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
200
    {
201
        $twig = $this->getTwig();
202
203
        $template = "{{ 'test' | leftpad(7) }}";
204
205
        $twigTemplate = $twig->createTemplate($template);
206
        $this->assertEquals($twigTemplate->render([]), '   test');
207
    }
208
209 View Code Duplication
    public function testRightpadFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
210
    {
211
        $twig = $this->getTwig();
212
213
        $template = "{{ 'test' | rightpad(7, 'o') }}";
214
215
        $twigTemplate = $twig->createTemplate($template);
216
        $this->assertEquals($twigTemplate->render([]), 'testooo');
217
    }
218
219 View Code Duplication
    public function testConfigFunction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
220
    {
221
        $twig = $this->getTwig();
222
223
        Config::set('app.custom.key', 'test value');
224
        $template = "{{ config('app.custom.key') }}";
225
226
        $twigTemplate = $twig->createTemplate($template);
227
        $this->assertEquals($twigTemplate->render([]), 'test value');
228
    }
229
}
230