Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Fix orWhereDay(), orWhereMonth() and orWhereYear() #29317

Merged
merged 1 commit into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ public function orWhereDay($column, $operator, $value = null)
$value, $operator, func_num_args() === 2
);

return $this->addDateBasedWhere('Day', $column, $operator, $value, 'or');
return $this->whereDay($column, $operator, $value, 'or');
}

/**
Expand Down Expand Up @@ -1264,7 +1264,7 @@ public function orWhereMonth($column, $operator, $value = null)
$value, $operator, func_num_args() === 2
);

return $this->addDateBasedWhere('Month', $column, $operator, $value, 'or');
return $this->whereMonth($column, $operator, $value, 'or');
}

/**
Expand Down Expand Up @@ -1303,7 +1303,7 @@ public function orWhereYear($column, $operator, $value = null)
$value, $operator, func_num_args() === 2
);

return $this->addDateBasedWhere('Year', $column, $operator, $value, 'or');
return $this->whereYear($column, $operator, $value, 'or');
}

/**
Expand Down
34 changes: 34 additions & 0 deletions tests/Integration/Database/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected function setUp(): void
parent::setUp();

Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('content');
$table->timestamp('created_at');
Expand All @@ -36,33 +37,66 @@ public function testWhereDate()
$this->assertSame(1, DB::table('posts')->whereDate('created_at', new Carbon('2018-01-02'))->count());
}

public function testOrWhereDate()
{
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereDate('created_at', '2018-01-02')->count());
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereDate('created_at', new Carbon('2018-01-02'))->count());
}

public function testWhereDay()
{
$this->assertSame(1, DB::table('posts')->whereDay('created_at', '02')->count());
$this->assertSame(1, DB::table('posts')->whereDay('created_at', 2)->count());
$this->assertSame(1, DB::table('posts')->whereDay('created_at', new Carbon('2018-01-02'))->count());
}

public function testOrWhereDay()
{
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereDay('created_at', '02')->count());
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereDay('created_at', 2)->count());
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereDay('created_at', new Carbon('2018-01-02'))->count());
}

public function testWhereMonth()
{
$this->assertSame(1, DB::table('posts')->whereMonth('created_at', '01')->count());
$this->assertSame(1, DB::table('posts')->whereMonth('created_at', 1)->count());
$this->assertSame(1, DB::table('posts')->whereMonth('created_at', new Carbon('2018-01-02'))->count());
}

public function testOrWhereMonth()
{
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereMonth('created_at', '01')->count());
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereMonth('created_at', 1)->count());
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereMonth('created_at', new Carbon('2018-01-02'))->count());
}

public function testWhereYear()
{
$this->assertSame(1, DB::table('posts')->whereYear('created_at', '2018')->count());
$this->assertSame(1, DB::table('posts')->whereYear('created_at', 2018)->count());
$this->assertSame(1, DB::table('posts')->whereYear('created_at', new Carbon('2018-01-02'))->count());
}

public function testOrWhereYear()
{
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereYear('created_at', '2018')->count());
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereYear('created_at', 2018)->count());
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereYear('created_at', new Carbon('2018-01-02'))->count());
}

public function testWhereTime()
{
$this->assertSame(1, DB::table('posts')->whereTime('created_at', '03:04:05')->count());
$this->assertSame(1, DB::table('posts')->whereTime('created_at', new Carbon('2018-01-02 03:04:05'))->count());
}

public function testOrWhereTime()
{
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereTime('created_at', '03:04:05')->count());
$this->assertSame(2, DB::table('posts')->where('id', 1)->orWhereTime('created_at', new Carbon('2018-01-02 03:04:05'))->count());
}

public function testPaginateWithSpecificColumns()
{
$result = DB::table('posts')->paginate(5, ['title', 'content']);
Expand Down