diff --git a/.gitignore b/.gitignore index ec14a3c..0aa47ba 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ /phpunit.xml /phpcs.xml /psalm.xml +/.idea /.phpunit.cache /vendor diff --git a/src/ORM/Association/Loader/PartitionableSelectLoaderTrait.php b/src/ORM/Association/Loader/PartitionableSelectLoaderTrait.php index 2c36c92..2481963 100644 --- a/src/ORM/Association/Loader/PartitionableSelectLoaderTrait.php +++ b/src/ORM/Association/Loader/PartitionableSelectLoaderTrait.php @@ -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 @@ -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]; @@ -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); }; } @@ -257,7 +260,7 @@ protected function _addCleanupListener(SelectQuery $query, array $removals = []) ) use ( $removals, $processedStateOptionName - ): SelectQuery { + ): void { if ($removals['limit']) { $query->limit(null); } @@ -272,7 +275,7 @@ protected function _addCleanupListener(SelectQuery $query, array $removals = []) $query->applyOptions([$processedStateOptionName => true]); - return $query; + $event->setResult($query); }; static::$_cleanUpListenerMap[$trackingId] = $listener; diff --git a/tests/TestCase/ORM/Association/PartitionedBelongsToManyTest.php b/tests/TestCase/ORM/Association/PartitionedBelongsToManyTest.php index 8f24ac6..bc429e5 100644 --- a/tests/TestCase/ORM/Association/PartitionedBelongsToManyTest.php +++ b/tests/TestCase/ORM/Association/PartitionedBelongsToManyTest.php @@ -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) @@ -548,7 +548,7 @@ public function testOverrideLimitAndSortInBeforeFindQueryBuilder(string $loaderS ]); } - return $query; + $event->setResult($query); }); $this->assertResultsEqualFile(__FUNCTION__, $queryClone->toArray()); @@ -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(); @@ -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 diff --git a/tests/TestCase/ORM/Association/PartitionedHasManyTest.php b/tests/TestCase/ORM/Association/PartitionedHasManyTest.php index a94124e..58507ca 100644 --- a/tests/TestCase/ORM/Association/PartitionedHasManyTest.php +++ b/tests/TestCase/ORM/Association/PartitionedHasManyTest.php @@ -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) @@ -494,7 +494,7 @@ public function testOverrideLimitAndSortInBeforeFindQueryBuilder(string $loaderS ]); } - return $query; + $event->setResult($query); }); $query = $this->_articlesTable @@ -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(); @@ -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