blob: e446aeba93014f3c8e0061682f4b58adde03606f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<?php
namespace SMW\Tests\Elastic\Connection;
use SMW\Elastic\Connection\ConnectionProvider;
use SMW\Elastic\Connection\DummyClient;
use SMW\Elastic\Connection\Client;
use SMW\Options;
use SMW\Tests\PHPUnitCompat;
/**
* @covers \SMW\Elastic\Connection\ConnectionProvider
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 3.0
*
* @author mwjames
*/
class ConnectionProviderTest extends \PHPUnit_Framework_TestCase {
use PHPUnitCompat;
private $logger;
private $cache;
protected function setUp() {
$this->logger = $this->getMockBuilder( '\Psr\Log\LoggerInterface' )
->disableOriginalConstructor()
->getMock();
$this->cache = $this->getMockBuilder( '\Onoi\Cache\Cache' )
->disableOriginalConstructor()
->getMock();
$this->options = new Options();
}
public function testCanConstruct() {
$this->assertInstanceOf(
ConnectionProvider::class,
new ConnectionProvider( $this->options, $this->cache )
);
}
public function testGetConnection_DummyClient() {
$options = new Options (
[
'is.elasticstore' => false,
'endpoints' => []
]
);
$instance = new ConnectionProvider(
$options,
$this->cache
);
$instance->setLogger( $this->logger );
$this->assertInstanceOf(
DummyClient::class,
$instance->getConnection()
);
}
public function testGetConnection_Client() {
if ( !class_exists( '\Elasticsearch\ClientBuilder' ) ) {
$this->markTestSkipped( "elasticsearch-php dependency is not available." );
}
$options = new Options (
[
'is.elasticstore' => true,
'endpoints' => []
]
);
$instance = new ConnectionProvider(
$options,
$this->cache
);
$instance->setLogger( $this->logger );
$this->assertInstanceOf(
Client::class,
$instance->getConnection()
);
}
public function testGetConnectionThrowsExceptionWhenNotInstalled() {
if ( class_exists( '\Elasticsearch\ClientBuilder' ) ) {
$this->markTestSkipped( "No exception thrown when ClientBuilder is available!" );
}
$options = new Options (
[
'is.elasticstore' => true,
'endpoints' => []
]
);
$instance = new ConnectionProvider(
$options,
$this->cache
);
$this->setExpectedException( '\SMW\Elastic\Exception\ClientBuilderNotFoundException' );
$instance->getConnection();
}
}
|