diff --git a/composer.json b/composer.json index ced7d662..e3942962 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "minimum-stability": "dev", - "prefer-stable":true, + "prefer-stable": true, "extra": { "branch-alias": { "dev-master": "0.1.x-dev" @@ -35,6 +35,7 @@ "phpunit/phpunit": "^4.8", "squizlabs/php_codesniffer": "^2.4", "satooshi/php-coveralls": "~1.0.1", + "tedivm/stash": "~0.14", "pimple/pimple": "^3.0" }, "suggest": { @@ -45,8 +46,16 @@ "Charcoal\\": "src/Charcoal/" } }, + "autoload-dev": { + "psr-4": { + "Charcoal\\Tests\\": "tests/Charcoal" + } + }, "scripts": { "test": [ + "@tests" + ], + "tests": [ "@phplint", "@phpcs", "@phpunit" diff --git a/src/Charcoal/Ui/AbstractUiItem.php b/src/Charcoal/Ui/AbstractUiItem.php index 6cc5fa32..72126f20 100644 --- a/src/Charcoal/Ui/AbstractUiItem.php +++ b/src/Charcoal/Ui/AbstractUiItem.php @@ -78,7 +78,6 @@ public function __construct(array $data = null) public function setDependencies(Container $container) { $this->setTranslator($container['translator']); - $this->setAuthDependencies($container); } /** diff --git a/tests/Charcoal/Ui/AbstractUiItemTest.php b/tests/Charcoal/Ui/AbstractUiItemTest.php index 22bd987e..b6a7c31c 100644 --- a/tests/Charcoal/Ui/AbstractUiItemTest.php +++ b/tests/Charcoal/Ui/AbstractUiItemTest.php @@ -2,20 +2,38 @@ namespace Charcoal\Tests\Ui; -use Pimple\Container; +use ReflectionClass; -class AbstractUiTest extends \PHPUnit_Framework_TestCase +// From 'charcoal-ui' +use Charcoal\Ui\AbstractUiItem; + +/** + * + */ +class AbstractUiItemTest extends \PHPUnit_Framework_TestCase { + use \Charcoal\Tests\Ui\ContainerIntegrationTrait; + public $obj; public function setUp() { - $container = new Container; - $container['translator'] = $GLOBALS['translator']; + $container = $this->getContainer(); - $this->obj = $this->getMockForAbstractClass('\Charcoal\Ui\AbstractUiItem', [[ + $this->obj = $this->getMockForAbstractClass(AbstractUiItem::class, [[ 'container' => $container ]]); + + $setAuthDependencies = self::getMethod($this->obj, 'setAuthDependencies'); + $setAuthDependencies->invoke($this->obj, $container); + } + + public static function getMethod($obj, $name) + { + $class = new ReflectionClass($obj); + $method = $class->getMethod($name); + $method->setAccessible(true); + return $method; } public function testSetType() diff --git a/tests/Charcoal/Ui/ContainerIntegrationTrait.php b/tests/Charcoal/Ui/ContainerIntegrationTrait.php new file mode 100644 index 00000000..c919f395 --- /dev/null +++ b/tests/Charcoal/Ui/ContainerIntegrationTrait.php @@ -0,0 +1,45 @@ +container === null) { + $provider = new ContainerProvider(); + $container = new Container(); + + $provider->registerBaseServices($container); + $provider->registerAuthServices($container); + $provider->registerTranslator($container); + $provider->registerMetadataLoader($container); + $provider->registerSourceFactory($container); + $provider->registerPropertyFactory($container); + + $this->container = $container; + } + + return $this->container; + } +} diff --git a/tests/Charcoal/Ui/ContainerProvider.php b/tests/Charcoal/Ui/ContainerProvider.php new file mode 100644 index 00000000..a1d03655 --- /dev/null +++ b/tests/Charcoal/Ui/ContainerProvider.php @@ -0,0 +1,267 @@ +registerSource($container); + $this->registerLogger($container); + $this->registerCache($container); + } + + /** + * Register the admin services. + * + * @param Container $container A DI container. + * @return void + */ + public function registerAuthServices(Container $container) + { + $this->registerAuthenticator($container); + $this->registerAuthorizer($container); + } + + /** + * Setup the application's data source interface. + * + * Note: Uses SQLite to create a database in memory. + * + * @param Container $container A DI container. + * @return void + */ + public function registerSource(Container $container) + { + $container['database'] = function (Container $container) { + $pdo = new PDO('sqlite::memory:'); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + return $pdo; + }; + } + + /** + * Setup the application's logging interface. + * + * @param Container $container A DI container. + * @return void + */ + public function registerLogger(Container $container) + { + $container['logger'] = function (Container $container) { + return new NullLogger(); + }; + } + + /** + * Setup the application's caching interface. + * + * @param Container $container A DI container. + * @return void + */ + public function registerCache(Container $container) + { + $container['cache'] = function ($container) { + return new Pool(new Ephemeral()); + }; + } + + /** + * Setup the application's translator service. + * + * @param Container $container A DI container. + * @return void + */ + public function registerTranslator(Container $container) + { + $container['language/manager'] = function (Container $container) { + return new LocalesManager([ + 'locales' => [ + 'en' => [ 'locale' => 'en-US' ] + ] + ]); + }; + + $container['translator'] = function (Container $container) { + return new Translator([ + 'manager' => $container['language/manager'] + ]); + }; + } + + /** + * Setup the framework's metadata loader interface. + * + * @param Container $container A DI container. + * @return void + */ + public function registerMetadataLoader(Container $container) + { + $container['metadata/loader'] = function (Container $container) { + return new MetadataLoader([ + 'cache' => $container['cache'], + 'logger' => $container['logger'], + 'base_path' => realpath(__DIR__.'/../../../'), + 'paths' => [ + 'metadata', + 'vendor/locomotivemtl/charcoal-property/metadata' + ] + ]); + }; + } + + /** + * Setup the framework's data source factory. + * + * @param Container $container A DI container. + * @return void + */ + public function registerSourceFactory(Container $container) + { + $container['source/factory'] = function ($container) { + return new Factory([ + 'map' => [ + 'database' => DatabaseSource::class + ], + 'arguments' => [[ + 'logger' => $container['logger'], + 'cache' => $container['cache'], + 'pdo' => $container['database'] + ]] + ]); + }; + } + + /** + * Setup the framework's model factory. + * + * @param Container $container A DI container. + * @return void + */ + public function registerModelFactory(Container $container) + { + $container['model/factory'] = function ($container) { + return new Factory([ + 'arguments' => [[ + 'container' => $container, + 'logger' => $container['logger'], + 'metadata_loader' => $container['metadata/loader'], + 'source_factory' => $container['source/factory'], + 'property_factory' => $container['property/factory'] + ]] + ]); + }; + } + + /** + * Setup the framework's property factory. + * + * @param Container $container A DI container. + * @return void + */ + public function registerPropertyFactory(Container $container) + { + $container['property/factory'] = function (Container $container) { + return new Factory([ + 'resolver_options' => [ + 'prefix' => '\\Charcoal\\Property\\', + 'suffix' => 'Property' + ], + 'arguments' => [[ + 'container' => $container, + 'database' => $container['database'], + 'logger' => $container['logger'], + 'translator' => $container['translator'] + ]] + ]); + }; + } + + /** + * Setup the framework's collection loader interface. + * + * @param Container $container A DI container. + * @return void + */ + public function registerModelCollectionLoader(Container $container) + { + $container['model/collection/loader'] = function (Container $container) { + return new CollectionLoader([ + 'logger' => $container['logger'], + 'cache' => $container['cache'] + ]); + }; + } + + public function registerAuthenticator(Container $container) + { + $this->registerLogger($container); + $this->registerModelFactory($container); + + $container['authenticator'] = function (Container $container) { + return new Authenticator([ + 'logger' => $container['logger'], + 'user_type' => 'charcoal/user', + 'user_factory' => $container['model/factory'], + 'token_type' => 'charcoal/user/auth-token', + 'token_factory' => $container['model/factory'] + ]); + }; + } + + public function registerAuthorizer(Container $container) + { + $this->registerLogger($container); + + $container['authorizer'] = function (Container $container) { + return new Authorizer([ + 'logger' => $container['logger'], + 'acl' => new Acl(), + 'resource' => 'test' + ]); + }; + } +} diff --git a/tests/Charcoal/Ui/Dashboard/AbstractDashboardTest.php b/tests/Charcoal/Ui/Dashboard/AbstractDashboardTest.php index d66e0221..ccb2eadc 100644 --- a/tests/Charcoal/Ui/Dashboard/AbstractDashboardTest.php +++ b/tests/Charcoal/Ui/Dashboard/AbstractDashboardTest.php @@ -2,15 +2,9 @@ namespace Charcoal\Tests\Ui\Dashboard; -// PSR-3 logger test dependencies -use \Psr\Log\NullLogger; - -// Pimple test dependencies -use \Pimple\Container; - -// Tested module (`charcoal-ui`) test dependencies +// From 'charcoal-ui' use \Charcoal\Ui\UiItemInterface; -use \Charcoal\Ui\Dashboard\GenericDashboard; +use \Charcoal\Ui\Dashboard\AbstractDashboard; use \Charcoal\Ui\DashboardGroup\DashboardGroupBuilder; use \Charcoal\Ui\ServiceProvider\DashboardServiceProvider; use \Charcoal\Ui\ServiceProvider\LayoutServiceProvider; @@ -18,36 +12,26 @@ class AbstractDashboardTest extends \PHPUnit_Framework_TestCase { - public $container; + use \Charcoal\Tests\Ui\ContainerIntegrationTrait; /** * @var AbstractViewClass $obj */ public $obj; - /** - * @var \Psr\Log\NullLogger $logger - */ - public $logger; - /** * */ public function setUp() { - $container = new Container(); + $container = $this->getContainer(); $container->register(new DashboardServiceProvider()); $container->register(new LayoutServiceProvider()); $container->register(new FormServiceProvider()); - // Fulfills the services dependencies on `logger` and `view`. - $container['logger'] = new NullLogger(); $container['view'] = null; - - $this->container = $container; - - $this->obj = $this->getMockForAbstractClass('\Charcoal\Ui\Dashboard\AbstractDashboard', [[ + $this->obj = $this->getMockForAbstractClass(AbstractDashboard::class, [[ 'logger' => $container['logger'], 'layout_builder' => $container['layout/builder'], 'widget_builder' => $container['form/builder'] @@ -88,11 +72,13 @@ public function testSetWidgetCallback() */ public function testSetLayout() { + $container = $this->getContainer(); + $obj = $this->obj; $this->assertNull($obj->layout()); $exampleLayout = $this->exampleLayout(); - $layout = $this->container['layout/builder']->build($exampleLayout); + $layout = $container['layout/builder']->build($exampleLayout); $ret = $obj->setLayout($layout); $this->assertSame($ret, $obj); @@ -142,7 +128,7 @@ public function testWidgets() $widgets = $obj->widgets(); $num = 0; foreach ($widgets as $w) { - $this->assertInstanceOf('\Charcoal\Ui\UiItemInterface', $w); + $this->assertInstanceOf(UiItemInterface::class, $w); } } diff --git a/tests/Charcoal/Ui/Form/AbstractFormTest.php b/tests/Charcoal/Ui/Form/AbstractFormTest.php index bf591156..331ce8c8 100644 --- a/tests/Charcoal/Ui/Form/AbstractFormTest.php +++ b/tests/Charcoal/Ui/Form/AbstractFormTest.php @@ -2,15 +2,16 @@ namespace Charcoal\Tests\Ui\Form; -use \Charcoal\Ui\Form\GenericForm; -use \Charcoal\Ui\FormGroup\FormGroupBuilder; +use Charcoal\Ui\Form\AbstractForm; +use Charcoal\Ui\ServiceProvider\FormServiceProvider; +use Charcoal\Ui\ServiceProvider\LayoutServiceProvider; /** * */ class AbstractFormTest extends \PHPUnit_Framework_TestCase { - public $container; + use \Charcoal\Tests\Ui\ContainerIntegrationTrait; /** * @var AbstractViewClass $obj @@ -22,19 +23,13 @@ class AbstractFormTest extends \PHPUnit_Framework_TestCase */ public function setUp() { - $container = new \Pimple\Container(); - $container->register(new \Charcoal\Ui\ServiceProvider\FormServiceProvider()); - $container->register(new \Charcoal\Ui\ServiceProvider\LayoutServiceProvider()); + $container = $this->getContainer(); + $container->register(new FormServiceProvider()); + $container->register(new LayoutServiceProvider()); - $container['logger'] = new \Psr\Log\NullLogger(); $container['view'] = null; - $container['translator'] = $GLOBALS['translator']; - $this->container = $container; - - - $this->logger = new \Psr\Log\NullLogger(); - $this->obj = $this->getMockForAbstractClass('\Charcoal\Ui\Form\AbstractForm', [[ + $this->obj = $this->getMockForAbstractClass(AbstractForm::class, [[ 'logger' => $container['logger'], 'layout_builder' => $container['layout/builder'], 'form_group_factory' => $container['form/group/factory'], @@ -90,7 +85,7 @@ public function testSetGroup() { $obj = $this->obj; $ret = $obj->setGroups([ - 'test'=>[] + 'test' => [] ]); $this->assertSame($ret, $obj); @@ -103,7 +98,7 @@ public function testHasGroups() $this->assertFalse($obj->hasGroups()); $ret = $obj->setGroups([ - 'test'=>[] + 'test' => [] ]); $this->assertTrue($obj->hasGroups()); @@ -115,8 +110,8 @@ public function testNumGroups() $this->assertEquals(0, $obj->numGroups()); $ret = $obj->setGroups([ - 'test'=>[], - 'foobar'=>[] + 'test' => [], + 'foobar' => [] ]); $this->assertEquals(2, $obj->numGroups()); @@ -125,21 +120,21 @@ public function testNumGroups() public function testSetFormData() { $this->assertEquals([], $this->obj->formData()); - $ret = $this->obj->setFormData(['foo'=>'bar']); + $ret = $this->obj->setFormData([ 'foo' => 'bar' ]); $this->assertSame($ret, $this->obj); - $this->assertEquals(['foo'=>'bar'], $this->obj->formData()); + $this->assertEquals([ 'foo' => 'bar' ], $this->obj->formData()); - $this->obj->setFormData(['baz'=>42]); - $this->assertEquals(['baz'=>42], $this->obj->formData()); + $this->obj->setFormData([ 'baz' => 42 ]); + $this->assertEquals([ 'baz' => 42 ], $this->obj->formData()); } public function testAddData() { $ret = $this->obj->addFormData('foo', 'bar'); $this->assertSame($ret, $this->obj); - $this->assertEquals(['foo'=>'bar'], $this->obj->formData()); + $this->assertEquals([ 'foo' => 'bar' ], $this->obj->formData()); $this->obj->addFormData('baz', 42); - $this->assertEquals(['foo'=>'bar', 'baz'=>42], $this->obj->formData()); + $this->assertEquals([ 'foo' => 'bar', 'baz' => 42], $this->obj->formData()); $this->setExpectedException('\InvalidArgumentException'); $this->obj->addFormData(false, 'bar'); diff --git a/tests/Charcoal/Ui/Form/GenericFormTest.php b/tests/Charcoal/Ui/Form/GenericFormTest.php index 6eda8d45..c6809813 100644 --- a/tests/Charcoal/Ui/Form/GenericFormTest.php +++ b/tests/Charcoal/Ui/Form/GenericFormTest.php @@ -2,31 +2,28 @@ namespace Charcoal\Tests\Ui; -use \Charcoal\Ui\Form\GenericForm; +use Charcoal\Ui\Form\GenericForm; +use Charcoal\Ui\ServiceProvider\FormServiceProvider; +use Charcoal\Ui\ServiceProvider\LayoutServiceProvider; class GenericFormTest extends \PHPUnit_Framework_TestCase { + use \Charcoal\Tests\Ui\ContainerIntegrationTrait; + /** * @var AbstractViewClass $obj */ public $obj; - /** - * @var \Psr\Log\NullLogger $logger - */ - public $logger; - /** * */ public function setUp() { + $container = $this->getContainer(); + $container->register(new FormServiceProvider()); + $container->register(new LayoutServiceProvider()); - $container = new \Pimple\Container(); - $container->register(new \Charcoal\Ui\ServiceProvider\FormServiceProvider()); - $container->register(new \Charcoal\Ui\ServiceProvider\LayoutServiceProvider()); - - $container['logger'] = new \Psr\Log\NullLogger(); $container['view'] = null; $this->obj = new GenericForm([ @@ -38,6 +35,6 @@ public function setUp() public function testConstructor() { - $this->assertInstanceOf('\Charcoal\Ui\Form\GenericForm', $this->obj); + $this->assertInstanceOf(GenericForm::class, $this->obj); } } diff --git a/tests/Charcoal/Ui/FormGroup/AbstractFormGroupTest.php b/tests/Charcoal/Ui/FormGroup/AbstractFormGroupTest.php index 8f71db19..7455c5a5 100644 --- a/tests/Charcoal/Ui/FormGroup/AbstractFormGroupTest.php +++ b/tests/Charcoal/Ui/FormGroup/AbstractFormGroupTest.php @@ -2,15 +2,16 @@ namespace Charcoal\Tests\Ui\Form; -use \Charcoal\Ui\Form\GenericForm; -use \Charcoal\Ui\FormGroup\FormGroupBuilder; +use Charcoal\Ui\FormGroup\AbstractFormGroup; +use Charcoal\Ui\ServiceProvider\FormServiceProvider; +use Charcoal\Ui\ServiceProvider\LayoutServiceProvider; /** * */ class AbstractFormGroupTest extends \PHPUnit_Framework_TestCase { - public $container; + use \Charcoal\Tests\Ui\ContainerIntegrationTrait; /** * @var AbstractViewClass $obj @@ -22,20 +23,17 @@ class AbstractFormGroupTest extends \PHPUnit_Framework_TestCase */ public function setUp() { - $container = new \Pimple\Container(); - $container->register(new \Charcoal\Ui\ServiceProvider\FormServiceProvider()); - $container->register(new \Charcoal\Ui\ServiceProvider\LayoutServiceProvider()); + $container = $this->getContainer(); + $container->register(new FormServiceProvider()); + $container->register(new LayoutServiceProvider()); - $container['logger'] = new \Psr\Log\NullLogger(); $container['view'] = null; - $this->container = $container; - $form = $container['form/builder']->build([ - 'type'=>null + 'type' => null ]); - $this->obj = $this->getMockForAbstractClass('\Charcoal\Ui\FormGroup\AbstractFormGroup', [[ + $this->obj = $this->getMockForAbstractClass(AbstractFormGroup::class, [[ 'form' => $form, 'logger' => $container['logger'], 'view' => $container['view'], @@ -58,7 +56,7 @@ public function testSetInputs() { $obj = $this->obj; $ret = $obj->setInputs([ - 'test'=>[] + 'test' => [] ]); $this->assertSame($ret, $obj); } @@ -90,7 +88,7 @@ public function testHasInputs() $this->assertFalse($obj->hasInputs()); $ret = $obj->setInputs([ - 'test'=>[] + 'test' => [] ]); $this->assertTrue($obj->hasInputs()); @@ -102,8 +100,8 @@ public function testNumInput() $this->assertEquals(0, $obj->numInputs()); $ret = $obj->setInputs([ - 'test'=>[], - 'foobar'=>[] + 'test' => [], + 'foobar' => [] ]); $this->assertEquals(2, $obj->numInputs()); diff --git a/tests/Charcoal/Ui/FormGroup/GenericFormGroupTest.php b/tests/Charcoal/Ui/FormGroup/GenericFormGroupTest.php index 09475bc3..8f83b1b6 100644 --- a/tests/Charcoal/Ui/FormGroup/GenericFormGroupTest.php +++ b/tests/Charcoal/Ui/FormGroup/GenericFormGroupTest.php @@ -2,31 +2,29 @@ namespace Charcoal\Tests\Ui; -use \Charcoal\Ui\Form\GenericForm; -use \Charcoal\Ui\FormGroup\GenericFormGroup; +use Charcoal\Ui\Form\GenericForm; +use Charcoal\Ui\FormGroup\GenericFormGroup; +use Charcoal\Ui\ServiceProvider\FormServiceProvider; +use Charcoal\Ui\ServiceProvider\LayoutServiceProvider; class GenericFormGroupTest extends \PHPUnit_Framework_TestCase { + use \Charcoal\Tests\Ui\ContainerIntegrationTrait; + /** * @var AbstractViewClass $obj */ public $obj; - /** - * @var \Psr\Log\NullLogger $logger - */ - public $logger; - /** * */ public function setUp() { - $container = new \Pimple\Container(); - $container->register(new \Charcoal\Ui\ServiceProvider\FormServiceProvider()); - $container->register(new \Charcoal\Ui\ServiceProvider\LayoutServiceProvider()); + $container = $this->getContainer(); + $container->register(new FormServiceProvider()); + $container->register(new LayoutServiceProvider()); - $container['logger'] = new \Psr\Log\NullLogger(); $container['view'] = null; $form = new GenericForm([ @@ -45,6 +43,6 @@ public function setUp() public function testConstructor() { - $this->assertInstanceOf('\Charcoal\Ui\FormGroup\GenericFormGroup', $this->obj); + $this->assertInstanceOf(GenericFormGroup::class, $this->obj); } } diff --git a/tests/Charcoal/Ui/Layout/AbstractLayoutTest.php b/tests/Charcoal/Ui/Layout/AbstractLayoutTest.php index 0b076066..f69446bd 100644 --- a/tests/Charcoal/Ui/Layout/AbstractLayoutTest.php +++ b/tests/Charcoal/Ui/Layout/AbstractLayoutTest.php @@ -2,6 +2,8 @@ namespace Charcoal\Tests\Ui\Layout; +use Charcoal\Ui\Layout\AbstractLayout; + /** * */ @@ -11,7 +13,7 @@ class AbstractLayoutTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->obj = $this->getMockForAbstractClass('\Charcoal\Ui\Layout\AbstractLayout'); + $this->obj = $this->getMockForAbstractClass(AbstractLayout::class); } /** @@ -44,15 +46,15 @@ public function testDefaultPosition() public function testSetData() { $struct = [[ - 'columns'=>[1] + 'columns' => [ 1 ] ]]; $computed = [ - 'columns'=>[1] + 'columns' => [ 1 ] ]; $obj = $this->obj; $ret = $obj->setData([ - 'structure'=>$struct + 'structure' => $struct ]); $this->assertSame($ret, $obj); //$this->assertEquals($computed, $obj->structure()); @@ -65,32 +67,32 @@ public function testSetStructure() $struct = [ [ - 'columns'=>[1,2], + 'columns' => [ 1, 2 ], ], [ - 'columns'=>[1] + 'columns' => [ 1 ] ], [ - 'columns'=>[1,1,1,1], - 'loop'=>3 + 'columns' => [ 1, 1, 1, 1 ], + 'loop' => 3 ] ]; $res = [ [ - 'columns'=>[1,2], + 'columns' => [ 1, 2 ], ], [ - 'columns'=>[1] + 'columns' => [ 1 ] ], [ - 'columns'=>[1,1,1,1] + 'columns' => [ 1, 1, 1, 1 ] ], [ - 'columns'=>[1,1,1,1] + 'columns' => [ 1, 1, 1, 1 ] ], [ - 'columns'=>[1,1,1,1] + 'columns' => [ 1, 1, 1, 1 ] ] ]; @@ -106,9 +108,9 @@ public function testNumRows() $obj = $this->obj; $this->assertEquals(0, $obj->numRows()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[2,1]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 2, 1 ] ] ]); $this->assertEquals(3, $obj->numRows()); } @@ -118,9 +120,9 @@ public function testRowIndex() $obj = $this->obj; $this->assertNull($obj->rowIndex()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[2,1]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 2, 1 ] ] ]); $this->assertEquals(0, $obj->rowIndex(0)); $this->assertEquals(1, $obj->rowIndex(1)); @@ -135,15 +137,15 @@ public function testRowData() $obj = $this->obj; $this->assertNull($obj->rowData()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[2,1]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 2, 1 ] ] ]); - $this->assertEquals(['columns'=>[1]], $obj->rowData(0)); - $this->assertEquals(['columns'=>[1,2]], $obj->rowData(1)); - $this->assertEquals(['columns'=>[1,2]], $obj->rowData(2)); - $this->assertEquals(['columns'=>[2,1]], $obj->rowData(3)); - $this->assertEquals(['columns'=>[2,1]], $obj->rowData(4)); + $this->assertEquals([ 'columns' => [ 1 ] ], $obj->rowData(0)); + $this->assertEquals([ 'columns' => [ 1, 2 ] ], $obj->rowData(1)); + $this->assertEquals([ 'columns' => [ 1, 2 ] ], $obj->rowData(2)); + $this->assertEquals([ 'columns' => [ 2, 1 ] ], $obj->rowData(3)); + $this->assertEquals([ 'columns' => [ 2, 1 ] ], $obj->rowData(4)); $this->assertNull($obj->rowData(5)); } @@ -152,9 +154,9 @@ public function testRowNumColumns() $obj = $this->obj; $this->assertNull($obj->rowNumColumns()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[2,2]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 2, 2 ] ] ]); $this->assertEquals(1, $obj->rowNumColumns(0)); $this->assertEquals(3, $obj->rowNumColumns(1)); @@ -169,9 +171,9 @@ public function testRowNumCells() $obj = $this->obj; $this->assertNull($obj->rowNumCells()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[2,2]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 2, 2 ] ] ]); $this->assertEquals(1, $obj->rowNumCells(0)); $this->assertEquals(2, $obj->rowNumCells(1)); @@ -186,9 +188,9 @@ public function testRowFirstCellIndex() $obj = $this->obj; $this->assertNull($obj->rowFirstCellIndex()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[2,2]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 2, 2 ] ] ]); $this->assertEquals(0, $obj->rowFirstCellIndex(0)); $this->assertEquals(1, $obj->rowFirstCellIndex(1)); @@ -203,9 +205,9 @@ public function testCellRowIndex() $obj = $this->obj; //$this->assertNull($obj->cellRowIndex()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[2,2]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 2, 2 ] ] ]); $this->assertEquals(0, $obj->cellRowIndex(0)); $this->assertEquals(0, $obj->cellRowIndex(1)); @@ -220,9 +222,9 @@ public function testNumCellsTotal() $obj = $this->obj; $this->assertEquals(0, $obj->numCellsTotal()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[2,2]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 2, 2 ] ] ]); $this->assertEquals(5, $obj->numCellsTotal()); } @@ -232,9 +234,9 @@ public function testNumCellSpan() $obj = $this->obj; $this->assertNull($obj->cellSpan()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[2,2]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 2, 2 ] ] ]); $this->assertEquals(1, $obj->cellSpan(0)); $this->assertEquals(1, $obj->cellSpan(1)); @@ -249,9 +251,9 @@ public function testNumCellSpanBy12() $obj = $this->obj; $this->assertNull($obj->cellSpanBy12()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[3,1]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 3, 1 ] ] ]); $this->assertEquals(12, $obj->cellSpanBy12(0)); $this->assertEquals(4, $obj->cellSpanBy12(1)); @@ -266,9 +268,9 @@ public function testCellStartsRow() $obj = $this->obj; //$this->assertNull($obj->cellStartsRow()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[3,1]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 3, 1 ] ] ]); $this->assertEquals(true, $obj->cellStartsRow(0)); $this->assertEquals(true, $obj->cellStartsRow(1)); @@ -283,9 +285,9 @@ public function testCellEndsRow() $obj = $this->obj; //$this->assertNull($obj->cellStartsRow()); $obj->setStructure([ - ['columns'=>[1]], - ['columns'=>[1,2]], - ['columns'=>[3,1]] + [ 'columns' => [ 1 ] ], + [ 'columns' => [ 1, 2 ] ], + [ 'columns' => [ 3, 1 ] ] ]); $this->assertEquals(true, $obj->cellEndsRow(0)); $this->assertEquals(false, $obj->cellEndsRow(1)); diff --git a/tests/Charcoal/Ui/Menu/AbstractMenuTest.php b/tests/Charcoal/Ui/Menu/AbstractMenuTest.php index 2c33fbdc..5a00ef9e 100644 --- a/tests/Charcoal/Ui/Menu/AbstractMenuTest.php +++ b/tests/Charcoal/Ui/Menu/AbstractMenuTest.php @@ -2,30 +2,26 @@ namespace Charcoal\Tests\Ui\Layout; -// PSR-3 logger test dependencies -use \Psr\Log\NullLogger; - -// Pimple test dependencies -use \Pimple\Container; - -use \Charcoal\Ui\ServiceProvider\MenuServiceProvider; +use Charcoal\Ui\Menu\AbstractMenu; +use Charcoal\Ui\ServiceProvider\MenuServiceProvider; class AbstractMenuTest extends \PHPUnit_Framework_TestCase { + use \Charcoal\Tests\Ui\ContainerIntegrationTrait; + public $obj; public function setUp() { - $container = new Container(); + $container = $this->getContainer(); $container->register(new MenuServiceProvider()); - $container['logger'] = new NullLogger(); $container['view'] = null; - $this->obj = $this->getMockForAbstractClass('\Charcoal\Ui\Menu\AbstractMenu', [[ - 'view' => $container['view'], - 'menu_item_builder' => $container['menu/item/builder'] - ]]); + $this->obj = $this->getMockForAbstractClass(AbstractMenu::class, [[ + 'view' => $container['view'], + 'menu_item_builder' => $container['menu/item/builder'] + ]]); } public function testHasItems() @@ -34,7 +30,7 @@ public function testHasItems() $this->assertFalse($obj->hasItems()); $ret = $obj->setItems([ - 'test'=>[] + 'test' => [] ]); $this->assertTrue($obj->hasItems()); @@ -46,8 +42,8 @@ public function testNumItems() $this->assertEquals(0, $obj->numItems()); $ret = $obj->setItems([ - 'test'=>[], - 'foobar'=>[] + 'test' => [], + 'foobar' => [] ]); $this->assertEquals(2, $obj->numItems()); diff --git a/tests/Charcoal/Ui/MenuItem/AbstractMenuItemTest.php b/tests/Charcoal/Ui/MenuItem/AbstractMenuItemTest.php index 53067102..848e610e 100644 --- a/tests/Charcoal/Ui/MenuItem/AbstractMenuItemTest.php +++ b/tests/Charcoal/Ui/MenuItem/AbstractMenuItemTest.php @@ -2,33 +2,29 @@ namespace Charcoal\Tests\Ui\MenuItem; -// PSR-3 logger test dependencies -use \Psr\Log\NullLogger; - -// Pimple test dependencies -use \Pimple\Container; - -use \Charcoal\Ui\ServiceProvider\MenuServiceProvider; +use Charcoal\Ui\MenuItem\AbstractMenuItem; +use Charcoal\Ui\ServiceProvider\MenuServiceProvider; class AbstractMenuItemTest extends \PHPUnit_Framework_TestCase { + use \Charcoal\Tests\Ui\ContainerIntegrationTrait; + public $obj; public function setUp() { - $container = new Container(); + $container = $this->getContainer(); $container->register(new MenuServiceProvider()); - $container['logger'] = new NullLogger(); $container['view'] = null; $menu = $container['menu/builder']->build([]); - $this->obj = $this->getMockForAbstractClass('\Charcoal\Ui\MenuItem\AbstractMenuItem', [[ - 'view' => $container['view'], - 'menu' => $menu, - 'menu_item_builder' => $container['menu/item/builder'] - ]]); + $this->obj = $this->getMockForAbstractClass(AbstractMenuItem::class, [[ + 'view' => $container['view'], + 'menu' => $menu, + 'menu_item_builder' => $container['menu/item/builder'] + ]]); } public function testHasChildren() @@ -37,7 +33,7 @@ public function testHasChildren() $this->assertFalse($obj->hasChildren()); $ret = $obj->setChildren([ - 'test'=>[] + 'test' => [] ]); $this->assertTrue($obj->hasChildren()); @@ -49,8 +45,8 @@ public function testNumChildren() $this->assertEquals(0, $obj->numChildren()); $ret = $obj->setChildren([ - 'test'=>[], - 'foobar'=>[] + 'test' => [], + 'foobar' => [] ]); $this->assertEquals(2, $obj->numChildren()); diff --git a/tests/Charcoal/Ui/ServiceProvider/DashboardServiceProviderTest.php b/tests/Charcoal/Ui/ServiceProvider/DashboardServiceProviderTest.php index 9178b751..65636c78 100644 --- a/tests/Charcoal/Ui/ServiceProvider/DashboardServiceProviderTest.php +++ b/tests/Charcoal/Ui/ServiceProvider/DashboardServiceProviderTest.php @@ -2,10 +2,13 @@ namespace Charcoal\Tests\Ui\ServiceProvider; +// From PSR-3 use \Psr\Log\NullLogger; +// From Pimple use \Pimple\Container; +// From 'charcoal-ui' use \Charcoal\Ui\ServiceProvider\DashboardServiceProvider; /** diff --git a/tests/Charcoal/Ui/ServiceProvider/UiServiceProviderTest.php b/tests/Charcoal/Ui/ServiceProvider/UiServiceProviderTest.php index d54ffc71..9f7be289 100644 --- a/tests/Charcoal/Ui/ServiceProvider/UiServiceProviderTest.php +++ b/tests/Charcoal/Ui/ServiceProvider/UiServiceProviderTest.php @@ -2,8 +2,10 @@ namespace Charcoal\Tests\Ui\ServiceProvider; +// From Pimple use \Pimple\Container; +// From 'charcoal-ui' use \Charcoal\Ui\ServiceProvider\UiServiceProvider; /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 8b781872..bdf19943 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,17 +1,6 @@ add('Charcoal\\', __DIR__.'/src/'); -$autoloader->add('Charcoal\\Tests\\', __DIR__); - -$GLOBALS['translator'] = new Translator([ - 'manager' => new LocalesManager([ - 'locales' => [ - 'foo' => [] - ] - ]) -]); +/** @var \Composer\Autoload\ClassLoader $autoloader */ +$autoloader = require dirname(__DIR__) . '/vendor/autoload.php';