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)
Location:
src/webservice/tests
Files:
2 added
2 edited

Legend:

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

    r02fbeb8 rd55ec21  
    1919*/
    2020
     21require_once(__DIR__ ."/TestHelpers/TestSetup.php");
     22
    2123class SetupTest extends PHPUnit_Framework_TestCase
    2224{
    … …  
    3133
    3234                require_once($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
    33 
     35               
    3436                self::$_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
    3537                self::assertNotNull(self::$_webserviceConfig);
    … …  
    3840                self::assertInternaltype("string", self::$_dataDirectory);
    3941                self::assertTrue(!empty(self::$_dataDirectory));
     42                if(file_exists(self::$_dataDirectory))
     43                        self::assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
     44
    4045                self::assertTrue(!file_exists(self::$_dataDirectory));
    4146        }
    … …  
    4348        public static function tearDownAfterClass()
    4449        {
    45                 if(!file_exists(self::$_dataDirectory)){
    46                         return;
    47                 }
    48                 // clear data directory (not recursive, because there should be only a database file in it
    49                 $content = scandir(self::$_dataDirectory);
    50                 self::assertInternalType("array", $content);
    51                 foreach($content as $file){
    52                         if(!in_array($file, array(".",".."))){
    53                                 self::assertTrue(unlink(self::$_dataDirectory ."/". $file));
    54                         }
    55                 }
    56                
    57                 // remove datadirectory
    58                 self::assertTrue(rmdir(self::$_dataDirectory));
     50                if(file_exists(self::$_dataDirectory))
     51                        self::assertTrue(TestHelpers\TestSetup::wipeDataDirectory());
    5952        }
    6053
    … …  
    163156                $this->assertLessThan($versionSpatalite, 0, $prefix ." (Could not determine Spatalite version: ". $errorMessage .")");
    164157                $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
    165    }
     158        }
    166159   
    167    protected static $_webserviceConfig;
    168    protected static $_dataDirectory;
    169    protected static $_testconfig;
     160        protected static $_webserviceConfig;
     161        protected static $_dataDirectory;
     162        protected static $_testconfig;
    170163}
    171164?>
  • 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.