Ignore:
Timestamp:
Aug 26, 2015, 8:14:40 PM (11 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
master
Children:
b38cc03
Parents:
8f38d1e
Message:
  • Finished setup
    • Added tests for setup
    • Added translation to setup
File:
1 moved

Legend:

Unmodified
Added
Removed
  • src/webservice/tests/StationsTest.php

    r8f38d1e r8c356c1  
    1919*/
    2020
    21 class TestStations extends PHPUnit_Framework_TestCase
     21class StationsTest extends PHPUnit_Framework_TestCase
    2222{
    23         protected $config;
    24 
    2523    protected function setUp()
    2624    {
    27                 $file = "webtests/webservice/testconfig/testconfig.php";
     25                $file = __DIR__ ."/testconfig/testconfig.php";
    2826                $this->assertFileExists($file);
    2927                require($file);
    30                 $this->config = $testconfig;
    31                 $this->assertNotNull($this->config);
     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);
    3235    }
    3336
    3437        public function testEmptyStations()
    3538        {
    36                 $this->queryEmptyStationList($this->config["webserviceUrl"]);
     39                $stations = $this->query("index.php/stations");
     40
     41                $this->assertInternalType("array", $stations);
     42                $this->assertEquals(count($stations), 0);
    3743        }
    3844       
    3945        public function testStationRewrite()
    4046        {
    41                 $this->queryEmptyStationList($this->config["webserviceUrlRewrite"]);
     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);
    4255        }
    4356       
    44         protected function queryEmptyStationList($url){
    45                 $this->assertInternalType('string', $url ."/");
     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));
    4663                $client = new GuzzleHttp\Client
    4764                (
    4865                        [
    49                                 "base_uri" => $url,
     66                                "base_uri" => $baseUrl,
    5067                                "timeout" => 2.0,
     68                                "http_errors" => false,
    5169                        ]
    5270                );
    53                 $response = $client->get("index.php/stations");
     71                $response = $client->get($url);
    5472                $this->assertNotNull($response);
    5573                $this->assertEquals($response->getStatusCode(), 200);
    … …  
    5876                $body = $response->getBody();
    5977                $this->assertTrue(!empty($body));
    60                 $stations = json_decode($body);
    61                 $this->assertNotNull($stations);
    62                 $this->assertInternalType("array", $stations);
    63                 $this->assertEquals(count($stations), 0);
     78                $json = json_decode($body);
     79                $this->assertNotNull($json);
     80                return $json;
    6481        }
     82       
     83        protected $_testconfig;
     84        protected $_webserviceConfig;
    6585}
    6686?>
Note: See TracChangeset for help on using the changeset viewer.