ILIAS  release_8 Revision v8.24
ilObjSearchRpcClientCoordinatorTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use PHPUnit\Framework\TestCase;
22
28{
29 public function testRefreshLuceneSettings(): void
30 {
31 $src_logger = $this->getMockBuilder(ilLogger::class)
32 ->disableOriginalConstructor()
33 ->onlyMethods(['error'])
34 ->getMock();
35 $src_logger->expects($this->never())
36 ->method('error');
37
38 $settings = $this->getMockBuilder(ilSetting::class)
39 ->disableOriginalConstructor()
40 ->onlyMethods(['get'])
41 ->getMock();
42 $settings->expects($this->once())
43 ->method('get')
44 ->with('inst_id', '0')
45 ->willReturn('test');
46
47 $rpc_client = $this->getMockBuilder(ilRpcClient::class)
48 ->disableOriginalConstructor()
49 ->addMethods(['refreshSettings'])
50 ->getMock();
51 $rpc_client->expects($this->once())
52 ->method('refreshSettings')
53 ->with('id_test');
54
55 $coord = $this->getMockBuilder(ilObjSearchRpcClientCoordinator::class)
56 ->setConstructorArgs([$settings, $src_logger])
57 ->onlyMethods(['getRpcClient', 'getClientId'])
58 ->getMock();
59 $coord->expects($this->once())
60 ->method('getClientId')
61 ->willReturn('id');
62 $coord->expects($this->once())
63 ->method('getRpcClient')
64 ->willReturn($rpc_client);
65
66 $this->assertSame(true, $coord->refreshLuceneSettings());
67 }
68
69 public function testRefreshLuceneSettingsException(): void
70 {
71 $src_logger = $this->getMockBuilder(ilLogger::class)
72 ->disableOriginalConstructor()
73 ->onlyMethods(['error'])
74 ->getMock();
75 $src_logger->expects($this->once())
76 ->method('error')
77 ->with(
78 'Refresh of lucene server settings ' .
79 'failed with message: message'
80 );
81
82 $settings = $this->getMockBuilder(ilSetting::class)
83 ->disableOriginalConstructor()
84 ->onlyMethods(['get'])
85 ->getMock();
86 $settings->expects($this->once())
87 ->method('get')
88 ->with('inst_id', '0')
89 ->willReturn('test');
90
91 $rpc_client = $this->getMockBuilder(ilRpcClient::class)
92 ->disableOriginalConstructor()
93 ->addMethods(['refreshSettings'])
94 ->getMock();
95 $rpc_client->expects($this->once())
96 ->method('refreshSettings')
97 ->with('id_test')
98 ->willThrowException(new Exception('message'));
99
100 $coord = $this->getMockBuilder(ilObjSearchRpcClientCoordinator::class)
101 ->setConstructorArgs([$settings, $src_logger])
102 ->onlyMethods(['getRpcClient', 'getClientId'])
103 ->getMock();
104 $coord->expects($this->once())
105 ->method('getClientId')
106 ->willReturn('id');
107 $coord->expects($this->once())
108 ->method('getRpcClient')
109 ->willReturn($rpc_client);
110
111 $this->expectException(Exception::class);
112 $coord->refreshLuceneSettings();
113 }
114}
Unit tests for class ilObjSearchRpcClientCoordinator.
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200