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

DateExtensionTest::testLocalTimeShort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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