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 {
$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 $this->member($member['id']);
}));

View File

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

View File

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