Skip to content

Commit

Permalink
Merge branch '2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Dec 19, 2013
2 parents d029c30 + 99b0c6f commit a053a49
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 152 deletions.
22 changes: 5 additions & 17 deletions src/Orchestra/Widget/Drivers/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@
use Countable;
use IteratorAggregate;
use InvalidArgumentException;
use Illuminate\Container\Container;
use Orchestra\Support\Nesty;

abstract class Driver implements Countable, IteratorAggregate
{
/**
* Application instance.
*
* @var \Illuminate\Container\Container
*/
protected $app = null;

/**
* Nesty instance.
*
* @var \Orchestra\Support\Nesty
*/
protected $nesty = null;
protected $nesty;

/**
* Name of this instance.
Expand All @@ -47,16 +39,12 @@ abstract class Driver implements Countable, IteratorAggregate
/**
* Construct a new instance.
*
* @param \Illuminate\Container\Container $app
* @param string $name
* @param string $name
* @param array $config
*/
public function __construct(Container $app, $name)
public function __construct($name, array $config = array())
{
$this->app = $app;
$this->config = array_merge(
$this->app['config']->get("orchestra/widget::{$this->type}.{$name}", array()),
$this->config
);
$this->config = array_merge($config, $this->config);

$this->name = $name;
$this->nesty = new Nesty($this->config);
Expand Down
12 changes: 9 additions & 3 deletions src/Orchestra/Widget/WidgetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class WidgetManager extends Manager
*/
protected function createMenuDriver($name)
{
return new Drivers\Menu($this->app, $name);
$config = $this->app['config']->get("orchestra/widget::menu.{$name}", array());

return new Drivers\Menu($name, $config);
}

/**
Expand All @@ -28,7 +30,9 @@ protected function createMenuDriver($name)
*/
protected function createPaneDriver($name)
{
return new Drivers\Pane($this->app, $name);
$config = $this->app['config']->get("orchestra/widget::pane.{$name}", array());

return new Drivers\Pane($name, $config);
}

/**
Expand All @@ -39,7 +43,9 @@ protected function createPaneDriver($name)
*/
protected function createPlaceholderDriver($name)
{
return new Drivers\Placeholder($this->app, $name);
$config = $this->app['config']->get("orchestra/widget::placeholder.{$name}", array());

return new Drivers\Placeholder($name, $config);
}

/**
Expand Down
38 changes: 3 additions & 35 deletions tests/Drivers/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,11 @@

class DriverTest extends \PHPUnit_Framework_TestCase
{
/**
* Application mock instance.
*
* @var Illuminate\Foundation\Application
*/
private $app = null;

/**
* Setup the test environment.
*/
public function setUp()
{
$this->app = new \Illuminate\Container\Container;
}

/**
* Teardown the test environment.
*/
public function tearDown()
{
unset($this->app);
m::close();
}

Expand All @@ -36,13 +20,7 @@ public function tearDown()
*/
public function testConstructMethod()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');

$config->shouldReceive('get')->once()
->with("orchestra/widget::stub.foo", m::any())->andReturn(array());

$stub = new DriverStub($app, 'foo');
$stub = new DriverStub('foo', array());

$refl = new \ReflectionObject($stub);
$config = $refl->getProperty('config');
Expand Down Expand Up @@ -70,12 +48,7 @@ public function testConstructMethod()
*/
public function testGetItemMethod()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');

$config->shouldReceive('get')->once()->andReturn(array());

$stub = new DriverStub($app, 'foo');
$stub = new DriverStub('foo', array());

$this->assertInstanceOf('\Illuminate\Support\Collection', $stub->getItems());
$this->assertInstanceOf('\Illuminate\Support\Collection', $stub->items);
Expand All @@ -98,12 +71,7 @@ public function testGetItemMethod()
*/
public function testMagicMethodGetThrowsException()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');

$config->shouldReceive('get')->once()->andReturn(array());

with(new DriverStub($app, 'foo'))->helloWorld;
with(new DriverStub('foo', array()))->helloWorld;
}
}

Expand Down
32 changes: 2 additions & 30 deletions tests/Drivers/MenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,11 @@

class MenuTest extends \PHPUnit_Framework_TestCase
{
/**
* Application mock instance.
*
* @var Illuminate\Foundation\Application
*/
private $app = null;

/**
* Setup the test environment.
*/
public function setUp()
{
$this->app = new \Illuminate\Container\Container;
}

/**
* Teardown the test environment.
*/
public function tearDown()
{
unset($this->app);
m::close();
}

Expand All @@ -38,13 +22,7 @@ public function tearDown()
*/
public function testConstructMethod()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');

$config->shouldReceive('get')->once()
->with("orchestra/widget::menu.foo", m::any())->andReturn(array());

$stub = new Menu($app, 'foo');
$stub = new Menu('foo', array());
$refl = new \ReflectionObject($stub);
$config = $refl->getProperty('config');
$name = $refl->getProperty('name');
Expand Down Expand Up @@ -78,13 +56,7 @@ public function testConstructMethod()
*/
public function testAddMethod()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');

$config->shouldReceive('get')->once()
->with("orchestra/widget::menu.foo", m::any())->andReturn(array());

$stub = new Menu($app, 'foo');
$stub = new Menu('foo', array());

$expected = new Collection(array(
'foo' => new Fluent(array(
Expand Down
31 changes: 2 additions & 29 deletions tests/Drivers/PaneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,11 @@

class PaneTest extends \PHPUnit_Framework_TestCase
{
/**
* Application mock instance.
*
* @var Illuminate\Foundation\Application
*/
private $app = null;

/**
* Setup the test environment.
*/
public function setUp()
{
$this->app = new \Illuminate\Container\Container;
}

/**
* Teardown the test environment.
*/
public function tearDown()
{
unset($this->app);
m::close();
}

Expand All @@ -38,13 +22,8 @@ public function tearDown()
*/
public function testConstructMethod()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');
$stub = new Pane('foo', array());

$config->shouldReceive('get')->once()
->with("orchestra/widget::pane.foo", m::any())->andReturn(array());

$stub = new Pane($app, 'foo');
$refl = new \ReflectionObject($stub);
$config = $refl->getProperty('config');
$name = $refl->getProperty('name');
Expand Down Expand Up @@ -78,13 +57,7 @@ public function testConstructMethod()
*/
public function testAddMethod()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');

$config->shouldReceive('get')->once()
->with("orchestra/widget::pane.foo", m::any())->andReturn(array());

$stub = new Pane($app, 'foo');
$stub = new Pane('foo', array());

$expected = new Collection(array(
'foo' => new Fluent(array(
Expand Down
32 changes: 2 additions & 30 deletions tests/Drivers/PlaceholderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,11 @@

class PlaceholderTest extends \PHPUnit_Framework_TestCase
{
/**
* Application mock instance.
*
* @var Illuminate\Foundation\Application
*/
private $app = null;

/**
* Setup the test environment.
*/
public function setUp()
{
$this->app = new \Illuminate\Container\Container;
}

/**
* Teardown the test environment.
*/
public function tearDown()
{
unset($this->app);
m::close();
}

Expand All @@ -38,13 +22,7 @@ public function tearDown()
*/
public function testConstructMethod()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');

$config->shouldReceive('get')->once()
->with("orchestra/widget::placeholder.foo", m::any())->andReturn(array());

$stub = new Placeholder($app, 'foo');
$stub = new Placeholder('foo', array());

$refl = new \ReflectionObject($stub);
$config = $refl->getProperty('config');
Expand Down Expand Up @@ -76,13 +54,7 @@ public function testConstructMethod()
*/
public function testAddMethod()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');

$config->shouldReceive('get')->once()
->with("orchestra/widget::placeholder.foo", m::any())->andReturn(array());

$stub = new Placeholder($app, 'foo');
$stub = new Placeholder('foo', array());

$callback = function () {
return 'hello world';
Expand Down
17 changes: 9 additions & 8 deletions tests/WidgetManagerTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Orchestra\Widget\Tests;

use Mockery as m;
use Illuminate\Container\Container;
use Orchestra\Widget\WidgetManager;

class WidgetManagerTest extends \PHPUnit_Framework_TestCase
Expand All @@ -17,7 +18,7 @@ class WidgetManagerTest extends \PHPUnit_Framework_TestCase
*/
public function setUp()
{
$this->app = new \Illuminate\Container\Container;
$this->app = new Container;
}

/**
Expand Down Expand Up @@ -76,7 +77,7 @@ public function testExtendMethod()
public function testMakeMethodForMenu()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');
$app['config'] = $config = m::mock('\Illuminate\Config\Repository');

$config->shouldReceive('get')->once()
->with("orchestra/widget::menu.foo", m::any())->andReturn(array())
Expand All @@ -98,7 +99,7 @@ public function testMakeMethodForMenu()
public function testMakeMethodForPane()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');
$app['config'] = $config = m::mock('\Illuminate\Config\Repository');

$config->shouldReceive('get')->once()
->with("orchestra/widget::pane.foo", m::any())->andReturn(array());
Expand All @@ -116,12 +117,12 @@ public function testMakeMethodForPane()
public function testMakeMethodForPlaceholder()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');
$app['config'] = $config = m::mock('\Illuminate\Config\Repository');

$config->shouldReceive('get')->once()
->with("orchestra/widget::placeholder.foo", m::any())->andReturn(array());

$stub = with(new \Orchestra\Widget\WidgetManager($app))->make('placeholder.foo');
$stub = with(new WidgetManager($app))->make('placeholder.foo');

$this->assertInstanceOf('\Orchestra\Widget\Drivers\Placeholder', $stub);
}
Expand All @@ -134,12 +135,12 @@ public function testMakeMethodForPlaceholder()
public function testMakeMethodForDefaultDriver()
{
$app = $this->app;
$app['config'] = $config = m::mock('Config');
$app['config'] = $config = m::mock('\Illuminate\Config\Repository');

$config->shouldReceive('get')->once()
->with("orchestra/widget::placeholder.default", m::any())->andReturn(array());

$stub = with(new \Orchestra\Widget\WidgetManager($app))->driver();
$stub = with(new WidgetManager($app))->driver();

$this->assertInstanceOf('\Orchestra\Widget\Drivers\Placeholder', $stub);
}
Expand All @@ -152,6 +153,6 @@ public function testMakeMethodForDefaultDriver()
*/
public function testMakeMethodThrowsException()
{
with(new \Orchestra\Widget\WidgetManager($this->app))->make('foobar');
with(new WidgetManager($this->app))->make('foobar');
}
}

0 comments on commit a053a49

Please sign in to comment.