Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Oct 21, 2023
1 parent cea970b commit f173b89
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/framework/tests/Unit/CreatesNewMarkdownPostFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Hyde\Framework\Testing\Unit;

use Hyde\Testing\TestCase;
use Illuminate\Support\Str;
use Hyde\Framework\Actions\CreatesNewMarkdownPostFile;

/**
* @covers \Hyde\Framework\Actions\CreatesNewMarkdownPostFile
* @see \Hyde\Framework\Testing\Feature\Commands\MakePostCommandTest
*/
class CreatesNewMarkdownPostFileTest extends TestCase
{
public function testWithDefaultData()
{
$action = new CreatesNewMarkdownPostFile('Example Title', null, null, null);
$array = $action->toArray();

// Truncate date as it can cause tests to fail when the clock switches over a second
$array['date'] = Str::before($array['date'], ' ');

$this->assertSame([
'title' => 'Example Title',
'description' => 'A short description used in previews and SEO',
'category' => 'blog',
'author' => 'default',
'date' => date('Y-m-d'),
], $array);
}

public function testWithCustomData()
{
$action = new CreatesNewMarkdownPostFile('foo', 'bar', 'baz', 'qux');
$array = $action->toArray();

// Truncate date as it can cause tests to fail when the clock switches over a second
$array['date'] = Str::before($array['date'], ' ');

$this->assertSame([
'title' => 'foo',
'description' => 'bar',
'category' => 'baz',
'author' => 'qux',
'date' => date('Y-m-d'),
], $array);
}
}

0 comments on commit f173b89

Please sign in to comment.