|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Integration; |
| 4 | + |
| 5 | +use Tests\Integration\Support\User; |
| 6 | + |
| 7 | +abstract class TestCase extends \Orchestra\Testbench\TestCase |
| 8 | +{ |
| 9 | + public $testUser; |
| 10 | + |
| 11 | + /** |
| 12 | + * Get package providers. At a minimum this is the package being tested, but also |
| 13 | + * would include packages upon which our package depends, e.g. Cartalyst/Sentry |
| 14 | + * In a normal app environment these would be added to the 'providers' array in |
| 15 | + * the config/app.php file. |
| 16 | + * |
| 17 | + * @param \Illuminate\Foundation\Application $app |
| 18 | + * |
| 19 | + * @return array |
| 20 | + */ |
| 21 | + protected function getPackageProviders($app) |
| 22 | + { |
| 23 | + return [ |
| 24 | + \BoxedCode\Laravel\Auth\Ip\IpAuthServiceProvider::class, |
| 25 | + ]; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Setup the test environment. |
| 30 | + */ |
| 31 | + protected function setUp(): void |
| 32 | + { |
| 33 | + parent::setUp(); |
| 34 | + |
| 35 | + // Run the migrations. |
| 36 | + $this->loadLaravelMigrations(['--database' => 'testing']); |
| 37 | + $this->artisan('migrate', ['--database' => 'testing']); |
| 38 | + |
| 39 | + // Create a test user. |
| 40 | + $this->testUser = User::create([ |
| 41 | + 'name' => 'Test User', |
| 42 | + 'email' => 'test@user.com', |
| 43 | + 'password' => 'password', |
| 44 | + ]); |
| 45 | + |
| 46 | + \Route::get('/', '\Tests\Integration\Support\Controller@home')->middleware([ |
| 47 | + 'auth', |
| 48 | + \BoxedCode\Laravel\Auth\Ip\Middleware\RequireIpAuthorization::class, |
| 49 | + ]); |
| 50 | + |
| 51 | + \Route::get('/logout', '\Tests\Integration\Support\Controller@logout')->name('logout'); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Define environment setup. |
| 56 | + * |
| 57 | + * @param \Illuminate\Foundation\Application $app |
| 58 | + * |
| 59 | + * @return void |
| 60 | + */ |
| 61 | + protected function getEnvironmentSetUp($app) |
| 62 | + { |
| 63 | + // Setup default database to use sqlite :memory: |
| 64 | + $app['config']->set('database.default', 'testing'); |
| 65 | + $app['config']->set('database.connections.testing', [ |
| 66 | + 'driver' => 'sqlite', |
| 67 | + 'database' => ':memory:', |
| 68 | + 'prefix' => '', |
| 69 | + ]); |
| 70 | + |
| 71 | + // Set default user model. |
| 72 | + $app['config']->set('auth.providers.users.model', User::class); |
| 73 | + //$app['config']->set() |
| 74 | + } |
| 75 | +} |
0 commit comments