Skip to content

Commit afad5e7

Browse files
authored
Expand comparison tests for Int64 to cover scalars (#1439)
1 parent b9fe58f commit afad5e7

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

tests/bson/bson-int64-compare-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
MongoDB\BSON\Int64 comparisons
2+
MongoDB\BSON\Int64 comparisons between objects
33
--FILE--
44
<?php
55

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
MongoDB\BSON\Int64 comparisons with scalars
3+
--FILE--
4+
<?php
5+
6+
$int64 = new MongoDB\BSON\Int64('123');
7+
8+
$tests = [
9+
'matching int' => 123,
10+
'matching numeric string' => '123',
11+
'matching float' => 123.0,
12+
'matching float string' => '123.0',
13+
14+
'wrong int' => 456,
15+
'wrong numeric string' => '456',
16+
'wrong float' => 456.0,
17+
'wrong float string' => '456.0',
18+
'float with decimals' => 123.456,
19+
'string float with decimals' => '123.456',
20+
21+
'non-numeric string' => 'foo',
22+
];
23+
24+
foreach ($tests as $name => $value) {
25+
printf('Testing %s: %s' . PHP_EOL, $name, var_export($int64 == $value, true));
26+
}
27+
28+
?>
29+
===DONE===
30+
<?php exit(0); ?>
31+
--EXPECT--
32+
Testing matching int: true
33+
Testing matching numeric string: true
34+
Testing matching float: true
35+
Testing matching float string: true
36+
Testing wrong int: false
37+
Testing wrong numeric string: false
38+
Testing wrong float: false
39+
Testing wrong float string: false
40+
Testing float with decimals: false
41+
Testing string float with decimals: false
42+
Testing non-numeric string: false
43+
===DONE===
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
MongoDB\BSON\Int64 comparisons with scalars (64-bit values)
3+
--FILE--
4+
<?php
5+
6+
// Use 2**33 to ensure it still fits in a float
7+
$int64 = new MongoDB\BSON\Int64('8589934592');
8+
9+
$tests = [
10+
'matching numeric string' => '8589934592',
11+
'matching float' => 8589934592.0,
12+
'matching float string' => '8589934592.0',
13+
14+
'wrong numeric string' => '8589934593',
15+
'wrong float' => 8589934593.0,
16+
'wrong float string' => '8589934593.0',
17+
'float with decimals' => 8589934592.1,
18+
'string float with decimals' => '8589934592.1',
19+
];
20+
21+
foreach ($tests as $name => $value) {
22+
printf('Testing %s: %s' . PHP_EOL, $name, var_export($int64 == $value, true));
23+
}
24+
25+
?>
26+
===DONE===
27+
<?php exit(0); ?>
28+
--EXPECT--
29+
Testing matching numeric string: true
30+
Testing matching float: true
31+
Testing matching float string: true
32+
Testing wrong numeric string: false
33+
Testing wrong float: false
34+
Testing wrong float string: false
35+
Testing float with decimals: false
36+
Testing string float with decimals: false
37+
===DONE===
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
MongoDB\BSON\Int64 comparisons with scalars (64-bit values, 64-bit platforms only)
3+
--SKIPIF--
4+
<?php if (8 !== PHP_INT_SIZE) { die('skip Only for 64-bit platform'); } ?>
5+
--FILE--
6+
<?php
7+
8+
// Use 2**33 to ensure it still fits in a float
9+
$int64 = new MongoDB\BSON\Int64('8589934592');
10+
11+
$tests = [
12+
'matching int' => 8589934592,
13+
'wrong int' => 8589934593,
14+
];
15+
16+
foreach ($tests as $name => $value) {
17+
printf('Testing %s: %s' . PHP_EOL, $name, var_export($int64 == $value, true));
18+
}
19+
20+
?>
21+
===DONE===
22+
<?php exit(0); ?>
23+
--EXPECT--
24+
Testing matching int: true
25+
Testing wrong int: false
26+
===DONE===

0 commit comments

Comments
 (0)