@@ -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 ' ]);
@@ -1038,11 +1044,25 @@ public function testWhereKeyMethodWithInt()
1038
1044
1039
1045
$ int = 1 ;
1040
1046
1047
+ $ model ->shouldReceive ('getKeyType ' )->once ()->andReturn ('int ' );
1041
1048
$ builder ->getQuery ()->shouldReceive ('where ' )->once ()->with ($ keyName , '= ' , $ int );
1042
1049
1043
1050
$ builder ->whereKey ($ int );
1044
1051
}
1045
1052
1053
+ public function testWhereKeyMethodWithStringZero ()
1054
+ {
1055
+ $ model = new EloquentBuilderTestStubStringPrimaryKey ();
1056
+ $ builder = $ this ->getBuilder ()->setModel ($ model );
1057
+ $ keyName = $ model ->getQualifiedKeyName ();
1058
+
1059
+ $ int = 0 ;
1060
+
1061
+ $ builder ->getQuery ()->shouldReceive ('where ' )->once ()->with ($ keyName , '= ' , (string ) $ int );
1062
+
1063
+ $ builder ->whereKey ($ int );
1064
+ }
1065
+
1046
1066
public function testWhereKeyMethodWithArray ()
1047
1067
{
1048
1068
$ model = $ this ->getMockModel ();
@@ -1069,6 +1089,19 @@ public function testWhereKeyMethodWithCollection()
1069
1089
$ builder ->whereKey ($ collection );
1070
1090
}
1071
1091
1092
+ public function testWhereKeyNotMethodWithStringZero ()
1093
+ {
1094
+ $ model = new EloquentBuilderTestStubStringPrimaryKey ();
1095
+ $ builder = $ this ->getBuilder ()->setModel ($ model );
1096
+ $ keyName = $ model ->getQualifiedKeyName ();
1097
+
1098
+ $ int = 0 ;
1099
+
1100
+ $ builder ->getQuery ()->shouldReceive ('where ' )->once ()->with ($ keyName , '!= ' , (string ) $ int );
1101
+
1102
+ $ builder ->whereKeyNot ($ int );
1103
+ }
1104
+
1072
1105
public function testWhereKeyNotMethodWithInt ()
1073
1106
{
1074
1107
$ model = $ this ->getMockModel ();
@@ -1077,6 +1110,7 @@ public function testWhereKeyNotMethodWithInt()
1077
1110
1078
1111
$ int = 1 ;
1079
1112
1113
+ $ model ->shouldReceive ('getKeyType ' )->once ()->andReturn ('int ' );
1080
1114
$ builder ->getQuery ()->shouldReceive ('where ' )->once ()->with ($ keyName , '!= ' , $ int );
1081
1115
1082
1116
$ builder ->whereKeyNot ($ int );
@@ -1445,3 +1479,12 @@ class EloquentBuilderTestStubWithoutTimestamp extends Model
1445
1479
1446
1480
protected $ table = 'table ' ;
1447
1481
}
1482
+
1483
+ class EloquentBuilderTestStubStringPrimaryKey extends Model
1484
+ {
1485
+ public $ incrementing = false ;
1486
+
1487
+ protected $ table = 'foo_table ' ;
1488
+
1489
+ protected $ keyType = 'string ' ;
1490
+ }
0 commit comments