File: mongocollection-toindexstring.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 (42 lines) | stat: -rw-r--r-- 854 bytes parent folder | download
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
--TEST--
MongoCollection::toIndexString
--SKIPIF--
<?php require_once dirname(__FILE__) ."/skipif.inc"; ?>
--FILE--
<?php
if (version_compare( phpversion(), '5.3', '<' )) {
	ini_set('error_reporting', E_ALL & ~E_STRICT);
} else {
	ini_set('error_reporting', E_ALL & ~E_DEPRECATED);
}

class MyCollection extends MongoCollection
{
	static public function toIndexString($a)
	{
		return parent::toIndexString($a);
	}
}

$tests = array(
	'x', 'x.y.z', 'x_y.z',
	array('x' => 1),
	array('x' => -1),
	array('x' => 1, 'y' => -1),
	array('x' => '2dsphere', 'y' => 1),
	array('x' => 'text', 'y' => '2d'),
);

foreach ($tests as $test) {
	var_dump(MyCollection::toIndexString($test));
}
?>
--EXPECT--
string(3) "x_1"
string(7) "x_y_z_1"
string(7) "x_y_z_1"
string(3) "x_1"
string(4) "x_-1"
string(8) "x_1_y_-1"
string(14) "x_2dsphere_y_1"
string(11) "x_text_y_2d"