Changeset d55ec21 for src/webservice/tests
- Timestamp:
- Sep 1, 2015, 4:45:03 PM (11 years ago)
- Branches:
- master
- Children:
- 256102b
- Parents:
- 02fbeb8
- Location:
- src/webservice/tests
- Files:
-
- 2 added
- 2 edited
-
SetupTest.php (modified) (5 diffs)
-
StationsTest.php (modified) (7 diffs)
-
TestHelpers/TestSetup.php (added)
-
bootstrap.php (added)
Legend:
- Unmodified
- Added
- Removed
-
src/webservice/tests/SetupTest.php
r02fbeb8 rd55ec21 19 19 */ 20 20 21 require_once(__DIR__ ."/TestHelpers/TestSetup.php"); 22 21 23 class SetupTest extends PHPUnit_Framework_TestCase 22 24 { … … 31 33 32 34 require_once($testconfig["webserviceDirectory"] ."/inc/envsetup.php"); 33 35 34 36 self::$_webserviceConfig = new SiWeather\Webservice\WebserviceConfig(); 35 37 self::assertNotNull(self::$_webserviceConfig); … … 38 40 self::assertInternaltype("string", self::$_dataDirectory); 39 41 self::assertTrue(!empty(self::$_dataDirectory)); 42 if(file_exists(self::$_dataDirectory)) 43 self::assertTrue(TestHelpers\TestSetup::wipeDataDirectory()); 44 40 45 self::assertTrue(!file_exists(self::$_dataDirectory)); 41 46 } … … 43 48 public static function tearDownAfterClass() 44 49 { 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()); 59 52 } 60 53 … … 163 156 $this->assertLessThan($versionSpatalite, 0, $prefix ." (Could not determine Spatalite version: ". $errorMessage .")"); 164 157 $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty"); 165 }158 } 166 159 167 protected static $_webserviceConfig;168 protected static $_dataDirectory;169 protected static $_testconfig;160 protected static $_webserviceConfig; 161 protected static $_dataDirectory; 162 protected static $_testconfig; 170 163 } 171 164 ?> -
src/webservice/tests/StationsTest.php
r02fbeb8 rd55ec21 19 19 */ 20 20 21 /** 22 * @todo Reset database before this test is run 23 */ 21 require_once(__DIR__ ."/TestHelpers/TestSetup.php"); 22 24 23 class StationsTest extends PHPUnit_Framework_TestCase 25 24 { … … 37 36 $this->_webserviceConfig = new SiWeather\Webservice\WebserviceConfig(); 38 37 $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()); 39 50 } 40 51 … … 44 55 45 56 $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); 46 61 $this->assertEquals(count($stations), 0); 47 62 } 48 49 public function testStationRewrite()50 {51 $stations = $this->query("stations");52 63 53 $this->assertInternalType("array", $stations);54 $this->assertEquals(count($stations), 0);55 }56 57 64 public function testRegisterStationUnprovenLocation() 58 65 { 59 $baseUrl = $this->_webserviceConfig->webserviceBaseUrl();66 $baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl(); 60 67 $this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl); 61 68 $this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl); … … 82 89 public function testRegisterStation() 83 90 { 84 $baseUrl = $this->_webserviceConfig->webserviceBaseUrl();91 $baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl(); 85 92 $this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl); 86 93 $this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl); … … 94 101 ); 95 102 96 // sending must failing register request, caused by unproven location97 103 $response = $client->post("index.php/stations/register", 98 104 [ "json" => ["name" => "My Weather Station", "city" => "Clausthal-Zellerfeld", "longitude" => 10.28152, "latitude" => 51.8281, "email" => "test@example.org"]] … … 113 119 114 120 protected function query($url){ 115 $baseUrl = $this->_webserviceConfig->webserviceBaseUrl();121 $baseUrl = TestHelpers\TestSetup::webserviceTestBaseUrl(); 116 122 $this->assertInternalType('string', $baseUrl, "baseUrl is not of type string: ". $baseUrl); 117 123 $this->assertTrue(!empty($baseUrl), "baseUrl is empty: ". $baseUrl); … … 138 144 protected $_testconfig; 139 145 protected $_webserviceConfig; 146 protected $_dataDirectory; 140 147 } 141 148 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/siweather/chrome/site/your_project_logo.png)