ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
EventTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
23
24require_once __DIR__ . "/../../../../vendor/composer/vendor/autoload.php";
25
31class EventTest extends TestCase
32{
33 //protected $backupGlobals = false;
34
35 protected function setUp(): void
36 {
38 $GLOBALS['DIC'] = $dic;
39
40 if (!defined("ILIAS_LOG_ENABLED")) {
41 define("ILIAS_LOG_ENABLED", false);
42 }
43
44 parent::setUp();
45
46 $db_mock = $this->createMock(ilDBInterface::class);
47 $db_mock->method("fetchAssoc")
48 ->will(
49 $this->onConsecutiveCalls(
50 [
51 "component" => "components/ILIAS/EventHandling",
52 "id" => "MyTestComponent"
53 ],
54 null
55 )
56 );
57
58
59 $this->setGlobalVariable(
60 "ilDB",
61 $db_mock
62 );
63 $this->setGlobalVariable(
64 "ilSetting",
65 $this->createMock(ilSetting::class)
66 );
67 $component_repository = $this->createMock(ilComponentRepository::class);
68 $this->setGlobalVariable(
69 "component.repository",
70 $component_repository
71 );
72 $component_factory = $this->createMock(ilComponentFactory::class);
73 $this->setGlobalVariable(
74 "component.factory",
75 $component_factory
76 );
77 }
78
83 protected function setGlobalVariable(string $name, $value): void
84 {
85 global $DIC;
86
87 $GLOBALS[$name] = $value;
88
89 unset($DIC[$name]);
90 $DIC[$name] = static function (Container $c) use ($value) {
91 return $value;
92 };
93 }
94
95 protected function tearDown(): void
96 {
97 }
98
99 protected function getHandler(): ilAppEventHandler
100 {
101 $logger = $this->createMock(ilLogger::class);
102
103 return new ilAppEventHandler($logger);
104 }
105
109 public function testEvent(): void
110 {
111 $handler = $this->getHandler();
112
113 $this->expectException(ilEventHandlingTestException::class);
114
115 $handler->raise(
116 "components/ILIAS/EventHandling",
117 "myEvent",
118 [
119 "par1" => "val1",
120 "par2" => "val2"
121 ]
122 );
123 }
124}
Test clipboard repository.
Definition: EventTest.php:32
getHandler()
Definition: EventTest.php:99
setGlobalVariable(string $name, $value)
Definition: EventTest.php:83
testEvent()
Test event.
Definition: EventTest.php:109
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Global event handler.
$c
Definition: deliver.php:25
$dic
Definition: ltiresult.php:33
$handler
Definition: oai.php:29
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54