Completed
Pull Request — develop (#605)
by
unknown
14:48
created

DefaultControllerTest::testIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
/**
3
 * Test cases for basic coverage for ProxyApi Bundle
4
 */
5
namespace Graviton\ProxyApiBundle\Tests\Controller;
6
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\Routing\Router;
9
10
use Graviton\TestBundle\Test\RestTestCase;
11
12
/**
13
 * Basic functional test for ProxyApi
14
 *
15
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
16
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
17
 * @link     http://swisscom.ch
18
 */
19
class DefaultControllerTest extends RestTestCase
20
{
21
    /**
22
     * Testing basic functionality
23
     * Api to Weather station, json response
24
     * @return void
25
     */
26
    public function testIndex()
27
    {
28
        $client = static::createClient();
29
30
        // Let's get information from the schema
31
        $client->request('GET', '/proxy/');
32
        $content = $client->getResponse()->getContent();
33
        $services = json_decode($content, true);
34
35
        $this->assertArrayHasKey('weather', $services, '');
36
        $this->assertArrayHasKey('weather-by-city', $services, '');
37
        $this->assertArrayHasKey('weather-swiss', $services, '');
38
    }
39
    /**
40
     * Testing basic functionality
41
     * Api to Weather station, json response
42
     * @return void
43
     */
44 View Code Duplication
    public function testProxyWithParams()
45
    {
46
        $client = static::createClient();
47
48
        // Lets get graviton version, core is or endpoint in test config for weather api
49
        $client->request('GET', '/proxy/weather/weather?q=London,uk');
50
        $content = $client->getResponse()->getContent();
51
        $weather = json_decode($content, true);
52
53
        $this->assertArrayHasKey('coord', $weather, '');
54
        $this->assertArrayHasKey('weather', $weather, '');
55
        $this->assertArrayHasKey('name', $weather, '');
56
        $this->assertEquals('London', $weather['name'], '');
57
    }
58
59
    /**
60
     * Testing basic functionality
61
     * Api to Weather station, limit query params and convert
62
     * @return void
63
     */
64 View Code Duplication
    public function testProxyQueryParamsLimit()
65
    {
66
        $client = static::createClient();
67
68
        // Lets get graviton version, core is or endpoint in test config for weather api
69
        $client->request('GET', '/proxy/weather-by-city?city=London&country=uk');
70
        $content = $client->getResponse()->getContent();
71
        $weather = json_decode($content, true);
72
73
        $this->assertArrayHasKey('coord', $weather, '');
74
        $this->assertArrayHasKey('weather', $weather, '');
75
        $this->assertArrayHasKey('name', $weather, '');
76
        $this->assertEquals('London', $weather['name'], '');
77
    }
78
79
    /**
80
     * Testing basic functionality
81
     * Api to Weather station, limit query params and convert
82
     * @return void
83
     */
84
    public function testProxyQueryParamsLimitMeteoTest()
85
    {
86
        $client = static::createClient();
87
88
        // ZURICH Lets get graviton version, core is or endpoint in test config for weather api
89
        $client->request('GET', '/proxy/weather-swiss/ortswetter?city=Zurich');
90
        $content = $client->getResponse()->getContent();
91
        $weather = json_decode($content, true);
92
93
        $this->assertArrayHasKey('currentWeather', $weather, '');
94
        $this->assertArrayHasKey('tt', $weather['currentWeather'], '');
95
        $this->assertArrayHasKey('prognose', $weather, '');
96
        $this->assertArrayHasKey('mtLocation', $weather, '');
97
        $this->assertArrayHasKey('name', $weather['mtLocation'], '');
98
        $this->assertEquals('Zurich', $weather['mtLocation']['name'], '');
99
100
101
        // BERN Lets get graviton version, core is or endpoint in test config for weather api
102
        $client->request('GET', '/proxy/weather-swiss/ortswetter?city=Bern');
103
        $content = $client->getResponse()->getContent();
104
        $weather = json_decode($content, true);
105
        
106
        $this->assertEquals('Bern', $weather['mtLocation']['name'], '');
107
    }
108
}
109