Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/storage/connection/isolated/AphrontIsolatedDatabaseConnection.php b/src/storage/connection/isolated/AphrontIsolatedDatabaseConnection.php
index 1f10af78b8..54081463b7 100644
--- a/src/storage/connection/isolated/AphrontIsolatedDatabaseConnection.php
+++ b/src/storage/connection/isolated/AphrontIsolatedDatabaseConnection.php
@@ -1,102 +1,102 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group storage
*/
class AphrontIsolatedDatabaseConnection extends AphrontDatabaseConnection {
private $configuration;
private static $nextInsertID;
private $insertID;
public function __construct(array $configuration) {
$this->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);
}
}
public function escapeString($string) {
return '<S>';
}
public function escapeColumnName($name) {
return '<C>';
}
public function escapeMultilineComment($comment) {
return '<K>';
}
public function escapeStringForLikeClause($value) {
return '<L>';
}
private function getConfiguration($key, $default = null) {
return idx($this->configuration, $key, $default);
}
public function getInsertID() {
return $this->insertID;
}
public function getAffectedRows() {
return $this->affectedRows;
}
public function getTransactionKey() {
return 'xaction'; // TODO, probably need to stub this better.
}
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 INSERT/UPDATE, since this connection escapes them
- // as "<K>" (above).
- if (!preg_match('/^[\s<>K]*(INSERT|UPDATE)\s*/i', $raw_query)) {
+ // appear prior to the INSERT/UPDATE/DELETE, since this connection escapes
+ // them as "<K>" (above).
+ if (!preg_match('/^[\s<>K]*(INSERT|UPDATE|DELETE)\s*/i', $raw_query)) {
$doc_uri = PhabricatorEnv::getDoclink('article/Writing_Unit_Tests.html');
throw new Exception(
- "Database isolation currently only supports INSERT and UPDATE ".
+ "Database isolation currently only supports INSERT, UPDATE and DELETE ".
"queries. For more information, see <{$doc_uri}>. You are trying to ".
- "issue a query which does not begin with INSERT or UPDATE: ".
+ "issue a query which does not begin with INSERT, UPDATE or DELETE: ".
"'".$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;
}
}
diff --git a/src/storage/connection/isolated/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php b/src/storage/connection/isolated/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php
index 60c045ee75..5df4a3caad 100644
--- a/src/storage/connection/isolated/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php
+++ b/src/storage/connection/isolated/__tests__/AphrontIsolatedDatabaseConnectionTestCase.php
@@ -1,77 +1,82 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class AphrontIsolatedDatabaseConnectionTestCase
extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
// We disable this here because this test is unique (it is testing that
// isolation actually occurs) and must establish a live connection to the
// database to verify that.
self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK => false,
);
}
public function testIsolation() {
$conn = $this->newIsolatedConnection();
$test_phid = 'PHID-TEST-'.Filesystem::readRandomCharacters(20);
queryfx(
$conn,
'INSERT INTO phabricator_phid.phid (phid) VALUES (%s)',
$test_phid);
try {
$real_phid = id(new PhabricatorPHID())->loadOneWhere(
'phid = %s',
$test_phid);
$this->assertEqual(
null,
$real_phid,
'Expect fake PHID to exist only in isolation.');
} catch (AphrontQueryConnectionException $ex) {
// If we can't connect to the database, conclude that the isolated
// connection actually is isolated. Philosophically, this perhaps allows
// us to claim this test does not depend on the database?
}
}
public function testInsertGeneratesID() {
$conn = $this->newIsolatedConnection();
queryfx($conn, 'INSERT');
$id1 = $conn->getInsertID();
queryfx($conn, 'INSERT');
$id2 = $conn->getInsertID();
$this->assertEqual(true, (bool)$id1, 'ID1 exists.');
$this->assertEqual(true, (bool)$id2, 'ID2 exists.');
$this->assertEqual(
true,
$id1 != $id2,
"IDs '{$id1}' and '{$id2}' are distinct.");
}
+ public function testDeletePermitted() {
+ $conn = $this->newIsolatedConnection();
+ queryfx($conn, 'DELETE');
+ }
+
private function newIsolatedConnection() {
$config = array();
return new AphrontIsolatedDatabaseConnection($config);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 15, 9:22 AM (17 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
337749
Default Alt Text
(6 KB)

Event Timeline