File: MongoCollectionTest2.php

package info (click to toggle)
php-mongo 1.5.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,040 kB
  • ctags: 2,802
  • sloc: ansic: 17,632; xml: 2,195; php: 1,630; pascal: 330; makefile: 52; sh: 39
file content (72 lines) | stat: -rw-r--r-- 2,388 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
71
72
<?php
class MongoCollectionTest2 extends PHPUnit_Framework_TestCase
{
    /**
     * @var    MongoCollection
     * @access protected
     */
    protected $object;

    /**
     * @access protected
     */
    protected function setUp()
    {
        $m = new Mongo();
        $db = new MongoDB($m, "phpunit");
        $this->object = $db->selectCollection('c');
        $this->object->drop();
    }

    public function testFsyncOpt() {
        $result = $this->object->insert(array("x" => 1), array("fsync" => 1));
        $this->assertArrayHasKey("err", $result, json_encode($result));
    }

    public function testSafeW() {
        $result = $this->object->insert(array("category" => "fruit", "name" => "apple"), array("safe" => 1));
        $this->assertArrayHasKey("ok", $result, json_encode($result));
    }

    public function testFields() {
        $this->object->insert(array("x" => array(1,2,3,4,5)));
        $results = $this->object->find(array(),array("x" => array('$slice' => 3)))->getNext();
        $r = $results['x'];

        $this->assertTrue(array_key_exists(0, $r));
        $this->assertTrue(array_key_exists(1, $r));
        $this->assertTrue(array_key_exists(2, $r));
        $this->assertFalse(array_key_exists(3, $r));
        $this->assertFalse(array_key_exists(4, $r));
    }

    /**
     * @expectedException MongoException
     */
    public function testIndexNameLen1() {
      $this->object->ensureIndex(array("x" => 1), array("name" => "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"));
    }

    /**
     * @expectedException MongoException
     */
    public function testIndexNameLen2() {
      $this->object->ensureIndex(array("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" => 1));
    }

    public function testTimeout() {
        $this->object->insert(array("x" => 1), array("safe" => true, "timeout" => -1));
        $this->object->insert(array("x" => 1), array("safe" => true, "timeout" => 30));
        $this->object->insert(array("x" => 1), array("safe" => true, "timeout" => 1000));
    }

    /**
     * @expectedException Exception
     */
    public function testCtor() {
        $db = $this->object->db;
        $c = new MongoCollection($db, "");
    }
}

?>