ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SubscriberRepositoryTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 public function testSubscribersCanBeRetrieved(): void
26 {
27 $user = $this->getMockBuilder(ilObjUser::class)->onlyMethods(['getId'])->disableOriginalConstructor()->getMock();
28 $user->method('getId')->willReturn(1);
29 $db = $this->createMock(ilDBInterface::class);
30 $resultMock = $this->createMock(ilDBStatement::class);
31
32 $consecutive = ['FROM osc_activity', 'FROM osc_messages'];
33 $db->expects($this->exactly(2))
34 ->method('queryF')
35 ->with(
36 $this->callback(function ($value) use (&$consecutive) {
37 $this->assertStringContainsString(array_shift($consecutive), $value);
38 return true;
39 }),
40 $this->isType('array'),
41 $this->isType('array')
42 )
43 ->willReturn($resultMock);
44
45 $db->expects($this->once())
46 ->method('query')
47 ->with($this->stringContains('FROM osc_conversation'))
48 ->willReturn($resultMock);
49
50 $db->expects($this->exactly(10))->method('fetchAssoc')->with($resultMock)->willReturnOnConsecutiveCalls(
51 ['conversation_id' => '1'],
52 ['conversation_id' => '2'],
53 null,
54 ['conversation_id' => '1'],
55 ['conversation_id' => '3'],
56 null,
57 ['participants' => json_encode([['id' => 1], ['id' => 2], ['id' => 3]], JSON_THROW_ON_ERROR)],
58 ['participants' => json_encode([['id' => 1], ['id' => 4]], JSON_THROW_ON_ERROR)],
59 ['participants' => json_encode([['id' => 1], ['id' => 6]], JSON_THROW_ON_ERROR)],
60 null,
61 );
62
63 $repository = new class ($db, $user) extends Subscriber {
64 public function getDataByUserIds(array $usrIds): array
65 {
66 $data = [];
67 foreach ($usrIds as $usrId) {
68 $data[$usrId] = [
69 'public_name' => 'User ' . $usrId,
70 'profile_image' => 'Image ' . $usrId
71 ];
72 }
73
74 return $data;
75 }
76 };
77
78 $profile_data = $repository->getInitialUserProfileData();
79 $this->assertCount(5, $profile_data);
80 }
81}
Class ilOnScreenChatBaseTest.