Skip to content

Commit

Permalink
Extract testing helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 3, 2024
1 parent 71a95c4 commit 123b592
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions packages/framework/tests/Feature/PostsAuthorIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ protected function setUp(): void
*/
public function testCreatePostWithUndefinedAuthor()
{
(new CreatesNewMarkdownPostFile(
title: 'post-with-undefined-author',
description: '',
category: '',
author: 'test_undefined_author'
))->save();

$this->assertFileExists(Hyde::path('_posts/post-with-undefined-author.md'));
$this->createPostFile('post-with-undefined-author', 'test_undefined_author');

$this->artisan('rebuild _posts/post-with-undefined-author.md')->assertExitCode(0);
$this->assertFileExists(Hyde::path('_site/posts/post-with-undefined-author.html'));

Expand All @@ -58,14 +52,7 @@ public function testCreatePostWithUndefinedAuthor()
*/
public function testCreatePostWithDefinedAuthorWithName()
{
(new CreatesNewMarkdownPostFile(
title: 'post-with-defined-author-with-name',
description: '',
category: '',
author: 'named_author'
))->save();

$this->assertFileExists(Hyde::path('_posts/post-with-defined-author-with-name.md'));
$this->createPostFile('post-with-defined-author-with-name', 'named_author');

Config::set('hyde.authors', [
Author::create('named_author', 'Test Author', null),
Expand All @@ -90,14 +77,7 @@ public function testCreatePostWithDefinedAuthorWithName()
*/
public function testCreatePostWithDefinedAuthorWithWebsite()
{
(new CreatesNewMarkdownPostFile(
title: 'post-with-defined-author-with-name',
description: '',
category: '',
author: 'test_author_with_website'
))->save();

$this->assertFileExists(Hyde::path('_posts/post-with-defined-author-with-name.md'));
$this->createPostFile('post-with-defined-author-with-name', 'test_author_with_website');

Config::set('hyde.authors', [
Author::create('test_author_with_website', 'Test Author', 'https://example.org'),
Expand All @@ -122,4 +102,11 @@ public function testCreatePostWithDefinedAuthorWithWebsite()
Filesystem::unlink('_posts/post-with-defined-author-with-name.md');
Filesystem::unlink('_site/posts/post-with-defined-author-with-name.html');
}

protected function createPostFile(string $title, string $author): void
{
(new CreatesNewMarkdownPostFile(title: $title, description: '', category: '', author: $author))->save();

$this->assertFileExists(Hyde::path('_posts/'.$title.'.md'));
}
}

0 comments on commit 123b592

Please sign in to comment.