Skip to content

Commit 1390ad5

Browse files
committed
Merge pull request #1104 from simon-n/master
adapted Type namespace collision fix for Query\Ids, see PR #438
2 parents b5a7030 + 937c817 commit 1390ad5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/Elastica/Query/Ids.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Elastica\Query;
44

5-
use Elastica\Type;
5+
use Elastica\Type as ElasticaType;
66

77
/**
88
* Ids Query.
@@ -50,7 +50,7 @@ public function addId($id)
5050
*/
5151
public function addType($type)
5252
{
53-
if ($type instanceof Type) {
53+
if ($type instanceof ElasticaType) {
5454
$type = $type->getName();
5555
} elseif (empty($type) && !is_numeric($type)) {
5656
// A type can be 0, but cannot be empty
@@ -71,7 +71,7 @@ public function addType($type)
7171
*/
7272
public function setType($type)
7373
{
74-
if ($type instanceof Type) {
74+
if ($type instanceof ElasticaType) {
7575
$type = $type->getName();
7676
} elseif (empty($type) && !is_numeric($type)) {
7777
// A type can be 0, but cannot be empty

test/lib/Elastica/Test/Query/IdsTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Elastica\Document;
66
use Elastica\Query\Ids;
7+
use Elastica\Query\Type;
78
use Elastica\Test\Base as BaseTest;
89

910
class IdsTest extends BaseTest
@@ -185,4 +186,17 @@ public function testSetTypeArraySearchSingle()
185186

186187
$this->assertEquals(1, $resultSet->count());
187188
}
189+
190+
public function testQueryTypeAndTypeCollision()
191+
{
192+
// This test ensures that Elastica\Type and Elastica\Query\Type
193+
// do not collide when used together, which at one point
194+
// happened because of a use statement in Elastica\Query\Ids
195+
// Test goal is to make sure a Fatal Error is not triggered
196+
//
197+
// adapted fix for Elastica\Filter\Type
198+
// see https://github.com/ruflin/Elastica/pull/438
199+
$queryType = new Type();
200+
$filter = new Ids();
201+
}
188202
}

0 commit comments

Comments
 (0)