12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- 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.
- *
- * @return void
- */
- public function testBasicTest()
- {
- // $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);
- }
- }
|