This repository has been archived by the owner on Nov 11, 2020. It is now read-only.
/
CursorTest.php
64 lines (53 loc) · 1.75 KB
/
CursorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Doctrine\MongoDB\Tests;
class CursorTest extends BaseTest
{
private $doc1;
private $doc2;
private $doc3;
private $cursor;
public function setUp()
{
parent::setUp();
$this->doc1 = array('name' => 'A');
$this->doc2 = array('name' => 'B');
$this->doc3 = array('name' => 'C');
$collection = $this->conn->selectCollection(self::$dbName, 'docs');
$collection->insert($this->doc1);
$collection->insert($this->doc2);
$collection->insert($this->doc3);
$this->cursor = $collection->createQueryBuilder()->getQuery()->execute();
$this->cursor->sort(array('name' => 1));
}
/**
* @covers Doctrine\MongoDB\Cursor::getSingleResult
*/
public function testGetSingleResult()
{
$this->assertEquals($this->doc1, $this->cursor->getSingleResult());
}
/**
* @covers Doctrine\MongoDB\Cursor::getSingleResult
*/
public function testCursorIsResetAfterGetSingleResult()
{
$this->assertEquals($this->doc1, $this->cursor->getSingleResult());
// Make sure limit is restored and cursor is rewound
$expected = array($this->doc1, $this->doc2, $this->doc3);
$actual = array();
foreach ($this->cursor as $entry) {
$actual[] = $entry;
}
$this->assertEquals($expected, $actual);
}
/**
* @covers Doctrine\MongoDB\Cursor::getSingleResult
*/
public function testGetSingleResultReturnsNull()
{
$collection = $this->conn->selectCollection(self::$dbName, 'tmp');
$collection->remove(array());
$cursor = $collection->createQueryBuilder()->getQuery()->execute();
$this->assertNull($cursor->getSingleResult());
}
}