1 | <?php |
||
13 | class GuzzleTest extends BaseTest |
||
14 | { |
||
15 | public static function setUpbeforeClass(): void |
||
21 | |||
22 | protected function setUp(): void |
||
23 | { |
||
24 | \putenv('http_proxy='); |
||
25 | } |
||
26 | |||
27 | protected function tearDown(): void |
||
32 | |||
33 | /** |
||
34 | * @group functional |
||
35 | */ |
||
36 | public function testWithEnvironmentalProxy(): void |
||
37 | { |
||
38 | $this->checkProxy($this->_getProxyUrl()); |
||
39 | \putenv('http_proxy='.$this->_getProxyUrl().'/'); |
||
40 | |||
41 | $client = $this->_getClient(['transport' => 'Guzzle', 'persistent' => false]); |
||
42 | $transferInfo = $client->request('/_nodes')->getTransferInfo(); |
||
43 | $this->assertEquals(200, $transferInfo['http_code']); |
||
44 | |||
45 | $client->getConnection()->setProxy(null); // will not change anything |
||
46 | $transferInfo = $client->request('/_nodes')->getTransferInfo(); |
||
47 | $this->assertEquals(200, $transferInfo['http_code']); |
||
48 | |||
49 | \putenv('http_proxy='); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @group functional |
||
54 | */ |
||
55 | public function testWithEnabledEnvironmentalProxy(): void |
||
56 | { |
||
57 | $this->checkProxy($this->_getProxyUrl403()); |
||
58 | \putenv('http_proxy='.$this->_getProxyUrl403().'/'); |
||
59 | |||
60 | $client = $this->_getClient(['transport' => 'Guzzle', 'persistent' => false]); |
||
61 | $transferInfo = $client->request('/_nodes')->getTransferInfo(); |
||
62 | $this->assertEquals(403, $transferInfo['http_code']); |
||
63 | |||
64 | $client = $this->_getClient(['transport' => 'Guzzle', 'persistent' => false]); |
||
65 | $client->getConnection()->setProxy(''); |
||
66 | $transferInfo = $client->request('/_nodes')->getTransferInfo(); |
||
67 | $this->assertEquals(200, $transferInfo['http_code']); |
||
68 | |||
69 | \putenv('http_proxy='); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @group functional |
||
74 | */ |
||
75 | public function testWithProxy(): void |
||
76 | { |
||
77 | $this->checkProxy($this->_getProxyUrl()); |
||
78 | $client = $this->_getClient(['transport' => 'Guzzle', 'persistent' => false]); |
||
79 | $client->getConnection()->setProxy($this->_getProxyUrl()); |
||
80 | |||
81 | $transferInfo = $client->request('/_nodes')->getTransferInfo(); |
||
82 | $this->assertEquals(200, $transferInfo['http_code']); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @group functional |
||
87 | */ |
||
88 | public function testWithoutProxy(): void |
||
89 | { |
||
90 | $client = $this->_getClient(['transport' => 'Guzzle', 'persistent' => false]); |
||
91 | $client->getConnection()->setProxy(''); |
||
92 | |||
93 | $transferInfo = $client->request('/_nodes')->getTransferInfo(); |
||
94 | $this->assertEquals(200, $transferInfo['http_code']); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @group functional |
||
99 | */ |
||
100 | public function testBodyReuse(): void |
||
101 | { |
||
102 | $client = $this->_getClient(['transport' => 'Guzzle', 'persistent' => false]); |
||
103 | $index = $client->getIndex('elastica_body_reuse_test'); |
||
104 | $index->create([], [ |
||
105 | 'recreate' => true, |
||
106 | ]); |
||
107 | $this->_waitForAllocation($index); |
||
108 | |||
109 | $index->addDocument(new Document(1, ['test' => 'test'])); |
||
110 | |||
111 | $index->refresh(); |
||
112 | |||
113 | $resultSet = $index->search([ |
||
114 | 'query' => [ |
||
115 | 'query_string' => [ |
||
116 | 'query' => 'pew pew pew', |
||
117 | ], |
||
118 | ], |
||
119 | ]); |
||
120 | |||
121 | $this->assertEquals(0, $resultSet->getTotalHits()); |
||
122 | |||
123 | $response = $index->request('/_search', 'POST'); |
||
124 | |||
125 | $builder = new DefaultBuilder(); |
||
126 | $resultSet = $builder->buildResultSet($response, Query::create([])); |
||
127 | |||
128 | $this->assertEquals(1, $resultSet->getTotalHits()); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * @group unit |
||
133 | */ |
||
134 | public function testInvalidConnection(): void |
||
142 | |||
143 | protected function checkProxy($url): void |
||
148 | } |
||
149 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.