Skip to content

Commit

Permalink
Merge branch '3.1' into 3.2
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Feb 13, 2016
2 parents 2cd9bac + 487b6a0 commit 73fe101
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 15 deletions.
10 changes: 10 additions & 0 deletions docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ title: Memory Change Log

## Version 3.1 {#v3-1}

### v3.1.3 {#v3-1-3}

* Add support for new `Orchestra\Memory\Provider::secureGet()` and `Orchestra\Memory\Provider::secureSet()`.
* Add `Orchestra\Memory\Provider::securePut()` as an encrypted alias to `Orchestra\Memory\Provider::put()`.

### v3.1.2 {#v3-1-2}

* Ignores `PDOException` exception when saving database based driver as the code maybe executed from outside of configured environment.
Expand All @@ -30,6 +35,11 @@ title: Memory Change Log

## Version 3.0 {#v3-0}

### v3.0.6 {#v3-0-6}

* Add support for new `Orchestra\Memory\Provider::secureGet()` and `Orchestra\Memory\Provider::secureSet()`.
* Add `Orchestra\Memory\Provider::securePut()` as an encrypted alias to `Orchestra\Memory\Provider::put()`.

### v3.0.5 {#v3-0-5}

* Use `database_path()` helper.
Expand Down
31 changes: 24 additions & 7 deletions src/MemoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ class MemoryManager extends Manager
*/
protected $config = [];

/**
* The encrypter implementation.
*
* @var \Illuminate\Contracts\Encryption\Encrypter|null
*/
protected $encrypter;

/**
* Create a new manager instance.
*
* @param \Illuminate\Foundation\Application $app
*/
public function __construct($app)
{
parent::__construct($app);

try {
$this->encrypter = $app->make('encrypter');
} catch (RuntimeException $e) {
$this->encrypter = null;
}
}

/**
* Create Fluent driver.
*
Expand Down Expand Up @@ -87,13 +110,7 @@ protected function createRuntimeDriver($name)
*/
protected function createProvider(HandlerContract $handler)
{
try {
$encrypter = $this->app->make('encrypter');
} catch (RuntimeException $e) {
$encrypter = null;
}

return new Provider($handler, $encrypter);
return new Provider($handler, $this->encrypter);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Provider implements ProviderContract
*/
public function __construct(HandlerContract $handler, Encrypter $encrypter = null)
{
$this->handler = $handler;
$this->handler = $handler;
$this->encrypter = $encrypter;
$this->items = $this->handler->initiate();
$this->items = $this->handler->initiate();
}

/**
Expand Down
27 changes: 21 additions & 6 deletions tests/MemoryManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function testMakeMethod()
$eloquent = m::mock('EloquentHandlerModelMock');

$app->shouldReceive('make')->times(3)->with('cache')->andReturn($cache)
->shouldReceive('make')->once()->with('db')->andReturn($db);
->shouldReceive('make')->once()->with('db')->andReturn($db)
->shouldReceive('make')->once()->with('encrypter')->andThrow('\RuntimeException');

$cache->shouldReceive('driver')->times(3)->with(null)->andReturnSelf()
->shouldReceive('get')->andReturn([])
Expand Down Expand Up @@ -86,7 +87,8 @@ public function testMakeOrFallbackMethodReturnFluent()
$data = [];

$app->shouldReceive('make')->once()->with('cache')->andReturn($cache)
->shouldReceive('make')->once()->with('db')->andReturn($db);
->shouldReceive('make')->once()->with('db')->andReturn($db)
->shouldReceive('make')->once()->with('encrypter')->andThrow('\RuntimeException');

$cache->shouldReceive('driver')->once()->with(null)->andReturnSelf()
->shouldReceive('rememberForever')->once()->with('db-memory:fluent-default', m::type('Closure'))
Expand Down Expand Up @@ -122,7 +124,8 @@ public function testMakeOrFallbackMethodReturnRuntime()
$db = m::mock('\Illuminate\Database\DatabaseManager');

$app->shouldReceive('make')->once()->with('cache')->andReturn($cache)
->shouldReceive('make')->once()->with('db')->andReturn($db);
->shouldReceive('make')->once()->with('db')->andReturn($db)
->shouldReceive('make')->once()->with('encrypter')->andThrow('\RuntimeException');

$cache->shouldReceive('driver')->once()->with('foo')->andReturnSelf()
->shouldReceive('rememberForever')->once()->with('db-memory:fluent-default', m::type('Closure'))
Expand Down Expand Up @@ -154,7 +157,11 @@ public function testMakeOrFallbackMethodReturnRuntime()
*/
public function testMakeExpectedException()
{
with(new MemoryManager($this->app))->make('orm');
$app = $this->app;

$app->shouldReceive('make')->once()->with('encrypter')->andThrow('\RuntimeException');

with(new MemoryManager($app))->make('orm');
}

/**
Expand All @@ -166,6 +173,8 @@ public function testStubMemory()
{
$app = $this->app;

$app->shouldReceive('make')->once()->with('encrypter')->andThrow('\RuntimeException');

$stub = new MemoryManager($app);

$stub->extend('stub', function ($app, $name) {
Expand Down Expand Up @@ -193,7 +202,9 @@ public function testStubMemory()
*/
public function testFinishMethod()
{
$app = $this->app;
$app = $this->app;

$app->shouldReceive('make')->once()->with('encrypter')->andThrow('\RuntimeException');

$stub = new MemoryManager($app);
$foo = $stub->make('runtime.fool');
Expand All @@ -212,9 +223,11 @@ public function testFinishMethod()
*/
public function testMakeMethodForDefaultDriver()
{
$app = $this->app;
$app = $this->app;
$config = ['driver' => 'runtime.default'];

$app->shouldReceive('make')->once()->with('encrypter')->andThrow('\RuntimeException');

$stub = new MemoryManager($app);
$stub->setConfig($config);
$stub->make();
Expand All @@ -229,6 +242,8 @@ public function testSetDefaultDriverMethod()
{
$app = $this->app;

$app->shouldReceive('make')->once()->with('encrypter')->andThrow('\RuntimeException');

$stub = new MemoryManager($app);
$stub->setDefaultDriver('foo');

Expand Down

0 comments on commit 73fe101

Please sign in to comment.