Skip to content

Commit

Permalink
Add a PHPUnit deprecations handler (#1867)
Browse files Browse the repository at this point in the history
* Add a PHPUnit deprecations handler

* Assert expected deprecations

* Fix deprecations

* Fix remaining deprecations

* Add more deprecation tests

* Fix minimum version for symfony/phpunit-bridge
  • Loading branch information
deguif committed Nov 16, 2020
1 parent 41ab9bf commit 7598f2d
Show file tree
Hide file tree
Showing 32 changed files with 355 additions and 90 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"require-dev": {
"aws/aws-sdk-php": "^3.155",
"guzzlehttp/guzzle": "^6.3 || ^7.2",
"phpunit/phpunit": "^8.5.8 || ^9.4"
"phpunit/phpunit": "^8.5.8 || ^9.4",
"symfony/phpunit-bridge": "^5.1.1"
},
"suggest": {
"aws/aws-sdk-php": "Allow using IAM authentication with Amazon ElasticSearch Service",
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<directory>src/</directory>
</whitelist>
</filter>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
<testsuites>
<testsuite name="default">
<directory>tests/</directory>
Expand Down
2 changes: 1 addition & 1 deletion src/QueryBuilder/DSL/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function global(string $name): GlobalAggregation
*/
public function global_agg(string $name): GlobalAggregation
{
trigger_deprecation('ruflin/elastica', '7.1.0', 'The "%s()" method is deprecated, use "global()" instead. It will be removed in 8.0.', __METHOD__);
trigger_deprecation('ruflin/elastica', '7.1.0', 'The "%s()" method is deprecated, use "global()" instead. It will be removed in 8.0.', __METHOD__);

return $this->global($name);
}
Expand Down
14 changes: 13 additions & 1 deletion tests/Aggregation/ChildrenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,19 @@ protected function _getIndexForTest(): Index
{
$client = $this->_getClient();
$index = $client->getIndex('testaggregationchildren');
$index->create(['settings' => ['index' => ['number_of_shards' => 2, 'number_of_replicas' => 1]]], true);
$index->create(
[
'settings' => [
'index' => [
'number_of_shards' => 2,
'number_of_replicas' => 1,
],
],
],
[
'recreate' => true,
]
);

$mapping = new Mapping([
'text' => ['type' => 'keyword'],
Expand Down
28 changes: 21 additions & 7 deletions tests/ClientFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public function testConnectionsArray(): void
// Creates a new index 'xodoa' and a type 'user' inside this index
$client = $this->_getClient(['connections' => [['host' => $this->_getHost(), 'port' => 9200]]]);
$index = $client->getIndex('elastica_test1');
$index->create([], true);
$index->create([], [
'recreate' => true,
]);

// Adds 1 document to the index
$doc1 = new Document(
Expand Down Expand Up @@ -97,7 +99,9 @@ public function testTwoServersSame(): void
['host' => $this->_getHost(), 'port' => 9200],
]]);
$index = $client->getIndex('elastica_test1');
$index->create([], true);
$index->create([], [
'recreate' => true,
]);

// Adds 1 document to the index
$doc1 = new Document(
Expand Down Expand Up @@ -242,7 +246,9 @@ public function testDeleteIdsIdxString(): void
$index = $this->_createIndex();

// Create the index, deleting it first if it already exists
$index->create([], true);
$index->create([], [
'recreate' => true,
]);

// Adds 1 document to the index
$doc = new Document(null, $data);
Expand Down Expand Up @@ -301,7 +307,9 @@ public function testDeleteIdsIdxObjectTypeObject(): void
$index = $this->_createIndex();

// Create the index, deleting it first if it already exists
$index->create([], true);
$index->create([], [
'recreate' => true,
]);

// Adds 1 document to the index
$doc = new Document(null, $data);
Expand Down Expand Up @@ -807,7 +815,9 @@ public function testArrayQuery(): void
$client = $this->_getClient();

$index = $client->getIndex('test');
$index->create([], true);
$index->create([], [
'recreate' => true,
]);
$index->addDocument(new Document(1, ['username' => 'ruflin']));
$index->refresh();

Expand All @@ -832,7 +842,9 @@ public function testJSONQuery(): void
$client = $this->_getClient();

$index = $client->getIndex('test');
$index->create([], true);
$index->create([], [
'recreate' => true,
]);
$index->addDocument(new Document(1, ['username' => 'ruflin']));
$index->refresh();

Expand Down Expand Up @@ -969,7 +981,9 @@ public function testEndpointQueryRequest($query, $totalHits): void
$client = $this->_getClient();

$index = $client->getIndex('test');
$index->create([], true);
$index->create([], [
'recreate' => true,
]);
$index->addDocument(new Document(1, ['username' => 'ruflin']));
$index->refresh();

Expand Down
4 changes: 3 additions & 1 deletion tests/ExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function testExample(): void
// Creates a new index 'xodoa' and a type 'user' inside this index
$client = $this->_getClient();
$index = $client->getIndex('elastica_test');
$index->create([], true);
$index->create([], [
'recreate' => true,
]);

// Adds 1 document to the index
$index->addDocument(new Document(1, ['username' => 'hans', 'test' => ['2', '3', '5']]));
Expand Down
4 changes: 3 additions & 1 deletion tests/Exception/PartialShardFailureExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function testPartialFailure(): void
],
],
],
true
[
'recreate' => true,
]
);

$index->addDocument(new Document('', ['name' => 'ruflin']));
Expand Down
4 changes: 3 additions & 1 deletion tests/Index/RecoveryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public function testGetSettings(): void

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index->create([], true);
$index->create([], [
'recreate' => true,
]);
$recovery = $index->getRecovery();
$this->assertInstanceOf(Recovery::class, $recovery);

Expand Down
48 changes: 36 additions & 12 deletions tests/Index/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public function testGet(): void

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index->create([], true);
$index->create([], [
'recreate' => true,
]);
$index->refresh();
$settings = $index->getSettings();

Expand All @@ -45,7 +47,9 @@ public function testGetWithAlias(): void

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index->create([], true);
$index->create([], [
'recreate' => true,
]);
$index->refresh();

$index->addAlias($aliasName);
Expand All @@ -70,7 +74,9 @@ public function testDeleteAliasWithException(): void
$aliasName = 'deletetestaliasexception_alias';
$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index->create([], true);
$index->create([], [
'recreate' => true,
]);
$index->refresh();

$index->addAlias($aliasName);
Expand All @@ -94,7 +100,9 @@ public function testDeleteAliasWithException(): void
public function testSetGetNumberOfReplicas(): void
{
$index = $this->_createIndex();
$index->create([], true);
$index->create([], [
'recreate' => true,
]);
$settings = $index->getSettings();

// Check for zero replicas
Expand All @@ -118,7 +126,9 @@ public function testSetGetNumberOfReplicas(): void
public function testGetNumberOfReplicas(): void
{
$index = $this->_createIndex();
$index->create([], true);
$index->create([], [
'recreate' => true,
]);

$settings = $index->getSettings();

Expand All @@ -135,7 +145,9 @@ public function testGetNumberOfReplicas(): void
public function testGetNumberOfShards(): void
{
$index = $this->_createIndex();
$index->create([], true);
$index->create([], [
'recreate' => true,
]);

$settings = $index->getSettings();

Expand All @@ -152,7 +164,9 @@ public function testGetNumberOfShards(): void
public function testGetDefaultNumberOfShards(): void
{
$index = $this->_createIndex();
$index->create([], true);
$index->create([], [
'recreate' => true,
]);
$index->refresh();

$settings = $index->getSettings();
Expand All @@ -170,7 +184,9 @@ public function testGetDefaultNumberOfShards(): void
public function testSetRefreshInterval(): void
{
$index = $this->_createIndex();
$index->create([], true);
$index->create([], [
'recreate' => true,
]);

$settings = $index->getSettings();

Expand All @@ -191,7 +207,9 @@ public function testSetRefreshInterval(): void
public function testGetRefreshInterval(): void
{
$index = $this->_createIndex();
$index->create([], true);
$index->create([], [
'recreate' => true,
]);

$settings = $index->getSettings();

Expand All @@ -212,7 +230,9 @@ public function testGetRefreshInterval(): void
public function testSetMergePolicy(): void
{
$index = $this->_createIndex();
$index->create([], true);
$index->create([], [
'recreate' => true,
]);
//wait for the shards to be allocated
$this->_waitForAllocation($index);

Expand All @@ -233,7 +253,9 @@ public function testSetMergePolicy(): void
public function testSetMaxMergeAtOnce(): void
{
$index = $this->_createIndex();
$index->create([], true);
$index->create([], [
'recreate' => true,
]);

//wait for the shards to be allocated
$this->_waitForAllocation($index);
Expand Down Expand Up @@ -391,7 +413,9 @@ public function testNotFoundIndex(): void
public function testSetMultiple(): void
{
$index = $this->_createIndex();
$index->create([], true);
$index->create([], [
'recreate' => true,
]);

$settings = $index->getSettings();

Expand Down
4 changes: 3 additions & 1 deletion tests/Index/StatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public function testGetSettings(): void

$client = $this->_getClient();
$index = $client->getIndex($indexName);
$index->create([], true);
$index->create([], [
'recreate' => true,
]);
$stats = $index->getStats();
$this->assertInstanceOf(Stats::class, $stats);

Expand Down
Loading

0 comments on commit 7598f2d

Please sign in to comment.