Skip to content
Browse files

Add adapter plugin manager tests

Add adapter plugin manager tests
  • Loading branch information...
1 parent f8d6046 commit 76ee4e74a96e7d1d92d6f055dc9f86d27306893e @blanchonvincent blanchonvincent committed Sep 8, 2012
View
31 library/Zend/Paginator/AdapterPluginManager.php
@@ -35,6 +35,37 @@ class AdapterPluginManager extends AbstractPluginManager
'iterator' => 'Zend\Paginator\Adapter\Iterator',
'null' => 'Zend\Paginator\Adapter\Null',
);
+
+ /**
+ * Attempt to create an instance via an invokable class
+ *
+ * Overrides parent implementation by passing $creationOptions to the
+ * constructor, if non-null.
+ *
+ * @param string $canonicalName
+ * @param string $requestedName
+ * @return null|\stdClass
+ * @throws Exception\ServiceNotCreatedException If resolved class does not exist
+ */
+ protected function createFromInvokable($canonicalName, $requestedName)
+ {
+ $invokable = $this->invokableClasses[$canonicalName];
+
+ if (null === $this->creationOptions
+ || (is_array($this->creationOptions) && empty($this->creationOptions))
+ ) {
+ $instance = new $invokable();
+ } else {
+ if($canonicalName == "dbselect" && is_array($this->creationOptions)) {
+ $class = new \ReflectionClass($invokable);
+ $instance = $class->newInstanceArgs($this->creationOptions);
+ } else {
+ $instance = new $invokable($this->creationOptions);
+ }
+ }
+
+ return $instance;
+ }
/**
* Validate the plugin
View
62 tests/ZendTest/Paginator/AdapterPluginManagerTest.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Paginator
+ */
+
+namespace ZendTest\Paginator;
+
+use Zend\Paginator\AdapterPluginManager;
+
+/**
+ * @category Zend
+ * @package Zend_Paginator
+ * @subpackage UnitTests
+ * @group Zend_Paginator
+ */
+class FactoryTest extends \PHPUnit_Framework_TestCase
+{
+ protected $adapaterPluginManager;
+
+ /** @var \PHPUnit_Framework_MockObject_MockObject */
+ protected $mockSelect;
+
+ protected $mockAdapter;
+
+ protected function setUp()
+ {
+ $this->adapaterPluginManager = new AdapterPluginManager();
+ $this->mockSelect = $this->getMock('Zend\Db\Sql\Select');
+
+ $mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
+ $mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
+
+ $mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
+ $mockDriver->expects($this->any())->method('createStatement')->will($this->returnValue($mockStatement));
+ $mockStatement->expects($this->any())->method('execute')->will($this->returnValue($mockResult));
+ $mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
+ $mockPlatform->expects($this->any())->method('getName')->will($this->returnValue('platform'));
+
+ $this->mockAdapter = $this->getMockForAbstractClass(
+ 'Zend\Db\Adapter\Adapter',
+ array($mockDriver, $mockPlatform)
+ );
+ }
+
+ public function testCanRetrieveAdapterPlugin()
+ {
+ $plugin = $this->adapaterPluginManager->get('array', array(1, 2, 3));
+ $this->assertInstanceOf('Zend\Paginator\Adapter\ArrayAdapter', $plugin);
+ $plugin = $this->adapaterPluginManager->get('iterator', new \ArrayIterator(range(1, 101)));
+ $this->assertInstanceOf('Zend\Paginator\Adapter\Iterator', $plugin);
+ $plugin = $this->adapaterPluginManager->get('dbselect', array($this->mockSelect, $this->mockAdapter));
+ $this->assertInstanceOf('Zend\Paginator\Adapter\DbSelect', $plugin);
+ $plugin = $this->adapaterPluginManager->get('null', 101);
+ $this->assertInstanceOf('Zend\Paginator\Adapter\Null', $plugin);
+ }
+
+}
View
27 tests/ZendTest/Paginator/FactoryTest.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Paginator
+ */
+
+namespace ZendTest\Paginator;
+
+use Zend\Paginator\Factory;
+
+/**
+ * @category Zend
+ * @package Zend_Paginator
+ * @subpackage UnitTests
+ * @group Zend_Paginator
+ */
+class FactoryTest extends \PHPUnit_Framework_TestCase
+{
+ public function testCanFactoryPaginatorWithStringAdapterName()
+ {
+
+ }
+}

0 comments on commit 76ee4e7

Please sign in to comment.
Something went wrong with that request. Please try again.