source: src/webservice/tests/StationsTest.php@ 1e37648

Last change on this file since 1e37648 was 1e37648, checked in by Joachim Langenbach <joachim.langenbach@…>, 11 years ago
  • Rewrites are now working
    • Setup is now accessable via Slim too
    • Added 404 template to Slim app
  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[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]21class 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
[1e37648]31 require($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
[8c356c1]32 require_once($testconfig["webserviceDirectory"] ."/SiWeather/Webservice/WebserviceConfig.php");
33
34 $this->_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
35 $this->assertNotNull($this->_webserviceConfig);
[1c92d58]36 }
37
38 public function testEmptyStations()
39 {
[8c356c1]40 $stations = $this->query("index.php/stations");
41
42 $this->assertInternalType("array", $stations);
43 $this->assertEquals(count($stations), 0);
[1c92d58]44 }
45
46 public function testStationRewrite()
47 {
[1e37648]48 $stations = $this->query("stations");
[8c356c1]49
50 $this->assertInternalType("array", $stations);
51 $this->assertEquals(count($stations), 0);
[1c92d58]52 }
53
[8c356c1]54 protected function query($url){
[1e37648]55 $baseUrl = $this->_webserviceConfig->webserviceBaseUrl();
56 $this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl);
57 $this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl);
[1c92d58]58 $client = new GuzzleHttp\Client
59 (
60 [
[8c356c1]61 "base_uri" => $baseUrl,
[1c92d58]62 "timeout" => 2.0,
[8c356c1]63 "http_errors" => false,
[1c92d58]64 ]
65 );
[8c356c1]66 $response = $client->get($url);
[1e37648]67 $this->assertNotNull($response, "Response is empty. Url: ". $baseUrl . $url);
68 $this->assertEquals($response->getStatusCode(), 200, "Status code != 200. Url: ". $baseUrl . $url);
69 $this->assertEquals($response->getReasonPhrase(), "OK", "Reason phrase not empty. Url: ". $baseUrl . $url);
[1c92d58]70
71 $body = $response->getBody();
[1e37648]72 $this->assertTrue(!empty($body), "Response body is empty. Url: ". $baseUrl . $url);
[8c356c1]73 $json = json_decode($body);
[1e37648]74 $this->assertNotNull($json, "Json decode returned null. Url: ". $baseUrl . $url ."\nBody: ". $body);
[8c356c1]75 return $json;
[1c92d58]76 }
[8c356c1]77
78 protected $_testconfig;
79 protected $_webserviceConfig;
[1c92d58]80}
81?>
Note: See TracBrowser for help on using the repository browser.