Skip to content

Commit f955686

Browse files
authored
[9.x] Improve test for whereNot and WhereNested in query Builder Class (#44148)
1 parent 0432012 commit f955686

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/Integration/Database/QueryBuilderTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ public function testWhereNot()
158158
$this->assertSame('Bar Post', $results[0]->title);
159159
}
160160

161+
public function testWhereNotInputStringParameter()
162+
{
163+
$results = DB::table('posts')->whereNot('title', 'Foo Post')->get();
164+
165+
$this->assertCount(1, $results);
166+
$this->assertSame('Bar Post', $results[0]->title);
167+
168+
DB::table('posts')->insert([
169+
['title' => 'Baz Post', 'content' => 'Lorem Ipsum.', 'created_at' => new Carbon('2017-11-12 13:14:15')],
170+
]);
171+
172+
$results = DB::table('posts')->whereNot('title', 'Foo Post')->whereNot('title', 'Bar Post')->get();
173+
$this->assertSame('Baz Post', $results[0]->title);
174+
}
175+
161176
public function testOrWhereNot()
162177
{
163178
$results = DB::table('posts')->where('id', 1)->orWhereNot(function ($query) {
@@ -233,6 +248,15 @@ public function testOrWhereTime()
233248
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereTime('created_at', new Carbon('2018-01-02 03:04:05'))->count());
234249
}
235250

251+
public function testWhereNested()
252+
{
253+
$results = DB::table('posts')->where('content', 'Lorem Ipsum.')->whereNested(function ($query) {
254+
$query->where('title', 'Foo Post')
255+
->orWhere('title', 'Bar Post');
256+
})->count();
257+
$this->assertSame(2, $results);
258+
}
259+
236260
public function testPaginateWithSpecificColumns()
237261
{
238262
$result = DB::table('posts')->paginate(5, ['title', 'content']);

0 commit comments

Comments
 (0)