Permalink
Browse files

Add tests for factory for one argument

Add tests for factory for one argument
  • Loading branch information...
1 parent 3da4598 commit dd24e43b29897f0be4bb608c3c3730a668e8fd61 @blanchonvincent blanchonvincent committed Sep 27, 2012
View
1 tests/ZendTest/Paginator/Adapter/DbSelectTest.php
@@ -13,7 +13,6 @@
use Zend\Paginator\Adapter\DbSelect;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Expression;
-use Zend\Db\Adapter\Adapter as DbAdapter;
/**
* @category Zend
View
14 tests/ZendTest/Paginator/AdapterPluginManagerTest.php
@@ -21,17 +21,17 @@
class AdapterPluginManagerTest 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');
@@ -40,13 +40,13 @@ protected function setUp()
$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));
@@ -59,4 +59,4 @@ public function testCanRetrieveAdapterPlugin()
$this->assertInstanceOf('Zend\Paginator\Adapter\Null', $plugin);
}
-}
+}
View
49 tests/ZendTest/Paginator/FactoryTest.php
@@ -24,13 +24,13 @@ class FactoryTest extends \PHPUnit_Framework_TestCase
{
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $mockSelect;
-
+
protected $mockAdapter;
-
+
protected function setUp()
{
$this->mockSelect = $this->getMock('Zend\Db\Sql\Select');
-
+
$mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
$mockResult = $this->getMock('Zend\Db\Adapter\Driver\ResultInterface');
@@ -39,38 +39,69 @@ protected function setUp()
$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 testCanFactoryPaginatorWithStringAdapterObject()
{
$datas = array(1, 2, 3);
$paginator = Paginator\Factory::factory($datas, new Adapter\ArrayAdapter($datas));
$this->assertInstanceOf('Zend\Paginator\Adapter\ArrayAdapter', $paginator->getAdapter());
$this->assertEquals(count($datas), $paginator->getCurrentItemCount());
}
-
+
public function testCanFactoryPaginatorWithStringAdapterName()
{
$datas = array(1, 2, 3);
$paginator = Paginator\Factory::factory($datas, 'array');
$this->assertInstanceOf('Zend\Paginator\Adapter\ArrayAdapter', $paginator->getAdapter());
$this->assertEquals(count($datas), $paginator->getCurrentItemCount());
}
-
+
public function testCanFactoryPaginatorWithStringAdapterAggregate()
{
$paginator = Paginator\Factory::factory(null, new TestArrayAggregate);
$this->assertInstanceOf('Zend\Paginator\Adapter\ArrayAdapter', $paginator->getAdapter());
}
-
+
public function testCanFactoryPaginatorWithDbSelect()
{
$paginator = Paginator\Factory::factory(array($this->mockSelect, $this->mockAdapter), 'dbselect');
$this->assertInstanceOf('Zend\Paginator\Adapter\DbSelect', $paginator->getAdapter());
}
-}
+
+ public function testCanFactoryPaginatorWithOneParameterWithArrayAdapter()
+ {
+ $datas = array(
+ 'items' => array(1, 2, 3),
+ 'adapter' => 'array',
+ );
+ $paginator = Paginator\Factory::factory($datas);
+ $this->assertInstanceOf('Zend\Paginator\Adapter\ArrayAdapter', $paginator->getAdapter());
+ $this->assertEquals(count($datas['items']), $paginator->getCurrentItemCount());
+ }
+
+ public function testCanFactoryPaginatorWithOneParameterWithDbAdapter()
+ {
+ $datas = array(
+ 'items' => array($this->mockSelect, $this->mockAdapter),
+ 'adapter' => 'dbselect',
+ );
+ $paginator = Paginator\Factory::factory($datas);
+ $this->assertInstanceOf('Zend\Paginator\Adapter\DbSelect', $paginator->getAdapter());
+ }
+
+ public function testCanFactoryPaginatorWithOneBadParameter()
+ {
+ $datas = array(
+ array(1, 2, 3),
+ 'array',
+ );
+ $this->setExpectedException('Zend\Paginator\Exception\InvalidArgumentException');
+ $paginator = Paginator\Factory::factory($datas);
+ }
+}
View
2 tests/ZendTest/Paginator/PaginatorTest.php
@@ -13,7 +13,6 @@
use ReflectionMethod;
use stdClass;
use Zend\Cache\StorageFactory as CacheFactory;
-use Zend\Cache\Storage\Adapter\AdapterInterface as CacheAdapter;
use Zend\Config;
use Zend\Db\Adapter as DbAdapter;
use Zend\Db\Sql;
@@ -83,6 +82,7 @@ protected function _getTmpDir()
mkdir($tmpDir);
}
$this->cacheDir = $tmpDir;
+
return $tmpDir;
}

0 comments on commit dd24e43

Please sign in to comment.