Skip to content

Commit d99a1b8

Browse files
committed
Split tests in unit and integration
1 parent 036e508 commit d99a1b8

9 files changed

+86
-24
lines changed

.ci/yaml-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
php util/RestSpecRunner.php
55

66
# Run YAML tests
7-
vendor/bin/phpunit -c phpunit-integration.xml --group sync
7+
vendor/bin/phpunit -c phpunit-yaml-tests.xml

phpunit-integration-test.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.3/phpunit.xsd"
4+
bootstrap="tests/bootstrap.php"
5+
colors="true"
6+
failOnRisky="true"
7+
verbose="true"
8+
beStrictAboutChangesToGlobalState="true"
9+
beStrictAboutOutputDuringTests="true"
10+
>
11+
<testsuites>
12+
<testsuite name="Integration tests">
13+
<directory>tests</directory>
14+
<exclude>tests/Elasticsearch/Tests/YamlRunnerTest.php</exclude>
15+
</testsuite>
16+
</testsuites>
17+
<groups>
18+
<include>
19+
<group>Integration</group>
20+
</include>
21+
</groups>
22+
<filter>
23+
<whitelist>
24+
<directory suffix=".php">src</directory>
25+
</whitelist>
26+
</filter>
27+
</phpunit>

phpunit-integration.xml renamed to phpunit-yaml-tests.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@
99
beStrictAboutOutputDuringTests="true"
1010
>
1111
<php>
12-
<env name="ES_TEST_HOST" value="http://localhost:9200"/>
1312
<!-- Disable E_USER_DEPRECATED setting E_ALL & ~E_USER_DEPRECATED-->
1413
<ini name="error_reporting" value="16383"/>
1514
</php>
1615
<testsuites>
17-
<testsuite name="Integration Tests">
16+
<testsuite name="Yaml tests">
1817
<file>tests/Elasticsearch/Tests/YamlRunnerTest.php</file>
1918
</testsuite>
2019
</testsuites>
20+
<groups>
21+
<include>
22+
<group>sync</group>
23+
</include>
24+
</groups>
2125
<filter>
2226
<whitelist>
2327
<directory suffix=".php">src</directory>

phpunit.xml.dist

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
beStrictAboutChangesToGlobalState="true"
99
beStrictAboutOutputDuringTests="true"
1010
>
11-
<php>
12-
<env name="ES_TEST_HOST" value=""/>
13-
</php>
1411
<testsuites>
15-
<testsuite name="Tests">
12+
<testsuite name="Unit tests">
1613
<directory>tests</directory>
1714
<exclude>tests/Elasticsearch/Tests/YamlRunnerTest.php</exclude>
1815
</testsuite>
1916
</testsuites>
17+
<groups>
18+
<exclude>
19+
<group>Integration</group>
20+
</exclude>
21+
</groups>
2022
<filter>
2123
<whitelist>
2224
<directory suffix=".php">src</directory>

tests/Elasticsearch/Tests/ClientIntegrationTest.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* Class ClientTest
3030
*
3131
* @subpackage Tests
32+
* @group Integration
3233
*/
3334
class ClientIntegrationTest extends \PHPUnit\Framework\TestCase
3435
{
@@ -51,12 +52,21 @@ public function setUp()
5152
$this->logger = new ArrayLogger();
5253
}
5354

54-
public function testLogRequestSuccessHasInfoNotEmpty()
55+
private function getClient(): Client
5556
{
5657
$client = ClientBuilder::create()
5758
->setHosts([$this->host])
58-
->setLogger($this->logger)
59-
->build();
59+
->setLogger($this->logger);
60+
61+
if (getenv('TEST_SUITE') === 'xpack') {
62+
$client->setSSLVerification(__DIR__ . '/../../../.ci/certs/ca.crt');
63+
}
64+
return $client->build();
65+
}
66+
67+
public function testLogRequestSuccessHasInfoNotEmpty()
68+
{
69+
$client = $this->getClient();
6070

6171
$result = $client->info();
6272

@@ -65,10 +75,7 @@ public function testLogRequestSuccessHasInfoNotEmpty()
6575

6676
public function testLogRequestSuccessHasPortInInfo()
6777
{
68-
$client = ClientBuilder::create()
69-
->setHosts([$this->host])
70-
->setLogger($this->logger)
71-
->build();
78+
$client = $this->getClient();
7279

7380
$result = $client->info();
7481

@@ -77,10 +84,7 @@ public function testLogRequestSuccessHasPortInInfo()
7784

7885
public function testLogRequestFailHasWarning()
7986
{
80-
$client = ClientBuilder::create()
81-
->setHosts([$this->host])
82-
->setLogger($this->logger)
83-
->build();
87+
$client = $this->getClient();
8488

8589
try {
8690
$result = $client->get([

tests/Elasticsearch/Tests/ConnectionPool/SniffingConnectionPoolIntegrationTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020

2121
use Elasticsearch\ClientBuilder;
2222
use Elasticsearch\ConnectionPool\SniffingConnectionPool;
23+
use Elasticsearch\Tests\Utility;
2324

2425
/**
2526
* Class SniffingConnectionPoolIntegrationTest
2627
*
2728
* @subpackage Tests/SniffingConnectionPoolTest
29+
* @group Integration
2830
*/
2931
class SniffingConnectionPoolIntegrationTest extends \PHPUnit\Framework\TestCase
3032
{
@@ -36,7 +38,7 @@ protected function setUp()
3638
public function testSniff()
3739
{
3840
$client = ClientBuilder::create()
39-
->setHosts([getenv('ES_TEST_HOST')])
41+
->setHosts([Utility::getHost()])
4042
->setConnectionPool(SniffingConnectionPool::class, ['sniffingInterval' => -10])
4143
->build();
4244

tests/Elasticsearch/Tests/ConnectionPool/StaticConnectionPoolIntegrationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Class StaticConnectionPoolIntegrationTest
2626
*
2727
* @subpackage Tests/StaticConnectionPoolTest
28+
* @group Integration
2829
*/
2930
class StaticConnectionPoolIntegrationTest extends \PHPUnit\Framework\TestCase
3031
{

tests/Elasticsearch/Tests/Utility.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function getHost(): ?string
3030
case 'oss':
3131
return 'http://localhost:9200';
3232
case 'xpack':
33-
return 'https://elastic:changeme@localhost:9200';
33+
return 'https://elastic:changeme@instance:9200';
3434
}
3535
return null;
3636
}

tests/Elasticsearch/Tests/YamlRunnerTest.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,17 @@ public static function setUpBeforeClass()
135135
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
136136
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
137137
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
138+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
139+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
138140

139141
$response = curl_exec($ch);
140142
curl_close($ch);
141143
if (false === $response) {
142-
throw new \Exception('I cannot connect to ES');
144+
throw new \Exception(sprintf(
145+
"I cannot connect to ES: %d %s",
146+
curl_errno($ch),
147+
curl_error($ch)
148+
));
143149
}
144150
$response = json_decode($response, true);
145151
static::$esVersion = $response['version']['number'];
@@ -149,8 +155,11 @@ public static function setUpBeforeClass()
149155
public function setUp()
150156
{
151157
$this->client = Elasticsearch\ClientBuilder::create()
152-
->setHosts([self::getHost()])
153-
->build();
158+
->setHosts([self::getHost()]);
159+
if (getenv('TEST_SUITE') === 'xpack') {
160+
$this->client->setSSLVerification(__DIR__ . '/../../../.ci/certs/ca.crt');
161+
}
162+
$this->client->build();
154163
}
155164

156165
public function tearDown()
@@ -830,7 +839,14 @@ private function assertException(\Exception $exception, string $expectedError, s
830839
public function yamlProvider(): array
831840
{
832841
$this->yaml = new Yaml();
833-
$path = __DIR__ . '/../../../util/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/test';
842+
$testSuite = getenv('TEST_SUITE');
843+
if ($testSuite === false) {
844+
throw new \Exception("The TEST_SUITE env does not exist");
845+
}
846+
$path = $testSuite === 'oss'
847+
? __DIR__ . '/../../../util/elasticsearch/rest-api-spec/src/main/resources/rest-api-spec/test'
848+
: __DIR__ . '/../../../util/elasticsearch/x-pack/plugin/src/test/resources/rest-api-spec/test';
849+
834850
$files = [];
835851

836852
$finder = new Finder();
@@ -1072,6 +1088,8 @@ private function clean()
10721088
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
10731089
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
10741090
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
1091+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1092+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
10751093

10761094
$response = curl_exec($ch);
10771095
curl_close($ch);
@@ -1080,6 +1098,8 @@ private function clean()
10801098
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
10811099
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
10821100
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
1101+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1102+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
10831103

10841104
$response = curl_exec($ch);
10851105
curl_close($ch);
@@ -1121,6 +1141,8 @@ private function waitForYellow()
11211141
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
11221142
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
11231143
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
1144+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1145+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
11241146

11251147
$response = curl_exec($ch);
11261148
if (false !== $response) {

0 commit comments

Comments
 (0)