Skip to content

Commit

Permalink
Add more thread denormalization unit test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jun 27, 2011
1 parent b074426 commit d1e5f89
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 1 addition & 3 deletions Document/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,11 @@ protected function greaterMessageTimestampForCondition(array $dates, \Closure $c
{
foreach ($this->getParticipants() as $participant) {
$participantId = $participant->getId();
$date = isset($dates[$participantId]) ? $dates[$participantId] : 0;
foreach ($this->getMessages() as $message) {
if ($condition($participantId, $message->getSender()->getId())) {
$date = max($date, $message->getTimestamp());
$dates[$participantId] = max(isset($dates[$participantId]) ? $dates[$participantId] : 0, $message->getTimestamp());
}
}
$dates[$participantId] = $date;
}

return $dates;
Expand Down
22 changes: 17 additions & 5 deletions Tests/Document/ThreadDenormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function testDenormalize()
$this->assertSame(array('u1' => $this->dates[2]->getTimestamp(), 'u2' => $this->dates[3]->getTimestamp()), $thread->getDatesOfLastMessageWrittenByOtherParticipant());
$this->assertSame(array('u1' => $this->dates[3]->getTimestamp(), 'u2' => $this->dates[2]->getTimestamp()), $thread->getDatesOfLastMessageWrittenByParticipant());

$this->assertEquals('test thread subject hi dude', $thread->getKeywords());
$this->assertSame(array('u1' => false, 'u2' => false), $thread->getIsDeletedByParticipant());
}

protected function createMessageMock($sender, $recipient, DateTime $date)
Expand All @@ -80,13 +82,13 @@ protected function createMessageMock($sender, $recipient, DateTime $date)
->method('getSender')
->will($this->returnValue($sender));
$message->expects($this->atLeastOnce())
->method('getRecipient')
->will($this->returnValue($recipient));
->method('getTimestamp')
->will($this->returnValue($date->getTimestamp()));
$message->expects($this->atLeastOnce())
->method('getCreatedAt')
->will($this->returnValue($date));
$message->expects($this->once())
->method('ensureIsReadByParticipant');
$message->expects($this->atLeastOnce())
->method('getBody')
->will($this->returnValue('hi dude'));

return $message;
}
Expand Down Expand Up @@ -117,6 +119,16 @@ public function getDatesOfLastMessageWrittenByOtherParticipant()
return $this->datesOfLastMessageWrittenByOtherParticipant;
}

public function getKeywords()
{
return $this->keywords;
}

public function getIsDeletedByParticipant()
{
return $this->isDeletedByParticipant;
}

public function addMessage(MessageInterface $message)
{
parent::addMessage($message);
Expand Down

0 comments on commit d1e5f89

Please sign in to comment.