Skip to content

Commit

Permalink
Create possible breaking changes because many package developer think…
Browse files Browse the repository at this point in the history
… "stable" dependency is the way to go when developing package.

If you need to use `--realpath` migration for whatever reason, run `composer require --dev "orchestra/database=~3.1"` and be damn sure you set your minimum-stability to dev.

/end of rant

Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jan 27, 2017
1 parent c56ae2b commit e80767d
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 76 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench`.

## 3.4.1

Date: 2017-01-27

### Changes

* Made `orchestra/database` optional dependency as it's only needed when you need to use `--realpath` as option for migration.

## 3.4.0

Date: 2017-01-27
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,17 @@ protected function getApplicationTimezone($app)

Package developer should be using `ServiceProvider::loadMigrationsFrom()` feature to automatically handle migrations for packages.

Testbench include a custom migrations command that support `realpath` option instead of the basic relative `path` option, this would make it easier for you to run database migrations during testing by just including the full realpath to your package database/migration folder.
```php
$this->artisan('migrate', ['--database' => 'testbench']);
```

#### Realpath Migration

In order to use a custom migrations command that support `realpath` option instead of the basic relative `path` option you need to first install the following package add include `Orchestra\Database\ConsoleServiceProvider` to your [Custom Service Provider](#custom-service-provider):

composer require --dev "orchestra/database=~3.1"

This would make it easier for you to run database migrations during testing by just including the full realpath to your package database/migration folder.

```php
$this->loadMigrationsFrom([
Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,27 @@
"Orchestra\\Testbench\\" : "src/"
}
},
"autoload-dev": {
"psr-4": {
"Orchestra\\Testbench\\Tests\\": "tests/"
}
},
"require": {
"php": ">=5.6.0",
"laravel/framework": "~5.4.0",
"orchestra/database": "~3.4.0",
"fzaninotto/faker": "~1.4",
"symfony/css-selector": "~3.2.0",
"symfony/dom-crawler": "~3.2.0"
},
"require-dev": {
"mockery/mockery": "^0.9.4",
"phpunit/phpunit": "~5.7"
"phpunit/phpunit": "~5.7",
"orchestra/database": "~3.4.0"
},
"suggest": {
"mockery/mockery": "Allow to use Mockery for testing (^0.9.4).",
"phpunit/phpunit": "Allow to use PHPUnit for testing (~5.7).",
"orchestra/database": "Allow to use --realpath migration for testing (~3.4).",
"orchestra/testbench-browser-kit": "Allow to use legacy BrowserKit for testing (~3.4)."
},
"extra": {
Expand Down
21 changes: 3 additions & 18 deletions tests/DatabaseFixtureTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Orchestra\Testbench\TestCase;
namespace Orchestra\Testbench\Tests;

class DatabaseFixtureTest extends \Orchestra\Testbench\TestCase
{
Expand All @@ -11,23 +11,7 @@ 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'),
]);
$this->artisan('migrate', ['--database' => 'testing']);
}

/**
Expand Down Expand Up @@ -55,6 +39,7 @@ protected function getEnvironmentSetUp($app)
protected function getPackageProviders($app)
{
return [
Stubs\ServiceProvider::class,
//'Cartalyst\Sentry\SentryServiceProvider',
//'YourProject\YourPackage\YourPackageServiceProvider',
];
Expand Down
94 changes: 94 additions & 0 deletions tests/DatabaseWithCustomMigrationFixtureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Orchestra\Testbench\Tests;

class DatabaseWithCustomMigrationFixtureTest extends \Orchestra\Testbench\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('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/DefaultConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Orchestra\Testbench\TestCase;
namespace Orchestra\Testbench\Tests;

class DefaultConfigurationTest extends \Orchestra\Testbench\TestCase
{
Expand Down
37 changes: 2 additions & 35 deletions tests/Integrations/AggregateServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Orchestra\Testbench\Integrations\TestCase;
namespace Orchestra\Testbench\Tests\Integrations;

use Orchestra\Testbench\TestCase;
use Illuminate\Support\ServiceProvider;
Expand All @@ -18,7 +18,7 @@ class AggregateServiceProviderTest extends TestCase
protected function getPackageProviders($app)
{
return [
'Orchestra\Testbench\Integrations\TestCase\ParentService',
'Orchestra\Testbench\Tests\Stubs\ParentServiceProvider',
];
}

Expand All @@ -38,36 +38,3 @@ public function testServiceIsAvailable()
$this->assertTrue($this->app->make('child.deferred.loaded'));
}
}

class ParentService extends AggregateServiceProvider
{
protected $providers = [
'Orchestra\Testbench\Integrations\TestCase\ChildService',
'Orchestra\Testbench\Integrations\TestCase\DeferredChildService',
];

public function register()
{
parent::register();

$this->app['parent.loaded'] = true;
}
}

class ChildService extends ServiceProvider
{
public function register()
{
$this->app['child.loaded'] = true;
}
}

class DeferredChildService extends ServiceProvider
{
protected $defer = true;

public function register()
{
$this->app['child.deferred.loaded'] = true;
}
}
16 changes: 4 additions & 12 deletions tests/RouteTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Orchestra\Testbench\TestCase;
namespace Orchestra\Testbench\Tests;

use Illuminate\Routing\Router;

Expand All @@ -9,7 +9,7 @@ class RouteTest extends \Orchestra\Testbench\TestCase
/**
* Define environment setup.
*
* @param Illuminate\Foundation\Application $app
* @param Illuminate\Foundation\Application $app
*
* @return void
*/
Expand All @@ -33,7 +33,7 @@ protected function getEnvironmentSetUp($app)
})->name('boss.bye');
});

$app['router']->resource('foo', 'Orchestra\Testbench\TestCase\FooController');
$app['router']->resource('foo', 'Orchestra\Testbench\Tests\Stubs\Controller');
}

/**
Expand Down Expand Up @@ -78,14 +78,6 @@ public function testGetFooIndexRouteUsingCall()
$response = $this->call('GET', 'foo');

$response->assertStatus(200);
$this->assertEquals('FooController@index', $response->getContent());
}
}

class FooController extends \Illuminate\Routing\Controller
{
public function index()
{
return 'FooController@index';
$this->assertEquals('Controller@index', $response->getContent());
}
}
11 changes: 11 additions & 0 deletions tests/Stubs/ChildServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Orchestra\Testbench\Tests\Stubs;

class ChildServiceProvider extends ServiceProvider
{
public function register()
{
$this->app['child.loaded'] = true;
}
}
11 changes: 11 additions & 0 deletions tests/Stubs/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Orchestra\Testbench\Tests\Stubs;

class Controller extends \Illuminate\Routing\Controller
{
public function index()
{
return 'Controller@index';
}
}
13 changes: 13 additions & 0 deletions tests/Stubs/DeferredChildServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Orchestra\Testbench\Tests\Stubs;

class DeferredChildServiceProvider extends ServiceProvider
{
protected $defer = true;

public function register()
{
$this->app['child.deferred.loaded'] = true;
}
}
20 changes: 20 additions & 0 deletions tests/Stubs/ParentServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Orchestra\Testbench\Tests\Stubs;

use Illuminate\Support\AggregateServiceProvider;

class ParentServiceProvider extends AggregateServiceProvider
{
protected $providers = [
ChildServiceProvider::class,
DeferredChildServiceProvider::class,
];

public function register()
{
parent::register();

$this->app['parent.loaded'] = true;
}
}
11 changes: 11 additions & 0 deletions tests/Stubs/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Orchestra\Testbench\Tests\Stubs;

class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function boot()
{
$this->loadMigrationsFrom(realpath(__DIR__.'/../migrations'));
}
}
8 changes: 8 additions & 0 deletions tests/Stubs/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Orchestra\Testbench\Tests\Stubs;

class TestCase extends \Orchestra\Testbench\TestCase
{
//
}
Loading

0 comments on commit e80767d

Please sign in to comment.