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.2] Fix scopes method and add test #14078

Merged
merged 1 commit into from
Jun 20, 2016
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
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ public function scopes(array $scopes)
}

$builder = $builder->callScope(
'scope'.ucfirst($scope), (array) $parameters
[$this->model, 'scope'.ucfirst($scope)], (array) $parameters
);
}

Expand Down
33 changes: 33 additions & 0 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Mockery as m;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;

class DatabaseEloquentModelTest extends PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -1348,6 +1349,22 @@ public function testStringIdTypePreserved()
$this->assertEquals('string id', $model->id);
}

public function testScopesMethod()
{
$model = new EloquentModelStub;
$this->addMockConnection($model);

$scopes = [
'published',
'category' => 'Laravel',
'framework' => ['Laravel', '5.2'],
];

$this->assertInstanceOf(Builder::class, $model->scopes($scopes));

$this->assertSame($scopes, $model->scopesCalled);
}

protected function addMockConnection($model)
{
$model->setConnectionResolver($resolver = m::mock('Illuminate\Database\ConnectionResolverInterface'));
Expand All @@ -1371,6 +1388,7 @@ public function saved()
class EloquentModelStub extends Model
{
public $connection;
public $scopesCalled = [];
protected $table = 'stub';
protected $guarded = [];
protected $morph_to_stub_type = 'EloquentModelSaveStub';
Expand Down Expand Up @@ -1429,6 +1447,21 @@ public function getAppendableAttribute()
{
return 'appended';
}

public function scopePublished(Builder $builder)
{
$this->scopesCalled[] = 'published';
}

public function scopeCategory(Builder $builder, $category)
{
$this->scopesCalled['category'] = $category;
}

public function scopeFramework(Builder $builder, $framework, $version)
{
$this->scopesCalled['framework'] = [$framework, $version];
}
}

class EloquentModelCamelStub extends EloquentModelStub
Expand Down