예제 #1
0
 /**
  * function will create a temporary batchmake config, copying over test data
  * to the the locations in that config needed for the tests, returning an
  * array of config property names to directory locations.
  *
  * @todo figure out a way to copy over Batchmake or else mock it
  * @return array
  * @throws Zend_Exception
  */
 public function setupAndGetConfig()
 {
     // create a test batchmake setup in the temp dir
     // and initialize test data
     $tmpDir = $this->getTempDirectory();
     $subDirs = array('batchmake', 'tests');
     KWUtils::createSubDirectories($tmpDir . '/', $subDirs);
     $configProps = array(MIDAS_BATCHMAKE_TMP_DIR_PROPERTY => $tmpDir . '/batchmake/tests/tmp', MIDAS_BATCHMAKE_BIN_DIR_PROPERTY => $tmpDir . '/batchmake/tests/bin', MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY => $tmpDir . '/batchmake/tests/script', MIDAS_BATCHMAKE_APP_DIR_PROPERTY => $tmpDir . '/batchmake/tests/bin', MIDAS_BATCHMAKE_DATA_DIR_PROPERTY => $tmpDir . '/batchmake/tests/data', MIDAS_BATCHMAKE_CONDOR_BIN_DIR_PROPERTY => $tmpDir . '/batchmake/tests/condorbin');
     // now make sure these dirs exist
     // later can actually add some stuff to these dirs
     foreach ($configProps as $dir) {
         if (!file_exists($dir) && !KWUtils::mkDir($dir)) {
             throw new Zend_Exception("couldn't create dir " . $dir);
         }
     }
     // now copy over the bms files
     $srcDir = BASE_PATH . 'modules/batchmake/tests/testfiles/script';
     $targetDir = $configProps[MIDAS_BATCHMAKE_SCRIPT_DIR_PROPERTY];
     $extension = '.bms';
     $this->symlinkFileset($srcDir, $targetDir, $extension);
     // and now the bmms
     $srcDir = BASE_PATH . 'modules/batchmake/tests/testfiles/bin';
     $targetDir = $configProps[MIDAS_BATCHMAKE_APP_DIR_PROPERTY];
     $extension = '.bmm';
     $this->symlinkFileset($srcDir, $targetDir, $extension);
     // the mock object strategy requires both an interface and for
     // executable files to exist on disk in a particular location,
     // so here we will create symlinks to a known executable
     // ls
     // which should be on most systems
     $params = array('ls');
     $cmd = KWUtils::prepareExeccommand('which', $params);
     // dir doesn't matter, just send in srcDir as it is convenient
     KWUtils::exec($cmd, $output, $srcDir, $returnVal);
     if ($returnVal !== 0 || !isset($output) || !isset($output[0])) {
         throw new Zend_Exception('Problem finding ls on your system, used for testing');
     }
     $pathToLs = $output[0];
     // get the applications and their path properties from the component that
     // expects them
     $applicationsPaths = Batchmake_KWBatchmakeComponent::getApplicationsPaths();
     foreach ($applicationsPaths as $application => $pathProperty) {
         // now in the place of each executable, symlink the ls exe
         $link = $configProps[$pathProperty] . '/' . $application;
         if (!file_exists($link) && !symlink($pathToLs, $link)) {
             throw new Zend_Exception($pathToLs . ' could not be sym-linked to ' . $link);
         }
     }
     return $configProps;
 }
예제 #2
0
 /**
  * Create a task.
  *
  * @param UserDao $userDao
  * @param string $tmpWorkDirRoot
  * @return Batchmake_TaskDao
  * @throws Zend_Exception
  */
 public function createTask($userDao, $tmpWorkDirRoot)
 {
     if (!$userDao instanceof UserDao) {
         throw new Zend_Exception('Error parameters.');
     }
     /** @var Batchmake_TaskDao $task */
     $task = MidasLoader::newDao('TaskDao', 'batchmake');
     $task->setUserId($userDao->getKey());
     $this->save($task);
     $userId = $task->getUserId();
     $taskId = $task->getKey();
     $subdirs = array(MIDAS_BATCHMAKE_SSP_DIR, $userId, $taskId);
     // create a workDir based on the task and user
     $workDir = KWUtils::createSubDirectories($tmpWorkDirRoot . '/', $subdirs);
     $task->setWorkDir($workDir);
     $this->save($task);
     return $task;
 }
예제 #3
0
 /** tests createSubDirectories function */
 public function testCreateSubDirectories()
 {
     // test creating directories, do this in the tmp dir
     //
     // create a nested set of directories
     $tmpDir = UtilityComponent::getTempDirectory();
     $subDirs = array('KWUtilsTest', '1', '2', '3');
     $outDir = KWUtils::createSubDirectories($tmpDir . '/', $subDirs);
     // now check that all the subdirs have been created
     // according to what we wanted
     $this->assertFileExists($tmpDir);
     // and what we got back
     $this->assertFileExists($outDir);
     $currDir = $tmpDir;
     foreach ($subDirs as $subdir) {
         $currDir = $currDir . '/' . $subdir;
         $this->assertFileExists($currDir);
         $this->assertTrue(is_dir($currDir));
     }
     $topDir = UtilityComponent::getTempDirectory() . '/KWUtilsTest';
     KWUtils::recursiveRemoveDirectory($topDir);
 }