configuration = $configuration; if (self::$nextInsertID === null) { // Generate test IDs into a distant ID space to reduce the risk of // collisions and make them distinctive. self::$nextInsertID = 55555000000 + mt_rand(0, 1000); } $this->transactionKey = 'iso-xaction-'.(self::$nextTransactionKey++); } public function escapeString($string) { return ''; } public function escapeColumnName($name) { return ''; } public function escapeMultilineComment($comment) { return ''; } public function escapeStringForLikeClause($value) { return ''; } private function getConfiguration($key, $default = null) { return idx($this->configuration, $key, $default); } public function getInsertID() { return $this->insertID; } public function getAffectedRows() { return $this->affectedRows; } protected function getTransactionKey() { return $this->transactionKey; } public function selectAllResults() { return $this->allResults; } public function executeRawQuery($raw_query) { // NOTE: "[\s<>K]*" allows any number of (properly escaped) comments to // appear prior to the allowed keyword, since this connection escapes // them as "" (above). $keywords = array( 'INSERT', 'UPDATE', 'DELETE', 'START', 'SAVEPOINT', 'COMMIT', 'ROLLBACK', ); $preg_keywords = array(); foreach ($keywords as $key => $word) { $preg_keywords[] = preg_quote($word, '/'); } $preg_keywords = implode('|', $preg_keywords); if (!preg_match('/^[\s<>K]*('.$preg_keywords.')\s*/i', $raw_query)) { $doc_uri = PhabricatorEnv::getDoclink('article/Writing_Unit_Tests.html'); throw new Exception( "Database isolation currently only supports some queries. For more ". "information, see <{$doc_uri}>. You are trying to issue a query which ". "does not begin with an allowed keyword ". "(".implode(', ', $keywords)."): '".$raw_query."'"); } $this->transcript[] = $raw_query; // NOTE: This method is intentionally simplified for now, since we're only // using it to stub out inserts/updates. In the future it will probably need // to grow more powerful. $this->allResults = array(); // NOTE: We jitter the insert IDs to keep tests honest; a test should cover // the relationship between objects, not their exact insertion order. This // guarantees that IDs are unique but makes it impossible to hard-code tests // against this specific implementation detail. $this->insertID = (self::$nextInsertID += mt_rand(1, 10)); $this->affectedRows = 1; } public function getQueryTranscript() { return $this->transcript; } }