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

Refactor tests #82

Merged
merged 21 commits into from
Apr 10, 2022
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Refactor to be self-contained
  • Loading branch information
caendesilva committed Apr 10, 2022
commit 39e544d61fef68c704ec9904e8f1e152e7cbf498
32 changes: 5 additions & 27 deletions tests/Unit/MarkdownPostParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,23 @@
*/
class MarkdownPostParserTest extends TestCase
{
/**
* Setup the test environment.
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();

// Create a Markdown file to work with
copy(Hyde::path('vendor/hyde/framework/tests/stubs/_posts/test-parser-post.md'), $this->getPath());
createTestPost();
}

/**
* Clean up the testing environment before the next test.
*
* @return void
*/
protected function tearDown(): void
{
// Remove the published stub file
unlink($this->getPath());
unlink(Hyde::path('_posts/test-post.md'));

parent::tearDown();
}

/**
* Get the path of the test Markdown file.
*
* @return string
*/
public function getPath(): string
{
return Hyde::path('_posts/test-parser-post.md');
}

public function test_can_parse_markdown_file()
{
$post = (new MarkdownPostParser('test-parser-post'))->get();
$post = (new MarkdownPostParser('test-post'))->get();
$this->assertInstanceOf(MarkdownPost::class, $post);
$this->assertCount(4, ($post->matter));
$this->assertIsArray($post->matter);
Expand All @@ -62,10 +40,10 @@ public function test_can_parse_markdown_file()

public function test_parsed_markdown_post_contains_valid_front_matter()
{
$post = (new MarkdownPostParser('test-parser-post'))->get();
$post = (new MarkdownPostParser('test-post'))->get();
$this->assertEquals('My New Post', $post->matter['title']);
$this->assertEquals('Mr. Hyde', $post->matter['author']);
$this->assertEquals('blog', $post->matter['category']);
$this->assertEquals('test-parser-post', $post->matter['slug']);
$this->assertEquals('test-post', $post->matter['slug']);
}
}