10
10
use Doctrine \DBAL \Types \Types ;
11
11
use Generator ;
12
12
use PHPUnit \Framework \Attributes \DataProvider ;
13
- use PHPUnit \Framework \Constraint \IsIdentical ;
14
- use PHPUnit \Framework \Constraint \LogicalOr ;
15
13
16
14
use const PHP_INT_MAX ;
17
15
use const PHP_INT_MIN ;
@@ -30,13 +28,13 @@ public function testSelectBigInt(string $sqlLiteral, int|string|null $expectedVa
30
28
31
29
$ this ->connection ->executeStatement (<<<SQL
32
30
INSERT INTO bigint_type_test (id, my_integer)
33
- VALUES (42 , $ sqlLiteral)
31
+ VALUES (1 , $ sqlLiteral)
34
32
SQL );
35
33
36
34
self ::assertSame (
37
35
$ expectedValue ,
38
36
$ this ->connection ->convertToPHPValue (
39
- $ this ->connection ->fetchOne ('SELECT my_integer from bigint_type_test WHERE id = 42 ' ),
37
+ $ this ->connection ->fetchOne ('SELECT my_integer from bigint_type_test ' ),
40
38
Types::BIGINT ,
41
39
),
42
40
);
@@ -46,47 +44,23 @@ public function testSelectBigInt(string $sqlLiteral, int|string|null $expectedVa
46
44
public static function provideBigIntLiterals (): Generator
47
45
{
48
46
yield 'zero ' => ['0 ' , 0 ];
47
+ yield 'minus zero ' => ['-0 ' , 0 ];
48
+ yield 'plus zero ' => ['+0 ' , 0 ];
49
49
yield 'null ' => ['null ' , null ];
50
50
yield 'positive number ' => ['42 ' , 42 ];
51
51
yield 'negative number ' => ['-42 ' , -42 ];
52
-
53
- if (PHP_INT_SIZE < 8 ) {
54
- // The following tests only work on 64bit systems.
55
- return ;
56
- }
57
-
58
- yield 'large positive number ' => ['9223372036854775806 ' , PHP_INT_MAX - 1 ];
59
- yield 'large negative number ' => ['-9223372036854775807 ' , PHP_INT_MIN + 1 ];
60
- }
61
-
62
- #[DataProvider('provideBigIntEdgeLiterals ' )]
63
- public function testSelectBigIntEdge (int $ value ): void
64
- {
65
- $ table = new Table ('bigint_type_test ' );
66
- $ table ->addColumn ('id ' , Types::SMALLINT , ['notnull ' => true ]);
67
- $ table ->addColumn ('my_integer ' , Types::BIGINT , ['notnull ' => false ]);
68
- $ table ->setPrimaryKey (['id ' ]);
69
- $ this ->dropAndCreateTable ($ table );
70
-
71
- $ this ->connection ->executeStatement (<<<SQL
72
- INSERT INTO bigint_type_test (id, my_integer)
73
- VALUES (42, $ value)
74
- SQL );
75
-
76
- self ::assertThat (
77
- $ this ->connection ->convertToPHPValue (
78
- $ this ->connection ->fetchOne ('SELECT my_integer from bigint_type_test WHERE id = 42 ' ),
79
- Types::BIGINT ,
80
- ),
81
- LogicalOr::fromConstraints (new IsIdentical ($ value ), new IsIdentical ((string ) $ value )),
82
- );
83
- }
84
-
85
- /** @return Generator<string, array{int}> */
86
- public static function provideBigIntEdgeLiterals (): Generator
87
- {
88
- yield 'max int ' => [PHP_INT_MAX ];
89
- yield 'min int ' => [PHP_INT_MIN ];
52
+ yield 'large positive number ' => [PHP_INT_SIZE === 4 ? '2147483646 ' : '9223372036854775806 ' , PHP_INT_MAX - 1 ];
53
+ yield 'large negative number ' => [PHP_INT_SIZE === 4 ? '-2147483647 ' : '-9223372036854775807 ' , PHP_INT_MIN + 1 ];
54
+ yield 'largest positive number ' => [PHP_INT_SIZE === 4 ? '2147483647 ' : '9223372036854775807 ' , PHP_INT_MAX ];
55
+ yield 'largest negative number ' => [PHP_INT_SIZE === 4 ? '-2147483648 ' : '-9223372036854775808 ' , PHP_INT_MIN ];
56
+ yield 'too large positive number ' => [
57
+ PHP_INT_SIZE === 4 ? '2147483648 ' : '9223372036854775808 ' ,
58
+ PHP_INT_SIZE === 4 ? '2147483648 ' : '9223372036854775808 ' ,
59
+ ];
60
+ yield 'too large negative number ' => [
61
+ PHP_INT_SIZE === 4 ? '-2147483649 ' : '-9223372036854775809 ' ,
62
+ PHP_INT_SIZE === 4 ? '-2147483649 ' : '-9223372036854775809 ' ,
63
+ ];
90
64
}
91
65
92
66
public function testUnsignedBigIntOnMySQL (): void
@@ -104,13 +78,13 @@ public function testUnsignedBigIntOnMySQL(): void
104
78
// Insert (2 ** 64) - 1
105
79
$ this ->connection ->executeStatement (<<<'SQL'
106
80
INSERT INTO bigint_type_test (id, my_integer)
107
- VALUES (42 , 0xFFFFFFFFFFFFFFFF)
81
+ VALUES (1 , 0xFFFFFFFFFFFFFFFF)
108
82
SQL);
109
83
110
84
self ::assertSame (
111
85
'18446744073709551615 ' ,
112
86
$ this ->connection ->convertToPHPValue (
113
- $ this ->connection ->fetchOne ('SELECT my_integer from bigint_type_test WHERE id = 42 ' ),
87
+ $ this ->connection ->fetchOne ('SELECT my_integer from bigint_type_test ' ),
114
88
Types::BIGINT ,
115
89
),
116
90
);
0 commit comments