Add lazy collection for members

This commit is contained in:
philipp lang 2020-07-04 02:11:30 +02:00
parent 7b9cad7580
commit 6e04bc2de6
3 changed files with 13 additions and 5 deletions

View File

@ -26,6 +26,13 @@ class Group implements Arrayable {
} }
public function members(): MemberCollection { public function members(): MemberCollection {
$members = Nami::membersOf($this->id);
return MemberCollection::make(function() use ($members) {
foreach ($members as $member) {
yield $this->member($member['id']);
}
});
return new MemberCollection(Nami::membersOf($this->id)->map(function($member) { return new MemberCollection(Nami::membersOf($this->id)->map(function($member) {
return $this->member($member['id']); return $this->member($member['id']);
})); }));

View File

@ -2,9 +2,9 @@
namespace Zoomyboy\LaravelNami; namespace Zoomyboy\LaravelNami;
use Illuminate\Support\Collection; use Illuminate\Support\LazyCollection;
class MemberCollection extends Collection { class MemberCollection extends LazyCollection {
public static function fromOverview($items) { public static function fromOverview($items) {
$self = new self($items); $self = new self($items);

View File

@ -100,9 +100,10 @@ class PullMemberTest extends TestCase
Nami::login(); Nami::login();
$member = Nami::group(103)->members(); $members = Nami::group(103)->members();
$this->assertSame($values[0], $member->get(0)->toArray()[$key]); foreach ($members as $i => $m) {
$this->assertSame($values[1], $member->get(1)->toArray()[$key]); $this->assertSame($values[$i], $m->toArray()[$key]);
}
Http::assertSentCount(6); Http::assertSentCount(6);
} }