EloquentCollectionFreshTest.php 1010 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Illuminate\Tests\Integration\Database;
  3. use Illuminate\Database\Eloquent\Collection as EloquentCollection;
  4. use Illuminate\Database\Schema\Blueprint;
  5. use Illuminate\Support\Facades\Schema;
  6. use Illuminate\Tests\Integration\Database\Fixtures\User;
  7. class EloquentCollectionFreshTest extends DatabaseTestCase
  8. {
  9. protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
  10. {
  11. Schema::create('users', function (Blueprint $table) {
  12. $table->increments('id');
  13. $table->string('email');
  14. });
  15. }
  16. public function testEloquentCollectionFresh()
  17. {
  18. User::insert([
  19. ['email' => 'laravel@framework.com'],
  20. ['email' => 'laravel@laravel.com'],
  21. ]);
  22. $collection = User::all();
  23. $collection->first()->delete();
  24. $freshCollection = $collection->fresh();
  25. $this->assertCount(1, $freshCollection);
  26. $this->assertInstanceOf(EloquentCollection::class, $freshCollection);
  27. }
  28. }