JsDataTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 72
rs 10
c 0
b 0
f 0

6 Methods

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