Skip to content

Commit 4d9a240

Browse files
Fix BC issue introduced in #1087 (#1098)
1 parent 0e1d769 commit 4d9a240

File tree

7 files changed

+94
-4
lines changed

7 files changed

+94
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
### Changed
99
- Spatial component distance type changed from int to float
10+
- Revert return type for Solarium\Component\QueryTrait::setQuery() from `self` to `QueryInterface` for backward compatibility with custom query classes that override this method
11+
1012

1113
## [6.3.2]
1214
### Added

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Please see the [docs](http://solarium.readthedocs.io/en/stable/) for a more deta
1010

1111
## Requirements
1212

13-
Solarium 6.4.x only supports PHP 8.0 and up.
13+
Solarium 6.3.2 and up only supports PHP 8.0 and up.
1414

1515
It's highly recommended to have cURL enabled in your PHP environment. However if you don't have cURL available you can
1616
switch from using cURL (the default) to a pure PHP based HTTP client adapter which works for the essential stuff but
@@ -28,9 +28,9 @@ Example:
2828
composer require solarium/solarium
2929
```
3030

31-
### Pitfall when upgrading to 6.4
31+
### Pitfall when upgrading to 6.3.2
3232

33-
Support for PHP 7 was removed in Solarium 6.4.0. Upgrade to PHP 8 first to use the latest Solarium version.
33+
Support for PHP 7 was removed in Solarium 6.3.2. Upgrade to PHP 8 first to use the latest Solarium version.
3434

3535
### Pitfall when upgrading to 6.3
3636

src/Component/QueryTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait QueryTrait
2424
*
2525
* @return self Provides fluent interface
2626
*/
27-
public function setQuery(string $query, array $bind = null): self
27+
public function setQuery(string $query, array $bind = null): QueryInterface
2828
{
2929
if (null !== $bind) {
3030
$helper = $this->getHelper();

tests/Integration/AbstractTechproductsTestCase.php

+30
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPUnit\Framework\TestCase;
66
use Solarium\Component\ComponentAwareQueryInterface;
77
use Solarium\Component\Highlighting\Highlighting;
8+
use Solarium\Component\QueryInterface;
89
use Solarium\Component\QueryTraits\GroupingTrait;
910
use Solarium\Component\QueryTraits\TermsTrait;
1011
use Solarium\Component\Result\Grouping\FieldGroup;
@@ -57,6 +58,9 @@
5758
use Solarium\QueryType\Update\RequestBuilder\Xml as XmlUpdateRequestBuilder;
5859
use Solarium\Support\Utility;
5960
use Solarium\Tests\Integration\Plugin\EventTimer;
61+
use Solarium\Tests\Integration\Query\CustomQueryInterfaceQuery;
62+
use Solarium\Tests\Integration\Query\CustomSelfQuery;
63+
use Solarium\Tests\Integration\Query\CustomStaticQuery;
6064
use Symfony\Contracts\EventDispatcher\Event;
6165

6266
abstract class AbstractTechproductsTestCase extends TestCase
@@ -5066,6 +5070,32 @@ public function testEventDispatching()
50665070

50675071
self::$client->removePlugin('eventtimer');
50685072
}
5073+
5074+
/**
5075+
* Test the various return types that are valid for custom query classes that
5076+
* override the {@see \Solarium\Component\QueryTrait::setQuery()} method.
5077+
*
5078+
* If this test throws a fatal error, the return type of the parent might no
5079+
* longer be backward compatible with existing code that overrides it.
5080+
*
5081+
* @see https://github.com/solariumphp/solarium/issues/1097
5082+
*
5083+
* @dataProvider customQueryClassProvider
5084+
*/
5085+
public function testCustomQueryClassSetQueryReturnType(string $queryClass)
5086+
{
5087+
$query = new $queryClass();
5088+
$this->assertInstanceOf(QueryInterface::class, $query->setQuery('*:*'));
5089+
}
5090+
5091+
public function customQueryClassProvider(): array
5092+
{
5093+
return [
5094+
[CustomStaticQuery::class],
5095+
[CustomSelfQuery::class],
5096+
[CustomQueryInterfaceQuery::class],
5097+
];
5098+
}
50695099
}
50705100

50715101
class GroupingTestQuery extends SelectQuery
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Solarium\Tests\Integration\Query;
4+
5+
use Solarium\Component\QueryInterface;
6+
use Solarium\QueryType\Select\Query\Query as SelectQuery;
7+
8+
/**
9+
* Custom query that overrides the setQuery() method with a QueryInterface return type.
10+
*/
11+
class CustomQueryInterfaceQuery extends SelectQuery
12+
{
13+
/**
14+
* @return self Provides fluent interface
15+
*/
16+
public function setQuery(string $query, array $bind = null): QueryInterface
17+
{
18+
return parent::setQuery($query, $bind);
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Solarium\Tests\Integration\Query;
4+
5+
use Solarium\QueryType\Select\Query\Query as SelectQuery;
6+
7+
/**
8+
* Custom query that overrides the setQuery() method with a self return type.
9+
*/
10+
class CustomSelfQuery extends SelectQuery
11+
{
12+
/**
13+
* @return self Provides fluent interface
14+
*/
15+
public function setQuery(string $query, array $bind = null): self
16+
{
17+
return parent::setQuery($query, $bind);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Solarium\Tests\Integration\Query;
4+
5+
use Solarium\QueryType\Select\Query\Query as SelectQuery;
6+
7+
/**
8+
* Custom query that overrides the setQuery() method with a static return type.
9+
*/
10+
class CustomStaticQuery extends SelectQuery
11+
{
12+
/**
13+
* @return static Provides fluent interface
14+
*/
15+
public function setQuery(string $query, array $bind = null): static
16+
{
17+
return parent::setQuery($query, $bind);
18+
}
19+
}

0 commit comments

Comments
 (0)