Skip to content

Commit

Permalink
Merge pull request #2 from lmc-eu/feature/profile-endpoint-details
Browse files Browse the repository at this point in the history
Profile used endpoint details for a query
  • Loading branch information
MortalFlesh authored Jul 28, 2021
2 parents 14934cb + 01ee24c commit 9ff8d52
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- There should always be "Unreleased" section at the beginning. -->

## Unreleased
- Profile used endpoint details for a query

## 1.0.0 - 2021-05-13
- Initial implementation
4 changes: 3 additions & 1 deletion src/Query/AbstractSolrQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public function getProfilerId(): string

public function getProfilerData(): ?array
{
return null;
return [
'Endpoint' => $this->getEndpoint() ?? 'Default',
];
}

public function getEndpoint(): ?string
Expand Down
7 changes: 7 additions & 0 deletions src/Query/AbstractSolrSelectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ private function prepareQuery(Query $select): Query
}

abstract public function prepareSelect(Query $select): Query;

public function getProfilerData(): ?array
{
return parent::getProfilerData() + [
'Endpoint.details' => clone $this->client->getEndpoint($this->getEndpoint()),
];
}
}
4 changes: 2 additions & 2 deletions tests/QueryBuilder/Applicator/GroupingApplicatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public function shouldApplyGroupingOnQuery(): void
$this->assertStringContainsString('rows=' . $entity->getNumberOfRows(), $queryUri);

$this->assertStringContainsString('group=true', $queryUri);
$this->assertStringContainsString('group.main=' . $entity->getMainResult() ? 'true' : 'false', $queryUri);
$this->assertStringContainsString('group.main=' . ($entity->getMainResult() ? 'true' : 'false'), $queryUri);
$this->assertStringContainsString('group.field=' . $entity->getGroupingField(), $queryUri);
$this->assertStringContainsString('group.limit=' . $entity->getGroupingLimit(), $queryUri);
$this->assertStringContainsString(
'group.ngroups=' . $entity->getNumberOfGroups() ? 'true' : 'false',
'group.ngroups=' . ($entity->getNumberOfGroups() ? 'true' : 'false'),
$queryUri
);
}
Expand Down
29 changes: 29 additions & 0 deletions tests/QueryBuilder/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Lmc\Cqrs\Solr\QueryBuilder\Query\BuilderPrototypeQuery;
use PHPUnit\Framework\TestCase;
use Solarium\Core\Client\Client;
use Solarium\Core\Client\Endpoint;

class QueryBuilderTest extends TestCase
{
Expand Down Expand Up @@ -324,4 +325,32 @@ public function provideQueryOptions(): array
],
];
}

/**
* @test
*/
public function shouldProfileUsedValues(): void
{
$client = new Client();
$entity = new BaseDummyEntity('query');

$query = $this->queryBuilderWithApplicators->buildQuery($entity);
$query->setSolrClient($client);

$profilerData = $query->getProfilerData();

$this->assertIsArray($profilerData);

$this->assertArrayHasKey('Endpoint', $profilerData);
$this->assertSame('Default', $profilerData['Endpoint']);

$this->assertArrayHasKey('Endpoint.details', $profilerData);
$this->assertInstanceOf(Endpoint::class, $profilerData['Endpoint.details']);

$this->assertNotSame(
$client->getEndpoint($query->getEndpoint()),
$profilerData['Endpoint.details'],
'Profiled endpoint should not be a real instance of endpoint, but it should be cloned, so it remains unchanged in time of profiling.'
);
}
}

0 comments on commit 9ff8d52

Please sign in to comment.