Completed
Push — master ( 17df9a...99bd38 )
by Arnold
03:12
created

DateExtensionTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 52
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 1
dl 8
loc 52
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 4 1
A buildEnv() 8 8 1
A process() 0 5 1
A check() 0 4 1
A testLocalDate() 0 3 1
A testLocalDateLong() 0 3 1
A testLocalDateShort() 0 3 1
A testLocalTime() 0 3 1
A testLocalTimeLong() 0 3 1
A testLocalTimeShort() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Jasny\Twig;
4
5
use Jasny\Twig\DateExtension;
6
7
class DateExtensionTest extends PHPUnit_Framework_TestCase {
8
9
    public static function setUpBeforeClass() {
10
        parent::setUpBeforeClass();
11
        Locale::setDefault("en_CA");
12
    }
13
    
14 View Code Duplication
    private function buildEnv($template) {
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...
15
        $loader = new Twig_Loader_Array(array(
16
            'template' => $template,
17
        ));
18
        $twig = new Twig_Environment($loader);
19
        $twig->addExtension(new DateExtension());
20
        return $twig;
21
    }
22
    
23
    private function process($template, $data = array()) {
24
        $twig = $this->buildEnv($template);
25
        $result = $twig->render('template', $data);
26
        return $result;
27
    }
28
    
29
    private function check($expected, $template) {
30
        $result = $this->process($template);
31
        $this->assertEquals($expected, $result);
32
    }
33
    
34
    public function testLocalDate() {
35
        $this->check('9/20/2015', "{{ '20-09-2015'|localdate() }}");
36
    }
37
38
    public function testLocalDateLong() {
39
        $this->check('September 20, 2015', "{{ '20-09-2015'|localdate('long') }}");
40
    }
41
42
    public function testLocalDateShort() {
43
        $this->check('9/20/15', "{{ '20-09-2015'|localdate('short') }}");
44
    }
45
46
    public function testLocalTime() {
47
        $this->check('11:14 PM', "{{ '23:14:12'|localtime() }}");
48
    }
49
50
    public function testLocalTimeLong() {
51
        $this->check('11:14:12 PM PDT', "{{ '23:14:12'|localtime('long') }}");
52
    }
53
54
    public function testLocalTimeShort() {
55
        $this->check('11:14 PM', "{{ '23:14:12'|localtime('short') }}");
56
    }
57
58
}
59