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

Migrate to Timber v2 #55

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove QueryBuilder::as()
joelambert committed Nov 12, 2024
commit 41c6cbf396c910235f533f84e628ea5438910d37
9 changes: 1 addition & 8 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
@@ -159,16 +159,9 @@ public function whereMetaRelationshipIs(string $relation): QueryBuilderContract
return $this;
}

public function as($postClass): QueryBuilderContract
{
$this->postClass = $postClass;

return $this;
}

public function get(): Collection
{
$posts = Timber::get_posts($this->getParameters(), $this->postClass);
$posts = Timber::get_posts($this->getParameters());

if (!is_array($posts)) {
$posts = [];
26 changes: 0 additions & 26 deletions tests/Unit/QueryBuilderTest.php
Original file line number Diff line number Diff line change
@@ -334,7 +334,6 @@ public function get_retrieves_list_of_posts()
'post_status' => 'publish',
'offset' => 10,
]),
Post::class,
])
->once()
->andReturn($posts);
@@ -361,7 +360,6 @@ public function get_retrieves_empty_collection_when_timber_returns_false()
'post_status' => 'publish',
'offset' => 10,
]),
Post::class,
])
->once()
->andReturn(false);
@@ -388,7 +386,6 @@ public function get_retrieves_empty_collection_when_timber_returns_null()
'post_status' => 'publish',
'offset' => 10,
]),
Post::class,
])
->once()
->andReturn(null);
@@ -400,29 +397,6 @@ public function get_retrieves_empty_collection_when_timber_returns_null()
$this->assertSame(0, $returnedPosts->count());
}

/**
* @test
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function can_specify_the_class_type_to_return()
{
$timber = Mockery::mock('alias:' . Timber::class);
$timber
->shouldReceive('get_posts')
->withArgs([
Mockery::subset([
'post_status' => 'publish',
'offset' => 10,
]),
PostWithCustomPostType::class,
])
->once();

$builder = new QueryBuilder();
$builder->whereStatus('publish')->offset(10)->as(PostWithCustomPostType::class)->get();
}

/**
* @test
* @runInSeparateProcess