Skip to content

Commit

Permalink
feat(test): add MarkdownWithDateModelTest and change test dummy conte…
Browse files Browse the repository at this point in the history
…nt directory structure
  • Loading branch information
thebatclaudio committed May 26, 2024
1 parent 816faf7 commit 5f92bd7
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Models/MarkdownWithDateModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Illuminate\Support\Str;

/**
* Abstract class MarkdownModel.
* Abstract class MarkdownWithDateModel.
*
* @property Carbon $date
* @property string $slug
Expand Down
4 changes: 2 additions & 2 deletions tests/Models/MarkdownModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestModel extends MarkdownModel
}

beforeEach(function () {
Config::set('markdown-model.path', __DIR__.'/../content');
Config::set('markdown-model.path', __DIR__.'/../content/pages');
});

it('returns the right file calling find method', function () {
Expand Down Expand Up @@ -50,7 +50,7 @@ class TestModel extends MarkdownModel
->toBe($fileId);
});

it('returns all files calling all methods', function () {
it('returns all files calling all method', function () {
$markdowns = TestModel::all()->toArray();

expect($markdowns)
Expand Down
56 changes: 56 additions & 0 deletions tests/Models/MarkdownWithDateModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

use Carbon\Carbon;
use Illuminate\Support\Facades\Config;
use TheBatClaudio\EloquentMarkdown\Models\MarkdownWithDateModel;

class TestWithDateModel extends MarkdownWithDateModel
{
}

beforeEach(function () {
Config::set('markdown-model.path', __DIR__.'/../content/blog');
});

it('returns all files calling all method', function () {
$markdowns = TestWithDateModel::all()->toArray();

expect($markdowns)
->not->toBeEmpty()
->toHaveCount(3)
->and(array_keys($markdowns))
->toContain(
'2024-05-26-yet-another-test',
'2024-05-24-another-test',
'2024-05-22-test',
);
});

it('should have date attribute', function () {
$markdown = TestWithDateModel::find('2024-05-26-yet-another-test');

expect($markdown)
->not->toBeNull()
->and($markdown->toArray())
->toHaveKey('date')
->and($markdown->date)
->toBeInstanceOf(Carbon::class)
->and(
(new Carbon('2024-05-26'))
->equalTo($markdown->date)
)
->toBeTrue();
});

it('should have slug attribute', function () {
$markdown = TestWithDateModel::find('2024-05-26-yet-another-test');

expect($markdown)
->not->toBeNull()
->and($markdown->toArray())
->toHaveKey('slug')
->and($markdown->slug)
->toBe('yet-another-test');
});
7 changes: 7 additions & 0 deletions tests/content/blog/2024-05-22-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
first_attribute: First attribute
second_attribute: Second attribute
third_attribute: Third attribute
---
The time has come. You know it. In your mind. In your heart. In your soul. You tried to hold me back. But you can't,
Bruce. You're weak. You're a shell. A rusty trap that cannot hold me. Let it go. Let me OUT.
7 changes: 7 additions & 0 deletions tests/content/blog/2024-05-24-another-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
first_attribute: First attribute
second_attribute: Second attribute
third_attribute: Third attribute
---
The time has come. You know it. In your mind. In your heart. In your soul. You tried to hold me back. But you can't,
Bruce. You're weak. You're a shell. A rusty trap that cannot hold me. Let it go. Let me OUT.
7 changes: 7 additions & 0 deletions tests/content/blog/2024-05-26-yet-another-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
first_attribute: First attribute
second_attribute: Second attribute
third_attribute: Third attribute
---
The time has come. You know it. In your mind. In your heart. In your soul. You tried to hold me back. But you can't,
Bruce. You're weak. You're a shell. A rusty trap that cannot hold me. Let it go. Let me OUT.
Empty file removed tests/content/folder/test.md
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ first_attribute: First attribute
second_attribute: Second attribute
third_attribute: Third attribute
---

The time has come. You know it. In your mind. In your heart. In your soul. You tried to hold me back. But you can't,
Bruce. You're weak. You're a shell. A rusty trap that cannot hold me. Let it go. Let me OUT.
7 changes: 7 additions & 0 deletions tests/content/pages/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
first_attribute: First attribute
second_attribute: Second attribute
third_attribute: Third attribute
---
The time has come. You know it. In your mind. In your heart. In your soul. You tried to hold me back. But you can't,
Bruce. You're weak. You're a shell. A rusty trap that cannot hold me. Let it go. Let me OUT.
1 change: 0 additions & 1 deletion tests/content/test2.md → tests/content/pages/test2.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ first_attribute: First attribute
second_attribute: Second attribute
third_attribute: Third attribute
---

The time has come. You know it. In your mind. In your heart. In your soul. You tried to hold me back. But you can't,
Bruce. You're weak. You're a shell. A rusty trap that cannot hold me. Let it go. Let me OUT.
1 change: 0 additions & 1 deletion tests/content/test3.md → tests/content/pages/test3.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ first_attribute: First attribute
second_attribute: Second attribute
third_attribute: Third attribute
---

The time has come. You know it. In your mind. In your heart. In your soul. You tried to hold me back. But you can't,
Bruce. You're weak. You're a shell. A rusty trap that cannot hold me. Let it go. Let me OUT.

0 comments on commit 5f92bd7

Please sign in to comment.