Skip to content

Commit

Permalink
Remove as() casting from ScopedQueryBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
joelambert committed Nov 12, 2024
1 parent f8b8f09 commit b7891e1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
8 changes: 1 addition & 7 deletions src/ScopedQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function __construct($postClass)
$this->queryBuilder = Helpers::app(QueryBuilderContract::class);

$this->queryBuilder
->as($postClass)
->wherePostType(call_user_func([$this->postClass, 'getPostType']));
}

Expand Down Expand Up @@ -65,7 +64,7 @@ public function __call($name, $arguments)
* @param string $name The method name
* @return boolean
*/
protected function hasQueryBuilderMethod(string $name) : bool
protected function hasQueryBuilderMethod(string $name): bool
{
if (method_exists($this->queryBuilder, $name)) {
return true;
Expand All @@ -82,9 +81,4 @@ public function wherePostType($postType)
{
throw new CannotRedeclarePostTypeOnQueryException;
}

public function as($postClass)
{
throw new CannotRedeclarePostClassOnQueryException;
}
}
12 changes: 1 addition & 11 deletions tests/Unit/ScopedQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,12 @@ public function cannot_overwrite_post_type()
$builder->wherePostType('test_post_type');
}

/** @test */
public function cannot_overwrite_post_class()
{
$this->expectException(\Rareloop\Lumberjack\Exceptions\CannotRedeclarePostClassOnQueryException::class);

$builder = new ScopedQueryBuilder(PostWithQueryScope::class);
$builder->as(Post::class);
}

/**
* @test
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function get_retrieves_list_of_posts_of_correct_type()
public function get_retrieves_list_of_posts()
{
$posts = [new PostWithQueryScope(1, true), new PostWithQueryScope(2, true)];

Expand All @@ -73,7 +64,6 @@ public function get_retrieves_list_of_posts_of_correct_type()
'post_status' => 'publish',
'offset' => 10,
]),
PostWithQueryScope::class,
])->once()->andReturn($posts);

$builder = new ScopedQueryBuilder(PostWithQueryScope::class);
Expand Down

0 comments on commit b7891e1

Please sign in to comment.