ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilChatroomAbstractTestBase.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use PHPUnit\Framework\TestCase;
23use PHPUnit\Framework\MockObject\MockObject;
24
25abstract 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
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}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
MockObject &ilChatroom $ilChatroomMock
MockObject &ilChatroomUser $ilChatroomUserMock
Class ilChatroomUser.
Class ilChatroom.
$c
Definition: deliver.php:25
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54