ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
InitCtrlServiceTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2021 Thibeau Fuhrer <thf@studer-raimann.ch> Extended GPL, see docs/LICENSE */
6
7use PHPUnit\Framework\TestCase;
8use Psr\Http\Message\ServerRequestInterface;
10use ILIAS\HTTP\Services as HttpService;
11use ILIAS\Refinery\Factory as Refinery;
13
18final class InitCtrlServiceTest extends TestCase
19{
21 {
22 $dic = new Container();
23 // $dic['ilDB'] = $this->createMock(ilDBInterface::class);
24 $dic['http'] = $this->createMock(HttpService::class);
25
26 $this->expectException(ilCtrlException::class);
27 $this->expectExceptionMessage("Cannot initialize ilCtrl if Refinery Factory is not yet available.");
28 (new InitCtrlService())->init($dic);
29 }
30
32 {
33 $dic = new Container();
34 // $dic['ilDB'] = $this->createMock(ilDBInterface::class);
35 $dic['refinery'] = $this->createMock(Refinery::class);
36
37 $this->expectException(ilCtrlException::class);
38 $this->expectExceptionMessage("Cannot initialize ilCtrl if HTTP Services are not yet available.");
39 (new InitCtrlService())->init($dic);
40 }
41
42 // public function testCtrlServiceInitializationWithoutDatabase() : void
43 // {
44 // $dic = new Container();
45 // $dic['refinery'] = $this->createMock(Refinery::class);
46 // $dic['http'] = $this->createMock(HttpService::class);
47 //
48 // $this->expectException(ilCtrlException::class);
49 // $this->expectExceptionMessage("Cannot initialize ilCtrl if Database is not yet available.");
50 // (new InitCtrlService())->init($dic);
51 // }
52
54 {
55 $dic = new Container();
56 $dic['refinery'] = $this->createMock(Refinery::class);
57 // $dic['ilDB'] = $this->createMock(ilDBInterface::class);
58 $dic['http.response_sender_strategy'] = $this->createMock(DefaultResponseSenderStrategy::class);
59 $dic['http'] = $this->createMock(HttpService::class);
60 $dic['http']
61 ->method('request')
62 ->willReturn(
63 $this->createMock(ServerRequestInterface::class)
64 );
65 $dic['component.factory'] = $this->createMock(ilComponentFactory::class);
66
67 $this->assertFalse(isset($dic['ilCtrl']));
68
69 (new InitCtrlService())->init($dic);
70
71 $this->assertTrue(isset($dic['ilCtrl']));
72 $this->assertInstanceOf(
73 ilCtrlInterface::class,
74 $dic->ctrl()
75 );
76 }
77}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
Class InitCtrlServiceTest.
Class InitCtrlService wraps the initialization of ilCtrl.
$dic
Definition: result.php:32