Пример #1
0
 /**
  * Builds a system db for the test environment
  * 
  * @todo This replicates some code in Command/System/Build - needs to be much more DRY
  */
 protected function buildTestSystemDatabase()
 {
     // Load the Meshing_Test_Paths class
     $projectRoot = Meshing_Utils::getProjectRoot();
     require_once $projectRoot . '/tests/unit/Meshing_Test_Paths.php';
     Meshing_Utils::reinitialise(new Meshing_Test_Paths());
     $paths = Meshing_Utils::getPaths();
     // Build a system connection file
     $task = new Meshing_Propel_ConfBuilder();
     $task->addSchemas($projectRoot . $paths->getPathDbConfig(), $paths->getLeafStandardSchema());
     $task->setXmlFile($projectRoot . $paths->getFileRuntimeXml());
     $task->setPropelConnection(Meshing_Utils::CONN_SYSTEM_TEST);
     $task->setOutputDir($projectRoot . $paths->getPathConnsSystem());
     $task->setOutputFile($paths->getLeafRuntimePhp());
     $task->run();
     // Build the SQL for a test system database
     $task = new Meshing_Propel_SqlBuilder();
     $task->addSchemas($projectRoot . $paths->getPathDbConfig(), $paths->getLeafStandardSchema());
     $task->setOutputDir($projectRoot . $paths->getPathSqlSystem());
     $task->setPropelConnection(Meshing_Utils::CONN_SYSTEM_TEST);
     $task->run();
     // Run the sql
     $task = new Meshing_Propel_SqlRunner();
     $task->setSqlDir($projectRoot . $paths->getPathSqlSystem());
     $task->setMapFile($projectRoot . $paths->getFileDbMap());
     $task->setPropelConnection(Meshing_Utils::CONN_SYSTEM_TEST);
     $task->run();
 }
Пример #2
0
 protected function useVersionStrategy()
 {
     $paths = Meshing_Utils::getPaths();
     $strategy = new Meshing_Hash_Strategy_Version($this->conNode);
     $paths->setHashProvider($strategy);
     $this->clearProviderCache();
     return $strategy;
 }
Пример #3
0
 /**
  * Testing syncing node 1 containing a few rows with node 2, which is empty 
  */
 public function testSimpleSync1()
 {
     // Set up data in node 1
     $fixtures = $this->projectRoot . Meshing_Utils::getPaths()->getFixturesPath();
     $data = (require_once $fixtures . '/simpleSync1.php');
     $dbUtils = new Meshing_Database_Utils();
     $dbUtils->writeVersionableData($data, $this->node1, $this->conNode);
     // @todo Sync data into node 2 here :)
 }
Пример #4
0
 /**
  * Takes an XML config file and converts it to PHP config files
  * 
  * @param string $runTime Full pathname of the XML config file
  * @param string $outputDir Path of the output directory
  * @param string $outputFile Base leafname of the output PHP file
  */
 protected function convertConf($runTime, $outputDir, $outputFile)
 {
     $schemaDir = $this->projectRoot . Meshing_Utils::getPaths()->getPathDbConfig();
     $schemas = "schema.xml";
     $task = new Meshing_Propel_ConfBuilder();
     $task->addSchemas($schemaDir, $schemas);
     $task->setXmlFile($runTime);
     $task->setOutputDir($outputDir);
     $task->setOutputFile($outputFile);
     $task->setPropelConnection();
     $task->run();
 }
Пример #5
0
 /**
  * Specify which connection on which to carry out the schema task
  * 
  * @param strings $connName Optional connection name (defaults to system connection)
  */
 public function setPropelConnection($connName = Meshing_Utils::SYSTEM_CONNECTION)
 {
     // Grab the db details directly out of the Propel config file
     $xmlPath = Meshing_Utils::getProjectRoot() . Meshing_Utils::getPaths()->getFileRuntimeXml();
     $conf = simplexml_load_file($xmlPath);
     /* @var $conf SimpleXMLElement */
     $entry = $conf->xpath('/config/propel/datasources/datasource[@id="' . $connName . '"]');
     // If an element doesn't exist here, we've probably got the connection name wrong
     if (!array_key_exists(0, $entry)) {
         throw new Exception("Connection name '{$connName}' not found");
     }
     $entry = $entry[0];
     $this->setDatabaseCredentials((string) $entry->adapter, (string) $entry->connection->dsn, (string) $entry->connection->user, (string) $entry->connection->password);
 }
Пример #6
0
 protected function deleteDirectories()
 {
     $projectRoot = Meshing_Utils::getProjectRoot();
     $schemaDir = $projectRoot . Meshing_Utils::getPaths()->getPathSchemasNodes() . '/' . $this->opts->name;
     $modelDir = $projectRoot . Meshing_Utils::getPaths()->getPathModelsNodes() . '/' . $this->opts->name;
     echo "Done.\n";
     $ok = @rmdir($schemaDir);
     $ok = $ok && @rmdir($modelDir);
     if (!$ok) {
         echo "Not (yet) deleting empty dirs. Please run these, if safe:\n";
         echo "rm -rf " . $schemaDir . "\n";
         echo "rm -rf " . $modelDir . "\n";
     }
 }
Пример #7
0
 protected static function readCommands($incHidden = false)
 {
     static $commands = array();
     static $hidden = array();
     if (!$commands) {
         $projectRoot = Meshing_Utils::getProjectRoot();
         $consoleRoot = $projectRoot . Meshing_Utils::getPaths()->getPathMeshingCommands();
         $directory = new RecursiveDirectoryIterator($consoleRoot);
         $iterator = new RecursiveIteratorIterator($directory);
         $regex = new RegexIterator($iterator, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH);
         $regex->next();
         $i++;
         while ($regex->valid()) {
             // For safety!
             if ($i > 50) {
                 break;
             }
             // Get the full pathname of the class
             $item = $regex->current();
             $item = $item[0];
             // Strip out the full path bit, and generally tidy
             $item = str_replace($consoleRoot . DIRECTORY_SEPARATOR, '', $item);
             $item = str_replace('.php', '', $item);
             $className = 'Meshing_Console_Command_' . str_replace(DIRECTORY_SEPARATOR, '_', $item);
             $item = strtolower(str_replace(DIRECTORY_SEPARATOR, ':', $item));
             // Classes without this method are not commands at all
             $realCommand = method_exists($className, 'getDescription');
             // We consult a special method to determine whether to show the command
             if ($realCommand) {
                 $cmdClass = new $className();
                 $commands[$className] = $item;
                 if ($cmdClass->isHiddenCommand()) {
                     $hidden[] = $className;
                 }
             }
             $regex->next();
         }
         // Preserve the keys when sorting
         asort($commands);
     }
     // Strip out hidden commands
     if (!$incHidden) {
         foreach ($hidden as $removeClass) {
             unset($commands[$removeClass]);
         }
     }
     return $commands;
 }
Пример #8
0
 /**
  * Initialisation for all tests
  * 
  * We're using the constructor rather than setUp() as the latter is called once
  * per test, and we want an init to be called once for all tests here.
  */
 public function __construct($package, $label = false)
 {
     parent::__construct($label);
     $this->package = $package;
     $this->projectRoot = realpath(dirname(__FILE__) . '/../../..');
     $this->paths = Meshing_Utils::getPaths();
     $this->schemaDir = $this->projectRoot . $this->paths->getPathTestSchema();
     $this->outputSchemaDir = $this->projectRoot . $this->paths->getPathSchemasNodes() . '/' . $package;
     $this->schemas = 'test_schema1.xml';
     $this->modelDir = $this->projectRoot . $this->paths->getPathModelsNodes();
     $this->sqlDir = $this->projectRoot . $this->paths->getPathSqlNodes() . '/' . $package;
     $this->connSystemDir = $this->projectRoot . $this->paths->getPathConnsSystem();
     $this->connNodeDir = $this->projectRoot . $this->paths->getPathConnsNodes($package);
     // These all use the package name as a subfolder (the model one is done by Propel)
     $this->deleteFolderContents($this->outputSchemaDir, 'schema');
     $this->deleteFolderContents($this->modelDir . '/' . $package, 'model');
     $this->deleteFolderContents($this->sqlDir, 'sql');
     // This is common to all db tests (note also: the system dir contains the node dir)
     $this->deleteFolderContents($this->connSystemDir, 'connections');
     $this->createSchemaDir($this->outputSchemaDir);
 }
Пример #9
0
 public function testMaxContention()
 {
     // If Windows, we can't test
     if (substr(PHP_OS, 0, 3) == 'WIN') {
         user_error("Can't currently test locking on the Windows platform", E_USER_WARNING);
         return;
     }
     // Append errors to this log file
     $logDir = Meshing_Utils::getProjectRoot() . Meshing_Utils::getPaths()->getTestLogPath();
     $childCount = 10;
     for ($id = 0; $id < $childCount; $id++) {
         $command = 'php "' . __FILE__ . '" ' . CHILD_TOKEN . ' ' . $id;
         $background = '>> ' . $logDir . '/' . LOCKING_TEST_LOG . ' 2>&1 &';
         $return = null;
         $output = system($command . ' ' . $background, $return);
         // @todo Need to find a way to detect if the process launch failed
         // (no $output is returned even if errors are output to stdout)
         if ($output === false) {
             user_error('There was a problem executing a background task', E_USER_WARNING);
             break;
         }
     }
     // Wait for all children to finish
     $iter = 0;
     $okCount = null;
     do {
         sleep(1);
         $iter++;
         $completed = $this->allChildrenFinished($childCount, $okCount);
         // Time limit
         if ($iter > 20 && !$completed) {
             user_error("Time limit expired, but only {$okCount} of {$childCount} children finished", E_USER_WARNING);
             break;
         }
     } while (!$completed);
     $this->assertEqual($okCount, $childCount, 'Check that all inserts have completed without race condition problems');
 }
Пример #10
0
 protected function createConf()
 {
     $paths = Meshing_Utils::getPaths();
     $configName = $paths->getLeafRuntimePhp();
     $this->convertConf($this->projectRoot . $paths->getFileRuntimeXml(), $this->projectRoot . $paths->getPathConnsNodes($this->opts->name), $configName);
     // We only want the autoloading file, not the connections file... deleting to be tidy!
     $configPath = $this->projectRoot . Meshing_Utils::getPaths()->getPathConnsNodes($this->opts->name) . '/' . $configName;
     @unlink($configPath);
 }
Пример #11
0
 public function testCreateChangeTables()
 {
     $paths = Meshing_Utils::getPaths();
     $snippetsPath = Meshing_Utils::getProjectRoot() . $paths->getPathSystemSnippets();
     $tables = $this->xml->getTables();
     $changeTables = $this->xml->createChangeTables($snippetsPath . '/change_table.xml', $tables);
     $this->assertEqual(count($tables), count($changeTables), 'Ensure there is a change table for each real table');
     // @todo Check that the prefix is the same for each change table
     // @todo Check that the FKs in each change table are mapped to current table PK equivs
 }
Пример #12
0
 public function __construct($inFilename, $outFilename)
 {
     $this->xml = simplexml_load_file($inFilename, 'Meshing_Schema_Element');
     $this->filename = $outFilename;
     $this->snippetDir = Meshing_Utils::getProjectRoot() . Meshing_Utils::getPaths()->getPathSystemSnippets();
 }
Пример #13
0
 /**
  * Gets an instance of the hashing object
  * 
  * It is possible that Meshing will connect to several connections, either in a production
  * nodeset where several databases are in use, or in testing. To ensure our provider uses
  * the right connection, we cache hash providers per connection.
  * 
  * @staticvar Meshing_Hash_Base $hashProvider
  * @param PropelPDO $con
  * @return Meshing_Hash_Base
  */
 protected function getHashProvider(Meshing_Database_Connection $con)
 {
     $key = (string) $con;
     if (!array_key_exists($key, self::$hashProviders)) {
         self::$hashProviders[$key] = Meshing_Utils::getPaths()->getHashProvider($con);
     }
     return self::$hashProviders[$key];
 }
Пример #14
0
 protected function runFixtures($verbose)
 {
     $fixturesFile = $this->projectRoot . Meshing_Utils::getPaths()->getPathSystemFixtures() . '/fixtures.php';
     if (file_exists($fixturesFile)) {
         $runner = new Meshing_Propel_FixturesRunner($fixturesFile);
         $runner->run();
     }
 }
Пример #15
0
 /**
  * Runs the already-built SQL for the system db (deletes the existing system tables)
  * 
  * @todo This is similar to system:build, fix this?
  * 
  * @param string $projectRoot 
  */
 protected function runSql($projectRoot)
 {
     $sqlDir = $projectRoot . Meshing_Utils::getPaths()->getPathSqlNodes() . '/' . $this->opts->name;
     $mapFile = $projectRoot . Meshing_Utils::getPaths()->getFileDbMap();
     $task = new Meshing_Propel_SqlRunner();
     $task->setSqlDir($sqlDir);
     $task->setMapFile($mapFile);
     // Set build properties (@todo switch this to use setPropelConnection)
     $task->addProperty('propel.database', $this->connection->getAdaptor());
     $task->addProperty('propel.database.url', $this->connection->getCalculatedDsn());
     $task->addProperty('propel.database.user', $this->connection->getUsername());
     $task->addProperty('propel.database.password', $this->connection->getPassword());
     $task->run();
 }