BaseTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /*
  3. * This file is part of ibrand/balace.
  4. *
  5. * (c) GuoJiangClub <https://www.ibrand.cc>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace GuoJiangClub\Component\User\Test;
  11. use GuoJiangClub\Component\User\Models\User;
  12. use GuoJiangClub\Component\User\Models\UserBind;
  13. use Illuminate\Foundation\Testing\DatabaseMigrations;
  14. use GuoJiangClub\Component\User\Repository\UserRepository;
  15. use GuoJiangClub\Component\User\Repository\UserBindRepository;
  16. use Orchestra\Testbench\TestCase;
  17. /**
  18. * Class BaseTest.
  19. */
  20. abstract class BaseTest extends TestCase
  21. {
  22. use DatabaseMigrations;
  23. public $user;
  24. public $userBind;
  25. /**
  26. * set up test.
  27. */
  28. protected function setUp()
  29. {
  30. parent::setUp();
  31. $this->loadMigrationsFrom(__DIR__ . '/database');
  32. $this->user = $this->app->make(UserRepository::class);
  33. $this->userBind = $this->app->make(UserBindRepository::class);
  34. $this->seedUser();
  35. }
  36. /**
  37. * @param \Illuminate\Foundation\Application $app
  38. */
  39. protected function getEnvironmentSetUp($app)
  40. {
  41. $app['config']->set('database.default', 'testing');
  42. $app['config']->set('database.connections.testing', [
  43. 'driver' => 'sqlite',
  44. 'database' => ':memory:',
  45. ]);
  46. $app['config']->set('repository.cache.enabled', true);
  47. }
  48. /**
  49. * @param \Illuminate\Foundation\Application $app
  50. *
  51. * @return array
  52. */
  53. protected function getPackageProviders($app)
  54. {
  55. return [
  56. \Orchestra\Database\ConsoleServiceProvider::class,
  57. \GuoJiangClub\Component\User\UserServiceProvider::class,
  58. ];
  59. }
  60. /**
  61. * seed some balance.
  62. */
  63. public function seedUser()
  64. {
  65. $user = User::create([
  66. 'name' => 'tangqi',
  67. 'nick_name' => '承诺',
  68. 'email' => '923332947@qq.com',
  69. 'mobile' => '18684738715',
  70. 'password' => '123456',
  71. 'status' => '1',
  72. 'sex' => '男',
  73. 'avatar' => 'https://avatars1.githubusercontent.com/u/11305589?s=400&u=e05d3607f4347e3b739a995ea3b9d2374476627d&v=4',
  74. 'city' => '长沙市',
  75. ]);
  76. UserBind::create([
  77. 'type' => UserBind::TYPE_WECHAT,
  78. 'open_id' => 'ovNizjmZxfWoVZ28vLdElWi8YsAw',
  79. 'user_id' => $user->id,
  80. 'nick_name' => '承诺',
  81. 'sex' => '男',
  82. 'email' => '923332947@qq.com',
  83. 'avatar' => 'https://avatars1.githubusercontent.com/u/11305589?s=400&u=e05d3607f4347e3b739a995ea3b9d2374476627d&v=4',
  84. 'app_id' => 'wx49f648b10ef7f110b',
  85. 'city' => '长沙市',
  86. ]);
  87. }
  88. }