summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Bridge.php13
-rw-r--r--test/BridgeTest.php20
2 files changed, 31 insertions, 2 deletions
diff --git a/src/Bridge.php b/src/Bridge.php
index 2afbd34..7f8996c 100644
--- a/src/Bridge.php
+++ b/src/Bridge.php
@@ -75,6 +75,19 @@ class Bridge {
return $rows;
}
+ public function reserveEditId($postId) {
+ throw_if_null($postId);
+
+ $sql = 'INSERT INTO posts (post_id) VALUES (' . $postId . ')';
+
+ $count = $this->db->exec($sql);
+ if ($count != 1) {
+ throw new Exception('Failed to register post id: ' . $postId);
+ }
+
+ return $this->db->lastInsertId();
+ }
+
public function registerMessage($postId, $messageId, $inReplyTo) {
throw_if_null($messageId);
diff --git a/test/BridgeTest.php b/test/BridgeTest.php
index 6c9ec01..b22d335 100644
--- a/test/BridgeTest.php
+++ b/test/BridgeTest.php
@@ -22,8 +22,8 @@ class BridgeTest extends PHPUnit_Framework_TestCase {
'message_id VARCHAR(255) NOT NULL, ' .
'in_reply_to VARCHAR(255), ' .
'edit_id MEDIUMINT NOT NULL AUTO_INCREMENT, ' .
- 'PRIMARY KEY (message_id), ' .
- 'UNIQUE KEY (edit_id), ' .
+ 'UNIQUE KEY (message_id), ' .
+ 'PRIMARY KEY (edit_id), ' .
'INDEX (post_id))'
);
@@ -94,6 +94,22 @@ class BridgeTest extends PHPUnit_Framework_TestCase {
array(1, '<20100302094228.33F0310091@charybdis.ellipsis.cx>', null),
);
}
+
+ /**
+ * @dataProvider providerReserveEditId
+ */
+ public function testReserveEditId($postId, $expected, $ex) {
+ if ($ex) $this->setExpectedException($ex);
+ $bridge = new Bridge($this->db);
+ $this->assertEquals($expected, $bridge->reserveEditId($postId));
+ }
+
+ public function providerReserveEditId() {
+ return array(
+ array(1, 2, null),
+ array(2, 3, null)
+ );
+ }
/**
* @dataProvider providerRegisterMessage