source: src/webservice/tests/StationsTest.php@ 8c356c1

Last change on this file since 8c356c1 was 8c356c1, checked in by Joachim Langenbach <joachim.langenbach@…>, 11 years ago
  • Finished setup
    • Added tests for setup
    • Added translation to setup
  • Property mode set to 100644
File size: 2.6 KB
Line 
1<?php
2/*
3 Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 MA 02110-1301 USA.
19*/
20
21class StationsTest extends PHPUnit_Framework_TestCase
22{
23 protected function setUp()
24 {
25 $file = __DIR__ ."/testconfig/testconfig.php";
26 $this->assertFileExists($file);
27 require($file);
28 $this->_testconfig = $testconfig;
29 $this->assertNotNull($this->_testconfig);
30
31 require_once($testconfig["webserviceDirectory"] ."/SiWeather/Webservice/WebserviceConfig.php");
32
33 $this->_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
34 $this->assertNotNull($this->_webserviceConfig);
35 }
36
37 public function testEmptyStations()
38 {
39 $stations = $this->query("index.php/stations");
40
41 $this->assertInternalType("array", $stations);
42 $this->assertEquals(count($stations), 0);
43 }
44
45 public function testStationRewrite()
46 {
47 $apiVersion = $this->_webserviceConfig->getConfig("webserviceApiVersion");
48 $this->assertInternalType('string', $apiVersion);
49 $this->assertTrue(!empty($apiVersion));
50
51 $stations = $this->query($apiVersion ."/stations");
52
53 $this->assertInternalType("array", $stations);
54 $this->assertEquals(count($stations), 0);
55 }
56
57 protected function query($url){
58 require(__DIR__ ."/../vendor/autoload.php");
59
60 $baseUrl = $this->_webserviceConfig->getConfig("webserviceBaseUrl");
61 $this->assertInternalType('string', $baseUrl);
62 $this->assertTrue(!empty($baseUrl));
63 $client = new GuzzleHttp\Client
64 (
65 [
66 "base_uri" => $baseUrl,
67 "timeout" => 2.0,
68 "http_errors" => false,
69 ]
70 );
71 $response = $client->get($url);
72 $this->assertNotNull($response);
73 $this->assertEquals($response->getStatusCode(), 200);
74 $this->assertEquals($response->getReasonPhrase(), "OK");
75
76 $body = $response->getBody();
77 $this->assertTrue(!empty($body));
78 $json = json_decode($body);
79 $this->assertNotNull($json);
80 return $json;
81 }
82
83 protected $_testconfig;
84 protected $_webserviceConfig;
85}
86?>
Note: See TracBrowser for help on using the repository browser.