@@ -56,10 +56,7 @@ public function addEntry(TestTableEntry ...$entry): static
5656 */
5757 public function query (Query $ query ): QueryResult
5858 {
59- $ entries = $ this ->findEntries ($ query ->getWhere (), $ query ->getLimit ()?->start, $ query ->getLimit ()?->length);
60- if ($ order = $ query ->getOrder ()) {
61- $ entries = $ this ->orderEntries ($ entries , $ order );
62- }
59+ $ entries = $ this ->findEntries ($ query ->getWhere (), $ query ->getLimit ()?->start, $ query ->getLimit ()?->length, $ query ->getOrder ());
6360
6461 if ($ query instanceof SelectQuery) {
6562 $ clonedEntries = [];
@@ -129,9 +126,10 @@ public function groupAndAggregateEntries(array $entries, ?array $group, ?array $
129126 * @param WhereGroup|null $where
130127 * @param int|null $offset
131128 * @param int|null $limit
129+ * @param array|null $order
132130 * @return TestTableEntry[]
133131 */
134- protected function findEntries (?WhereGroup $ where , ?int $ offset = null , ?int $ limit = null ): array
132+ protected function findEntries (?WhereGroup $ where , ?int $ offset = null , ?int $ limit = null , ? array $ order = null ): array
135133 {
136134 $ entries = [];
137135 if ($ offset === null ) {
@@ -141,16 +139,14 @@ protected function findEntries(?WhereGroup $where, ?int $offset = null, ?int $li
141139 if (!$ entry ->matchesWhereGroup ($ where )) {
142140 continue ;
143141 }
144- if ($ offset > 0 ) {
145- $ offset --;
146- continue ;
147- }
148142 $ entries [] = $ entry ;
149- if ($ limit !== null && count ($ entries ) >= $ limit ) {
150- break ;
151- }
152143 }
153- return $ entries ;
144+
145+ if ($ order !== null ) {
146+ $ entries = $ this ->orderEntries ($ entries , $ order );
147+ }
148+
149+ return array_slice ($ entries , $ offset , $ limit );
154150 }
155151
156152 /**
@@ -228,4 +224,4 @@ public function deleteEntry(TestTableEntry $entry): static
228224 }
229225 return $ this ;
230226 }
231- }
227+ }
0 commit comments