示例#1
0
 public function setStrict($checks)
 {
     $dbName = \Civi\Test::dsn('database');
     if ($checks) {
         $queries = array("USE {$dbName};", "SET global innodb_flush_log_at_trx_commit = 1;", "SET SQL_MODE='STRICT_ALL_TABLES';", "SET foreign_key_checks = 1;");
     } else {
         $queries = array("USE {$dbName};", "SET foreign_key_checks = 0", "SET SQL_MODE='STRICT_ALL_TABLES';", "SET global innodb_flush_log_at_trx_commit = 2;");
     }
     foreach ($queries as $query) {
         if (\Civi\Test::execute($query) === FALSE) {
             throw new RuntimeException("Query failed: {$query}");
         }
     }
     return $this;
 }
示例#2
0
 /**
  * Create a builder for the headless environment.
  *
  * @return \Civi\Test\CiviEnvBuilder
  *
  * @code
  * \Civi\Test::headless()->apply();
  * \Civi\Test::headless()->sqlFile('ex.sql')->apply();
  * @endCode
  */
 public static function headless()
 {
     $civiRoot = dirname(__DIR__);
     $builder = new \Civi\Test\CiviEnvBuilder('CiviEnvBuilder');
     $builder->callback(function ($ctx) {
         if (CIVICRM_UF !== 'UnitTests') {
             throw new \RuntimeException("\\Civi\\Test::headless() requires CIVICRM_UF=UnitTests");
         }
         $dbName = \Civi\Test::dsn('database');
         echo "Installing {$dbName} schema\n";
         \Civi\Test::schema()->dropAll();
     }, 'headless-drop')->sqlFile($civiRoot . "/sql/civicrm.mysql")->sql("DELETE FROM civicrm_extension")->callback(function ($ctx) {
         \Civi\Test::data()->populate();
     }, 'populate');
     return $builder;
 }
示例#3
0
 /**
  * Determine if there's been a change in the preferred configuration.
  * If the preferred-configuration matches the last test, keep it. Otherwise,
  * destroy and recreate.
  *
  * @param bool $force
  *   Forcibly execute the build, even if the configuration hasn't changed.
  *   This will slow-down the tests, but it may be appropriate for some very sloppy
  *   tests.
  * @return $this
  */
 public function apply($force = FALSE)
 {
     $dbName = \Civi\Test::dsn('database');
     $query = "USE {$dbName};" . "CREATE TABLE IF NOT EXISTS civitest_revs (name VARCHAR(64) PRIMARY KEY, rev VARCHAR(64));";
     if (\Civi\Test::execute($query) === FALSE) {
         throw new \RuntimeException("Failed to flag schema version: {$query}");
     }
     $this->assertValid();
     if (!$force && $this->getSavedSignature() === $this->getTargetSignature()) {
         return $this;
     }
     foreach ($this->steps as $step) {
         $step->run($this);
     }
     $this->setSavedSignature($this->getTargetSignature());
     return $this;
 }