Skip to content

Commit

Permalink
Add using mix of Laravel and custom realpath migration test to show t…
Browse files Browse the repository at this point in the history
…hat it's can rollback perfectly. #176

Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed May 31, 2017
1 parent 118b2a7 commit 1691a08
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/Databases/MigrateDatabaseTest.php
Expand Up @@ -72,7 +72,7 @@ protected function getPackageAliases($app)
*/
public function testRunningMigration()
{
$users = \DB::table('users')->where('id', '=', 1)->first();
$users = \DB::table('testbench_users')->where('id', '=', 1)->first();

$this->assertEquals('hello@orchestraplatform.com', $users->email);
$this->assertTrue(\Hash::check('123', $users->password));
Expand Down
96 changes: 96 additions & 0 deletions tests/Databases/MigrateWithRealpathAndLaravelTest.php
@@ -0,0 +1,96 @@
<?php

namespace Orchestra\Testbench\Tests\Databases;

use Orchestra\Testbench\TestCase;

class MigrateWithRealpathAndLaravelTest extends TestCase
{
/**
* Setup the test environment.
*/
public function setUp()
{
parent::setUp();

// call migrations for packages upon which our package depends, e.g. Cartalyst/Sentry
// not necessary if your package doesn't depend on another package that requires
// running migrations for proper installation
/* uncomment as necessary
$this->loadMigrationsFrom([
'--database' => 'testbench',
'--path' => '../vendor/cartalyst/sentry/src/migrations',
]);
*/

// call migrations specific to our tests, e.g. to seed the db
// the path option should be relative to the 'path.database'
// path unless `--path` option is available.
$this->loadMigrationsFrom([
'--database' => 'testing',
'--realpath' => realpath(__DIR__.'/../migrations'),
]);
}

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

/**
* Get package providers. At a minimum this is the package being tested, but also
* would include packages upon which our package depends, e.g. Cartalyst/Sentry
* In a normal app environment these would be added to the 'providers' array in
* the config/app.php file.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageProviders($app)
{
return [
\Orchestra\Database\ConsoleServiceProvider::class,
//'Cartalyst\Sentry\SentryServiceProvider',
//'YourProject\YourPackage\YourPackageServiceProvider',
];
}

/**
* Get package aliases. In a normal app environment these would be added to
* the 'aliases' array in the config/app.php file. If your package exposes an
* aliased facade, you should add the alias here, along with aliases for
* facades upon which your package depends, e.g. Cartalyst/Sentry.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageAliases($app)
{
return [
//'Sentry' => 'Cartalyst\Sentry\Facades\Laravel\Sentry',
//'YourPackage' => 'YourProject\YourPackage\Facades\YourPackage',
];
}

/**
* Test running migration.
*
* @test
*/
public function testRunningMigration()
{
$users = \DB::table('testbench_users')->where('id', '=', 1)->first();

$this->assertEquals('hello@orchestraplatform.com', $users->email);
$this->assertTrue(\Hash::check('123', $users->password));
}
}
2 changes: 1 addition & 1 deletion tests/Databases/MigrateWithRealpathTest.php
Expand Up @@ -88,7 +88,7 @@ protected function getPackageAliases($app)
*/
public function testRunningMigration()
{
$users = \DB::table('users')->where('id', '=', 1)->first();
$users = \DB::table('testbench_users')->where('id', '=', 1)->first();

$this->assertEquals('hello@orchestraplatform.com', $users->email);
$this->assertTrue(\Hash::check('123', $users->password));
Expand Down
Expand Up @@ -12,7 +12,7 @@ class CreateTestbenchUsersTable extends Migration
*/
public function up()
{
Schema::create('users', function ($table) {
Schema::create('testbench_users', function ($table) {
$table->increments('id');
$table->string('email');
$table->string('password');
Expand All @@ -22,7 +22,7 @@ public function up()

$now = Carbon::now();

DB::table('users')->insert([
DB::table('testbench_users')->insert([
'email' => 'hello@orchestraplatform.com',
'password' => Hash::make('123'),
'created_at' => $now,
Expand All @@ -37,6 +37,6 @@ public function up()
*/
public function down()
{
Schema::drop('users');
Schema::drop('testbench_users');
}
}

0 comments on commit 1691a08

Please sign in to comment.