Skip to content

Commit 5fd967c

Browse files
committed
Legacy can use collect() for now
1 parent 550037d commit 5fd967c

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

yii2-adapter/legacy/controllers/ElementsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ private function _contextMenuItems(
791791
->status(null)
792792
->orderBy(['dateUpdated' => SORT_DESC])
793793
->with(['draftCreator'])
794-
->get()
794+
->collect()
795795
->filter(fn(ElementInterface $draft) => $elementsService->canView($draft, $user))
796796
->all();
797797
} else {

yii2-adapter/tests/unit/elements/ElementCollectionTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function _fixtures(): array
3333

3434
public function testFind(): void
3535
{
36-
$collection = Entry::find()->get();
36+
$collection = Entry::find()->collect();
3737
self::assertInstanceOf(ElementCollection::class, $collection);
3838
$first = $collection->first();
3939
self::assertInstanceOf(Entry::class, $first);
@@ -47,7 +47,7 @@ public function testFind(): void
4747

4848
public function testContains(): void
4949
{
50-
$collection = Entry::find()->get();
50+
$collection = Entry::find()->collect();
5151
self::assertInstanceOf(ElementCollection::class, $collection);
5252
self::assertTrue($collection->contains('title', 'Theories of life'));
5353
self::assertTrue($collection->contains(fn(Entry $entry) => $entry->title === 'Theories of life'));
@@ -63,7 +63,7 @@ public function testContains(): void
6363

6464
public function testIds(): void
6565
{
66-
$collection = Entry::find()->get();
66+
$collection = Entry::find()->collect();
6767
self::assertInstanceOf(ElementCollection::class, $collection);
6868
$ids = $collection->map(fn(Entry $entry) => $entry->id)->all();
6969
self::assertSame($ids, $collection->ids()->all());
@@ -72,7 +72,7 @@ public function testIds(): void
7272
public function testMerge(): void
7373
{
7474
/** @var ElementCollection<Entry|User> $collection */
75-
$collection = Entry::find()->get();
75+
$collection = Entry::find()->collect();
7676
self::assertInstanceOf(ElementCollection::class, $collection);
7777
$first = $collection->first();
7878
self::assertInstanceOf(Entry::class, $first);
@@ -86,7 +86,7 @@ public function testMerge(): void
8686

8787
public function testMap(): void
8888
{
89-
$collection = Entry::find()->get();
89+
$collection = Entry::find()->collect();
9090
self::assertInstanceOf(ElementCollection::class, $collection);
9191
$mapped = $collection->map(fn(Entry $entry) => new Entry());
9292
self::assertInstanceOf(ElementCollection::class, $mapped);
@@ -96,7 +96,7 @@ public function testMap(): void
9696

9797
public function testMapWithKeys(): void
9898
{
99-
$collection = Entry::find()->get();
99+
$collection = Entry::find()->collect();
100100
self::assertInstanceOf(ElementCollection::class, $collection);
101101
$mapped = $collection->mapWithKeys(fn(Entry $entry, int|string $key) => [$entry->id => new Entry()]);
102102
self::assertInstanceOf(ElementCollection::class, $mapped);
@@ -107,7 +107,7 @@ public function testMapWithKeys(): void
107107

108108
public function testFresh(): void
109109
{
110-
$collection = Entry::find()->get();
110+
$collection = Entry::find()->collect();
111111
self::assertInstanceOf(ElementCollection::class, $collection);
112112
$collection->each(function(Entry $entry) {
113113
$entry->title .= 'edit';
@@ -120,10 +120,10 @@ public function testFresh(): void
120120

121121
public function testDiff(): void
122122
{
123-
$collection1 = Entry::find()->limit(4)->get();
123+
$collection1 = Entry::find()->limit(4)->collect();
124124
self::assertInstanceOf(ElementCollection::class, $collection1);
125125
self::assertSame(4, $collection1->count());
126-
$collection2 = Entry::find()->offset(3)->get();
126+
$collection2 = Entry::find()->offset(3)->collect();
127127
self::assertInstanceOf(ElementCollection::class, $collection2);
128128
self::assertTrue($collection2->isNotEmpty());
129129
$diff = $collection1->diff($collection2->all());
@@ -132,10 +132,10 @@ public function testDiff(): void
132132

133133
public function testIntersect(): void
134134
{
135-
$collection1 = Entry::find()->limit(4)->get();
135+
$collection1 = Entry::find()->limit(4)->collect();
136136
self::assertInstanceOf(ElementCollection::class, $collection1);
137137
self::assertSame(4, $collection1->count());
138-
$collection2 = Entry::find()->offset(3)->get();
138+
$collection2 = Entry::find()->offset(3)->collect();
139139
self::assertInstanceOf(ElementCollection::class, $collection2);
140140
self::assertTrue($collection2->isNotEmpty());
141141
$intersect = $collection1->intersect($collection2->all());
@@ -144,7 +144,7 @@ public function testIntersect(): void
144144

145145
public function testUnique(): void
146146
{
147-
$collection = Entry::find()->limit(4)->get();
147+
$collection = Entry::find()->limit(4)->collect();
148148
self::assertInstanceOf(ElementCollection::class, $collection);
149149
$count = $collection->count();
150150
$collection->push(...$collection->all());
@@ -155,7 +155,7 @@ public function testUnique(): void
155155

156156
public function testOnly(): void
157157
{
158-
$collection = Entry::find()->get();
158+
$collection = Entry::find()->collect();
159159
self::assertInstanceOf(ElementCollection::class, $collection);
160160
self::assertNotEquals(1, $collection->count());
161161
$first = $collection->first();
@@ -166,7 +166,7 @@ public function testOnly(): void
166166

167167
public function testExcept(): void
168168
{
169-
$collection = Entry::find()->get();
169+
$collection = Entry::find()->collect();
170170
self::assertInstanceOf(ElementCollection::class, $collection);
171171
$count = $collection->count();
172172
$first = $collection->first();
@@ -177,7 +177,7 @@ public function testExcept(): void
177177

178178
public function testBaseMethods(): void
179179
{
180-
$collection = Entry::find()->get();
180+
$collection = Entry::find()->collect();
181181
self::assertInstanceOf(ElementCollection::class, $collection);
182182
self::assertSame(Collection::class, get_class($collection->countBy(fn(Entry $entry) => $entry->sectionId)));
183183
self::assertSame(Collection::class, get_class($collection->collapse()));

0 commit comments

Comments
 (0)