public function testMap() { $collection = new DocumentSet(); $collection->set(array('title' => 'Lorem Ipsum', 'key' => 'value', 'foo' => 'bar')); $results = $collection->map(function ($value) { return $value . ' test'; }); $expected = array('Lorem Ipsum test', 'value test', 'bar test'); $this->assertEqual($results->to('array'), $expected); $this->assertNotEqual($results->to('array'), $collection->to('array')); }
public function testMappingToNewDocumentSet() { $result = new MockResult(); $model = $this->_model; $doc = new DocumentSet(compact('model', 'result')); $mapped = $doc->map(function ($data) { return $data; }); $this->assertEqual($doc->data(), $mapped->data()); $this->assertEqual($model, $doc->model()); $this->assertEqual($model, $mapped->model()); }
public function testMappingToNewDocumentSet() { $result = new MockResult(array('data' => array(array('_id' => '4c8f86167675abfabdbf0300', 'title' => 'bar'), array('_id' => '5c8f86167675abfabdbf0301', 'title' => 'foo'), array('_id' => '6c8f86167675abfabdbf0302', 'title' => 'dib')))); $model = $this->_model; $doc = new DocumentSet(compact('model', 'result')); $mapped = $doc->map(function ($data) { return $data; }); $this->assertEqual($doc->data(), $mapped->data()); $this->assertEqual($model, $doc->model()); $this->assertEqual($model, $mapped->model()); }
/** * Tests `Collection::sort`. */ public function testSort() { $collection = new DocumentSet(); $collection->set(array(array('id' => 1, 'name' => 'Annie'), array('id' => 2, 'name' => 'Zilean'), array('id' => 3, 'name' => 'Trynamere'), array('id' => 4, 'name' => 'Katarina'), array('id' => 5, 'name' => 'Nunu'))); $collection->sort('name'); $idsSorted = $collection->map(function ($v) { return $v['id']; })->to('array'); $this->assertEqual($idsSorted, array(1, 4, 5, 3, 2)); }