/**
  * Tests that arrays can be used to filter objects in `find()` and `first()` methods.
  */
 public function testArrayFiltering()
 {
     $collection = new DocumentSet(array('data' => array(new Document(array('data' => array('id' => 1, 'name' => 'Annie', 'active' => 1))), new Document(array('data' => array('id' => 2, 'name' => 'Zilean', 'active' => 1))), new Document(array('data' => array('id' => 3, 'name' => 'Trynamere', 'active' => 0))), new Document(array('data' => array('id' => 4, 'name' => 'Katarina', 'active' => 1))), new Document(array('data' => array('id' => 5, 'name' => 'Nunu', 'active' => 0))))));
     $result = $collection->find(array('active' => 1))->data();
     $expected = array(0 => array('id' => 1, 'name' => 'Annie', 'active' => 1), 1 => array('id' => 2, 'name' => 'Zilean', 'active' => 1), 3 => array('id' => 4, 'name' => 'Katarina', 'active' => 1));
     $this->assertEqual($expected, $result);
     $result = $collection->first(array('active' => 1))->data();
     $expected = array('id' => 1, 'name' => 'Annie', 'active' => 1);
     $this->assertEqual($expected, $result);
     $result = $collection->first(array('name' => 'Nunu'))->data();
     $expected = array('id' => 5, 'name' => 'Nunu', 'active' => 0);
     $this->assertEqual($expected, $result);
 }
Exemple #2
0
 /**
  * Tests that `Document`s with embedded objects are cast to arrays so as not to cause fatal
  * errors when traversing via array interfaces.
  *
  * @return void
  */
 public function testObjectIteration()
 {
     $doc = new DocumentSet(array('data' => array((object) array('foo' => 'bar'), (object) array('bar' => 'foo'))));
     $result = $doc->first()->foo;
     $expected = 'bar';
     $this->assertEqual($expected, $result);
     $result = $doc->next()->bar;
     $expected = 'foo';
     $this->assertEqual($expected, $result);
     $doc = new Document(array('data' => (object) array('first' => array('foo' => 'bar'), 'second' => array('bar' => 'foo'))));
     $result = $doc->first->foo;
 }