Debian Codegraph @

tests/phpunit/unit/includes/shell/ShellboxClientFactoryTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Http\HttpRequestFactory;
4 use MediaWiki\Shell\ShellboxClientFactory;
5 use Shellbox\RPC\RpcClient;
6
7 /**
8 * @group Shell
9 * @covers \MediaWiki\Shell\ShellboxClientFactory
10 */
11 class ShellboxClientFactoryTest extends MediaWikiUnitTestCase {
12
13 /** @dataProvider provideEnabledArgs */
14 public function testIsEnabled( ?array $urls, ?string $service, bool $expected ): void {
15 $shellboxClientFactory = new ShellboxClientFactory(
16 $this->createMock( HttpRequestFactory::class ),
17 $urls,
18 'key'
19 );
20
21 $actual = $shellboxClientFactory->isEnabled( $service );
22
23 $this->assertSame( $expected, $actual );
24 }
25
26 public static function provideEnabledArgs(): iterable {
27 yield 'not configured, default service' => [
28 'urls' => null,
29 'service' => null,
30 'expected' => false,
31 ];
32
33 yield 'not configured, custom service' => [
34 'urls' => null,
35 'service' => 'custom',
36 'expected' => false,
37 ];
38
39 yield 'default configured, default service' => [
40 'urls' => [ 'default' => 'http://example.com' ],
41 'service' => null,
42 'expected' => true,
43 ];
44
45 yield 'default configured, custom service' => [
46 'urls' => [ 'default' => 'http://example.com' ],
47 'service' => 'custom',
48 'expected' => true,
49 ];
50
51 yield 'custom configured, custom service' => [
52 'urls' => [ 'custom' => 'http://example.com' ],
53 'service' => 'custom',
54 'expected' => true,
55 ];
56
57 yield 'custom disabled, default service' => [
58 'urls' => [
59 'default' => 'http://example.com',
60 'custom' => false,
61 ],
62 'service' => 'default',
63 'expected' => true,
64 ];
65
66 yield 'custom disabled, custom service' => [
67 'urls' => [
68 'default' => 'http://example.com',
69 'custom' => false,
70 ],
71 'service' => 'custom',
72 'expected' => false,
73 ];
74 }
75
76 public function testIsEnabledWithoutKey(): void {
77 $shellboxClientFactory = new ShellboxClientFactory(
78 $this->createMock( HttpRequestFactory::class ),
79 [ 'default' => 'http://example.com' ],
80 null
81 );
82
83 $this->assertFalse( $shellboxClientFactory->isEnabled() );
84 }
85
86 public function testGetRemoteRpcClientNotEnabled() {
87 $shellboxClientFactory = new ShellboxClientFactory(
88 $this->createMock( HttpRequestFactory::class ),
89 null,
90 'key'
91 );
92 $this->expectException( RuntimeException::class );
93 $shellboxClientFactory->getRemoteRpcClient();
94 }
95
96 public function testGetRpcClientNotEnabled() {
97 $shellboxClientFactory = new ShellboxClientFactory(
98 $this->createMock( HttpRequestFactory::class ),
99 null,
100 'key'
101 );
102 $this->assertInstanceOf( RpcClient::class, $shellboxClientFactory->getRpcClient() );
103 }
104 }