Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 7909bf7c7bd98db77543930dde66921b6fac4362 1 parent 948aee1
Jeremy Mikola jmikola authored

Showing 2 changed files with 56 additions and 1 deletion. Show diff stats Hide diff stats

  1. +1 1  gridfs.c
  2. +55 0 tests/generic/gridfs-get.phpt
2  gridfs.c
@@ -1082,7 +1082,7 @@ PHP_METHOD(MongoGridFS, delete)
1082 1082 PHP_METHOD(MongoGridFS, get) {
1083 1083 zval *id, *criteria;
1084 1084
1085   - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &id, mongo_ce_Id) == FAILURE) {
  1085 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &id) == FAILURE) {
1086 1086 return;
1087 1087 }
1088 1088
55 tests/generic/gridfs-get.phpt
... ... @@ -0,0 +1,55 @@
  1 +--TEST--
  2 +GridFS: getting files by ID
  3 +--SKIPIF--
  4 +<?php require_once dirname(__FILE__) ."/skipif.inc"; ?>
  5 +--FILE--
  6 +<?php
  7 +require_once dirname(__FILE__) . "/../utils.inc";
  8 + $m = mongo("phpunit");
  9 + $db = $m->selectDB("phpunit");
  10 + $db->dropCollection("fs.files");
  11 + $db->dropCollection("fs.chunks");
  12 +
  13 + $gridfs = $db->getGridFS();
  14 +
  15 + $tempFileName = tempnam(sys_get_temp_dir(), "gridfs-delete");
  16 + $tempFileData = '1234567890';
  17 + file_put_contents($tempFileName, $tempFileData);
  18 +
  19 + $ids = array(
  20 + "file0",
  21 + 452,
  22 + true,
  23 + new MongoID(),
  24 + array( 'a', 'b' => 5 ),
  25 + );
  26 +
  27 + foreach ($ids as $id) {
  28 + $gridfs->storeFile($tempFileName, array('_id' => $id));
  29 + $file = $gridfs->get($id);
  30 +
  31 + echo 'File exists with ID: ';
  32 + var_dump($file->file['_id']);
  33 + echo "\n";
  34 + }
  35 +
  36 + unlink($tempFileName);
  37 +?>
  38 +--EXPECTF--
  39 +File exists with ID: string(5) "file0"
  40 +
  41 +File exists with ID: int(452)
  42 +
  43 +File exists with ID: bool(true)
  44 +
  45 +File exists with ID: object(MongoId)#%d (1) {
  46 + ["$id"]=>
  47 + string(24) "%s"
  48 +}
  49 +
  50 +File exists with ID: array(2) {
  51 + [0]=>
  52 + string(1) "a"
  53 + ["b"]=>
  54 + int(5)
  55 +}

0 comments on commit 7909bf7

Please sign in to comment.
Something went wrong with that request. Please try again.