Completed
Push — master ( 205cf7...842449 )
by Arnold
02:56
created

DateExtensionTest::localDateTimeProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Jasny\Twig;
4
5
/**
6
 * @covers Jasny\Twig\DateExtension
7
 */
8
class DateExtensionTest extends \PHPUnit_Framework_TestCase
9
{
10
    public static function setUpBeforeClass()
11
    {
12
        date_default_timezone_set('UTC');
13
        \Locale::setDefault("en_EN");
14
    }
15
    
16 View Code Duplication
    protected 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...
17
    {
18
        $loader = new \Twig_Loader_Array(array(
19
            'template' => $template,
20
        ));
21
        
22
        $twig = new \Twig_Environment($loader);
23
        $twig->addExtension(new DateExtension());
24
        return $twig;
25
    }
26
    
27
    protected function process($template, $data = array())
28
    {
29
        $twig = $this->buildEnv($template);
30
        $result = $twig->render('template', $data);
31
        
32
        return $result;
33
    }
34
    
35
    public function localDateTimeProvider()
36
    {
37
        return [
38
            ['9/20/2015', "{{ '20-09-2015'|localdate() }}"],
39
            ['September 20, 2015', "{{ '20-09-2015'|localdate('long') }}"],
40
            ['9/20/15', "{{ '20-09-2015'|localdate('short') }}"],
41
            ['11:14 PM', "{{ '23:14:12'|localtime() }}"],
42
            ['11:14:12 PM GMT', "{{ '23:14:12'|localtime('long') }}"],
43
            ['11:14 PM', "{{ '23:14:12'|localtime('short') }}"]
44
        ];
45
    }
46
    
47
    /**
48
     * @dataProvider localDateTimeProvider
49
     * 
50
     * @param string $expected
51
     * @param string $template
52
     */
53
    public function testLocalDateTime($expected, $template)
54
    {
55
        $result = $this->process($template);
56
        
57
        $this->assertEquals($expected, $result);
58
    }
59
}
60