Skip to content

Commit

Permalink
Merge branch '3.1' into 3.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/BehatFeatureContextTest.php
#	tests/RouteTest.php

Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Aug 16, 2016
2 parents 8b953d3 + ca41540 commit 2125735
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ protected function afterApplicationCreated(callable $callback)
}
}

/**
* Define hooks to migrate the database before and after each test.
*
* @param string $realpah
*
* @return void
*/
protected function loadMigrationsFrom($realpath)
{
$this->artisan('migrate', [
'--realpath' => $realpath,
]);

$this->beforeApplicationDestroyed(function () {
$this->artisan('migrate:rollback');
});
}

/**
* Register a callback to be run before the application is destroyed.
*
Expand Down
93 changes: 93 additions & 0 deletions tests/DatabaseLoadMigrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Orchestra\Testbench\TestCase;

class DatabaseLoadMigrationsTest extends \Orchestra\Testbench\TestCase
{
/**
* Setup the test environment.
*/
public function setUp()
{
parent::setUp();

// uncomment to enable route filters if your package defines routes with filters
// $this->app['router']->enableFilters();

// 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->artisan('migrate', [
'--database' => 'testbench',
'--path' => '../vendor/cartalyst/sentry/src/migrations',
]);
*/
$this->loadMigrationsFrom(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 [
//'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('users')->where('id', '=', 1)->first();

$this->assertEquals('hello@orchestraplatform.com', $users->email);
$this->assertTrue(\Hash::check('123', $users->password));

$this->beforeApplicationDestroyed(function () {
$this->assertSame(\Schema::hasTable('users'), false);
});
}
}
3 changes: 1 addition & 2 deletions tests/Integrations/AggregateServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function testServiceIsAvailable()
}
}


class ParentService extends AggregateServiceProvider
{
protected $providers = [
Expand Down Expand Up @@ -69,4 +68,4 @@ public function register()
{
$this->app['child.deferred.loaded'] = true;
}
}
}
1 change: 0 additions & 1 deletion tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function testGetRoutes()
$crawler = $this->call('GET', 'goodbye');

$this->assertEquals('goodbye world', $crawler->getContent());

}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestCaseTest extends \PHPUnit_Framework_TestCase
public function testCreateApplicationMethod()
{
$stub = new StubTestCase();
$app = $stub->createApplication();
$app = $stub->createApplication();

$this->assertInstanceOf('\Orchestra\Testbench\Contracts\TestCase', $stub);
$this->assertInstanceOf('\Illuminate\Foundation\Application', $app);
Expand Down

0 comments on commit 2125735

Please sign in to comment.