Completed
Push — develop ( 058245...bd9d6f )
by Narcotic
12s
created

testCustomerCreateDateFilteringIndex()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 14

Duplication

Lines 42
Ratio 100 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
dl 42
loc 42
rs 8.8571
c 3
b 1
f 1
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
/**
3
 * Test cases for basic coverage for Analytics Bundle
4
 */
5
namespace Graviton\AnalyticsBundle\Tests\Controller;
6
7
use Symfony\Component\Routing\Router;
8
9
use Graviton\TestBundle\Test\RestTestCase;
10
11
/**
12
 * Basic functional test for Analytics
13
 *
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class DefaultControllerTest extends RestTestCase
19
{
20
    /** @var Router */
21
    private $router;
22
23
    /**
24
     * Initial setup
25
     * @return void
26
     */
27
    public function setUp()
28
    {
29
        $this->router = $this->getContainer()->get('router');
30
31
        $this->loadFixtures(
32
            array(
33
                'Graviton\CoreBundle\DataFixtures\MongoDB\LoadAppData',
34
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadLanguageData',
35
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadMultiLanguageData',
36
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadTranslatableData',
37
                'Graviton\I18nBundle\DataFixtures\MongoDB\LoadTranslatablesApp',
38
                'GravitonDyn\CustomerBundle\DataFixtures\MongoDB\LoadCustomerData',
39
            ),
40
            null,
41
            'doctrine_mongodb'
42
        );
43
    }
44
45
    /**
46
     * Testing basic functionality
47
     * @return void
48
     */
49 View Code Duplication
    public function testIndex()
50
    {
51
        $client = static::createClient();
52
53
        // Let's get information from the schema
54
        $client->request('GET', '/analytics/schema/app');
55
        $content = $client->getResponse()->getContent();
56
        $schema = json_decode($content);
57
58
        // Check schema
59
        $sampleSchema = json_decode(
60
            '{
61
                    "title": "Application usage",
62
                    "description": "Data use for application access",
63
                    "type": "object",
64
                    "representation": "pie",
65
                    "properties": {
66
                      "id": {
67
                        "title": "ID",
68
                        "description": "Unique identifier",
69
                        "type": "string"
70
                      },
71
                      "count": {
72
                        "title": "count",
73
                        "description": "Sum of result",
74
                        "type": "integer"
75
                      }
76
                    }
77
                  }'
78
        );
79
        $this->assertEquals($sampleSchema, $schema);
80
81
        // Let's get information from the count
82
        $client->request('GET', '/analytics/app');
83
        $content = $client->getResponse()->getContent();
84
        $data = json_decode($content);
85
86
        // Counter data result of aggregate
87
        $sampleData = json_decode('{"_id":"app-count","count":2}');
88
        $this->assertEquals($sampleData, $data);
89
    }
90
91
    /**
92
     * Testing basic functionality
93
     * @return void
94
     */
95
    public function testApp2Index()
96
    {
97
        $client = static::createClient();
98
99
        // Let's get information from the count
100
        $client->request('GET', '/analytics/app2');
101
        $content = $client->getResponse()->getContent();
102
        $data = json_decode($content);
103
104
        // Counter data result of aggregate
105
        $sampleData = json_decode('{"_id":"app-count-2","count":1}');
106
        $this->assertEquals($sampleData, $data);
107
    }
108
109
    /**
110
     * Testing basic functionality
111
     * @return void
112
     */
113 View Code Duplication
    public function testCustomerCreateDateFilteringIndex()
114
    {
115
        $client = static::createClient();
116
117
        // Let's get information from the count
118
        $client->request('GET', '/analytics/customer-created-by-date');
119
        $content = $client->getResponse()->getContent();
120
        $data = json_decode($content);
121
122
        // Counter data result of aggregate
123
        $sampleData = json_decode(
124
            '[
125
              {
126
                "_id": "100",
127
                "customerNumber": 1100,
128
                "name": "Acme Corps.",
129
                "created_year": 2014,
130
                "created_month": 7
131
              }
132
            ]'
133
        );
134
        $this->assertEquals($sampleData, $data);
135
136
        // Let's get information from the count, but cached version
137
        $client->request('GET', '/analytics/customer-created-by-date');
138
        $content = $client->getResponse()->getContent();
139
        $data = json_decode($content);
140
141
        // Counter data result of aggregate
142
        $sampleData = json_decode(
143
            '[
144
              {
145
                "_id": "100",
146
                "customerNumber": 1100,
147
                "name": "Acme Corps.",
148
                "created_year": 2014,
149
                "created_month": 7
150
              }
151
            ]'
152
        );
153
        $this->assertEquals($sampleData, $data);
154
    }
155
}
156