TestCase.php 750 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Tests;
  3. use App\Models\AdminUser;
  4. use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
  5. use Illuminate\Support\Facades\DB;
  6. abstract class TestCase extends BaseTestCase
  7. {
  8. use CreatesApplication;
  9. /**
  10. * @var
  11. */
  12. protected $user;
  13. /**
  14. * @var string
  15. */
  16. protected $token;
  17. /**
  18. * 获取数据库最新插入的 id
  19. *
  20. * @param string|null $table 指定表名,或者整个数据库
  21. *
  22. * @return mixed|string
  23. */
  24. protected function getLastInsertId(string $table = null)
  25. {
  26. if (is_null($table)) {
  27. return DB::getPdo()->lastInsertId();
  28. } else {
  29. return DB::table($table)->orderByDesc('id')->value('id');
  30. }
  31. }
  32. }