public function testOverwrite()
 {
     $fh1 = fopen('tests/somefile', 'r');
     $fh2 = fopen('mongo.c', 'r');
     $this->object->storeFile($fh1, array('_id' => 1));
     $this->object->storeFile($fh2, array('_id' => 1));
     $file = $this->object->findOne();
     $this->assertEquals(129, $file->file['length'], json_encode($file->file));
 }
 public function testMD5()
 {
     $mid = $this->object->storeFile("mongo.c");
     $gid = $this->object->storeFile("gridfs.c");
     $mongo = $this->object->findOne(array("_id" => $mid));
     $gridfs = $this->object->findOne(array("_id" => $gid));
     $this->assertNotEquals($mongo->file['md5'], $gridfs->file['md5']);
     $this->assertEquals($mongo->file['md5'], md5(file_get_contents("mongo.c")));
     $this->assertEquals($gridfs->file['md5'], md5(file_get_contents("gridfs.c")));
 }
Exemplo n.º 3
0
 public function testTimeout3()
 {
     for ($i = 0; $i < 10000; $i++) {
         $this->object->insert(array("name" => "joe" . $i, "interests" => array(rand(), rand(), rand())));
     }
     $cmd = $this->object->db->selectCollection('$cmd');
     $query = 'r = 0; cursor = db.c.find(); while (cursor.hasNext()) { x = cursor.next(); for (i=0; i<200; i++) { if (x.name == "joe"+i) { r++; } } } return r;';
     $count = 0;
     for ($i = 0; $i < 3; $i++) {
         $cursor = $cmd->find(array('$eval' => $query))->limit(-1)->timeout(500);
         try {
             $x = $cursor->getNext();
             $this->assertFalse(true, json_encode($x));
         } catch (MongoCursorTimeoutException $e) {
             $count++;
         }
     }
     $this->assertEquals(3, $count);
     $x = $this->object->findOne();
     $this->assertNotNull($x);
     $this->assertTrue(array_key_exists('name', $x), json_encode($x));
     $this->assertTrue(array_key_exists('interests', $x), json_encode($x));
 }
 /**
  * @expectedException MongoException
  */
 public function test__construct4()
 {
     $this->object->findOne(array(), array("id", 123));
 }
 public function testEmpty() {
     $this->object->storeFile('tests/empty');
     $file = $this->object->findOne();
     $this->assertEquals(0, $file->file['length']);
 }