<?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));
}
}
?>