|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Elastica\Test; |
|
4
|
|
|
|
|
5
|
|
|
use Elastica\Node; |
|
6
|
|
|
use Elastica\Test\Base as BaseTest; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @internal |
|
10
|
|
|
*/ |
|
11
|
|
|
class NodeTest extends BaseTest |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @group functional |
|
15
|
|
|
*/ |
|
16
|
|
View Code Duplication |
public function testCreateNode(): void |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
$client = $this->_getClient(); |
|
19
|
|
|
$names = $client->getCluster()->getNodeNames(); |
|
20
|
|
|
$name = \reset($names); |
|
21
|
|
|
|
|
22
|
|
|
$node = new Node($name, $client); |
|
|
|
|
|
|
23
|
|
|
$this->assertSame($name, $node->getId()); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @group functional |
|
28
|
|
|
*/ |
|
29
|
|
View Code Duplication |
public function testGetInfo(): void |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$client = $this->_getClient(); |
|
32
|
|
|
$names = $client->getCluster()->getNodeNames(); |
|
33
|
|
|
$name = \reset($names); |
|
34
|
|
|
|
|
35
|
|
|
$node = new Node($name, $client); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$info = $node->getInfo(); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertSame($node, $info->getNode()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @group functional |
|
44
|
|
|
*/ |
|
45
|
|
View Code Duplication |
public function testGetStats(): void |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
$client = $this->_getClient(); |
|
48
|
|
|
$names = $client->getCluster()->getNodeNames(); |
|
49
|
|
|
$name = \reset($names); |
|
50
|
|
|
|
|
51
|
|
|
$node = new Node($name, $client); |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
$stats = $node->getStats(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertSame($node, $stats->getNode()); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @group functional |
|
60
|
|
|
*/ |
|
61
|
|
View Code Duplication |
public function testGetName(): void |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
$client = $this->_getClient(); |
|
64
|
|
|
|
|
65
|
|
|
$nodes = $client->getCluster()->getNodes(); |
|
66
|
|
|
// At least 1 instance must exist |
|
67
|
|
|
$this->assertGreaterThan(0, $nodes); |
|
68
|
|
|
|
|
69
|
|
|
$data = $client->request('_nodes')->getData(); |
|
70
|
|
|
$rawNodes = $data['nodes']; |
|
71
|
|
|
|
|
72
|
|
|
foreach ($nodes as $node) { |
|
73
|
|
|
$this->assertEquals($rawNodes[$node->getId()]['name'], $node->getName()); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.