Skip to content

Commit

Permalink
Merge branch '3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Dec 13, 2015
2 parents d429fc0 + 1ae08be commit 64a6071
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,12 @@ This error would only occur if your test suite require actual usage of the encry

</phpunit>
```
### Session not set on request

The error might pop-up when testing routes with `Request::old()` or `old()` helper inside the requested view. This is due to Testbench not loading the default global middleware made available with Laravel.

To avoid breaking Backward Compatibility (BC) under 3.1 please add the following code under your `setUp` or `getEnvironmentSetUp` method.

```php
$app->make('Illuminate\Contracts\Http\Kernel')->pushMiddleware('Illuminate\Session\Middleware\StartSession');
```
17 changes: 15 additions & 2 deletions fixture/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

return [


/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services your application utilizes. Set this in your ".env" file.
|
*/

'env' => env('APP_ENV', 'testing'),

/*
|--------------------------------------------------------------------------
| Application Debug Mode
Expand Down Expand Up @@ -78,7 +92,7 @@
|
*/

'key' => env('APP_KEY', 'SomeRandomString'),
'key' => env('APP_KEY'),

'cipher' => 'AES-256-CBC',

Expand Down Expand Up @@ -116,7 +130,6 @@
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Routing\ControllerServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Expand Down
21 changes: 21 additions & 0 deletions src/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ class Kernel extends \Illuminate\Foundation\Http\Kernel
*/
protected $bootstrappers = [];

/**
* The application's middleware stack.
*
* @var array
*/
protected $middleware = [];

/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
],

'api' => [],
];

/**
* Report the exception to the exception handler.
*
Expand Down
41 changes: 41 additions & 0 deletions src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,27 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase implements TestCaseI
*/
protected $baseUrl = 'http://localhost';

/**
* The callbacks that should be run after the application is created.
*
* @var array
*/
protected $afterApplicationCreatedCallbacks = [];

/**
* The callbacks that should be run before the application is destroyed.
*
* @var array
*/
protected $beforeApplicationDestroyedCallbacks = [];

/**
* Indicates if we have made it throught the base setUp function.
*
* @var bool
*/
protected $setUpHasRun = false;

/**
* Setup the test environment.
*
Expand All @@ -52,6 +66,12 @@ public function setUp()
if (! $this->app) {
$this->refreshApplication();
}

foreach ($this->afterApplicationCreatedCallbacks as $callback) {
call_user_func($callback);
}

$this->setUpHasRun = true;
}

/**
Expand Down Expand Up @@ -85,9 +105,30 @@ public function tearDown()
$this->app = null;
}

$this->setUpHasRun = false;

if (property_exists($this, 'serverVariables')) {
$this->serverVariables = [];
}

$this->afterApplicationCreatedCallbacks = [];
$this->beforeApplicationDestroyedCallbacks = [];
}

/**
* Register a callback to be run after the application is created.
*
* @param callable $callback
*
* @return void
*/
protected function afterApplicationCreated(callable $callback)
{
$this->afterApplicationCreatedCallbacks[] = $callback;

if ($this->setUpHasRun) {
call_user_func($callback);
}
}

/**
Expand Down

0 comments on commit 64a6071

Please sign in to comment.