ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
EventTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
7 
13 class EventTest extends TestCase
14 {
15  //protected $backupGlobals = false;
16 
17  protected function setUp(): void
18  {
19  $dic = new ILIAS\DI\Container();
20  $GLOBALS['DIC'] = $dic;
21 
22  if (!defined("ILIAS_LOG_ENABLED")) {
23  define("ILIAS_LOG_ENABLED", false);
24  }
25 
26  parent::setUp();
27 
28  $db_mock = $this->createMock(ilDBInterface::class);
29  $db_mock->method("fetchAssoc")
30  ->will(
31  $this->onConsecutiveCalls(
32  [
33  "component" => "Services/EventHandling",
34  "id" => "MyTestComponent"
35  ],
36  null
37  )
38  );
39 
40 
41  $this->setGlobalVariable(
42  "ilDB",
43  $db_mock
44  );
45  $this->setGlobalVariable(
46  "ilSetting",
47  $this->createMock(ilSetting::class)
48  );
49  $component_repository = $this->createMock(ilComponentRepository::class);
50  $this->setGlobalVariable(
51  "component.repository",
52  $component_repository
53  );
54  $component_factory = $this->createMock(ilComponentFactory::class);
55  $this->setGlobalVariable(
56  "component.factory",
57  $component_factory
58  );
59  }
60 
65  protected function setGlobalVariable(string $name, $value): void
66  {
67  global $DIC;
68 
69  $GLOBALS[$name] = $value;
70 
71  unset($DIC[$name]);
72  $DIC[$name] = static function (Container $c) use ($value) {
73  return $value;
74  };
75  }
76 
77  protected function tearDown(): void
78  {
79  }
80 
81  protected function getHandler(): ilAppEventHandler
82  {
83  return new ilAppEventHandler();
84  }
85 
89  public function testEvent(): void
90  {
91  $handler = $this->getHandler();
92 
93  $this->expectException(ilEventHandlingTestException::class);
94 
95  $handler->raise(
96  "MyTestComponent",
97  "MyEvent",
98  [
99  "par1" => "val1",
100  "par2" => "val2"
101  ]
102  );
103  }
104 }
Global event handler.
$c
Definition: cli.php:38
Test clipboard repository.
Definition: EventTest.php:13
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
testEvent()
Test event.
Definition: EventTest.php:89
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
setGlobalVariable(string $name, $value)
Definition: EventTest.php:65
$dic
Definition: result.php:32
getHandler()
Definition: EventTest.php:81