File: bug00508.phpt

package info (click to toggle)
php-mongo 1.5.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,040 kB
  • ctags: 2,802
  • sloc: ansic: 17,632; xml: 2,195; php: 1,630; pascal: 330; makefile: 52; sh: 39
file content (50 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
--TEST--
Test for PHP-508: Change BSON ID generation to use random "increment".
--SKIPIF--
<?php require "tests/utils/standalone.inc";?>
--FILE--
<?php
require_once "tests/utils/server.inc";
$m = new_mongo_standalone();
$c = $m->selectDB(dbname())->test;
$c->drop();

$d = array(
	array('c' => 0),
	array('c' => 1),
	array('c' => 2),
	array('c' => 3),
);

foreach ($d as $doc)
{
	$c->insert($doc);
	$id = $doc['_id']->__toString();

	var_dump($id);
	
	if ($doc['c'] == 0)	{
		/* For the first one, we make sure it doesn't end in 000000. It
		 * is technically possible, but very unlikely */
		echo preg_match('/000000$/', $id) ? "All zeroes :-(\n" : "All random!\n";
	} else {
		/* For subsequent once, we check whether it's one more than the
		 * last one. */
		$idInt = hexdec(substr($id, -6));

		echo ((($lastIdInt + 1) % 0x1000000) == $idInt) ? "One more\n" : "Something odd\n";
	}

	$lastIdInt = hexdec(substr($id, -6));
	unset($doc);
}
?>
--EXPECTF--
string(24) "%s"
All random!
string(24) "%s"
One more
string(24) "%s"
One more
string(24) "%s"
One more