ILIAS  release_7 Revision v7.30-3-g800a261c036
IliasMocks.php
Go to the documentation of this file.
1<?php
2
3use ILIAS\UI\Factory as UIFactory;
6
7trait IliasMocks
8{
14 protected function mockUIFactory()
15 {
16 $ui_reflection = new ReflectionClass(UIFactory::class);
17 $methods = array_map(
18 function ($m) {
19 return $m->getName();
20 },
21 $ui_reflection->getMethods()
22 );
23
24 $ui_factory = $this->getMockBuilder(UIFactory::class)
25 ->setMethods($methods)
26 ->getMock();
27
28 $signal_generator = new SignalGenerator();
29 $ui_factory->method('button')
30 ->willReturn(new CImpl\Button\Factory());
31 $ui_factory->method('viewControl')
32 ->willReturn(new CImpl\ViewControl\Factory($signal_generator));
33 $ui_factory->method('breadcrumbs')
34 ->will(
35 $this->returnCallback(function ($crumbs) {
36 return new CImpl\Breadcrumbs\Breadcrumbs($crumbs);
37 })
38 );
39 $ui_factory->method('link')
40 ->willReturn(new CImpl\Link\Factory());
41 $ui_factory->method('symbol')
42 ->willReturn(new CImpl\Symbol\Factory(
43 new CImpl\Symbol\Icon\Factory(),
44 new CImpl\Symbol\Glyph\Factory(),
45 new CImpl\Symbol\Avatar\Factory()
46 ));
47
48 return $ui_factory;
49 }
50
51
52 public function uiFactoryBreadcrumbs()
53 {
54 $args = func_get_args();
55 return new CImpl\Breadcrumbs\Breadcrumbs($args[0]);
56 }
57
58
59 protected function mockIlLanguage()
60 {
61 $lng = $this->getMockBuilder(ilLanguage::class)
62 ->disableOriginalConstructor()
63 ->setMethods(['txt'])
64 ->getMock();
65 $lng->method('txt')
66 ->willReturn('');
67
68 return $lng;
69 }
70}
An exception for terminatinating execution or to throw for unit testing.
This is how the factory for UI elements looks.
Definition: Factory.php:18
$lng