Skip to content

Commit

Permalink
Use create-sqlite-db command.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Feb 11, 2018
1 parent c2b32d6 commit d069f7a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:

before_script:
- composer config discard-changes true
- touch laravel/database/database.sqlite
- php ./create-sqlite-db
- if [[ $setup = 'basic' ]]; then travis_retry composer install --prefer-dist --no-interaction; fi
- if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable; fi
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ class BrowserTestCase extends Orchestra\Testbench\Dusk\TestCase
}
```

### Database

By default you can either use `sqlite`, `mysql`, `pgsql` or `sqlsrv` with Testbench Dusk, however do note that it is impossible to use `sqlite` using `:memory:` database as you would with **Testbench** or **Tesbench BrowserKit**.

If you opt to use `sqlite`, you might want to set the default database connection to `sqlite` either using `phpunit` configuration or setting it up on `getEnvironmentSetUp()` method.

```php
/**
* Define environment setup.
*
* @param Illuminate\Foundation\Application $app
*
* @return void
*/
protected function getEnvironmentSetUp($app)
{
$this->app['config']->set('database.default', 'sqlite');
}
```

To populate the database you just need to run the following code:

```bash
php vendor/orchestra/testbench-dusk/create-sqlite-db
```

## Advanced Usage

### Customising the Laravel App instance used during a test
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
},
"scripts": {
"test": [
"@php create-sqlite-db",
"@php vendor/bin/phpunit -c ./ --color"
]
},
Expand Down
8 changes: 8 additions & 0 deletions create-sqlite-db
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env php
<?php

$directory = realpath(__DIR__.'/laravel/database');

if (! file_exists("{$directory}/database.sqlite")) {
copy("{$directory}/database.sqlite.example", "{$directory}/database.sqlite");
}
4 changes: 0 additions & 4 deletions tests/Browser/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@

class AuthTest extends TestCase
{
use CreateTestingDatabase;

protected function setUp()
{
parent::setUp();

$this->createDatabase(config('database.default'));

$this->withFactories(__DIR__.'/../factories');
$this->loadLaravelMigrations(config('database.default'));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Browser/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RouteTest extends TestCase
/**
* Define environment setup.
*
* @param Illuminate\Foundation\Application $app
* @param Illuminate\Foundation\Application $app
*
* @return void
*/
Expand Down

0 comments on commit d069f7a

Please sign in to comment.