Skip to content

Commit

Permalink
Fix BC issue introduced in #1087 (#1098)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomascorthals authored Oct 2, 2023
1 parent 0e1d769 commit 4d9a240
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- Spatial component distance type changed from int to float
- Revert return type for Solarium\Component\QueryTrait::setQuery() from `self` to `QueryInterface` for backward compatibility with custom query classes that override this method


## [6.3.2]
### Added
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Please see the [docs](http://solarium.readthedocs.io/en/stable/) for a more deta

## Requirements

Solarium 6.4.x only supports PHP 8.0 and up.
Solarium 6.3.2 and up only supports PHP 8.0 and up.

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

### Pitfall when upgrading to 6.4
### Pitfall when upgrading to 6.3.2

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

### Pitfall when upgrading to 6.3

Expand Down
2 changes: 1 addition & 1 deletion src/Component/QueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait QueryTrait
*
* @return self Provides fluent interface
*/
public function setQuery(string $query, array $bind = null): self
public function setQuery(string $query, array $bind = null): QueryInterface
{
if (null !== $bind) {
$helper = $this->getHelper();
Expand Down
30 changes: 30 additions & 0 deletions tests/Integration/AbstractTechproductsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPUnit\Framework\TestCase;
use Solarium\Component\ComponentAwareQueryInterface;
use Solarium\Component\Highlighting\Highlighting;
use Solarium\Component\QueryInterface;
use Solarium\Component\QueryTraits\GroupingTrait;
use Solarium\Component\QueryTraits\TermsTrait;
use Solarium\Component\Result\Grouping\FieldGroup;
Expand Down Expand Up @@ -57,6 +58,9 @@
use Solarium\QueryType\Update\RequestBuilder\Xml as XmlUpdateRequestBuilder;
use Solarium\Support\Utility;
use Solarium\Tests\Integration\Plugin\EventTimer;
use Solarium\Tests\Integration\Query\CustomQueryInterfaceQuery;
use Solarium\Tests\Integration\Query\CustomSelfQuery;
use Solarium\Tests\Integration\Query\CustomStaticQuery;
use Symfony\Contracts\EventDispatcher\Event;

abstract class AbstractTechproductsTestCase extends TestCase
Expand Down Expand Up @@ -5066,6 +5070,32 @@ public function testEventDispatching()

self::$client->removePlugin('eventtimer');
}

/**
* Test the various return types that are valid for custom query classes that
* override the {@see \Solarium\Component\QueryTrait::setQuery()} method.
*
* If this test throws a fatal error, the return type of the parent might no
* longer be backward compatible with existing code that overrides it.
*
* @see https://github.com/solariumphp/solarium/issues/1097
*
* @dataProvider customQueryClassProvider
*/
public function testCustomQueryClassSetQueryReturnType(string $queryClass)
{
$query = new $queryClass();
$this->assertInstanceOf(QueryInterface::class, $query->setQuery('*:*'));
}

public function customQueryClassProvider(): array
{
return [
[CustomStaticQuery::class],
[CustomSelfQuery::class],
[CustomQueryInterfaceQuery::class],
];
}
}

class GroupingTestQuery extends SelectQuery
Expand Down
20 changes: 20 additions & 0 deletions tests/Integration/Query/CustomQueryInterfaceQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Solarium\Tests\Integration\Query;

use Solarium\Component\QueryInterface;
use Solarium\QueryType\Select\Query\Query as SelectQuery;

/**
* Custom query that overrides the setQuery() method with a QueryInterface return type.
*/
class CustomQueryInterfaceQuery extends SelectQuery
{
/**
* @return self Provides fluent interface
*/
public function setQuery(string $query, array $bind = null): QueryInterface
{
return parent::setQuery($query, $bind);
}
}
19 changes: 19 additions & 0 deletions tests/Integration/Query/CustomSelfQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Solarium\Tests\Integration\Query;

use Solarium\QueryType\Select\Query\Query as SelectQuery;

/**
* Custom query that overrides the setQuery() method with a self return type.
*/
class CustomSelfQuery extends SelectQuery
{
/**
* @return self Provides fluent interface
*/
public function setQuery(string $query, array $bind = null): self
{
return parent::setQuery($query, $bind);
}
}
19 changes: 19 additions & 0 deletions tests/Integration/Query/CustomStaticQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Solarium\Tests\Integration\Query;

use Solarium\QueryType\Select\Query\Query as SelectQuery;

/**
* Custom query that overrides the setQuery() method with a static return type.
*/
class CustomStaticQuery extends SelectQuery
{
/**
* @return static Provides fluent interface
*/
public function setQuery(string $query, array $bind = null): static
{
return parent::setQuery($query, $bind);
}
}

0 comments on commit 4d9a240

Please sign in to comment.