Skip to content

Commit

Permalink
Fix PHP notice on getAliases if index has no aliases (#1080)
Browse files Browse the repository at this point in the history
A php notice is triggered in `\Elastica\Index::getAliases()` if index
has no aliases. Only happens if php `error_reporting` setting is set to `-1`.

Closes #1078
  • Loading branch information
gbprod authored and ruflin committed Apr 21, 2016
1 parent 9240104 commit 832d570
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file based on the
### Backward Compatibility Breaks

### Bugfixes
- Fix php notice on `\Elastica\Index::getAliases()` if index has no aliases #1078

### Added

Expand Down
4 changes: 4 additions & 0 deletions lib/Elastica/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ public function getAliases()
{
$responseData = $this->request('_alias/*', \Elastica\Request::GET)->getData();

if (!isset($responseData[$this->getName()])) {
return array();
}

$data = $responseData[$this->getName()];
if (!empty($data['aliases'])) {
return array_keys($data['aliases']);
Expand Down
18 changes: 18 additions & 0 deletions test/lib/Elastica/Test/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,4 +941,22 @@ public function testConvertScalarsToString()
$this->assertEquals('1', $index->getName());
$this->assertInternalType('string', $index->getName());
}

/**
* @group functional
*/
public function testGetEmptyAliases()
{
$indexName = 'test-getaliases';

$client = $this->_getClient();
$index = $client->getIndex($indexName);

$index->create(array(), true);
$this->_waitForAllocation($index);
$index->refresh();
$index->optimize();

$this->assertEquals(array(), $index->getAliases());
}
}

0 comments on commit 832d570

Please sign in to comment.