Ignore:
Timestamp:
Sep 1, 2015, 4:45:03 PM (11 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
master
Children:
256102b
Parents:
02fbeb8
Message:
  • Improved testing execution of webservice related tests (they use the built in php webserver to create a test webservice instance)
File:
1 edited

Legend:

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

    r02fbeb8 rd55ec21  
    1919*/
    2020
    21 /**
    22         * @todo Reset database before this test is run
    23         */
     21require_once(__DIR__ ."/TestHelpers/TestSetup.php");
     22
    2423class StationsTest extends PHPUnit_Framework_TestCase
    2524{
    … …  
    3736                $this->_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
    3837                $this->assertNotNull($this->_webserviceConfig);
     38
     39                $this->_dataDirectory = $this->_webserviceConfig->getConfig("dataDirectory");
     40                $this->assertInternaltype("string", $this->_dataDirectory);
     41                $this->assertTrue(!empty($this->_dataDirectory));
     42                if(file_exists($this->_dataDirectory))
     43                        $this->assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
     44                $this->assertTrue(TestHelpers\TestSetup::databaseSetup());
     45    }
     46   
     47    protected function tearDown(){
     48                if(file_exists($this->_dataDirectory))
     49                        $this->assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
    3950    }
    4051
    … …  
    4455
    4556                $this->assertInternalType("array", $stations);
     57                $message = "";
     58                if(array_key_exists("message", $stations))
     59                        $message = $stations["message"];
     60                $this->assertTrue(!array_key_exists("result", $stations), $message);
    4661                $this->assertEquals(count($stations), 0);
    4762        }
    48        
    49         public function testStationRewrite()
    50         {
    51                 $stations = $this->query("stations");
    5263
    53                 $this->assertInternalType("array", $stations);
    54                 $this->assertEquals(count($stations), 0);
    55         }
    56        
    5764        public function testRegisterStationUnprovenLocation()
    5865        {
    59                 $baseUrl = $this->_webserviceConfig->webserviceBaseUrl();
     66                $baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl();
    6067                $this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl);
    6168                $this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl);
    … …  
    8289        public function testRegisterStation()
    8390        {
    84                 $baseUrl = $this->_webserviceConfig->webserviceBaseUrl();
     91                $baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl();
    8592                $this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl);
    8693                $this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl);
    … …  
    94101                );
    95102
    96                 // sending must failing register request, caused by unproven location
    97103                $response = $client->post("index.php/stations/register",
    98104                        [ "json" => ["name" => "My Weather Station", "city" => "Clausthal-Zellerfeld", "longitude" => 10.28152, "latitude" => 51.8281, "email" => "test@example.org"]]
    … …  
    113119       
    114120        protected function query($url){
    115                 $baseUrl = $this->_webserviceConfig->webserviceBaseUrl();
     121                $baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl();
    116122                $this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl);
    117123                $this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl);
    … …  
    138144        protected $_testconfig;
    139145        protected $_webserviceConfig;
     146        protected $_dataDirectory;
    140147}
    141148?>
Note: See TracChangeset for help on using the changeset viewer.