Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[PHP-616] Allow non-MongoId arguments for MongoGridFS::get()

  • Loading branch information...
commit 7909bf7c7bd98db77543930dde66921b6fac4362 1 parent 948aee1
Jeremy Mikola jmikola authored
Showing with 56 additions and 1 deletion.
  1. +1 −1  gridfs.c
  2. +55 −0 tests/generic/gridfs-get.phpt
2  gridfs.c
View
@@ -1082,7 +1082,7 @@ PHP_METHOD(MongoGridFS, delete)
PHP_METHOD(MongoGridFS, get) {
zval *id, *criteria;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &id, mongo_ce_Id) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &id) == FAILURE) {
return;
}
55 tests/generic/gridfs-get.phpt
View
@@ -0,0 +1,55 @@
+--TEST--
+GridFS: getting files by ID
+--SKIPIF--
+<?php require_once dirname(__FILE__) ."/skipif.inc"; ?>
+--FILE--
+<?php
+require_once dirname(__FILE__) . "/../utils.inc";
+ $m = mongo("phpunit");
+ $db = $m->selectDB("phpunit");
+ $db->dropCollection("fs.files");
+ $db->dropCollection("fs.chunks");
+
+ $gridfs = $db->getGridFS();
+
+ $tempFileName = tempnam(sys_get_temp_dir(), "gridfs-delete");
+ $tempFileData = '1234567890';
+ file_put_contents($tempFileName, $tempFileData);
+
+ $ids = array(
+ "file0",
+ 452,
+ true,
+ new MongoID(),
+ array( 'a', 'b' => 5 ),
+ );
+
+ foreach ($ids as $id) {
+ $gridfs->storeFile($tempFileName, array('_id' => $id));
+ $file = $gridfs->get($id);
+
+ echo 'File exists with ID: ';
+ var_dump($file->file['_id']);
+ echo "\n";
+ }
+
+ unlink($tempFileName);
+?>
+--EXPECTF--
+File exists with ID: string(5) "file0"
+
+File exists with ID: int(452)
+
+File exists with ID: bool(true)
+
+File exists with ID: object(MongoId)#%d (1) {
+ ["$id"]=>
+ string(24) "%s"
+}
+
+File exists with ID: array(2) {
+ [0]=>
+ string(1) "a"
+ ["b"]=>
+ int(5)
+}
Please sign in to comment.
Something went wrong with that request. Please try again.