Debian php-mongo / php-mongo-1.2.2 / mongo-1.2.2 / tests / CmdSymbolTest.php

<?php
require_once 'PHPUnit/Framework.php';

/**
 * Test class for Mongo.
 * Generated by PHPUnit on 2009-04-09 at 18:09:02.
 */
class CmdSymbolTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var    Mongo
     * @access protected
     */
    protected $object;

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     *
     * @access protected
     */
    public function setUp() {
        $m = new Mongo();
        $this->object = $m->selectCollection('foo', 'bar');
        $this->object->drop();
    }

    public function tearDown() {
        ini_set("mongo.cmd", '$');
    }

    public function testSet() {
        ini_set("mongo.cmd", "!");
        $this->object->save(array('name'=>'google.com'));
        $this->object->update(array(), array('!set' => array("name" => "yahoo.com")));
        $yahoo = $this->object->findOne();
        $this->assertEquals('yahoo.com', $yahoo['name']);

        ini_set("mongo.cmd", "#");
        $this->object->update(array(), array('#set' => array("name" => "askjeeves.com")));
        $jeeves = $this->object->findOne();
        $this->assertEquals('askjeeves.com', $jeeves['name']);
    }

    public function testNS() {
        ini_set("mongo.cmd", "@");

        $m=  new Mongo();
        $db = $m->selectDB("admin");
        $cmd = $db->selectCollection('@cmd');

        $info = $cmd->findOne(array('buildinfo' => 1));
        $this->assertArrayHasKey('version', $info, json_encode($info));
        $this->assertArrayHasKey('gitVersion', $info, json_encode($info));
        $this->assertArrayHasKey('sysInfo', $info, json_encode($info));
    }

    
    public function testRef() {
        ini_set("mongo.cmd", ":");

        $this->object->insert(array("_id" => 123, "hello" => "world"));
        $this->object->insert(array("_id" => 456, "ref" => array(":ref" => "bar", ":id" => 123)));

        $ref = $this->object->findOne(array("_id" => 456));
        $obj = MongoDBRef::get($this->object->db, $ref["ref"]);
        $this->assertNotNull($obj);
        $this->assertEquals("world", $obj["hello"], json_encode($obj));
    }

}

?>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.