public function testFindMethodFindsModelById() { $mockModel = m::mock('LMongo\\Eloquent\\Model'); $mockModel->shouldReceive('getKey')->andReturn(1); $c = new Collection(array($mockModel)); $this->assertTrue($mockModel === $c->find(1)); }
public function testLists() { $data = new Collection(array((object) array('name' => 'taylor', 'email' => 'foo'), (object) array('name' => 'dayle', 'email' => 'bar'))); $this->assertEquals(array('taylor' => 'foo', 'dayle' => 'bar'), $data->lists('email', 'name')); $this->assertEquals(array('foo', 'bar'), $data->lists('email')); }
/** * Save the model and all of its relationships. * * @return bool */ public function push() { if (!$this->save()) { return false; } // To sync all of the relationships to the database, we will simply spin through // the relationships and save each model via this "push" method, which allows // us to recurse into all of these nested relations for the model instance. foreach ($this->relations as $models) { foreach (Collection::make($models) as $model) { if (!$model->push()) { return false; } } } return true; }