BaseTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\Balance\Test;
  11. use GuoJiangClub\Component\Balance\Balance;
  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. /**
  21. * set up test.
  22. */
  23. protected function setUp()
  24. {
  25. parent::setUp(); // TODO: Change the autogenerated stub
  26. $this->seedBalances();
  27. }
  28. /**
  29. * @param \Illuminate\Foundation\Application $app
  30. */
  31. protected function getEnvironmentSetUp($app)
  32. {
  33. // Setup default database to use sqlite :memory:
  34. $app['config']->set('database.default', 'testing');
  35. $app['config']->set('database.connections.testing', [
  36. 'driver' => 'sqlite',
  37. 'database' => ':memory:',
  38. ]);
  39. $app['config']->set('repository.cache.enabled', true);
  40. }
  41. /**
  42. * @param $paths
  43. */
  44. protected function loadMigrationsFrom($paths)
  45. {
  46. $this->artisan('migrate', ['--database' => 'testing']);
  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\Balance\BalanceServiceProvider::class,
  58. \GuoJiangClub\Component\Balance\Test\BalanceServiceProvider::class,
  59. ];
  60. }
  61. /**
  62. * seed some balance.
  63. */
  64. public function seedBalances()
  65. {
  66. Balance::create(['user_id' => 1, 'type' => 'recharge', 'origin_id' => '1', 'origin_type' => 'GuoJiangClub\Distribution\Core\Models\AgentOrder', 'value' => '5000']);
  67. Balance::create(['user_id' => 1, 'type' => 'expend', 'origin_id' => '2', 'origin_type' => 'GuoJiangClub\Distribution\Core\Models\AgentOrder', 'value' => '-1000']);
  68. Balance::create(['user_id' => 1, 'type' => 'expend', 'origin_id' => '3', 'origin_type' => 'GuoJiangClub\Distribution\Core\Models\AgentOrder', 'value' => '-2000']);
  69. Balance::create(['user_id' => 2, 'type' => 'recharge', 'origin_id' => '4', 'origin_type' => 'GuoJiangClub\Distribution\Core\Models\AgentOrder', 'value' => '6000']);
  70. Balance::create(['user_id' => 2, 'type' => 'expend', 'origin_id' => '5', 'origin_type' => 'GuoJiangClub\Distribution\Core\Models\AgentOrder', 'value' => '-2000']);
  71. Balance::create(['user_id' => 2, 'type' => 'expend', 'origin_id' => '6', 'origin_type' => 'GuoJiangClub\Distribution\Core\Models\AgentOrder', 'value' => '-3000']);
  72. }
  73. }