| [1c92d58] | 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 |
|
|---|
| [8c356c1] | 21 | class StationsTest extends PHPUnit_Framework_TestCase
|
|---|
| [1c92d58] | 22 | {
|
|---|
| 23 | protected function setUp()
|
|---|
| 24 | {
|
|---|
| [8c356c1] | 25 | $file = __DIR__ ."/testconfig/testconfig.php";
|
|---|
| [1c92d58] | 26 | $this->assertFileExists($file);
|
|---|
| 27 | require($file);
|
|---|
| [8c356c1] | 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);
|
|---|
| [1c92d58] | 35 | }
|
|---|
| 36 |
|
|---|
| 37 | public function testEmptyStations()
|
|---|
| 38 | {
|
|---|
| [8c356c1] | 39 | $stations = $this->query("index.php/stations");
|
|---|
| 40 |
|
|---|
| 41 | $this->assertInternalType("array", $stations);
|
|---|
| 42 | $this->assertEquals(count($stations), 0);
|
|---|
| [1c92d58] | 43 | }
|
|---|
| 44 |
|
|---|
| 45 | public function testStationRewrite()
|
|---|
| 46 | {
|
|---|
| [8c356c1] | 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);
|
|---|
| [1c92d58] | 55 | }
|
|---|
| 56 |
|
|---|
| [8c356c1] | 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));
|
|---|
| [1c92d58] | 63 | $client = new GuzzleHttp\Client
|
|---|
| 64 | (
|
|---|
| 65 | [
|
|---|
| [8c356c1] | 66 | "base_uri" => $baseUrl,
|
|---|
| [1c92d58] | 67 | "timeout" => 2.0,
|
|---|
| [8c356c1] | 68 | "http_errors" => false,
|
|---|
| [1c92d58] | 69 | ]
|
|---|
| 70 | );
|
|---|
| [8c356c1] | 71 | $response = $client->get($url);
|
|---|
| [1c92d58] | 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));
|
|---|
| [8c356c1] | 78 | $json = json_decode($body);
|
|---|
| 79 | $this->assertNotNull($json);
|
|---|
| 80 | return $json;
|
|---|
| [1c92d58] | 81 | }
|
|---|
| [8c356c1] | 82 |
|
|---|
| 83 | protected $_testconfig;
|
|---|
| 84 | protected $_webserviceConfig;
|
|---|
| [1c92d58] | 85 | }
|
|---|
| 86 | ?>
|
|---|