summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruckelman <uckelman@nomic.net>2010-04-11 13:31:09 +0000
committeruckelman <uckelman@nomic.net>2010-04-11 13:31:09 +0000
commit33a97aa2acceadc777140579fa0c32bcbcdd7781 (patch)
treea243b271cf2ae65a08ae971c7f20a7b41db64ece
parentebae8d0e6a988599242d359b53fb09f3dde89867 (diff)
Refactoring.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6641 67b53d14-2c14-4ace-a08f-0dab2b34000c
-rw-r--r--src/Bridge.php27
-rw-r--r--test/BridgeTest.php27
2 files changed, 29 insertions, 25 deletions
diff --git a/src/Bridge.php b/src/Bridge.php
index 63d4ff0..9cbc64f 100644
--- a/src/Bridge.php
+++ b/src/Bridge.php
@@ -28,19 +28,16 @@ class Bridge {
return $row['message_id'];
}
- public function registerMessage($postId, $messageId, $inReplyTo, $refs) {
- $sql = 'INSERT INTO posts ' .
- '(post_id, message_id, in_reply_to, refs) ' .
- 'VALUES (' . $postId . ', '
- . $this->db->quote($messageId) . ', '
- . $this->db->quote($inReplyTo) . ', '
- . $this->db->quote($refs) . ')';
+ public function setPostId($messageId, $postId) {
+ $sql = 'UPDATE posts SET ' .
+ 'post_id = ' . $postId .
+ 'WHERE message_id = ' . $this->db->quote($messageId);
$count = $this->db->exec($sql);
if ($count != 1) {
trigger_error(
- 'Failed to register message: ' . $messageId, E_USER_ERROR
+ 'Failed to set post id: ' . $messageId, E_USER_ERROR
);
}
}
@@ -53,15 +50,19 @@ class Bridge {
return $row['forum_id'];
}
- public function setMessageIdIfAbsent($messageId) {
+ public function registerMessage($messageId, $inReplyTo, $refs) {
if ($messageId === null) {
- trigger_error('messageId === null', E_USER_ERROR);
- }
+ trigger_error('message id is null', E_USER_ERROR);
+ }
- $sql = 'INSERT IGNORE INTO posts (message_id) VALUES (' .
- $this->db->quote($messageId) . ')';
+ $sql = 'INSERT IGNORE INTO posts ' .
+ '(message_id, in_reply_to, refs) ' .
+ 'VALUES (' . $this->db->quote($messageId) . ', '
+ . $this->db->quote($inReplyTo) . ', '
+ . $this->db->quote($refs) . ')';
$count = $this->db->exec($sql);
+
return $count == 1;
}
diff --git a/test/BridgeTest.php b/test/BridgeTest.php
index 309a959..b646683 100644
--- a/test/BridgeTest.php
+++ b/test/BridgeTest.php
@@ -96,19 +96,20 @@ class BridgeTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider providerRegisterMessage
*/
- public function testRegisterMessage($postId, $messageId, $inReplyTo, $refs,
+ public function testRegisterMessage($messageId, $inReplyTo, $refs,
$expected, $ex) {
if ($ex) $this->setExpectedException($ex);
$bridge = new Bridge($this->db);
- $bridge->registerMessage($postId, $messageId, $inReplyTo, $refs);
+ $this->assertEquals(
+ $expected,
+ $bridge->registerMessage($messageId, $inReplyTo, $refs)
+ );
}
public function providerRegisterMessage() {
return array(
array('bogus', null, null, null, null, 'PDOException'),
- array(1, '', '', '', null, 'PDOException'),
array(
- 2,
'<20100302094228.33F0310091@charybdis.ellipsis.cx>',
null,
null,
@@ -116,11 +117,10 @@ class BridgeTest extends PHPUnit_Framework_TestCase {
'PDOException'
),
array(
- 2,
'<10100302094228.33F0310091@charybdis.ellipsis.cx>',
null,
null,
- null,
+ true,
null,
)
);
@@ -143,19 +143,22 @@ class BridgeTest extends PHPUnit_Framework_TestCase {
}
/**
- * @dataProvider providerSetMessageIdIfAbsent
+ * @dataProvider providerSetPostId
*/
- public function testSetMessageIdIfAbsent($messageId, $expected, $ex) {
+ public function testSetPostId($messageId, $postId, $ex) {
if ($ex) $this->setExpectedException($ex);
$bridge = new Bridge($this->db);
- $this->assertEquals($expected, $bridge->setMessageIdIfAbsent($messageId));
+
+ $bridge->setPostId($messageId, $postId);
+ $this->assertEquals($bridge->getPostId($messageId), $postId);
}
- public function providerSetMessageIdIfAbsent() {
+ public function providerSetPostId() {
return array(
array(null, null, 'PHPUnit_Framework_Error'),
- array('<20100302094228.33F0310091@charybdis.ellipsis.cx>', false, null),
- array('<10100302094228.33F0310091@charybdis.ellipsis.cx>', true, null),
+ array('<10100302094228.33F0310091@charybdis.ellipsis.cx>', null, 'PDOException'),
+ array('<20100302094228.33F0310091@charybdis.ellipsis.cx>', 2, null),
+ array('<20100302094228.33F0310091@charybdis.ellipsis.cx>', 3, null),
);
}
}