ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
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 ->willReturnOnConsecutiveCalls(
49 [
50 "component" => "components/ILIAS/EventHandling",
51 "id" => "MyTestComponent"
52 ],
53 null
54 );
55
56
57 $this->setGlobalVariable(
58 "ilDB",
59 $db_mock
60 );
61 $this->setGlobalVariable(
62 "ilSetting",
63 $this->createMock(ilSetting::class)
64 );
65 $component_repository = $this->createMock(ilComponentRepository::class);
66 $this->setGlobalVariable(
67 "component.repository",
68 $component_repository
69 );
70 $component_factory = $this->createMock(ilComponentFactory::class);
71 $this->setGlobalVariable(
72 "component.factory",
73 $component_factory
74 );
75 }
76
81 protected function setGlobalVariable(string $name, $value): void
82 {
83 global $DIC;
84
85 $GLOBALS[$name] = $value;
86
87 unset($DIC[$name]);
88 $DIC[$name] = static function (Container $c) use ($value) {
89 return $value;
90 };
91 }
92
93 protected function tearDown(): void
94 {
95 }
96
97 protected function getHandler(): ilAppEventHandler
98 {
99 $logger = $this->createMock(ilLogger::class);
100
101 return new ilAppEventHandler($logger);
102 }
103
107 public function testEvent(): void
108 {
109 $handler = $this->getHandler();
110
111 $this->expectException(ilEventHandlingTestException::class);
112
113 $handler->raise(
114 "components/ILIAS/EventHandling",
115 "myEvent",
116 [
117 "par1" => "val1",
118 "par2" => "val2"
119 ]
120 );
121 }
122}
Test clipboard repository.
Definition: EventTest.php:32
getHandler()
Definition: EventTest.php:97
setGlobalVariable(string $name, $value)
Definition: EventTest.php:81
testEvent()
Test event.
Definition: EventTest.php:107
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:31
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54