Browse Source

Increase the test coverage and fix return of method

Signed-off-by: Vitor Mattos <vitor@php.rio>
pull/7939/head
Vitor Mattos 3 years ago
parent
commit
c0228e8c23
No known key found for this signature in database GPG Key ID: B7AB4B76A7CA7318
  1. 4
      lib/Chat/ChatManager.php
  2. 32
      tests/php/Chat/ChatManagerTest.php

4
lib/Chat/ChatManager.php

@ -814,10 +814,10 @@ class ChatManager {
return array_filter($comments, function (IComment $comment) {
if ($this->isSharedFile($comment->getMessage())) {
if (!$this->fileOfMessageExists($comment->getMessage())) {
return true;
return false;
}
}
return false;
return true;
});
}
}

32
tests/php/Chat/ChatManagerTest.php

@ -764,4 +764,36 @@ class ChatManagerTest extends TestCase {
[json_encode(['parameters' => ['share' => 1]]), true],
];
}
/**
* @dataProvider dataRemoveFileNotExists
*/
public function testRemoveFileNotExists(array $list, int $expectedCount): void {
// Transform text messages in instance of comment and mock with the message
foreach ($list as $key => $message) {
$list[$key] = $this->createMock(IComment::class);
$list[$key]->method('getMessage')
->willReturn($message);
$messageDecoded = json_decode($message, true);
if (isset($messageDecoded['parameters']['share']) && $messageDecoded['parameters']['share'] === 'notExists') {
$this->shareProvider->expects($this->once())
->method('getShareById')
->with('notExists')
->willThrowException(new ShareNotFound());
}
}
if (count($list) !== $expectedCount) {
}
$result = $this->chatManager->removeFileNotExists($list);
$this->assertCount($expectedCount, $result);
}
public function dataRemoveFileNotExists(): array {
return [
[[], 0],
[[json_encode(['parameters' => ['not a shared file']])], 1],
[[json_encode(['parameters' => ['share' => 'notExists']])], 0],
[[json_encode(['parameters' => ['share' => 1]])], 1],
];
}
}
Loading…
Cancel
Save