/** * Return all the models that are both saved and changed * * @return Models */ public function getModelsToUpdate() { return $this->models->filter(function (AbstractModel $model) { return $model->isChanged() and ($model->isSaved() or $model->isSoftDeleted()); }); }
/** * Return a new RepoModels object with only the models that pass the filter callback * (Filter callback returned true). * * @param Closure $filter must return true for each item * @return RepoModels Filtered models */ public function filter(Closure $filter) { return $this->current->filter($filter); }
/** * @covers ::filter */ public function testFilter() { $source = [new City(['name' => 'test1']), new City(['name' => 'test1']), new City(['name' => 'test2'])]; $models = new Models($source); $filtered = $models->filter(function ($model) { return $model->name !== 'test1'; }); $this->assertInstanceOf('Harp\\Harp\\Model\\Models', $filtered); $this->assertEquals([$source[2]], Objects::toArray($filtered->all())); }