BaseTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /*
  3. * This file is part of ibrand/favorite.
  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\Favorite\Test;
  11. use GuoJiangClub\Component\Favorite\Favorite;
  12. use Illuminate\Foundation\Testing\DatabaseMigrations;
  13. use Orchestra\Testbench\TestCase;
  14. /**
  15. * Class BaseTest.
  16. */
  17. abstract class BaseTest extends TestCase
  18. {
  19. use DatabaseMigrations;
  20. public $repository;
  21. /**
  22. * set up test.
  23. */
  24. protected function setUp()
  25. {
  26. parent::setUp(); // TODO: Change the autogenerated stub
  27. $this->loadMigrationsFrom(__DIR__ . '/database');
  28. $this->repository = $this->app->make(\GuoJiangClub\Component\Favorite\RepositoryContract::class);
  29. $this->seedFavorite();
  30. $this->seedGoods();
  31. $this->seedActivitys();
  32. }
  33. /**
  34. * @param \Illuminate\Foundation\Application $app
  35. */
  36. protected function getEnvironmentSetUp($app)
  37. {
  38. // Setup default database to use sqlite :memory:
  39. $app['config']->set('database.default', 'testing');
  40. $app['config']->set('database.connections.testing', [
  41. 'driver' => 'sqlite',
  42. 'database' => ':memory:',
  43. ]);
  44. $app['config']->set('repository.cache.enabled', false);
  45. $app['config']->set('ibrand.favorite', require __DIR__.'/../config/favorite.php');
  46. $models = [
  47. 'goods' => Goods::class,
  48. 'activity' => Activity::class,
  49. ];
  50. $app['config']->set('ibrand.favorite.models', $models);
  51. }
  52. /**
  53. * @param \Illuminate\Foundation\Application $app
  54. *
  55. * @return array
  56. */
  57. protected function getPackageProviders($app)
  58. {
  59. return [
  60. \Prettus\Repository\Providers\RepositoryServiceProvider::class,
  61. \Orchestra\Database\ConsoleServiceProvider::class,
  62. \GuoJiangClub\Component\Favorite\FavoriteServiceProvider::class,
  63. ];
  64. }
  65. /**
  66. * seed some seedFavorite.
  67. */
  68. public function seedFavorite()
  69. {
  70. Favorite::create(['user_id' => 1, 'favoriteable_id' => 1, 'favoriteable_type' => 'goods']);
  71. Favorite::create(['user_id' => 1, 'favoriteable_id' => 2, 'favoriteable_type' => 'goods']);
  72. Favorite::create(['user_id' => 1, 'favoriteable_id' => 1, 'favoriteable_type' => 'activity']);
  73. Favorite::create(['user_id' => 2, 'favoriteable_id' => 1, 'favoriteable_type' => 'activity']);
  74. Favorite::create(['user_id' => 2, 'favoriteable_id' => 2, 'favoriteable_type' => 'activity']);
  75. Favorite::create(['user_id' => 2, 'favoriteable_id' => 3, 'favoriteable_type' => 'activity']);
  76. }
  77. /**
  78. * seed some seedGoods.
  79. */
  80. public function seedGoods()
  81. {
  82. Goods::create(['name' => 'goods1']);
  83. Goods::create(['name' => 'goods2']);
  84. }
  85. /**
  86. * seed some seedActivitys.
  87. */
  88. public function seedActivitys()
  89. {
  90. Activity::create(['title' => 'activity1']);
  91. Activity::create(['title' => 'activity2']);
  92. Activity::create(['title' => 'activity3']);
  93. }
  94. }