Add lazy collection for members
This commit is contained in:
parent
7b9cad7580
commit
6e04bc2de6
|
@ -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']);
|
||||
}));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue