@@ -31,7 +31,9 @@ protected function tearDown(): void
31
31
public function testFindMethod ()
32
32
{
33
33
$ builder = m::mock (Builder::class.'[first] ' , [$ this ->getMockQueryBuilder ()]);
34
- $ builder ->setModel ($ this ->getMockModel ());
34
+ $ model = $ this ->getMockModel ();
35
+ $ builder ->setModel ($ model );
36
+ $ model ->shouldReceive ('getKeyType ' )->once ()->andReturn ('int ' );
35
37
$ builder ->getQuery ()->shouldReceive ('where ' )->once ()->with ('foo_table.foo ' , '= ' , 'bar ' );
36
38
$ builder ->shouldReceive ('first ' )->with (['column ' ])->andReturn ('baz ' );
37
39
@@ -76,6 +78,7 @@ public function testFindManyMethod()
76
78
public function testFindOrNewMethodModelFound ()
77
79
{
78
80
$ model = $ this ->getMockModel ();
81
+ $ model ->shouldReceive ('getKeyType ' )->once ()->andReturn ('int ' );
79
82
$ model ->shouldReceive ('findOrNew ' )->once ()->andReturn ('baz ' );
80
83
81
84
$ builder = m::mock (Builder::class.'[first] ' , [$ this ->getMockQueryBuilder ()]);
@@ -91,6 +94,7 @@ public function testFindOrNewMethodModelFound()
91
94
public function testFindOrNewMethodModelNotFound ()
92
95
{
93
96
$ model = $ this ->getMockModel ();
97
+ $ model ->shouldReceive ('getKeyType ' )->once ()->andReturn ('int ' );
94
98
$ model ->shouldReceive ('findOrNew ' )->once ()->andReturn (m::mock (Model::class));
95
99
96
100
$ builder = m::mock (Builder::class.'[first] ' , [$ this ->getMockQueryBuilder ()]);
@@ -109,7 +113,9 @@ public function testFindOrFailMethodThrowsModelNotFoundException()
109
113
$ this ->expectException (ModelNotFoundException::class);
110
114
111
115
$ builder = m::mock (Builder::class.'[first] ' , [$ this ->getMockQueryBuilder ()]);
112
- $ builder ->setModel ($ this ->getMockModel ());
116
+ $ model = $ this ->getMockModel ();
117
+ $ model ->shouldReceive ('getKeyType ' )->once ()->andReturn ('int ' );
118
+ $ builder ->setModel ($ model );
113
119
$ builder ->getQuery ()->shouldReceive ('where ' )->once ()->with ('foo_table.foo ' , '= ' , 'bar ' );
114
120
$ builder ->shouldReceive ('first ' )->with (['column ' ])->andReturn (null );
115
121
$ builder ->findOrFail ('bar ' , ['column ' ]);
@@ -1017,11 +1023,25 @@ public function testWhereKeyMethodWithInt()
1017
1023
1018
1024
$ int = 1 ;
1019
1025
1026
+ $ model ->shouldReceive ('getKeyType ' )->once ()->andReturn ('int ' );
1020
1027
$ builder ->getQuery ()->shouldReceive ('where ' )->once ()->with ($ keyName , '= ' , $ int );
1021
1028
1022
1029
$ builder ->whereKey ($ int );
1023
1030
}
1024
1031
1032
+ public function testWhereKeyMethodWithStringZero ()
1033
+ {
1034
+ $ model = new EloquentBuilderTestStubStringPrimaryKey ();
1035
+ $ builder = $ this ->getBuilder ()->setModel ($ model );
1036
+ $ keyName = $ model ->getQualifiedKeyName ();
1037
+
1038
+ $ int = 0 ;
1039
+
1040
+ $ builder ->getQuery ()->shouldReceive ('where ' )->once ()->with ($ keyName , '= ' , (string ) $ int );
1041
+
1042
+ $ builder ->whereKey ($ int );
1043
+ }
1044
+
1025
1045
public function testWhereKeyMethodWithArray ()
1026
1046
{
1027
1047
$ model = $ this ->getMockModel ();
@@ -1048,6 +1068,19 @@ public function testWhereKeyMethodWithCollection()
1048
1068
$ builder ->whereKey ($ collection );
1049
1069
}
1050
1070
1071
+ public function testWhereKeyNotMethodWithStringZero ()
1072
+ {
1073
+ $ model = new EloquentBuilderTestStubStringPrimaryKey ();
1074
+ $ builder = $ this ->getBuilder ()->setModel ($ model );
1075
+ $ keyName = $ model ->getQualifiedKeyName ();
1076
+
1077
+ $ int = 0 ;
A3E2
1078
+
1079
+ $ builder ->getQuery ()->shouldReceive ('where ' )->once ()->with ($ keyName , '!= ' , (string ) $ int );
1080
+
1081
+ $ builder ->whereKeyNot ($ int );
1082
+ }
1083
+
1051
1084
public function testWhereKeyNotMethodWithInt ()
1052
1085
{
1053
1086
$ model = $ this ->getMockModel ();
@@ -1056,6 +1089,7 @@ public function testWhereKeyNotMethodWithInt()
1056
1089
1057
1090
$ int = 1 ;
1058
1091
1092
+ $ model ->shouldReceive ('getKeyType ' )->once ()->andReturn ('int ' );
1059
1093
$ builder ->getQuery ()->shouldReceive ('where ' )->once ()->with ($ keyName , '!= ' , $ int );
1060
1094
1061
1095
$ builder ->whereKeyNot ($ int );
@@ -1414,3 +1448,12 @@ class EloquentBuilderTestStubWithoutTimestamp extends Model
1414
1448
1415
1449
protected $ table = 'table ' ;
1416
1450
}
1451
+
1452
+ class EloquentBuilderTestStubStringPrimaryKey extends Model
1453
6042
+ {
1454
+ public $ incrementing = false ;
1455
+
1456
+ protected $ table = 'foo_table ' ;
1457
+
1458
+ protected $ keyType = 'string ' ;
1459
+ }
0 commit comments