Completed
Push — master ( 6e8cf0...77c5a1 )
by Tijs
13s
created

JsDataTest::testCorrectConstruction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SumoCoders\FrameworkCoreBundle\Tests\Service;
4
5
use SumoCoders\FrameworkCoreBundle\Service\JsData;
6
7
class JsDataTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var JsData
11
     */
12
    private $jsData;
13
14
    /**
15
     * @inherit
16
     */
17
    protected function setUp()
18
    {
19
        $this->jsData = new JsData($this->getRequestStack());
20
    }
21
22
    /**
23
     * @inherit
24
     */
25
    protected function tearDown()
26
    {
27
        $this->jsData = null;
28
    }
29
30
    /**
31
     * @return \PHPUnit_Framework_MockObject_MockObject
32
     */
33
    protected function getRequestStack()
34
    {
35
        $currentRequest = $this->getMock('\Symfony\Component\HttpFoundation\Request');
36
        $currentRequest->method('getLocale')
37
            ->will(
38
                $this->returnValue('nl')
39
            );
40
41
        $requestStack = $this->getMock('\Symfony\Component\HttpFoundation\RequestStack');
42
        $requestStack->method('getCurrentRequest')
43
            ->will(
44
                $this->returnValue(
45
                    $currentRequest
46
                )
47
            );
48
49
        return $requestStack;
50
    }
51
52
    /**
53
     * Test jsData->get()
54
     */
55
    public function testGet()
56
    {
57
        // request is only parsed when fetching the data from the javascript
58
        (string) $this->jsData;
59
        $this->assertEquals('nl', $this->jsData->get('request')['locale']);
60
    }
61
62
    /**
63
     * Test jsData->parse()
64
     */
65
    public function testToString()
66
    {
67
        $var = (string) $this->jsData;
68
        $this->assertEquals('{"request":{"locale":"nl"}}', $var);
69
    }
70
71
    /**
72
     * This will check that the parent constructor is called
73
     */
74
    public function testCorrectConstruction()
75
    {
76
        self::assertEquals([], $this->jsData->all());
77
    }
78
}
79