LuceneResultTest::testCountable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\ODM\CouchDB\View;
4
5
use Doctrine\CouchDB\View\LuceneResult;
6
7
class LuceneResultTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBTestCase
8
{
9
    public function testConstruction()
10
    {
11
        $result = new LuceneResult(array(
12
            "etag" => "asdf",
13
            "fetch_duration" => 1234,
14
            "limit" => 20,
15
            "q" => "asdf + foo",
16
            "rows" => array(
17
                array("id" => "bar", "score" => 1234),
18
                array("id" => "foo", "score" => 4321),
19
            ),
20
            "search_duration" => 4321,
21
            "skip" => 20,
22
            "total_rows" => 9999,
23
        ));
24
25
        $this->assertEquals("asdf", $result->getETag());
26
        $this->assertEquals(1234, $result->getFetchDuration());
27
        $this->assertEquals(20, $result->getLimit());
28
        $this->assertEquals("asdf + foo", $result->getExecutedQuery());
29
        $this->assertEquals(4321, $result->getSearchDuration());
30
        $this->assertEquals(20, $result->getSkip());
31
        $this->assertEquals(9999, $result->getTotalRows());
32
33
        $this->assertEquals(array(
34
                array("id" => "bar", "score" => 1234),
35
                array("id" => "foo", "score" => 4321),
36
            ), $result->getRows());
37
    }
38
39
    public function testGetRowsIterator()
40
    {
41
        $result = new LuceneResult(array(
42
            "rows" => array(
43
                array("id" => "foo", "score" => 1234),
44
                array("id" => "foo", "score" => 1234),
45
            ),
46
        ));
47
48
        $i = 0;
49
        foreach ($result AS $row) {
50
            $this->assertEquals("foo", $row['id']);
51
            $this->assertEquals(1234, $row['score']);
52
            $i++;
53
        }
54
        $this->assertEquals(2, $i);
55
    }
56
57
    public function testCountable()
58
    {
59
        $result = new LuceneResult(array('limit' => 1, "rows" => array(0 => array("_id" => "foo", "score" => 1234))));
60
61
        $this->assertCount(1, $result);
62
    }
63
64
    public function testArrayAccessForRows()
65
    {
66
        $result = new LuceneResult(array(
67
            "rows" => array(
68
                array("id" => "foo", "score" => 1234),
69
                array("id" => "foo", "score" => 1234),
70
            ),
71
        ));
72
73
        $this->assertEquals("foo", $result[0]['id']);
74
        $this->assertEquals("foo", $result[1]['id']);
75
        $this->assertEquals(1234, $result[0]['score']);
76
        $this->assertEquals(1234, $result[1]['score']);
77
    }
78
}