From 76606f0f4a5b2e377ec3f9b5f3937c6b19a3304c Mon Sep 17 00:00:00 2001 From: Robert Clancy Date: Wed, 14 Aug 2013 10:12:52 +1000 Subject: [PATCH] converted indentation to spaces --- README.md | 4 +- src/Robbo/Presenter/PresentableInterface.php | 12 +- src/Robbo/Presenter/Presenter.php | 346 +++++++++--------- .../Presenter/PresenterServiceProvider.php | 178 ++++----- src/Robbo/Presenter/View/Environment.php | 118 +++--- src/Robbo/Presenter/View/View.php | 30 +- tests/PresenterTest.php | 232 ++++++------ tests/ViewEnvironmentTest.php | 118 +++--- tests/ViewTest.php | 88 ++--- 9 files changed, 563 insertions(+), 563 deletions(-) diff --git a/README.md b/README.md index df43bc2..f848de6 100755 --- a/README.md +++ b/README.md @@ -198,8 +198,8 @@ echo 'And again: ', $user['url']; ### Extending the Decorator -As of 1.2.x I have added in a decorator object. This object takes care of turning an object that has `PresentableInterface` into a `Presenter`. -By default, this is done with Laravel's `View` objects. The reasoning behind a new class instead of the previous implementation is so it can be better tested and also to allow you to extend it. +As of 1.2.x I have added in a decorator object. This object takes care of turning an object that has `PresentableInterface` into a `Presenter`. +By default, this is done with Laravel's `View` objects. The reasoning behind a new class instead of the previous implementation is so it can be better tested and also to allow you to extend it. Here is an example of extending the `Decorator` so that instead of using the `PresentableInterface` and `getPresenter()` method you can use a public variable on the object called `$presenter`. Note: these instructions are for Laravel usage. diff --git a/src/Robbo/Presenter/PresentableInterface.php b/src/Robbo/Presenter/PresentableInterface.php index c5a7e26..9e033f3 100755 --- a/src/Robbo/Presenter/PresentableInterface.php +++ b/src/Robbo/Presenter/PresentableInterface.php @@ -2,10 +2,10 @@ interface PresentableInterface { - /** - * Return a created presenter. - * - * @return Robbo\Presenter\Presenter - */ - public function getPresenter(); + /** + * Return a created presenter. + * + * @return Robbo\Presenter\Presenter + */ + public function getPresenter(); } \ No newline at end of file diff --git a/src/Robbo/Presenter/Presenter.php b/src/Robbo/Presenter/Presenter.php index 46af26b..9f13724 100755 --- a/src/Robbo/Presenter/Presenter.php +++ b/src/Robbo/Presenter/Presenter.php @@ -2,170 +2,170 @@ abstract class Presenter implements \ArrayAccess { - /** - * The object injected on Presenter construction. - * - * @var mixed - */ - protected $object; - - /** - * The decorator instance so we can nest presenters. Underscores here to avoid conflicts - * if a presenter or object has "decorator" as a variable. - * - * @var \Robbo\Presenter\Decorator - */ - protected static $__decorator; - - /** - * Create the Presenter and store the object we are presenting. - * - * @param mixed $object - */ - public function __construct($object) - { - $this->object = $object; - } - - /** - * Get the decorator, if none exists then use the default. Underscores here to avoid conflicts - * if a presenter or object needs to use "getDecorator". - * - * @var \Robbo\Presenter\Decorator - */ - protected function __getDecorator() - { - if (is_null(static::$__decorator)) - { - static::$__decorator = new Decorator; - } - - return static::$__decorator; - } - - /** - * This is so you can extend the decorator and inject it into the presenter at the class level so the - * new decorator will be used for nested presenters. Method name should be "setDecorator" however - * like above I want to make conflicts less likely. - * - * @param \Robbo\Presenter\Decorator - * @return void - */ - public static function setExtendedDecorator(Decorator $decorator) - { - static::$__decorator = $decorator; - } - - /** - * Get the object we are wrapping. - * - * @return mixed - */ - public function getObject() - { - return $this->object; - } - - /* - * This will be called when isset() is called via array access. - * - * @param mixed $offset - * @return boolean - */ - public function offsetExists($offset) - { - // We only check isset on the array, if it is an object we return true as the object could be overloaded - if (is_array($this->object)) - { - return isset($this->object[$offset]); - } - - return true; - } - - /** - * Add ability to access properties like an array. - * - * @param mixed $offset - * @return mixed - */ - public function offsetGet($offset) - { - return $this->__get($offset); - } - - /** - * Set variable or key value using array access. - * - * @param mixed $offset - * @param mixed $value - * @return void - */ - public function offsetSet($offset, $value) - { - if (is_array($this->object)) - { - $this->object[$offset] = $value; - return; - } - - $this->object->$offset = $value; - } - - /** - * Unset a variable or key value using array access. - * - * @param mixed $offset - * @return void - */ - public function offsetUnset($offset) - { - if (is_array($this->object)) - { - unset($this->object[$offset]); - return; - } - - unset($this->object->$offset); - } - - /** - * Pass any unknown varible calls to present{$variable} or fall through to the injected object. - * - * @param string $var - * @return mixed - */ - public function __get($var) - { - $method = 'present'.str_replace(' ', '', ucwords(str_replace(array('-', '_'), ' ', $var))); - if (method_exists($this, $method)) - { - return $this->$method(); - } - - return $this->__getDecorator()->decorate(is_array($this->object) ? $this->object[$var] : $this->object->$var); - } - - /** - * Pass any uknown methods through to the inject object. - * - * @param string $method - * @param array $arguments - * @return mixed - */ - public function __call($method, $arguments) - { - if (is_object($this->object)) - { - $value = call_user_func_array(array($this->object, $method), $arguments); - - return $this->__getDecorator()->decorate($value); - } - - throw new \BadMethodCallException("Method {$method} does not exist."); - } - - /** + /** + * The object injected on Presenter construction. + * + * @var mixed + */ + protected $object; + + /** + * The decorator instance so we can nest presenters. Underscores here to avoid conflicts + * if a presenter or object has "decorator" as a variable. + * + * @var \Robbo\Presenter\Decorator + */ + protected static $__decorator; + + /** + * Create the Presenter and store the object we are presenting. + * + * @param mixed $object + */ + public function __construct($object) + { + $this->object = $object; + } + + /** + * Get the decorator, if none exists then use the default. Underscores here to avoid conflicts + * if a presenter or object needs to use "getDecorator". + * + * @var \Robbo\Presenter\Decorator + */ + protected function __getDecorator() + { + if (is_null(static::$__decorator)) + { + static::$__decorator = new Decorator; + } + + return static::$__decorator; + } + + /** + * This is so you can extend the decorator and inject it into the presenter at the class level so the + * new decorator will be used for nested presenters. Method name should be "setDecorator" however + * like above I want to make conflicts less likely. + * + * @param \Robbo\Presenter\Decorator + * @return void + */ + public static function setExtendedDecorator(Decorator $decorator) + { + static::$__decorator = $decorator; + } + + /** + * Get the object we are wrapping. + * + * @return mixed + */ + public function getObject() + { + return $this->object; + } + + /* + * This will be called when isset() is called via array access. + * + * @param mixed $offset + * @return boolean + */ + public function offsetExists($offset) + { + // We only check isset on the array, if it is an object we return true as the object could be overloaded + if (is_array($this->object)) + { + return isset($this->object[$offset]); + } + + return true; + } + + /** + * Add ability to access properties like an array. + * + * @param mixed $offset + * @return mixed + */ + public function offsetGet($offset) + { + return $this->__get($offset); + } + + /** + * Set variable or key value using array access. + * + * @param mixed $offset + * @param mixed $value + * @return void + */ + public function offsetSet($offset, $value) + { + if (is_array($this->object)) + { + $this->object[$offset] = $value; + return; + } + + $this->object->$offset = $value; + } + + /** + * Unset a variable or key value using array access. + * + * @param mixed $offset + * @return void + */ + public function offsetUnset($offset) + { + if (is_array($this->object)) + { + unset($this->object[$offset]); + return; + } + + unset($this->object->$offset); + } + + /** + * Pass any unknown varible calls to present{$variable} or fall through to the injected object. + * + * @param string $var + * @return mixed + */ + public function __get($var) + { + $method = 'present'.str_replace(' ', '', ucwords(str_replace(array('-', '_'), ' ', $var))); + if (method_exists($this, $method)) + { + return $this->$method(); + } + + return $this->__getDecorator()->decorate(is_array($this->object) ? $this->object[$var] : $this->object->$var); + } + + /** + * Pass any uknown methods through to the inject object. + * + * @param string $method + * @param array $arguments + * @return mixed + */ + public function __call($method, $arguments) + { + if (is_object($this->object)) + { + $value = call_user_func_array(array($this->object, $method), $arguments); + + return $this->__getDecorator()->decorate($value); + } + + throw new \BadMethodCallException("Method {$method} does not exist."); + } + + /** * Allow ability to run isset() on a variable * * @param string $name @@ -173,10 +173,10 @@ public function __call($method, $arguments) */ public function __isset($name) { - if (is_array($this->object)) - { - return isset($this->object[$name]); - } + if (is_array($this->object)) + { + return isset($this->object[$name]); + } return isset($this->object->$name); } @@ -188,11 +188,11 @@ public function __isset($name) */ public function __unset($name) { - if (is_array($this->object)) - { - unset($this->object[$name]); - return; - } + if (is_array($this->object)) + { + unset($this->object[$name]); + return; + } unset($this->object->$name); } diff --git a/src/Robbo/Presenter/PresenterServiceProvider.php b/src/Robbo/Presenter/PresenterServiceProvider.php index 7eed395..c41fc21 100755 --- a/src/Robbo/Presenter/PresenterServiceProvider.php +++ b/src/Robbo/Presenter/PresenterServiceProvider.php @@ -4,94 +4,94 @@ class PresenterServiceProvider extends ServiceProvider { - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ - protected $defer = false; - - /** - * Bootstrap the application events. - * - * @return void - */ - public function boot() - { - $this->package('robclancy/presenter'); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->registerDecorator(); - - $this->registerEnvironment(); - } - - /** - * Register the decorator. If you want to extend the decorator you would basically copy - * what this method does in start/global.php or your own service provider. - * - * @return void - */ - public function registerDecorator() - { - $this->app['presenter.decorator'] = $this->app->share(function($app) - { - $decorator = new Decorator; - - // This isn't really doing anything here however if you want to extend the decorator - // with your own instance then you need to do it like this in your own service - // provider or in start/global.php. - Presenter::setExtendedDecorator($decorator); - return $decorator; - }); - } - - /** - * Copied from the view service provider... - * - * Register the view environment. - * - * @return void - */ - public function registerEnvironment() - { - $this->app['view'] = $this->app->share(function($app) - { - // Next we need to grab the engine resolver instance that will be used by the - // environment. The resolver will be used by an environment to get each of - // the various engine implementations such as plain PHP or Blade engine. - $resolver = $app['view.engine.resolver']; - - $finder = $app['view.finder']; - - $env = new View\Environment($resolver, $finder, $app['events'], $app['presenter.decorator']); - - // We will also set the container instance on this view environment since the - // view composers may be classes registered in the container, which allows - // for great testable, flexible composers for the application developer. - $env->setContainer($app); - - $env->share('app', $app); - - return $env; - }); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array(); - } + /** + * Indicates if loading of the provider is deferred. + * + * @var bool + */ + protected $defer = false; + + /** + * Bootstrap the application events. + * + * @return void + */ + public function boot() + { + $this->package('robclancy/presenter'); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->registerDecorator(); + + $this->registerEnvironment(); + } + + /** + * Register the decorator. If you want to extend the decorator you would basically copy + * what this method does in start/global.php or your own service provider. + * + * @return void + */ + public function registerDecorator() + { + $this->app['presenter.decorator'] = $this->app->share(function($app) + { + $decorator = new Decorator; + + // This isn't really doing anything here however if you want to extend the decorator + // with your own instance then you need to do it like this in your own service + // provider or in start/global.php. + Presenter::setExtendedDecorator($decorator); + return $decorator; + }); + } + + /** + * Copied from the view service provider... + * + * Register the view environment. + * + * @return void + */ + public function registerEnvironment() + { + $this->app['view'] = $this->app->share(function($app) + { + // Next we need to grab the engine resolver instance that will be used by the + // environment. The resolver will be used by an environment to get each of + // the various engine implementations such as plain PHP or Blade engine. + $resolver = $app['view.engine.resolver']; + + $finder = $app['view.finder']; + + $env = new View\Environment($resolver, $finder, $app['events'], $app['presenter.decorator']); + + // We will also set the container instance on this view environment since the + // view composers may be classes registered in the container, which allows + // for great testable, flexible composers for the application developer. + $env->setContainer($app); + + $env->share('app', $app); + + return $env; + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array(); + } } \ No newline at end of file diff --git a/src/Robbo/Presenter/View/Environment.php b/src/Robbo/Presenter/View/Environment.php index dbea17e..eecaf7f 100755 --- a/src/Robbo/Presenter/View/Environment.php +++ b/src/Robbo/Presenter/View/Environment.php @@ -10,72 +10,72 @@ class Environment extends BaseEnvironment { - /** - * Used for "decorating" objects to have presenters. - * - * @var \Robbo\Presenter\Decorator - */ - protected $presenterDecorator; + /** + * Used for "decorating" objects to have presenters. + * + * @var \Robbo\Presenter\Decorator + */ + protected $presenterDecorator; - /** - * Create a new view environment instance. - * - * @param \Illuminate\View\Engines\EngineResolver $engines - * @param \Illuminate\View\ViewFinderInterface $finder - * @param \Illuminate\Events\Dispatcher $events - * @param \Robbo\Presenter\Decorator $decorator - * @return void - */ - public function __construct(EngineResolver $engines, ViewFinderInterface $finder, Dispatcher $events, Decorator $decorator) - { - $this->presenterDecorator = $decorator; + /** + * Create a new view environment instance. + * + * @param \Illuminate\View\Engines\EngineResolver $engines + * @param \Illuminate\View\ViewFinderInterface $finder + * @param \Illuminate\Events\Dispatcher $events + * @param \Robbo\Presenter\Decorator $decorator + * @return void + */ + public function __construct(EngineResolver $engines, ViewFinderInterface $finder, Dispatcher $events, Decorator $decorator) + { + $this->presenterDecorator = $decorator; - parent::__construct($engines, $finder, $events); - } + parent::__construct($engines, $finder, $events); + } - /** - * Get a evaluated view contents for the given view. - * - * @param string $view - * @param array $data - * @param array $mergeData - * @return Illuminate\View\View - */ - public function make($view, $data = array(), $mergeData = array()) - { - $path = $this->finder->find($view); + /** + * Get a evaluated view contents for the given view. + * + * @param string $view + * @param array $data + * @param array $mergeData + * @return Illuminate\View\View + */ + public function make($view, $data = array(), $mergeData = array()) + { + $path = $this->finder->find($view); - $data = array_merge($mergeData, $this->parseData($data)); + $data = array_merge($mergeData, $this->parseData($data)); - return new View($this, $this->getEngineFromPath($path), $view, $path, $this->decorate($data)); - } + return new View($this, $this->getEngineFromPath($path), $view, $path, $this->decorate($data)); + } - /** - * Add a piece of shared data to the environment. - * - * @param string $key - * @param mixed $value - * @return void - */ - public function share($key, $value = null) - { - if ( ! is_array($key)) - { - return parent::share($key, $this->decorate($value)); - } + /** + * Add a piece of shared data to the environment. + * + * @param string $key + * @param mixed $value + * @return void + */ + public function share($key, $value = null) + { + if ( ! is_array($key)) + { + return parent::share($key, $this->decorate($value)); + } - return parent::share($this->decorate($key)); - } + return parent::share($this->decorate($key)); + } - /** - * Decorate an object with a presenter. - * - * @param mixed $value - * @return mixed - */ - public function decorate($value) - { - return $this->presenterDecorator->decorate($value); - } + /** + * Decorate an object with a presenter. + * + * @param mixed $value + * @return mixed + */ + public function decorate($value) + { + return $this->presenterDecorator->decorate($value); + } } diff --git a/src/Robbo/Presenter/View/View.php b/src/Robbo/Presenter/View/View.php index f402397..eec7800 100755 --- a/src/Robbo/Presenter/View/View.php +++ b/src/Robbo/Presenter/View/View.php @@ -5,20 +5,20 @@ class View extends BaseView { - /** - * Add a piece of data to the view. - * - * @param string|array $key - * @param mixed $value - * @return \Illuminate\View\View - */ - public function with($key, $value = null) - { - if (is_array($key)) - { - return parent::with($this->environment->decorate($key)); - } + /** + * Add a piece of data to the view. + * + * @param string|array $key + * @param mixed $value + * @return \Illuminate\View\View + */ + public function with($key, $value = null) + { + if (is_array($key)) + { + return parent::with($this->environment->decorate($key)); + } - return parent::with($key, $this->environment->decorate($value)); - } + return parent::with($key, $this->environment->decorate($value)); + } } \ No newline at end of file diff --git a/tests/PresenterTest.php b/tests/PresenterTest.php index ec3d9de..7ce108f 100755 --- a/tests/PresenterTest.php +++ b/tests/PresenterTest.php @@ -4,137 +4,137 @@ class PresenterTest extends PHPUnit_Framework_TestCase { - public function testPresenterVariableCalls() - { - $presenter = new PresenterStub(new InjectStub); - - $this->assertEquals($presenter->testVar, 'testvar'); - $this->assertEquals($presenter['testVar'], 'testvar'); - $this->assertEquals($presenter->testVar2, 'testvar2'); - } - - public function testPresenterMethodCalls() - { - $presenter = new PresenterStub(new InjectStub); - - $this->assertEquals($presenter->testMethod(), 'testMethod'); - $this->assertEquals($presenter->testMethod2(), 'testMethod2'); - } - - public function testNestedPresenterVariableCalls() - { - $presenter = new PresenterStub(new PresenterStub2(new InjectStub)); - - $this->assertEquals($presenter->testVar, 'testvar'); - $this->assertEquals($presenter->testVar2, 'testvar2'); - $this->assertEquals($presenter->testVar3, 'testvar3'); - } - - public function testNestedPresenterMethodCalls() - { - $presenter = new PresenterStub(new PresenterStub2(new InjectStub)); - - $this->assertEquals($presenter->testMethod(), 'testMethod'); - $this->assertEquals($presenter->testMethod2(), 'testMethod2'); - $this->assertEquals($presenter->testMethod3(), 'testMethod3'); - } - - public function testPresentVariableCalls() - { - $presenter = new PresenterStub(new PresenterStub2(new InjectStub)); - - $this->assertEquals($presenter->awesome, 'presenting you the awesome'); - $this->assertEquals($presenter['awesome'], 'presenting you the awesome'); - } - - public function testArrayPresenterVariableCalls() - { - $presenter = new PresenterStub(array('testVar' => 'testvar')); - - $this->assertEquals($presenter->testVar, 'testvar'); - $this->assertEquals($presenter['testVar'], 'testvar'); - $this->assertEquals($presenter->testVar2, 'testvar2'); - } - - /** - * @expectedException BadMethodCallException - */ - public function testArrayMethodCallException() - { - $presenter = new PresenterStub(array('testVar' => 'testvar')); - $presenter->someMethod(); - } - - public function testArrayIsset() - { - $presenter = new PresenterStub(array('testVar' => 'testvar')); - - $this->assertTrue(isset($presenter['testVar'])); - $this->assertFalse(isset($presenter['unsetVar'])); - - $presenter = new PresenterStub(new InjectStub); - $this->assertTrue(isset($presenter['unsetVar'])); - } - - public function testArraySet() - { - $presenter = new PresenterStub(array('testVar' => 'testvar')); - $presenter['testNewVar'] = 'number 2'; - - $this->assertEquals($presenter['testNewVar'], 'number 2'); - $this->assertEquals($presenter->testNewVar, 'number 2'); - } - - public function testArrayUnset() - { - $presenter = new PresenterStub(array('testVar' => 'testvar')); - - $this->assertEquals($presenter['testVar'], 'testvar'); - - unset($presenter['testVar']); - $this->assertFalse(isset($presenter['testVar'])); - - $presenter = new PresenterStub(new InjectStub); - - $this->assertEquals($presenter->testVar, 'testvar'); - - unset($presenter['testVar']); - $this->assertFalse(isset($presenter->testVar)); - } + public function testPresenterVariableCalls() + { + $presenter = new PresenterStub(new InjectStub); + + $this->assertEquals($presenter->testVar, 'testvar'); + $this->assertEquals($presenter['testVar'], 'testvar'); + $this->assertEquals($presenter->testVar2, 'testvar2'); + } + + public function testPresenterMethodCalls() + { + $presenter = new PresenterStub(new InjectStub); + + $this->assertEquals($presenter->testMethod(), 'testMethod'); + $this->assertEquals($presenter->testMethod2(), 'testMethod2'); + } + + public function testNestedPresenterVariableCalls() + { + $presenter = new PresenterStub(new PresenterStub2(new InjectStub)); + + $this->assertEquals($presenter->testVar, 'testvar'); + $this->assertEquals($presenter->testVar2, 'testvar2'); + $this->assertEquals($presenter->testVar3, 'testvar3'); + } + + public function testNestedPresenterMethodCalls() + { + $presenter = new PresenterStub(new PresenterStub2(new InjectStub)); + + $this->assertEquals($presenter->testMethod(), 'testMethod'); + $this->assertEquals($presenter->testMethod2(), 'testMethod2'); + $this->assertEquals($presenter->testMethod3(), 'testMethod3'); + } + + public function testPresentVariableCalls() + { + $presenter = new PresenterStub(new PresenterStub2(new InjectStub)); + + $this->assertEquals($presenter->awesome, 'presenting you the awesome'); + $this->assertEquals($presenter['awesome'], 'presenting you the awesome'); + } + + public function testArrayPresenterVariableCalls() + { + $presenter = new PresenterStub(array('testVar' => 'testvar')); + + $this->assertEquals($presenter->testVar, 'testvar'); + $this->assertEquals($presenter['testVar'], 'testvar'); + $this->assertEquals($presenter->testVar2, 'testvar2'); + } + + /** + * @expectedException BadMethodCallException + */ + public function testArrayMethodCallException() + { + $presenter = new PresenterStub(array('testVar' => 'testvar')); + $presenter->someMethod(); + } + + public function testArrayIsset() + { + $presenter = new PresenterStub(array('testVar' => 'testvar')); + + $this->assertTrue(isset($presenter['testVar'])); + $this->assertFalse(isset($presenter['unsetVar'])); + + $presenter = new PresenterStub(new InjectStub); + $this->assertTrue(isset($presenter['unsetVar'])); + } + + public function testArraySet() + { + $presenter = new PresenterStub(array('testVar' => 'testvar')); + $presenter['testNewVar'] = 'number 2'; + + $this->assertEquals($presenter['testNewVar'], 'number 2'); + $this->assertEquals($presenter->testNewVar, 'number 2'); + } + + public function testArrayUnset() + { + $presenter = new PresenterStub(array('testVar' => 'testvar')); + + $this->assertEquals($presenter['testVar'], 'testvar'); + + unset($presenter['testVar']); + $this->assertFalse(isset($presenter['testVar'])); + + $presenter = new PresenterStub(new InjectStub); + + $this->assertEquals($presenter->testVar, 'testvar'); + + unset($presenter['testVar']); + $this->assertFalse(isset($presenter->testVar)); + } } class InjectStub { - public $testVar = 'testvar'; + public $testVar = 'testvar'; - public function testMethod() - { - return 'testMethod'; - } + public function testMethod() + { + return 'testMethod'; + } } class PresenterStub extends Presenter { - public $testVar2 = 'testvar2'; + public $testVar2 = 'testvar2'; - public function testMethod2() - { - return 'testMethod2'; - } + public function testMethod2() + { + return 'testMethod2'; + } - protected function presentAwesome() - { - return 'presenting you the awesome'; - } + protected function presentAwesome() + { + return 'presenting you the awesome'; + } } class PresenterStub2 extends Presenter { - public $testVar3 = 'testvar3'; + public $testVar3 = 'testvar3'; - public function testMethod3() - { - return 'testMethod3'; - } + public function testMethod3() + { + return 'testMethod3'; + } } \ No newline at end of file diff --git a/tests/ViewEnvironmentTest.php b/tests/ViewEnvironmentTest.php index 50b7046..df72ce0 100755 --- a/tests/ViewEnvironmentTest.php +++ b/tests/ViewEnvironmentTest.php @@ -10,81 +10,81 @@ class ViewEnvironmentTest extends PHPUnit_Framework_TestCase { - public function tearDown() - { - m::close(); - } - - public function testMakeView() - { - $data = array( - 'meh' => 'zomg', - 'presentable' => new PresentableStub, - 'collection' => new Collection(array( - 'presentable' => new PresentableStub - )) - ); - - $env = $this->getEnvironment(); - $env->finder->shouldReceive('find')->once()->andReturn('test'); - - $view = $env->make('test', $data); - - $this->assertInstanceOf('Robbo\Presenter\View\View', $view); - $this->assertSame($view['meh'], $data['meh']); - $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['presentable']); - $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['presentable']->presentableObject); - $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['presentable']->getPresentableObject()); - $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['collection']['presentable']); - } - - protected function getEnvironment() - { - return new EnvironmentStub( - m::mock('Illuminate\View\Engines\EngineResolver'), - m::mock('Illuminate\View\ViewFinderInterface'), - m::mock('Illuminate\Events\Dispatcher'), - new Decorator - ); - } + public function tearDown() + { + m::close(); + } + + public function testMakeView() + { + $data = array( + 'meh' => 'zomg', + 'presentable' => new PresentableStub, + 'collection' => new Collection(array( + 'presentable' => new PresentableStub + )) + ); + + $env = $this->getEnvironment(); + $env->finder->shouldReceive('find')->once()->andReturn('test'); + + $view = $env->make('test', $data); + + $this->assertInstanceOf('Robbo\Presenter\View\View', $view); + $this->assertSame($view['meh'], $data['meh']); + $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['presentable']); + $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['presentable']->presentableObject); + $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['presentable']->getPresentableObject()); + $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['collection']['presentable']); + } + + protected function getEnvironment() + { + return new EnvironmentStub( + m::mock('Illuminate\View\Engines\EngineResolver'), + m::mock('Illuminate\View\ViewFinderInterface'), + m::mock('Illuminate\Events\Dispatcher'), + new Decorator + ); + } } class EnvironmentStub extends Environment { - public $finder; + public $finder; - protected function getEngineFromPath($path) - { - return m::mock('Illuminate\View\Engines\EngineInterface'); - } + protected function getEngineFromPath($path) + { + return m::mock('Illuminate\View\Engines\EngineInterface'); + } } class PresentableStub implements PresentableInterface { - public $presentableObject; + public $presentableObject; - public function __construct() - { - $this->presentableObject = new SecondPresentableStub; - } + public function __construct() + { + $this->presentableObject = new SecondPresentableStub; + } - public function getPresentableObject() - { - return $this->presentableObject; - } + public function getPresentableObject() + { + return $this->presentableObject; + } - public function getPresenter() - { - return new EnvPresenterStub($this); - } + public function getPresenter() + { + return new EnvPresenterStub($this); + } } class SecondPresentableStub implements PresentableInterface { - public function getPresenter() - { - return new EnvPresenterStub($this); - } + public function getPresenter() + { + return new EnvPresenterStub($this); + } } class EnvPresenterStub extends Presenter {} \ No newline at end of file diff --git a/tests/ViewTest.php b/tests/ViewTest.php index 4b45196..0bae710 100755 --- a/tests/ViewTest.php +++ b/tests/ViewTest.php @@ -8,54 +8,54 @@ class ViewTest extends PHPUnit_Framework_TestCase { - public function tearDown() - { - m::close(); - } - - public function testWithMakesPresentable() - { - $env = new EnvironmentStub( - m::mock('Illuminate\View\Engines\EngineResolver'), - m::mock('Illuminate\View\ViewFinderInterface'), - m::mock('Illuminate\Events\Dispatcher'), - new Decorator - ); - - $view = new View($env, m::mock('Illuminate\View\Engines\EngineInterface'), 'test', 'test/path'); - - $view->with('presenter', new ViewPresentableStub); - - $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['presenter']); - } - - public function testWithMakesArrayPresentable() - { - $env = new EnvironmentStub( - m::mock('Illuminate\View\Engines\EngineResolver'), - m::mock('Illuminate\View\ViewFinderInterface'), - m::mock('Illuminate\Events\Dispatcher'), - new Decorator - ); - - $view = new View($env, m::mock('Illuminate\View\Engines\EngineInterface'), 'test', 'test/path'); - - $data = array( - 'presenter' => new ViewPresentableStub - ); - - $view->with($data); - - $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['presenter']); - } + public function tearDown() + { + m::close(); + } + + public function testWithMakesPresentable() + { + $env = new EnvironmentStub( + m::mock('Illuminate\View\Engines\EngineResolver'), + m::mock('Illuminate\View\ViewFinderInterface'), + m::mock('Illuminate\Events\Dispatcher'), + new Decorator + ); + + $view = new View($env, m::mock('Illuminate\View\Engines\EngineInterface'), 'test', 'test/path'); + + $view->with('presenter', new ViewPresentableStub); + + $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['presenter']); + } + + public function testWithMakesArrayPresentable() + { + $env = new EnvironmentStub( + m::mock('Illuminate\View\Engines\EngineResolver'), + m::mock('Illuminate\View\ViewFinderInterface'), + m::mock('Illuminate\Events\Dispatcher'), + new Decorator + ); + + $view = new View($env, m::mock('Illuminate\View\Engines\EngineInterface'), 'test', 'test/path'); + + $data = array( + 'presenter' => new ViewPresentableStub + ); + + $view->with($data); + + $this->assertInstanceOf('Robbo\Presenter\Presenter', $view['presenter']); + } } class ViewPresentableStub implements PresentableInterface { - public function getPresenter() - { - return new ViewPresenterStub($this); - } + public function getPresenter() + { + return new ViewPresenterStub($this); + } } class ViewPresenterStub extends Presenter {} \ No newline at end of file