Skip to content

Commit

Permalink
Sf4.3 testing and fix deprecations (#682) (#690)
Browse files Browse the repository at this point in the history
* Sf4.3 testing and fix deprecations (#682)

* test more symfony versions

* changed composer

* composer

* minimum-stability: dev,
prefer-stable: true
  • Loading branch information
Markus Kalkbrenner authored Aug 14, 2019
1 parent 44b778c commit 81f4d65
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 44 deletions.
13 changes: 6 additions & 7 deletions .travis.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ php:
- nightly

env:
- SYMFONY_VERSION=4.2.* SOLR_VERSION=8.1.1 SOLR_CLOUD=true
- SYMFONY_VERSION=4.2.* SOLR_VERSION=8.1.1 SOLR_CLOUD=false
- SYMFONY_VERSION=4.2.* SOLR_VERSION=7.7.2 SOLR_CLOUD=true
- SYMFONY_VERSION=4.2.* SOLR_VERSION=7.7.2 SOLR_CLOUD=false
- SYMFONY_VERSION=4.2.* SOLR_VERSION=6.6.6 SOLR_CLOUD=false
- SYMFONY_VERSION=3.3.* SOLR_VERSION=6.6.6 SOLR_CLOUD=false
- SYMFONY_VERSION=4.4.* SOLR_VERSION=8.2.0 SOLR_CLOUD=true
- SYMFONY_VERSION=4.3.* SOLR_VERSION=8.2.0 SOLR_CLOUD=false
- SYMFONY_VERSION=4.3.* SOLR_VERSION=7.7.2 SOLR_CLOUD=true
- SYMFONY_VERSION=4.4.* SOLR_VERSION=7.7.2 SOLR_CLOUD=false
- SYMFONY_VERSION=3.4.* SOLR_VERSION=6.6.6 SOLR_CLOUD=false

cache:
directories:
Expand All @@ -28,7 +27,7 @@ before_install:

before_script:
# - pecl install pecl_http
- composer require --prefer-source --dev symfony/event-dispatcher:${SYMFONY_VERSION}
- composer require --dev symfony/cache:${SYMFONY_VERSION}
- |
if [ ${SOLR_CLOUD} == "true" ]; then
solr-${SOLR_VERSION}/bin/solr start -e cloud -noprompt || travis_terminate 1;
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to the solarium library will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [5.0.4]
## [5.1.0]
### Added
- Solarium\Core\Query\Helper::formatDate() now handles DateTimeImmutable

Expand All @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- Complex ReRank queries should not cause Solr parse errors
- Update request builders format \DateTimeImmutable correctly
- Symfony >=4.3 event dispatcher deprecation warnings

### Removed
- Symfony <3.4 support


## [5.0.3]
Expand Down
4 changes: 3 additions & 1 deletion composer.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"require": {
"php": "^7.1",
"symfony/event-dispatcher": "^3.1 || ^4.0",
"symfony/event-dispatcher": "^4.3",
"symfony/cache": "^3.1 || ^4.0",
"ext-json": "*"
},
Expand All @@ -24,6 +24,8 @@
"squizlabs/php_codesniffer": "^3.4",
"zendframework/zend-http": "^2.8"
},
"minimum-stability": "dev",
"prefer-stable": true,
"suggest": {
"minimalcode/search": "Query builder compatible with Solarium, allows simplified solr-query handling"
},
Expand Down
46 changes: 19 additions & 27 deletions src/Core/Client/Client.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@
use Solarium\QueryType\Terms\Result as TermsResult;
use Solarium\QueryType\Update\Query\Query as UpdateQuery;
use Solarium\QueryType\Update\Result as UpdateResult;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;

/**
* Main interface for interaction with Solr.
Expand Down Expand Up @@ -283,7 +285,7 @@ class Client extends Configurable implements ClientInterface
*/
public function __construct(array $options = null, EventDispatcherInterface $eventDispatcher = null)
{
$this->eventDispatcher = $eventDispatcher;
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
parent::__construct($options);
}

Expand Down Expand Up @@ -623,7 +625,7 @@ public function getEventDispatcher(): EventDispatcherInterface
*/
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): ClientInterface
{
$this->eventDispatcher = $eventDispatcher;
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);

return $this;
}
Expand Down Expand Up @@ -766,7 +768,7 @@ public function removePlugin($plugin): ClientInterface
public function createRequest(QueryInterface $query): Request
{
$event = new PreCreateRequestEvent($query);
$this->eventDispatcher->dispatch(Events::PRE_CREATE_REQUEST, $event);
$this->eventDispatcher->dispatch($event, Events::PRE_CREATE_REQUEST);
if (null !== $event->getRequest()) {
return $event->getRequest();
}
Expand All @@ -778,10 +780,8 @@ public function createRequest(QueryInterface $query): Request

$request = $requestBuilder->build($query);

$this->eventDispatcher->dispatch(
Events::POST_CREATE_REQUEST,
new PostCreateRequestEvent($query, $request)
);
$event = new PostCreateRequestEvent($query, $request);
$this->eventDispatcher->dispatch($event, Events::POST_CREATE_REQUEST);

return $request;
}
Expand All @@ -800,7 +800,7 @@ public function createRequest(QueryInterface $query): Request
public function createResult(QueryInterface $query, $response): ResultInterface
{
$event = new PreCreateResultEvent($query, $response);
$this->eventDispatcher->dispatch(Events::PRE_CREATE_RESULT, $event);
$this->eventDispatcher->dispatch($event, Events::PRE_CREATE_RESULT);
if (null !== $event->getResult()) {
return $event->getResult();
}
Expand All @@ -812,10 +812,8 @@ public function createResult(QueryInterface $query, $response): ResultInterface
throw new UnexpectedValueException('Result class must implement the ResultInterface');
}

$this->eventDispatcher->dispatch(
Events::POST_CREATE_RESULT,
new PostCreateResultEvent($query, $response, $result)
);
$event = new PostCreateResultEvent($query, $response, $result);
$this->eventDispatcher->dispatch($event, Events::POST_CREATE_RESULT);

return $result;
}
Expand All @@ -831,7 +829,7 @@ public function createResult(QueryInterface $query, $response): ResultInterface
public function execute(QueryInterface $query, $endpoint = null): ResultInterface
{
$event = new PreExecuteEvent($query);
$this->eventDispatcher->dispatch(Events::PRE_EXECUTE, $event);
$this->eventDispatcher->dispatch($event, Events::PRE_EXECUTE);
if (null !== $event->getResult()) {
return $event->getResult();
}
Expand All @@ -840,10 +838,8 @@ public function execute(QueryInterface $query, $endpoint = null): ResultInterfac
$response = $this->executeRequest($request, $endpoint);
$result = $this->createResult($query, $response);

$this->eventDispatcher->dispatch(
Events::POST_EXECUTE,
new PostExecuteEvent($query, $result)
);
$event = new PostExecuteEvent($query, $result);
$this->eventDispatcher->dispatch($event, Events::POST_EXECUTE);

return $result;
}
Expand All @@ -864,17 +860,15 @@ public function executeRequest(Request $request, $endpoint = null): Response
}

$event = new PreExecuteRequestEvent($request, $endpoint);
$this->eventDispatcher->dispatch(Events::PRE_EXECUTE_REQUEST, $event);
$this->eventDispatcher->dispatch($event, Events::PRE_EXECUTE_REQUEST);
if (null !== $event->getResponse()) {
$response = $event->getResponse(); //a plugin result overrules the standard execution result
} else {
$response = $this->getAdapter()->execute($request, $endpoint);
}

$this->eventDispatcher->dispatch(
Events::POST_EXECUTE_REQUEST,
new PostExecuteRequestEvent($request, $endpoint, $response)
);
$event = new PostExecuteRequestEvent($request, $endpoint, $response);
$this->eventDispatcher->dispatch($event, Events::POST_EXECUTE_REQUEST);

return $response;
}
Expand Down Expand Up @@ -1115,7 +1109,7 @@ public function createQuery(string $type, array $options = null): QueryInterface
$type = strtolower($type);

$event = new PreCreateQueryEvent($type, $options);
$this->eventDispatcher->dispatch(Events::PRE_CREATE_QUERY, $event);
$this->eventDispatcher->dispatch($event, Events::PRE_CREATE_QUERY);
if (null !== $event->getQuery()) {
return $event->getQuery();
}
Expand All @@ -1131,10 +1125,8 @@ public function createQuery(string $type, array $options = null): QueryInterface
throw new UnexpectedValueException('All query classes must implement the QueryInterface');
}

$this->eventDispatcher->dispatch(
Events::POST_CREATE_QUERY,
new PostCreateQueryEvent($type, $options, $query)
);
$event = new PostCreateQueryEvent($type, $options, $query);
$this->eventDispatcher->dispatch($event, Events::POST_CREATE_QUERY);

return $query;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/BufferedAdd/BufferedAdd.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function addDocument(DocumentInterface $document): self
$this->buffer[] = $document;

$event = new AddDocumentEvent($document);
$this->client->getEventDispatcher()->dispatch(Events::ADD_DOCUMENT, $event);
$this->client->getEventDispatcher()->dispatch($event, Events::ADD_DOCUMENT);

if (count($this->buffer) == $this->options['buffersize']) {
$this->flush();
Expand Down
6 changes: 2 additions & 4 deletions src/Plugin/Loadbalancer/Loadbalancer.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,8 @@ protected function getLoadbalancedResponse(Request $request): Response
} catch (HttpException $e) {
// ignore HTTP errors and try again
// but do issue an event for things like logging
$this->client->getEventDispatcher()->dispatch(
Events::ENDPOINT_FAILURE,
new EndpointFailureEvent($endpoint, $e)
);
$event = new EndpointFailureEvent($endpoint, $e);
$this->client->getEventDispatcher()->dispatch($event, Events::ENDPOINT_FAILURE);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Plugin/ParallelExecution/ParallelExecution.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public function execute(): array
}

// executing multihandle (all requests)
$this->client->getEventDispatcher()->dispatch(Events::EXECUTE_START, new ExecuteStartEvent());
$event = new ExecuteStartEvent();
$this->client->getEventDispatcher()->dispatch($event, Events::EXECUTE_START);

do {
$mrc = curl_multi_exec($multiHandle, $active);
Expand All @@ -135,7 +136,8 @@ public function execute(): array
} while (CURLM_CALL_MULTI_PERFORM == $mrc);
}

$this->client->getEventDispatcher()->dispatch(Events::EXECUTE_END, new ExecuteEndEvent());
$event = new ExecuteEndEvent();
$this->client->getEventDispatcher()->dispatch(Events::EXECUTE_END, $event);

// get the results
$results = [];
Expand Down
2 changes: 1 addition & 1 deletion tests/Plugin/BufferedAdd/BufferedAddTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function testAddDocumentEventIsTriggered()
$mockEventDispatcher
->expects($this->once())
->method('dispatch')
->with($this->equalTo(Events::ADD_DOCUMENT), $this->equalTo($expectedEvent));
->with($this->equalTo($expectedEvent), $this->equalTo(Events::ADD_DOCUMENT));

$mockClient = $this->getClient($mockEventDispatcher);
$plugin = new BufferedAdd();
Expand Down

0 comments on commit 81f4d65

Please sign in to comment.