Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
/phpunit.xml
/phpcs.xml
/psalm.xml
/.idea
/.phpunit.cache
/vendor
13 changes: 8 additions & 5 deletions src/ORM/Association/Loader/PartitionableSelectLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ protected function _addCleanupListener(SelectQuery $query, array $removals = [])
) use (
$trackingOptionName,
$processedStateOptionName
): SelectQuery {
): void {
// Scope the listener to specific queries in order to avoid states
// being messed with when the listener is triggered for other queries
// of the same repository. Furthermore, this ensures that the listener
Expand All @@ -208,7 +208,9 @@ protected function _addCleanupListener(SelectQuery $query, array $removals = [])
!array_key_exists($trackingOptionName, $queryOptions) ||
$queryOptions[$processedStateOptionName] === true
) {
return $query;
$event->setResult($query);

return;
}

$trackingId = $queryOptions[$trackingOptionName];
Expand All @@ -219,7 +221,8 @@ protected function _addCleanupListener(SelectQuery $query, array $removals = [])
);
}

return (static::$_cleanUpListenerMap[$trackingId])($event, $query);
$result = (static::$_cleanUpListenerMap[$trackingId])($event, $query);
$event->setResult($result);
};
}

Expand Down Expand Up @@ -257,7 +260,7 @@ protected function _addCleanupListener(SelectQuery $query, array $removals = [])
) use (
$removals,
$processedStateOptionName
): SelectQuery {
): void {
if ($removals['limit']) {
$query->limit(null);
}
Expand All @@ -272,7 +275,7 @@ protected function _addCleanupListener(SelectQuery $query, array $removals = [])

$query->applyOptions([$processedStateOptionName => true]);

return $query;
$event->setResult($query);
};

static::$_cleanUpListenerMap[$trackingId] = $listener;
Expand Down
14 changes: 8 additions & 6 deletions tests/TestCase/ORM/Association/PartitionedBelongsToManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public function testOverrideLimitAndSortInBeforeFindQueryBuilder(string $loaderS

$association
->getEventManager()
->on('Model.beforeFind', function ($event, SelectQuery $query, Arrayobject $options) {
->on('Model.beforeFind', function ($event, SelectQuery $query, Arrayobject $options): void {
if (($options['partitionableQueryType'] ?? null) === 'fetcher') {
$query
->limit(2)
Expand All @@ -548,7 +548,7 @@ public function testOverrideLimitAndSortInBeforeFindQueryBuilder(string $loaderS
]);
}

return $query;
$event->setResult($query);
});

$this->assertResultsEqualFile(__FUNCTION__, $queryClone->toArray());
Expand All @@ -572,10 +572,11 @@ public function testRemovingTheObjectHashOption(): void

$association
->getEventManager()
->on('Model.beforeFind', function ($event, SelectQuery $query) {
return $query->applyOptions([
->on('Model.beforeFind', function ($event, SelectQuery $query): void {
$query->applyOptions([
PartitionableSelectWithPivotLoader::class . '_trackingId' => null,
]);
$event->setResult($query);
});

$query->toArray();
Expand All @@ -599,10 +600,11 @@ public function testLimitAndOffsetInBeforeFindDoAffectQueriesForTheSameRepositor
$this->_studentsTable
->getAssociation('TopGraduatedCourses')
->getEventManager()
->on('Model.beforeFind', function ($event, SelectQuery $query) {
return $query
->on('Model.beforeFind', function ($event, SelectQuery $query): void {
$query
->limit(2)
->offset(3);
$event->setResult($query);
});

$query = $this->_studentsTable
Expand Down
14 changes: 8 additions & 6 deletions tests/TestCase/ORM/Association/PartitionedHasManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public function testOverrideLimitAndSortInBeforeFindQueryBuilder(string $loaderS

$association
->getEventManager()
->on('Model.beforeFind', function ($event, SelectQuery $query, ArrayObject $options) {
->on('Model.beforeFind', function ($event, SelectQuery $query, ArrayObject $options): void {
if (($options['partitionableQueryType'] ?? null) === 'fetcher') {
$query
->limit(2)
Expand All @@ -494,7 +494,7 @@ public function testOverrideLimitAndSortInBeforeFindQueryBuilder(string $loaderS
]);
}

return $query;
$event->setResult($query);
});

$query = $this->_articlesTable
Expand Down Expand Up @@ -527,10 +527,11 @@ public function testRemovingTheObjectHashOption(): void

$association
->getEventManager()
->on('Model.beforeFind', function ($event, SelectQuery $query) {
return $query->applyOptions([
->on('Model.beforeFind', function ($event, SelectQuery $query): void {
$query->applyOptions([
PartitionableSelectLoader::class . '_trackingId' => null,
]);
$event->setResult($query);
});

$query->toArray();
Expand All @@ -554,10 +555,11 @@ public function testLimitAndOffsetInBeforeFindDoAffectQueriesForTheSameRepositor
$this->_articlesTable
->getAssociation('TopComments')
->getEventManager()
->on('Model.beforeFind', function ($event, SelectQuery $query) {
return $query
->on('Model.beforeFind', function ($event, SelectQuery $query): void {
$query
->limit(2)
->offset(3);
$event->setResult($query);
});

$query = $this->_articlesTable
Expand Down