ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilChatroomAbstractTestBase.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
25 abstract class ilChatroomAbstractTestBase extends TestCase
26 {
27  protected MockObject&ilChatroom $ilChatroomMock;
28  protected MockObject&ilChatroomUser $ilChatroomUserMock;
29  private ?Container $dic = null;
30 
31  protected function setUp(): void
32  {
33  global $DIC;
34 
35  $this->dic = is_object($DIC) ? clone $DIC : $DIC;
36 
37  $DIC = new Container();
38 
39  $this->setGlobalVariable(
40  'tpl',
41  $this->getMockBuilder(ilGlobalTemplateInterface::class)->getMock()
42  );
43 
44  parent::setUp();
45  }
46 
47  protected function tearDown(): void
48  {
49  global $DIC;
50 
51  $DIC = $this->dic;
52 
53  parent::tearDown();
54  }
55 
56  protected function createIlChatroomUserMock(): ilChatroomUser&MockObject
57  {
58  $this->ilChatroomUserMock = $this->getMockBuilder(ilChatroomUser::class)->disableOriginalConstructor()->onlyMethods(
59  ['getUserId', 'getUsername']
60  )->getMock();
61 
63  }
64 
65  protected function createGlobalIlDBMock(): ilDBInterface&MockObject
66  {
67  $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
68  $db->method('quote')->willReturnCallback(static fn($arg): string => "'" . $arg . "'");
69 
70  $this->setGlobalVariable('ilDB', $db);
71 
72  return $db;
73  }
74 
75  protected function setGlobalVariable(string $name, $value): void
76  {
77  global $DIC;
78 
79  $GLOBALS[$name] = $value;
80 
81  $DIC[$name] = (static fn(Container $c) => $GLOBALS[$name]);
82  }
83 }
MockObject &ilChatroomUser $ilChatroomUserMock
MockObject &ilChatroom $ilChatroomMock
$c
Definition: deliver.php:25
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$GLOBALS["DIC"]
Definition: wac.php:53
global $DIC
Definition: shib_login.php:26
Class ilChatroomUser.