|
@@ -2,12 +2,16 @@
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
+use App\Post;
|
|
|
+use Carbon\Carbon;
|
|
|
use Tests\TestCase;
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
|
|
class ExampleTest extends TestCase
|
|
|
{
|
|
|
+ use DatabaseTransactions;
|
|
|
+
|
|
|
/**
|
|
|
* A basic test example.
|
|
|
*
|
|
@@ -15,6 +19,34 @@ class ExampleTest extends TestCase
|
|
|
*/
|
|
|
public function testBasicTest()
|
|
|
{
|
|
|
- $this->assertTrue(true);
|
|
|
+ // $this->assertTrue(true);
|
|
|
+
|
|
|
+ // Given
|
|
|
+ // - I have two post records in the database
|
|
|
+ // - They are posted a month apart
|
|
|
+ $firstPost = factory(Post::class)->create();
|
|
|
+ $secondPost = factory(Post::class)->create([
|
|
|
+ 'created_at' => Carbon::now()->subMonth(),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // When I fetch the archives...
|
|
|
+ $posts = Post::archives();
|
|
|
+
|
|
|
+ // Then the response should be in the proper format.
|
|
|
+ $this->assertCount(2, $posts);
|
|
|
+
|
|
|
+ $this->assertSame([
|
|
|
+ [
|
|
|
+ 'year' => (int) $firstPost->created_at->format('Y'),
|
|
|
+ 'month' => $firstPost->created_at->format('F'),
|
|
|
+ 'published' => 1,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'year' => (int) $secondPost->created_at->format('Y'),
|
|
|
+ 'month' => $secondPost->created_at->format('F'),
|
|
|
+ 'published' => 1,
|
|
|
+ ],
|
|
|
+ ], $posts);
|
|
|
}
|
|
|
+
|
|
|
}
|