ExampleTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Post;
  4. use Carbon\Carbon;
  5. use Tests\TestCase;
  6. use Illuminate\Foundation\Testing\DatabaseMigrations;
  7. use Illuminate\Foundation\Testing\DatabaseTransactions;
  8. class ExampleTest extends TestCase
  9. {
  10. use DatabaseTransactions;
  11. /**
  12. * A basic test example.
  13. *
  14. * @return void
  15. */
  16. public function testBasicTest()
  17. {
  18. // $this->assertTrue(true);
  19. // Given
  20. // - I have two post records in the database
  21. // - They are posted a month apart
  22. $firstPost = factory(Post::class)->create();
  23. $secondPost = factory(Post::class)->create([
  24. 'created_at' => Carbon::now()->subMonth(),
  25. ]);
  26. // When I fetch the archives...
  27. $posts = Post::archives();
  28. // Then the response should be in the proper format.
  29. $this->assertCount(2, $posts);
  30. $this->assertSame([
  31. [
  32. 'year' => (int) $firstPost->created_at->format('Y'),
  33. 'month' => $firstPost->created_at->format('F'),
  34. 'published' => 1,
  35. ],
  36. [
  37. 'year' => (int) $secondPost->created_at->format('Y'),
  38. 'month' => $secondPost->created_at->format('F'),
  39. 'published' => 1,
  40. ],
  41. ], $posts);
  42. }
  43. }