/** * Group models by repo, call yield for each repo * * @param Closure $yield Call for each repo ($repo, $models) */ public function byRepo(Closure $yield) { $repos = Objects::groupBy($this->models, function (AbstractModel $model) { return $model->getRepo()->getRootRepo(); }); foreach ($repos as $repo) { $models = new Models(); $models->addObjects($repos->getInfo()); $yield($repo, $models); } }
/** * @covers ::addObjects */ public function testAddObjects() { $models = new Models(); $model1 = new City(); $model2 = new City(); $objects = new SplObjectStorage(); $objects->attach($model1); $objects->attach($model2); $models->addObjects($objects); $this->assertSame([$model1, $model2], Objects::toArray($models->all())); }