[mapguide-commits] r8224 - sandbox/jng/v30/UnitTest/WebTier/Php
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Sun Jun 15 04:14:08 PDT 2014
Author: jng
Date: 2014-06-15 04:14:08 -0700 (Sun, 15 Jun 2014)
New Revision: 8224
Added:
sandbox/jng/v30/UnitTest/WebTier/Php/UpdateDumpFiles.php
Modified:
sandbox/jng/v30/UnitTest/WebTier/Php/Utils.php
Log:
PHP test runner updates:
- Add an overwrite flag to Utils::CreateDumpFile()
- Add a new UpdateDumpFiles.php whose sole purpose is to update dump files from their respective dbs. This presents a simpler way of updating test database source without having to run the test runner through the whole suite in "generate" mode.
Added: sandbox/jng/v30/UnitTest/WebTier/Php/UpdateDumpFiles.php
===================================================================
--- sandbox/jng/v30/UnitTest/WebTier/Php/UpdateDumpFiles.php (rev 0)
+++ sandbox/jng/v30/UnitTest/WebTier/Php/UpdateDumpFiles.php 2014-06-15 11:14:08 UTC (rev 8224)
@@ -0,0 +1,74 @@
+<?php
+
+//
+// Copyright (C) 2004-2014 by Autodesk, Inc.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of version 2.1 of the GNU Lesser
+// General Public License as published by the Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+//Command line script that executes all tests in the given database files
+
+define('Run_MAIN_METHOD', true);
+require_once("sqlite_constants.php");
+require_once("Utils.php");
+main();
+
+function main()
+{
+ if (($_SERVER['argc'] >1) && ($_SERVER['argv'][1] == "-help"))
+ {
+ ShowUsage();
+ return 1;
+ }
+
+ $updatesFailed = 0;
+ $updatesFailed += UpdateDumpFile("../../TestData/ResourceService/ResourceServiceTest.db");
+ $updatesFailed += UpdateDumpFile("../../TestData/DrawingService/DrawingServiceTest.db");
+ $updatesFailed += UpdateDumpFile("../../TestData/FeatureService/FeatureServiceTest.db");
+ $updatesFailed += UpdateDumpFile("../../TestData/SiteService/SiteServiceTest.db");
+ $updatesFailed += UpdateDumpFile("../../TestData/MappingService/MappingServiceTest.db");
+ $updatesFailed += UpdateDumpFile("../../TestData/ServerAdmin/ServerAdminTest.db");
+ $updatesFailed += UpdateDumpFile("../../TestData/MapLayer/MapLayerTest.db");
+ $updatesFailed += UpdateDumpFile("../../TestData/WebLayout/WebLayoutTest.db");
+ $updatesFailed += UpdateDumpFile("../../TestData/Wfs/WfsTest.db");
+ $updatesFailed += UpdateDumpFile("../../TestData/Wms/WmsTest.db");
+ $updatesFailed += UpdateDumpFile("../../TestData/Unicode/UnicodeTest.db");
+
+ exit($updatesFailed);
+}
+
+function UpdateDumpFile($dbName)
+{
+ echo "Checking $dbName\n";
+ $ret = 0;
+ $db = NULL;
+ try {
+ $dbPath = Utils::GetPath($dbName);
+ $db = new SqliteDB();
+ $db->Open($dbPath);
+ Utils::CreateDumpFile($db, true);
+ } catch (SqliteException $ex) {
+ echo $ex->GetExceptionMessage()."\n";
+ $ret = 1;
+ }
+ $db = NULL;
+ return $ret;
+}
+
+function ShowUsage()
+{
+ printf("Usage: php UpdateDumpFiles.php\n");
+}
+
+?>
Modified: sandbox/jng/v30/UnitTest/WebTier/Php/Utils.php
===================================================================
--- sandbox/jng/v30/UnitTest/WebTier/Php/Utils.php 2014-06-15 02:07:23 UTC (rev 8223)
+++ sandbox/jng/v30/UnitTest/WebTier/Php/Utils.php 2014-06-15 11:14:08 UTC (rev 8224)
@@ -247,27 +247,50 @@
return $dbPath;
}
- public static function CreateDumpFile($db)
+ public static function CreateDumpFile($db, $overwrite = false)
{
$dbName = $db->GetName();
$iniFileName = substr($dbName, 0, strpos($dbName, ".db")).".ini";
$dumpFileName = substr($dbName, 0, strpos($dbName, ".db")).".dump";
- //Clear the stat cache as filemtime may not work correctly
- clearstatcache();
-
- //Check if the file exists and is writable before updating it
- if (!file_exists($dumpFileName) || (is_writable($dumpFileName)&&filemtime($db->GetName())>filemtime($dumpFileName)))
+ if ($overwrite)
{
+ if (file_exists($dumpFileName))
+ unlink($dumpFileName);
+
$iniFileContent =".output ".$dumpFileName;
file_put_contents($iniFileName, $iniFileContent);
$db->DumpDatabase($iniFileName);
- printf("<b>Updated dump file <i>%s</i></b>", $dumpFileName);
+ if (php_sapi_name() == 'cli')
+ printf("Updated dump file: %s\n", $dumpFileName);
+ else
+ printf("<b>Updated dump file <i>%s</i></b>", $dumpFileName);
unlink($iniFileName);
}
else
{
- printf("<b>Dump file <i>%s</i> already exists and is read only or is newer than the database. File has not been updated</b>", $dumpFileName);
+ //Clear the stat cache as filemtime may not work correctly
+ clearstatcache();
+
+ //Check if the file exists and is writable before updating it
+ if (!file_exists($dumpFileName) || (is_writable($dumpFileName)&&filemtime($db->GetName())>filemtime($dumpFileName)))
+ {
+ $iniFileContent =".output ".$dumpFileName;
+ file_put_contents($iniFileName, $iniFileContent);
+ $db->DumpDatabase($iniFileName);
+ if (php_sapi_name() == 'cli')
+ printf("Updated dump file: %s\n", $dumpFileName);
+ else
+ printf("<b>Updated dump file <i>%s</i></b>", $dumpFileName);
+ unlink($iniFileName);
+ }
+ else
+ {
+ if (php_sapi_name() == 'cli')
+ printf("Dump file %s already exists and is read only or is newer than the database. File has not been updated\n", $dumpFileName);
+ else
+ printf("<b>Dump file <i>%s</i> already exists and is read only or is newer than the database. File has not been updated</b>", $dumpFileName);
+ }
}
}
}
More information about the mapguide-commits
mailing list