diff --git a/.travis.yml b/.travis.yml
index 9749e69e..bd191039 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,6 +8,10 @@ php:
- 5.6
- 7
- hhvm
+ - nightly
+
+allow_failures:
+ - php: nightly
env:
matrix:
diff --git a/composer.json b/composer.json
index 3f6dfe52..425c6804 100644
--- a/composer.json
+++ b/composer.json
@@ -26,23 +26,21 @@
"require": {
"php": "~5.5|~7.0",
- "zendframework/zend-mvc": "~2.7",
+ "zendframework/zend-mvc": "~2.7|~3.0",
"zendframework/zend-modulemanager": "~2.5",
"zendframework/zend-session": "~2.5",
"zendframework/zend-view": "~2.5",
"zendframework/zend-http": "~2.5",
"zendframework/zend-paginator": "~2.5",
"zendframework/zend-cache": "~2.5",
- "zendframework/zend-servicemanager": "~2.7"
+ "zendframework/zend-servicemanager": "~2.7|~3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.2",
- "fabpot/php-cs-fixer": "^1.11",
-
- "doctrine/orm": ">=2.5,<2.7",
- "doctrine/dbal": ">=2.5,<2.7",
- "doctrine/doctrine-orm-module": "^0.9",
+ "friendsofphp/php-cs-fixer": "^1.11",
+ "doctrine/doctrine-orm-module": "dev-master as 1.2",
+ "doctrine/doctrine-module": "dev-master",
"zendframework/zend-console": "~2.5",
"zendframework/zend-db": "~2.5",
@@ -53,10 +51,7 @@
"suggest" : {
"ext-intl": "*",
-
- "doctrine/orm": ">=2.5,<2.7",
- "doctrine/dbal": ">=2.5,<2.7",
- "doctrine/doctrine-orm-module": "^0.9",
+ "doctrine/doctrine-orm-module": "for doctrine support",
"phpoffice/phpexcel": "^1.8",
"tecnickcom/tcpdf": "^6.2",
@@ -64,10 +59,14 @@
"zendframework/zend-text": "~2.5",
"zendframework/zend-json": "to support date ranges"
},
-
+
"autoload": {
"psr-0": {
- "ZfcDatagrid\\": "src/",
+ "ZfcDatagrid\\": "src/"
+ }
+ },
+ "autoload-dev": {
+ "psr-0": {
"ZfcDatagridTest\\": "tests/"
}
}
diff --git a/src/ZfcDatagrid/Column/Action/Button.php b/src/ZfcDatagrid/Column/Action/Button.php
index 7f8dbcdb..b8b50fd1 100644
--- a/src/ZfcDatagrid/Column/Action/Button.php
+++ b/src/ZfcDatagrid/Column/Action/Button.php
@@ -34,8 +34,8 @@ public function getLabel()
}
/**
- *
* @return string
+ * @throws \Exception
*/
protected function getHtmlType()
{
diff --git a/src/ZfcDatagrid/Column/Style/Color.php b/src/ZfcDatagrid/Column/Style/Color.php
index 9a823752..76802484 100644
--- a/src/ZfcDatagrid/Column/Style/Color.php
+++ b/src/ZfcDatagrid/Column/Style/Color.php
@@ -4,7 +4,6 @@
* general or based on a value
*
*/
-
namespace ZfcDatagrid\Column\Style;
class Color extends AbstractColor
diff --git a/src/ZfcDatagrid/Column/Type/Image.php b/src/ZfcDatagrid/Column/Type/Image.php
index 24b883a4..eb27a1ac 100644
--- a/src/ZfcDatagrid/Column/Type/Image.php
+++ b/src/ZfcDatagrid/Column/Type/Image.php
@@ -2,7 +2,6 @@
/**
* Image type
*/
-
namespace ZfcDatagrid\Column\Type;
use InvalidArgumentException;
diff --git a/src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php b/src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php
index 50fb3337..c8e57035 100644
--- a/src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php
+++ b/src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php
@@ -4,7 +4,6 @@
* or if we use the "safe" variant by Doctrine2
*
*/
-
namespace ZfcDatagrid\DataSource\Doctrine2;
use Doctrine\ORM\QueryBuilder;
diff --git a/src/ZfcDatagrid/Datagrid.php b/src/ZfcDatagrid/Datagrid.php
index 6976bef6..313fc85a 100644
--- a/src/ZfcDatagrid/Datagrid.php
+++ b/src/ZfcDatagrid/Datagrid.php
@@ -4,6 +4,7 @@
use ArrayIterator;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\QueryBuilder;
+use Interop\Container\ContainerInterface;
use Zend\Cache;
use Zend\Console\Request as ConsoleRequest;
use Zend\Db\Sql\Select as ZendSelect;
@@ -11,7 +12,7 @@
use Zend\I18n\Translator\Translator;
use Zend\Mvc\MvcEvent;
use Zend\Paginator\Paginator;
-use Zend\ServiceManager\ServiceLocatorAwareTrait;
+use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Session\Container as SessionContainer;
use Zend\Stdlib\ResponseInterface;
use Zend\View\Model\JsonModel;
@@ -20,8 +21,6 @@
class Datagrid
{
- use ServiceLocatorAwareTrait;
-
/**
*
* @var array
@@ -221,6 +220,11 @@ class Datagrid
'sortDefault',
];
+ /**
+ * @var ServiceLocatorInterface
+ */
+ protected $serviceLocator = null;
+
/**
* Init method is called automatically with the service creation
*/
@@ -1196,4 +1200,27 @@ public function setRendererService(Renderer\AbstractRenderer $rendererService)
return $this;
}
+
+ /**
+ * Set service locator
+ *
+ * @param ContainerInterface $serviceLocator
+ * @return mixed
+ */
+ public function setServiceLocator(ContainerInterface $serviceLocator)
+ {
+ $this->serviceLocator = $serviceLocator;
+
+ return $this;
+ }
+
+ /**
+ * Get service locator
+ *
+ * @return ContainerInterface
+ */
+ public function getServiceLocator()
+ {
+ return $this->serviceLocator;
+ }
}
diff --git a/src/ZfcDatagrid/PrepareData.php b/src/ZfcDatagrid/PrepareData.php
index 901ac69f..9401dfc6 100644
--- a/src/ZfcDatagrid/PrepareData.php
+++ b/src/ZfcDatagrid/PrepareData.php
@@ -221,7 +221,9 @@ public function prepare()
*/
if (is_array($row[$col->getUniqueId()])) {
array_walk_recursive($row[$col->getUniqueId()], function (&$value) {
- $value = trim($value);
+ if (!is_object($value)) {
+ $value = trim($value);
+ }
});
} elseif (!is_object($row[$col->getUniqueId()])) {
$row[$col->getUniqueId()] = trim($row[$col->getUniqueId()]);
diff --git a/src/ZfcDatagrid/Renderer/AbstractExport.php b/src/ZfcDatagrid/Renderer/AbstractExport.php
index 3f18298d..7d5f03ae 100644
--- a/src/ZfcDatagrid/Renderer/AbstractExport.php
+++ b/src/ZfcDatagrid/Renderer/AbstractExport.php
@@ -3,7 +3,6 @@
* Methods which can be used in (all) export renderer
*
*/
-
namespace ZfcDatagrid\Renderer;
use ZfcDatagrid\Column;
diff --git a/src/ZfcDatagrid/Renderer/BootstrapTable/View/Helper/TableRowFactory.php b/src/ZfcDatagrid/Renderer/BootstrapTable/View/Helper/TableRowFactory.php
index a086538e..7f1ea5cc 100644
--- a/src/ZfcDatagrid/Renderer/BootstrapTable/View/Helper/TableRowFactory.php
+++ b/src/ZfcDatagrid/Renderer/BootstrapTable/View/Helper/TableRowFactory.php
@@ -1,6 +1,7 @@
getServiceLocator()->has('translator')) {
- /** @noinspection PhpParamsInspection */
- $tableRow->setTranslator($serviceLocator->getServiceLocator()->get('translator'));
+ if ($container->has('translator')) {
+ $tableRow->setTranslator($container->get('translator'));
}
return $tableRow;
}
+
+ /**
+ * @param ServiceLocatorInterface|AbstractPluginManager $serviceLocator
+ * @return TableRow
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ return $this($serviceLocator->getServiceLocator(), TableRow::class);
+ }
}
diff --git a/src/ZfcDatagrid/Renderer/Csv/Renderer.php b/src/ZfcDatagrid/Renderer/Csv/Renderer.php
index 5efaff50..238a6ed5 100644
--- a/src/ZfcDatagrid/Renderer/Csv/Renderer.php
+++ b/src/ZfcDatagrid/Renderer/Csv/Renderer.php
@@ -3,7 +3,6 @@
* Render datagrid as CSV
*
*/
-
namespace ZfcDatagrid\Renderer\Csv;
use Zend\Http\Headers;
diff --git a/src/ZfcDatagrid/Renderer/JqGrid/View/Helper/ColumnsFactory.php b/src/ZfcDatagrid/Renderer/JqGrid/View/Helper/ColumnsFactory.php
index c5ca7242..f2517008 100644
--- a/src/ZfcDatagrid/Renderer/JqGrid/View/Helper/ColumnsFactory.php
+++ b/src/ZfcDatagrid/Renderer/JqGrid/View/Helper/ColumnsFactory.php
@@ -1,6 +1,7 @@
getServiceLocator()->has('translator')) {
- /** @noinspection PhpParamsInspection */
- $tableRow->setTranslator($serviceLocator->getServiceLocator()->get('translator'));
+ if ($container->has('translator')) {
+ $tableRow->setTranslator($container->get('translator'));
}
return $tableRow;
}
+
+ /**
+ * @param ServiceLocatorInterface|AbstractPluginManager $serviceLocator
+ * @return Columns
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ return $this($serviceLocator->getServiceLocator(), Columns::class);
+ }
}
diff --git a/src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php b/src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php
index eba68770..d5c46b40 100644
--- a/src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php
+++ b/src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php
@@ -2,7 +2,6 @@
/**
* Output as an excel file
*/
-
namespace ZfcDatagrid\Renderer\PHPExcel;
use PHPExcel;
diff --git a/src/ZfcDatagrid/Renderer/TCPDF/Renderer.php b/src/ZfcDatagrid/Renderer/TCPDF/Renderer.php
index 2fba8eeb..3ab5285a 100644
--- a/src/ZfcDatagrid/Renderer/TCPDF/Renderer.php
+++ b/src/ZfcDatagrid/Renderer/TCPDF/Renderer.php
@@ -2,7 +2,6 @@
/**
* Output as a PDF file
*/
-
namespace ZfcDatagrid\Renderer\TCPDF;
use TCPDF;
@@ -314,10 +313,10 @@ protected function printTableRow(array $row, $rowHeight)
if ($file !== false) {
list($width, $height) = $this->calcImageSize($file, $col->getWidth() - 2, $rowHeight - 2);
- $pdf->Image('@' . $file, $x + 1, $y + 1, $width, $height, '', '', 'L', false);
+ $pdf->Image('@' . $file, $x + 1, $y + 1, $width, $height, '', '', 'L', true);
}
} else {
- $pdf->Image($link, $x + 1, $y + 1, 0, $resizeHeight, '', '', 'L', false);
+ $pdf->Image($link, $x + 1, $y + 1, 0, $resizeHeight, '', '', 'L', true);
}
} catch (\Exception $e) {
// if tcpdf couldnt find a image, continue and log it
diff --git a/src/ZfcDatagrid/Service/AbstractDatagrid.php b/src/ZfcDatagrid/Service/AbstractDatagrid.php
index c807d12a..cbe34558 100644
--- a/src/ZfcDatagrid/Service/AbstractDatagrid.php
+++ b/src/ZfcDatagrid/Service/AbstractDatagrid.php
@@ -1,6 +1,7 @@
setServiceLocator($sm);
- $config = $sm->get('config');
+ $this->setServiceLocator($container);
+ $config = $container->get('config');
if (! isset($config['ZfcDatagrid'])) {
throw new InvalidArgumentException('Config key "ZfcDatagrid" is missing');
}
/* @var $application \Zend\Mvc\Application */
- $application = $sm->get('application');
+ $application = $container->get('application');
parent::setOptions($config['ZfcDatagrid']);
parent::setMvcEvent($application->getMvcEvent());
- if ($sm->has('translator') === true) {
- parent::setTranslator($sm->get('translator'));
+
+ if ($container->has('translator') === true) {
+ parent::setTranslator($container->get('translator'));
}
- /** @noinspection PhpParamsInspection */
- parent::setRendererService($sm->get('zfcDatagrid.renderer.' . parent::getRendererName()));
+
+ parent::setRendererService($container->get('zfcDatagrid.renderer.' . parent::getRendererName()));
parent::init();
return $this;
}
+ /**
+ * @param ServiceLocatorInterface $serviceLocator
+ * @return Datagrid
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ return $this($serviceLocator, Datagrid::class);
+ }
+
/**
* Call initGrid on rendering
*/
diff --git a/src/ZfcDatagrid/Service/DatagridFactory.php b/src/ZfcDatagrid/Service/DatagridFactory.php
index 56fa6f03..bb44c04c 100644
--- a/src/ZfcDatagrid/Service/DatagridFactory.php
+++ b/src/ZfcDatagrid/Service/DatagridFactory.php
@@ -2,6 +2,7 @@
namespace ZfcDatagrid\Service;
use Doctrine\Common\Proxy\Exception\InvalidArgumentException;
+use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcDatagrid\Datagrid;
@@ -9,32 +10,44 @@
class DatagridFactory implements FactoryInterface
{
/**
- *
- * @param ServiceLocatorInterface $sm
+ * @param ContainerInterface $container
+ * @param string $requestedName
+ * @param array|null $options
* @return Datagrid
*/
- public function createService(ServiceLocatorInterface $sm)
+ public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
- $config = $sm->get('config');
+ $config = $container->get('config');
if (!isset($config['ZfcDatagrid'])) {
throw new InvalidArgumentException('Config key "ZfcDatagrid" is missing');
}
/* @var $application \Zend\Mvc\Application */
- $application = $sm->get('application');
+ $application = $container->get('application');
$grid = new Datagrid();
- $grid->setServiceLocator($sm);
+ $grid->setServiceLocator($container);
$grid->setOptions($config['ZfcDatagrid']);
$grid->setMvcEvent($application->getMvcEvent());
- if ($sm->has('translator') === true) {
- $grid->setTranslator($sm->get('translator'));
+
+ if ($container->has('translator') === true) {
+ $grid->setTranslator($container->get('translator'));
}
- /** @noinspection PhpParamsInspection */
- $grid->setRendererService($sm->get('zfcDatagrid.renderer.' . $grid->getRendererName()));
+
+ $grid->setRendererService($container->get('zfcDatagrid.renderer.' . $grid->getRendererName()));
$grid->init();
return $grid;
}
+
+ /**
+ *
+ * @param ServiceLocatorInterface $serviceLocator
+ * @return Datagrid
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ return $this($serviceLocator, Datagrid::class);
+ }
}
diff --git a/src/ZfcDatagrid/Service/ZendDbAdapterFactory.php b/src/ZfcDatagrid/Service/ZendDbAdapterFactory.php
index c26880cf..88a31ef6 100644
--- a/src/ZfcDatagrid/Service/ZendDbAdapterFactory.php
+++ b/src/ZfcDatagrid/Service/ZendDbAdapterFactory.php
@@ -1,6 +1,7 @@
get('config');
+ $config = $container->get('config');
return new Adapter($config['zfcDatagrid_dbAdapter']);
}
+
+ /**
+ * @param ServiceLocatorInterface $serviceLocator
+ * @return Adapter
+ */
+ public function createService(ServiceLocatorInterface $serviceLocator)
+ {
+ return $this($serviceLocator, Adapter::class);
+ }
}
diff --git a/tests/ZfcDatagridTest/Column/Action/AbstractActionTest.php b/tests/ZfcDatagridTest/Column/Action/AbstractActionTest.php
index 04ccce0d..03dab540 100644
--- a/tests/ZfcDatagridTest/Column/Action/AbstractActionTest.php
+++ b/tests/ZfcDatagridTest/Column/Action/AbstractActionTest.php
@@ -206,21 +206,25 @@ public function testIsDisplayedAndOperatorNoDisplay()
]));
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testSetShowOnValueOperatorException()
{
/* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
$action = $this->getMockForAbstractClass('ZfcDatagrid\Column\Action\AbstractAction');
- $this->setExpectedException('InvalidArgumentException');
$action->setShowOnValueOperator('XOR');
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testIsDisplayedException()
{
/* @var $action \ZfcDatagrid\Column\Action\AbstractAction */
$action = $this->getMockForAbstractClass('ZfcDatagrid\Column\Action\AbstractAction');
- $this->setExpectedException('InvalidArgumentException');
$action->addShowOnValue($this->column, '23', 'UNknownFilter');
$action->isDisplayed([
$this->column->getUniqueId() => '32',
diff --git a/tests/ZfcDatagridTest/Column/Action/ButtonTest.php b/tests/ZfcDatagridTest/Column/Action/ButtonTest.php
index 0929b2e0..4b3592f2 100644
--- a/tests/ZfcDatagridTest/Column/Action/ButtonTest.php
+++ b/tests/ZfcDatagridTest/Column/Action/ButtonTest.php
@@ -45,11 +45,13 @@ public function testColumnLabelAndToHtml()
$this->assertEquals($html, $button->toHtml(['myCol' => 'Blubb']));
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testHtmlException()
{
$button = new Button();
- $this->setExpectedException('InvalidArgumentException');
$button->toHtml([]);
}
}
diff --git a/tests/ZfcDatagridTest/Column/Action/IconTest.php b/tests/ZfcDatagridTest/Column/Action/IconTest.php
index a08d8822..0ec9373b 100644
--- a/tests/ZfcDatagridTest/Column/Action/IconTest.php
+++ b/tests/ZfcDatagridTest/Column/Action/IconTest.php
@@ -45,12 +45,13 @@ public function testIconLink()
$this->assertEquals('', $icon->toHtml([]));
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testException()
{
$icon = new Icon();
- $this->setExpectedException('InvalidArgumentException');
-
$icon->toHtml([]);
}
}
diff --git a/tests/ZfcDatagridTest/Column/ActionTest.php b/tests/ZfcDatagridTest/Column/ActionTest.php
index 5667b376..6d50707c 100644
--- a/tests/ZfcDatagridTest/Column/ActionTest.php
+++ b/tests/ZfcDatagridTest/Column/ActionTest.php
@@ -27,14 +27,14 @@ public function testAddRemoveAction()
$this->assertCount(0, $column->getActions());
- $action = $this->getMock('ZfcDatagrid\Column\Action\Button');
+ $action = $this->getMockBuilder('ZfcDatagrid\Column\Action\Button')->getMock();
$column->addAction($action);
$this->assertCount(1, $column->getActions());
- $action2 = $this->getMock('ZfcDatagrid\Column\Action\Button');
+ $action2 = $this->getMockBuilder('ZfcDatagrid\Column\Action\Button')->getMock();
$column->addAction($action2);
- $action3 = $this->getMock('ZfcDatagrid\Column\Action\Button');
+ $action3 = $this->getMockBuilder('ZfcDatagrid\Column\Action\Button')->getMock();
$column->addAction($action3);
$this->assertCount(3, $column->getActions());
@@ -43,8 +43,8 @@ public function testAddRemoveAction()
$this->assertCount(2, $column->getActions());
$actions = [
- $this->getMock('ZfcDatagrid\Column\Action\Button'),
- $this->getMock('ZfcDatagrid\Column\Action\Button'),
+ $this->getMockBuilder('ZfcDatagrid\Column\Action\Button')->getMock(),
+ $this->getMockBuilder('ZfcDatagrid\Column\Action\Button')->getMock(),
];
$column->setActions($actions);
$this->assertEquals($actions, $column->getActions());
diff --git a/tests/ZfcDatagridTest/Column/DataPopulation/Object/GravatarTest.php b/tests/ZfcDatagridTest/Column/DataPopulation/Object/GravatarTest.php
index cfe5eb1d..fc3380b6 100644
--- a/tests/ZfcDatagridTest/Column/DataPopulation/Object/GravatarTest.php
+++ b/tests/ZfcDatagridTest/Column/DataPopulation/Object/GravatarTest.php
@@ -22,11 +22,13 @@ public function testAll()
$this->assertEquals('http://www.gravatar.com/avatar/' . md5('martin.keckeis1@gmail.com'), $gravatar->toString());
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testException()
{
$gravatar = new Gravatar();
- $this->setExpectedException('InvalidArgumentException');
$gravatar->setParameterFromColumn('invalidPara', 'someValue');
}
}
diff --git a/tests/ZfcDatagridTest/Column/DataPopulation/ObjectTest.php b/tests/ZfcDatagridTest/Column/DataPopulation/ObjectTest.php
index 21a36bff..8f643835 100644
--- a/tests/ZfcDatagridTest/Column/DataPopulation/ObjectTest.php
+++ b/tests/ZfcDatagridTest/Column/DataPopulation/ObjectTest.php
@@ -12,7 +12,7 @@ class ObjectTest extends PHPUnit_Framework_TestCase
{
public function testObject()
{
- $mock = $this->getMock('ZfcDatagrid\Column\DataPopulation\Object\Gravatar');
+ $mock = $this->getMockBuilder('ZfcDatagrid\Column\DataPopulation\Object\Gravatar')->getMock();
$mock->expects($this->any())
->method('toString')
->will($this->returnValue('myReturn'));
@@ -28,7 +28,7 @@ public function testObject()
public function testParameters()
{
$column = $this->getMockForAbstractClass('ZfcDatagrid\Column\AbstractColumn');
- $mock = $this->getMock('ZfcDatagrid\Column\DataPopulation\Object\Gravatar');
+ $mock = $this->getMockBuilder('ZfcDatagrid\Column\DataPopulation\Object\Gravatar')->getMock();
$mock->expects($this->any())
->method('toString')
->will($this->returnValue('myReturn'));
diff --git a/tests/ZfcDatagridTest/Column/ExternalDataTest.php b/tests/ZfcDatagridTest/Column/ExternalDataTest.php
index ff29fceb..57b6cd49 100644
--- a/tests/ZfcDatagridTest/Column/ExternalDataTest.php
+++ b/tests/ZfcDatagridTest/Column/ExternalDataTest.php
@@ -21,12 +21,13 @@ public function testConstruct()
$this->assertFalse($col->isUserSortEnabled());
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testGetDataPopulationException()
{
$col = new Column\ExternalData('myData');
- $this->setExpectedException('InvalidArgumentException');
-
$col->getDataPopulation();
}
@@ -44,12 +45,14 @@ public function testSetGetData()
$this->assertInstanceOf('ZfcDatagrid\Column\DataPopulation\Object', $col->getDataPopulation());
}
+ /**
+ * @expectedException \Exception
+ */
public function testException()
{
$col = new Column\ExternalData('myData');
$object = new DataPopulation\Object();
- $this->setExpectedException('Exception');
$col->setDataPopulation($object);
}
}
diff --git a/tests/ZfcDatagridTest/Column/SelectTest.php b/tests/ZfcDatagridTest/Column/SelectTest.php
index 0e786b4e..c1d8df19 100644
--- a/tests/ZfcDatagridTest/Column/SelectTest.php
+++ b/tests/ZfcDatagridTest/Column/SelectTest.php
@@ -45,18 +45,20 @@ public function testObject()
$this->assertEquals('myAlias', $col->getUniqueId());
}
+ /**
+ * @expectedException \Exception
+ */
public function testException()
{
- $this->setExpectedException('Exception');
-
$expr = new \Zend\Db\Sql\Expression('Something...');
$col = new Column\Select($expr);
}
+ /**
+ * @expectedException \Exception
+ */
public function testExceptionNotString()
{
- $this->setExpectedException('Exception');
-
$expr = new \Zend\Db\Sql\Expression('Something...');
$col = new Column\Select($expr, new \stdClass());
}
diff --git a/tests/ZfcDatagridTest/Column/Style/AbstractStyleTest.php b/tests/ZfcDatagridTest/Column/Style/AbstractStyleTest.php
index 18b57106..eea9a4a1 100644
--- a/tests/ZfcDatagridTest/Column/Style/AbstractStyleTest.php
+++ b/tests/ZfcDatagridTest/Column/Style/AbstractStyleTest.php
@@ -158,12 +158,14 @@ public function testIsApplyAndOperatorNoDisplay()
]));
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testSetByValueOperatorException()
{
/* @var $style \ZfcDatagrid\Column\Style\AbstractStyle */
$style = $this->getMockForAbstractClass('ZfcDatagrid\Column\Style\AbstractStyle');
- $this->setExpectedException('InvalidArgumentException');
$style->setByValueOperator('XOR');
}
diff --git a/tests/ZfcDatagridTest/DataSource/AbstractDataSourceTest.php b/tests/ZfcDatagridTest/DataSource/AbstractDataSourceTest.php
index a066711e..91c3dde7 100644
--- a/tests/ZfcDatagridTest/DataSource/AbstractDataSourceTest.php
+++ b/tests/ZfcDatagridTest/DataSource/AbstractDataSourceTest.php
@@ -87,7 +87,8 @@ public function testFilter()
{
$ds = clone $this->dsMock;
- $filter = $this->getMock('ZfcDatagrid\Filter');
+ $filter = $this->getMockBuilder('ZfcDatagrid\Filter')
+ ->getMock();
$ds->addFilter($filter);
$this->assertEquals([
@@ -99,7 +100,8 @@ public function testPaginatorAdapter()
{
$ds = clone $this->dsMock;
- $adapter = $this->getMock('Zend\Paginator\Adapter\ArrayAdapter');
+ $adapter = $this->getMockBuilder('Zend\Paginator\Adapter\ArrayAdapter')
+ ->getMock();
$ds->setPaginatorAdapter($adapter);
$this->assertInstanceOf('Zend\Paginator\Adapter\AdapterInterface', $ds->getPaginatorAdapter());
diff --git a/tests/ZfcDatagridTest/DataSource/Doctrine2/FilterTest.php b/tests/ZfcDatagridTest/DataSource/Doctrine2/FilterTest.php
index 1707de32..c749408f 100644
--- a/tests/ZfcDatagridTest/DataSource/Doctrine2/FilterTest.php
+++ b/tests/ZfcDatagridTest/DataSource/Doctrine2/FilterTest.php
@@ -314,9 +314,13 @@ public function testBetween()
$this->assertEquals('789', $parameters[1]->getValue());
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testException()
{
- $filter = $this->getMock('ZfcDatagrid\Filter');
+ $filter = $this->getMockBuilder('ZfcDatagrid\Filter')
+ ->getMock();
$filter->expects($this->any())
->method('getColumn')
->will($this->returnValue($this->colVolumne));
@@ -329,7 +333,6 @@ public function testException()
->method('getOperator')
->will($this->returnValue(' () '));
- $this->setExpectedException('InvalidArgumentException');
$filterDoctrine2 = clone $this->filterDoctrine2;
$filterDoctrine2->applyFilter($filter);
}
diff --git a/tests/ZfcDatagridTest/DataSource/Doctrine2/Mocks/EntityManagerMock.php b/tests/ZfcDatagridTest/DataSource/Doctrine2/Mocks/EntityManagerMock.php
index f0108c8b..deecde20 100644
--- a/tests/ZfcDatagridTest/DataSource/Doctrine2/Mocks/EntityManagerMock.php
+++ b/tests/ZfcDatagridTest/DataSource/Doctrine2/Mocks/EntityManagerMock.php
@@ -18,7 +18,6 @@
* and is licensed under the LGPL. For more information, see
* .
*/
-
namespace ZfcDatagridTest\DataSource\Doctrine2\Mocks;
/**
diff --git a/tests/ZfcDatagridTest/DataSource/Doctrine2CollectionTest.php b/tests/ZfcDatagridTest/DataSource/Doctrine2CollectionTest.php
index c5e67ee7..07212afb 100644
--- a/tests/ZfcDatagridTest/DataSource/Doctrine2CollectionTest.php
+++ b/tests/ZfcDatagridTest/DataSource/Doctrine2CollectionTest.php
@@ -40,15 +40,21 @@ public function setUp()
$this->source = $source;
}
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage Unknown data input: "instanceof stdClass"
+ */
public function testConstructException()
{
- $this->setExpectedException('InvalidArgumentException', 'Unknown data input: "instanceof stdClass"');
$source = new Doctrine2Collection(new \stdClass());
}
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage Unknown data input: ""
+ */
public function testConstructExceptionClass()
{
- $this->setExpectedException('InvalidArgumentException', 'Unknown data input: ""');
$source = new Doctrine2Collection(null);
}
@@ -61,7 +67,9 @@ public function testGetData()
public function testEntityManager()
{
- $em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
+ $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
+ ->disableOriginalConstructor()
+ ->getMock();
$source = clone $this->source;
$this->assertNull($source->getEntityManager());
diff --git a/tests/ZfcDatagridTest/DataSource/Doctrine2Test.php b/tests/ZfcDatagridTest/DataSource/Doctrine2Test.php
index 436d2e4a..8737ebe2 100644
--- a/tests/ZfcDatagridTest/DataSource/Doctrine2Test.php
+++ b/tests/ZfcDatagridTest/DataSource/Doctrine2Test.php
@@ -33,6 +33,9 @@ public function setUp()
]);
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testConstruct()
{
$source = clone $this->source;
@@ -40,7 +43,6 @@ public function testConstruct()
$this->assertInstanceOf('Doctrine\ORM\QueryBuilder', $source->getData());
$this->assertSame($this->qb, $source->getData());
- $this->setExpectedException('InvalidArgumentException');
$source = new Doctrine2(new \stdClass('something'));
}
diff --git a/tests/ZfcDatagridTest/DataSource/PhpArray/FilterTest.php b/tests/ZfcDatagridTest/DataSource/PhpArray/FilterTest.php
index 824d68d5..a97207fc 100644
--- a/tests/ZfcDatagridTest/DataSource/PhpArray/FilterTest.php
+++ b/tests/ZfcDatagridTest/DataSource/PhpArray/FilterTest.php
@@ -26,7 +26,8 @@ public function setUp()
public function testConstruct()
{
/* @var $filter \ZfcDatagrid\Filter */
- $filter = $this->getMock('ZfcDatagrid\Filter');
+ $filter = $this->getMockBuilder('ZfcDatagrid\Filter')
+ ->getMock();
$filter->setFromColumn($this->column, 'myValue,123');
$filterArray = new FilterArray($filter);
@@ -416,9 +417,13 @@ public function testBetween()
]));
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testException()
{
- $filter = $this->getMock('ZfcDatagrid\Filter');
+ $filter = $this->getMockBuilder('ZfcDatagrid\Filter')
+ ->getMock();
$filter->expects($this->any())
->method('getColumn')
->will($this->returnValue($this->column));
@@ -431,8 +436,6 @@ public function testException()
->method('getOperator')
->will($this->returnValue(' () '));
- $this->setExpectedException('InvalidArgumentException');
-
$filterArray = new FilterArray($filter);
$filterArray->applyFilter([
'myCol' => '15',
diff --git a/tests/ZfcDatagridTest/DataSource/PhpArrayTest.php b/tests/ZfcDatagridTest/DataSource/PhpArrayTest.php
index 85fda44b..fe282f89 100644
--- a/tests/ZfcDatagridTest/DataSource/PhpArrayTest.php
+++ b/tests/ZfcDatagridTest/DataSource/PhpArrayTest.php
@@ -30,14 +30,15 @@ public function setUp()
$this->source = $source;
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testConstruct()
{
$source = clone $this->source;
$this->assertEquals($this->data, $source->getData());
- $this->setExpectedException('InvalidArgumentException');
-
$source = new PhpArray(null);
}
diff --git a/tests/ZfcDatagridTest/DataSource/ZendSelect/FilterTest.php b/tests/ZfcDatagridTest/DataSource/ZendSelect/FilterTest.php
index 3e186b3f..5c047c31 100644
--- a/tests/ZfcDatagridTest/DataSource/ZendSelect/FilterTest.php
+++ b/tests/ZfcDatagridTest/DataSource/ZendSelect/FilterTest.php
@@ -53,16 +53,20 @@ public function setUp()
$this->column2->setUniqueId('myCol2');
$this->column2->setSelect('myCol2');
- $this->mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
- $this->mockConnection = $this->getMock('Zend\Db\Adapter\Driver\ConnectionInterface');
+ $this->mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')
+ ->getMock();
+ $this->mockConnection = $this->getMockBuilder('Zend\Db\Adapter\Driver\ConnectionInterface')
+ ->getMock();
$this->mockDriver->expects($this->any())
->method('checkEnvironment')
->will($this->returnValue(true));
$this->mockDriver->expects($this->any())
->method('getConnection')
->will($this->returnValue($this->mockConnection));
- $this->mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
- $this->mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
+ $this->mockPlatform = $this->getMockBuilder('Zend\Db\Adapter\Platform\PlatformInterface')
+ ->getMock();
+ $this->mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')
+ ->getMock();
$this->mockDriver->expects($this->any())
->method('createStatement')
->will($this->returnValue($this->mockStatement));
@@ -409,9 +413,13 @@ public function testBetween()
$this->assertEquals('myValue', $operator->getMaxValue());
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testException()
{
- $filter = $this->getMock('ZfcDatagrid\Filter');
+ $filter = $this->getMockBuilder('ZfcDatagrid\Filter')
+ ->getMock();
$filter->expects($this->any())
->method('getColumn')
->will($this->returnValue($this->column));
@@ -424,7 +432,6 @@ public function testException()
->method('getOperator')
->will($this->returnValue(' () '));
- $this->setExpectedException('InvalidArgumentException');
$filterSelect = clone $this->filterSelect;
$filterSelect->applyFilter($filter);
}
diff --git a/tests/ZfcDatagridTest/DataSource/ZendSelectTest.php b/tests/ZfcDatagridTest/DataSource/ZendSelectTest.php
index 35754d23..faca9fe3 100644
--- a/tests/ZfcDatagridTest/DataSource/ZendSelectTest.php
+++ b/tests/ZfcDatagridTest/DataSource/ZendSelectTest.php
@@ -46,20 +46,20 @@ public function setUp()
{
parent::setUp();
- $this->mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
- $this->mockConnection = $this->getMock('Zend\Db\Adapter\Driver\ConnectionInterface');
+ $this->mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock();
+ $this->mockConnection = $this->getMockBuilder('Zend\Db\Adapter\Driver\ConnectionInterface')->getMock();
$this->mockDriver->expects($this->any())
->method('checkEnvironment')
->will($this->returnValue(true));
$this->mockDriver->expects($this->any())
->method('getConnection')
->will($this->returnValue($this->mockConnection));
- $this->mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
+ $this->mockPlatform = $this->getMockBuilder('Zend\Db\Adapter\Platform\PlatformInterface')->getMock();
$this->mockPlatform->expects($this->any())
->method('getIdentifierSeparator')
->will($this->returnValue('.'));
- $this->mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
+ $this->mockStatement = $this->getMockBuilder('Zend\Db\Adapter\Driver\StatementInterface')->getMock();
$this->mockDriver->expects($this->any())
->method('createStatement')
->will($this->returnValue($this->mockStatement));
@@ -78,31 +78,38 @@ public function setUp()
]);
}
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage A instance of Zend\Db\SqlSelect is needed to use this dataSource!
+ */
public function testConstruct()
{
- $select = $this->getMock('Zend\Db\Sql\Select');
+ $select = $this->getMockBuilder('Zend\Db\Sql\Select')->getMock();
$source = new ZendSelect($select);
$this->assertInstanceOf('Zend\Db\Sql\Select', $source->getData());
$this->assertEquals($select, $source->getData());
- $this->setExpectedException('InvalidArgumentException', 'A instance of Zend\Db\SqlSelect is needed to use this dataSource!');
-
$source = new ZendSelect([]);
}
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage Object "Zend\Db\Sql\Sql" is missing, please call setAdapter() first!
+ */
public function testExecuteException()
{
- $select = $this->getMock('Zend\Db\Sql\Select');
+ $select = $this->getMockBuilder('Zend\Db\Sql\Select')->getMock();
$source = new ZendSelect($select);
- $this->setExpectedException('Exception', 'Object "Zend\Db\Sql\Sql" is missing, please call setAdapter() first!');
-
$source->execute();
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testAdapter()
{
$source = clone $this->source;
@@ -113,7 +120,6 @@ public function testAdapter()
$source->setAdapter($this->adapter);
$this->assertInstanceOf('Zend\Db\Sql\Sql', $source->getAdapter());
- $this->setExpectedException('InvalidArgumentException');
$source->setAdapter('something');
}
diff --git a/tests/ZfcDatagridTest/DatagridTest.php b/tests/ZfcDatagridTest/DatagridTest.php
index 6f2993a0..8b94e6ed 100644
--- a/tests/ZfcDatagridTest/DatagridTest.php
+++ b/tests/ZfcDatagridTest/DatagridTest.php
@@ -2,9 +2,13 @@
namespace ZfcDatagridTest;
use PHPUnit_Framework_TestCase;
+use Zend\Http\PhpEnvironment\Request;
+use Zend\I18n\Translator\Translator;
+use Zend\Mvc\MvcEvent;
use Zend\Session\Container;
use ZfcDatagrid\Column;
use ZfcDatagrid\Datagrid;
+use ZfcDatagrid\DataSource\PhpArray;
/**
* @group Datagrid
@@ -35,10 +39,10 @@ public function setUp()
$this->config = $config;
- $mvcEvent = $this->getMock('Zend\Mvc\MvcEvent');
+ $mvcEvent = $this->getMockBuilder(MvcEvent::class)->getMock();
$mvcEvent->expects($this->any())
->method('getRequest')
- ->will($this->returnValue($this->getMock('Zend\Http\PhpEnvironment\Request')));
+ ->will($this->returnValue($this->getMockBuilder(Request::class)->getMock()));
$this->grid = new Datagrid();
$this->grid->setOptions($this->config);
@@ -94,29 +98,32 @@ public function testCacheId()
public function testMvcEvent()
{
- $this->assertInstanceOf('Zend\Mvc\MvcEvent', $this->grid->getMvcEvent());
+ $this->assertInstanceOf(MvcEvent::class, $this->grid->getMvcEvent());
- $mvcEvent = $this->getMock('Zend\Mvc\MvcEvent');
+ $mvcEvent = $this->getMockBuilder(MvcEvent::class)->getMock();
$this->grid->setMvcEvent($mvcEvent);
- $this->assertInstanceOf('Zend\Mvc\MvcEvent', $this->grid->getMvcEvent());
+ $this->assertInstanceOf(MvcEvent::class, $this->grid->getMvcEvent());
$this->assertEquals($mvcEvent, $this->grid->getMvcEvent());
}
public function testRequest()
{
- $this->assertInstanceOf('Zend\Http\PhpEnvironment\Request', $this->grid->getRequest());
+ $this->assertInstanceOf(Request::class, $this->grid->getRequest());
}
public function testTranslator()
{
$this->assertFalse($this->grid->hasTranslator());
- $this->grid->setTranslator($this->getMock('Zend\I18n\Translator\Translator'));
+ $this->grid->setTranslator($this->getMockBuilder(Translator::class)->getMock());
$this->assertTrue($this->grid->hasTranslator());
- $this->assertInstanceOf('Zend\I18n\Translator\Translator', $this->grid->getTranslator());
+ $this->assertInstanceOf(Translator::class, $this->grid->getTranslator());
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testDataSourceArray()
{
$grid = new Datagrid();
@@ -124,49 +131,41 @@ public function testDataSourceArray()
$grid->setDataSource([]);
$this->assertTrue($grid->hasDataSource());
- $this->assertInstanceOf('ZfcDatagrid\DataSource\PhpArray', $grid->getDataSource());
+ $this->assertInstanceOf(PhpArray::class, $grid->getDataSource());
- $source = $this->getMock('ZfcDatagrid\DataSource\PhpArray', [], [
- [],
- ]);
+ $source = $this->getMockBuilder(PhpArray::class)
+ ->setMethods([])
+ ->disableOriginalConstructor()
+ ->getMock();
$grid->setDataSource($source);
$this->assertTrue($grid->hasDataSource());
- $this->setExpectedException('InvalidArgumentException');
$grid->setDataSource(null);
}
- public function testDataSourceZend()
- {
- // $this->assertFalse($this->grid->hasDataSource());
-
- // $this->grid->setDataSource(array());
- // $this->assertTrue($this->grid->hasDataSource());
- // $this->assertInstanceOf('ZfcDatagrid\DataSource\PhpArray', $this->grid->getDataSource());
-
- // $select = $this->getMock('Zend\Db\Sql\Select');
- // $this->grid->setDataSource($select);
-
- // $qb = $this->getMock('Doctrine\ORM\QueryBuilder', array(), array(
- // $this->getMock('Doctrine\ORM\EntityManager')
- // ));
- // $this->grid->setDataSource($qb);
- }
-
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage For "Zend\Db\Sql\Select" also a "Zend\Db\Adapter\Sql" or "Zend\Db\Sql\Sql" is needed.
+ */
public function testDataSourceZendSelect()
{
$grid = new Datagrid();
$this->assertFalse($grid->hasDataSource());
- $select = $this->getMock('Zend\Db\Sql\Select', [], [], '', false);
+ $select = $this->getMockBuilder('Zend\Db\Sql\Select')
+ ->disableOriginalConstructor()
+ ->getMock();
- $platform = $this->getMock('Zend\Db\Adapter\Platform\Sqlite');
+ $platform = $this->getMockBuilder('Zend\Db\Adapter\Platform\Sqlite')
+ ->getMock();
$platform->expects($this->any())
->method('getName')
->will($this->returnValue('myPlatform'));
- $adapter = $this->getMock('Zend\Db\Adapter\Adapter', [], [], '', false);
+ $adapter = $this->getMockBuilder('Zend\Db\Adapter\Adapter')
+ ->disableOriginalConstructor()
+ ->getMock();
$adapter->expects($this->any())
->method('getPlatform')
->will($this->returnValue($platform));
@@ -174,8 +173,6 @@ public function testDataSourceZendSelect()
$grid->setDataSource($select, $adapter);
$this->assertTrue($grid->hasDataSource());
$this->assertInstanceOf('ZfcDatagrid\Datasource\ZendSelect', $grid->getDataSource());
-
- $this->setExpectedException('InvalidArgumentException', 'For "Zend\Db\Sql\Select" also a "Zend\Db\Adapter\Sql" or "Zend\Db\Sql\Sql" is needed.');
$grid->setDataSource($select);
}
@@ -185,27 +182,36 @@ public function testDataSourceDoctrine()
$this->assertFalse($grid->hasDataSource());
- $qb = $this->getMock('Doctrine\ORM\QueryBuilder', [], [], '', false);
+ $qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
+ ->disableOriginalConstructor()
+ ->getMock();
$grid->setDataSource($qb);
$this->assertTrue($grid->hasDataSource());
$this->assertInstanceOf('ZfcDatagrid\DataSource\Doctrine2', $grid->getDataSource());
}
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage If providing a Collection, also the Doctrine\ORM\EntityManager is needed as a second parameter
+ */
public function testDataSourceDoctrineCollection()
{
$grid = new Datagrid();
$this->assertFalse($grid->hasDataSource());
- $coll = $this->getMock('Doctrine\Common\Collections\ArrayCollection', [], [], '', false);
- $em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
+ $coll = $this->getMockBuilder('Doctrine\Common\Collections\ArrayCollection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
+ ->disableOriginalConstructor()
+ ->getMock();
$grid->setDataSource($coll, $em);
$this->assertTrue($grid->hasDataSource());
$this->assertInstanceOf('ZfcDatagrid\DataSource\Doctrine2Collection', $grid->getDataSource());
- $this->setExpectedException('InvalidArgumentException', 'If providing a Collection, also the Doctrine\ORM\EntityManager is needed as a second parameter');
$grid->setDataSource($coll);
}
@@ -288,11 +294,14 @@ public function testAddColumn()
$this->assertEquals(null, $this->grid->getColumnByUniqueId('notAvailable'));
}
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage createColumn() supports only a config array or instanceof Column\AbstractColumn as a parameter
+ */
public function testAddColumnInvalidArgumentException()
{
$grid = new Datagrid();
- $this->setExpectedException('InvalidArgumentException', 'createColumn() supports only a config array or instanceof Column\AbstractColumn as a parameter');
$grid->addColumn(null);
}
@@ -318,6 +327,10 @@ public function testAddColumnArrayFQN()
$this->assertEquals('My label', $col->getLabel());
}
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage Column type: "ZfcDatagrid\Column\Unknown" not found!
+ */
public function testAddColumnArrayInvalidColType()
{
$grid = new Datagrid();
@@ -328,7 +341,6 @@ public function testAddColumnArrayInvalidColType()
'label' => 'My label',
];
- $this->setExpectedException('InvalidArgumentException', 'Column type: "ZfcDatagrid\Column\Unknown" not found!');
$grid->addColumn($column);
}
@@ -353,6 +365,10 @@ public function testAddColumnArraySelect()
$this->assertEquals('My label', $col->getLabel());
}
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage For "ZfcDatagrid\Column\Select" the option select[column] must be defined!
+ */
public function testAddColumnArraySelectInvalidArgumentException()
{
$grid = new Datagrid();
@@ -361,7 +377,7 @@ public function testAddColumnArraySelectInvalidArgumentException()
$column = [
'label' => 'My label',
];
- $this->setExpectedException('InvalidArgumentException', 'For "ZfcDatagrid\Column\Select" the option select[column] must be defined!');
+
$grid->addColumn($column);
}
@@ -487,11 +503,11 @@ public function testRowStyle()
$grid = new Datagrid();
$this->assertFalse($grid->hasRowStyles());
- $grid->addRowStyle($this->getMock('ZfcDatagrid\Column\Style\Bold'));
+ $grid->addRowStyle($this->getMockBuilder('ZfcDatagrid\Column\Style\Bold')->getMock());
$this->assertCount(1, $grid->getRowStyles());
$this->assertTrue($grid->hasRowStyles());
- $grid->addRowStyle($this->getMock('ZfcDatagrid\Column\Style\Italic'));
+ $grid->addRowStyle($this->getMockBuilder('ZfcDatagrid\Column\Style\Italic')->getMock());
$this->assertCount(2, $grid->getRowStyles());
$this->assertTrue($grid->hasRowStyles());
}
@@ -528,7 +544,7 @@ public function testRendererName()
$_ENV["FOO_VAR"] = "bar";
$request = new \Zend\Console\Request();
- $mvcEvent = $this->getMock('Zend\Mvc\MvcEvent');
+ $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->getMock();
$mvcEvent->expects($this->any())
->method('getRequest')
->will($this->returnValue($request));
@@ -542,7 +558,7 @@ public function testRendererName()
// by HTTP request
$_GET['rendererType'] = 'jqGrid';
$request = new \Zend\Http\PhpEnvironment\Request();
- $mvcEvent = $this->getMock('Zend\Mvc\MvcEvent');
+ $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')->getMock();
$mvcEvent->expects($this->any())
->method('getRequest')
->will($this->returnValue($request));
@@ -573,19 +589,22 @@ public function testSetViewModel()
{
$grid = new Datagrid();
- $customView = $this->getMock('Zend\View\Model\ViewModel');
+ $customView = $this->getMockBuilder('Zend\View\Model\ViewModel')->getMock();
$grid->setViewModel($customView);
$this->assertSame($customView, $grid->getViewModel());
}
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage A viewModel is already set. Did you already called $grid->render() or $grid->getViewModel() before?
+ */
public function testSetViewModelException()
{
$grid = new Datagrid();
$grid->getViewModel();
- $customView = $this->getMock('Zend\View\Model\ViewModel');
+ $customView = $this->getMockBuilder('Zend\View\Model\ViewModel')->getMock();
- $this->setExpectedException('Exception', 'A viewModel is already set. Did you already called $grid->render() or $grid->getViewModel() before?');
$grid->setViewModel($customView);
}
}
diff --git a/tests/ZfcDatagridTest/FilterTest.php b/tests/ZfcDatagridTest/FilterTest.php
index 79088e0a..0adc8e9d 100644
--- a/tests/ZfcDatagridTest/FilterTest.php
+++ b/tests/ZfcDatagridTest/FilterTest.php
@@ -590,19 +590,23 @@ public function testIsApplyBetween()
], Filter::BETWEEN));
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testIsApplyBetweenInvalidArgumentException()
{
$filter = new Filter();
- $this->setExpectedException('\InvalidArgumentException');
$filter->isApply(123, 100, Filter::BETWEEN);
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testIsApplyInvalidArgumentException()
{
$filter = new Filter();
- $this->setExpectedException('\InvalidArgumentException');
$filter->isApply(123, 100, 'UndefinedFilter');
}
}
diff --git a/tests/ZfcDatagridTest/PrepareDataTest.php b/tests/ZfcDatagridTest/PrepareDataTest.php
index 7cb3255a..3a72f471 100644
--- a/tests/ZfcDatagridTest/PrepareDataTest.php
+++ b/tests/ZfcDatagridTest/PrepareDataTest.php
@@ -136,7 +136,8 @@ public function testTranslator()
$this->col1,
]);
- $translator = $this->getMock('Zend\I18n\Translator\Translator');
+ $translator = $this->getMockBuilder('Zend\I18n\Translator\Translator')
+ ->getMock();
$prepare->setTranslator($translator);
$this->assertEquals($translator, $prepare->getTranslator());
@@ -288,7 +289,8 @@ public function testPrepareReplaceTranslate()
$this->col3,
]);
- $translator = $this->getMock('Zend\I18n\Translator\Translator');
+ $translator = $this->getMockBuilder('Zend\I18n\Translator\Translator')
+ ->getMock();
$translator->expects($this->any())
->method('translate')
->will($this->returnCallback(function ($name) {
@@ -339,7 +341,8 @@ public function testPrepareReplaceTranslateArray()
$col3,
]);
- $translator = $this->getMock('Zend\I18n\Translator\Translator');
+ $translator = $this->getMockBuilder('Zend\I18n\Translator\Translator')
+ ->getMock();
$translator->expects($this->any())
->method('translate')
->will($this->returnCallback(function ($name) {
@@ -383,7 +386,8 @@ public function testPrepareDataPopulation()
{
$data = $this->data;
- $mock = $this->getMock('ZfcDatagrid\Column\DataPopulation\Object\Gravatar');
+ $mock = $this->getMockBuilder('ZfcDatagrid\Column\DataPopulation\Object\Gravatar')
+ ->getMock();
$mock->expects($this->any())
->method('toString')
->will($this->returnValue('myReturn'));
@@ -392,7 +396,8 @@ public function testPrepareDataPopulation()
$object->setObject($mock);
$object->addObjectParameterColumn('email', $this->col1);
- $col = $this->getMock('ZfcDatagrid\Column\ExternalData');
+ $col = $this->getMockBuilder('ZfcDatagrid\Column\ExternalData')
+ ->getMock();
$col->expects($this->any())
->method('getUniqueId')
->will($this->returnValue('colPopulation'));
diff --git a/tests/ZfcDatagridTest/Renderer/AbstractExportTest.php b/tests/ZfcDatagridTest/Renderer/AbstractExportTest.php
index 0d7dda0a..edc8c4ad 100644
--- a/tests/ZfcDatagridTest/Renderer/AbstractExportTest.php
+++ b/tests/ZfcDatagridTest/Renderer/AbstractExportTest.php
@@ -38,6 +38,10 @@ public function testFilename()
$this->assertEquals(date('Y-m-d_H-i-s') . '_My_title', $filename);
}
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage Currently only "A" paper formats are supported!
+ */
public function testPaperWidth()
{
$exportMock = clone $this->exportMock;
@@ -110,7 +114,6 @@ public function testPaperWidth()
];
$exportMock->setOptions($options);
- $this->setExpectedException('Exception', 'Currently only "A" paper formats are supported!');
$width = $method->invoke($exportMock);
}
}
diff --git a/tests/ZfcDatagridTest/Renderer/AbstractRendererTest.php b/tests/ZfcDatagridTest/Renderer/AbstractRendererTest.php
index 1611029a..cb8229e0 100644
--- a/tests/ZfcDatagridTest/Renderer/AbstractRendererTest.php
+++ b/tests/ZfcDatagridTest/Renderer/AbstractRendererTest.php
@@ -62,7 +62,8 @@ public function testViewModel()
$this->assertNull($renderer->getViewModel());
- $viewModel = $this->getMock('Zend\View\Model\ViewModel');
+ $viewModel = $this->getMockBuilder('Zend\View\Model\ViewModel')
+ ->getMock();
$renderer->setViewModel($viewModel);
$this->assertSame($viewModel, $renderer->getViewModel());
}
@@ -239,9 +240,13 @@ public function testMvcEvent()
/* @var $renderer \ZfcDatagrid\Renderer\AbstractRenderer */
$renderer = $this->getMockForAbstractClass('ZfcDatagrid\Renderer\AbstractRenderer');
- $request = $this->getMock('Zend\Http\Request', [], [], '', false);
+ $request = $this->getMockBuilder('Zend\Http\Request')
+ ->disableOriginalConstructor()
+ ->getMock();
- $mvcEvent = $this->getMock('Zend\Mvc\MvcEvent', [], [], '', false);
+ $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')
+ ->disableOriginalConstructor()
+ ->getMock();
$mvcEvent->expects($this->any())
->method('getRequest')
->will($this->returnValue($request));
@@ -259,7 +264,9 @@ public function testTranslator()
/* @var $renderer \ZfcDatagrid\Renderer\AbstractRenderer */
$renderer = $this->getMockForAbstractClass('ZfcDatagrid\Renderer\AbstractRenderer');
- $translator = $this->getMock('Zend\I18n\Translator\Translator', [], [], '', false);
+ $translator = $this->getMockBuilder('Zend\I18n\Translator\Translator')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->assertNull($renderer->getTranslator());
$renderer->setTranslator($translator);
@@ -272,7 +279,10 @@ public function testTranslate()
$renderer = $this->getMockForAbstractClass('ZfcDatagrid\Renderer\AbstractRenderer');
$this->assertEquals('foobar', $renderer->translate('foobar'));
- $translator = $this->getMock('Zend\I18n\Translator\Translator', ['translate'], [], '', false);
+ $translator = $this->getMockBuilder('Zend\I18n\Translator\Translator')
+ ->disableOriginalConstructor()
+ ->setMethods(['translate'])
+ ->getMock();
$translator->expects($this->any())
->method('translate')
->willReturn('barfoo');
@@ -341,12 +351,16 @@ public function testGetSortConditionsSortDefault()
public function testGetFiltersDefault()
{
- $request = $this->getMock('Zend\Http\PhpEnvironment\Request', [], [], '', false);
+ $request = $this->getMockBuilder('Zend\Http\PhpEnvironment\Request')
+ ->disableOriginalConstructor()
+ ->getMock();
$request->expects($this->any())
->method('isPost')
->will($this->returnValue(false));
- $mvcEvent = $this->getMock('Zend\Mvc\MvcEvent', [], [], '', false);
+ $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')
+ ->disableOriginalConstructor()
+ ->getMock();
$mvcEvent->expects($this->any())
->method('getRequest')
->will($this->returnValue($request));
diff --git a/tests/ZfcDatagridTest/Renderer/BootstrapTable/RendererTest.php b/tests/ZfcDatagridTest/Renderer/BootstrapTable/RendererTest.php
index 9dc9b8b1..a5451901 100644
--- a/tests/ZfcDatagridTest/Renderer/BootstrapTable/RendererTest.php
+++ b/tests/ZfcDatagridTest/Renderer/BootstrapTable/RendererTest.php
@@ -31,11 +31,19 @@ public function testIsHtml()
$this->assertTrue($renderer->isHtml());
}
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage Request must be an instance of Zend\Http\PhpEnvironment\Request for HTML rendering
+ */
public function testGetRequestException()
{
- $request = $this->getMock('Zend\Console\Request', [], [], '', false);
+ $request = $this->getMockBuilder('Zend\Console\Request')
+ ->disableOriginalConstructor()
+ ->getMock();
- $mvcEvent = $this->getMock('Zend\Mvc\MvcEvent', [], [], '', false);
+ $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')
+ ->disableOriginalConstructor()
+ ->getMock();
$mvcEvent->expects($this->any())
->method('getRequest')
->will($this->returnValue($request));
@@ -43,15 +51,19 @@ public function testGetRequestException()
$renderer = new BootstrapTable\Renderer();
$renderer->setMvcEvent($mvcEvent);
- $this->setExpectedException('Exception', 'Request must be an instance of Zend\Http\PhpEnvironment\Request for HTML rendering');
$renderer->getRequest();
}
public function testGetRequest()
{
- $request = $this->getMock('Zend\Http\PhpEnvironment\Request', [], [], '', false);
+ $request = $this->getMockBuilder('Zend\Http\PhpEnvironment\Request')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')
+ ->disableOriginalConstructor()
+ ->getMock();
- $mvcEvent = $this->getMock('Zend\Mvc\MvcEvent', [], [], '', false);
$mvcEvent->expects($this->any())
->method('getRequest')
->will($this->returnValue($request));
diff --git a/tests/ZfcDatagridTest/Renderer/BootstrapTable/View/Helper/TableRowTest.php b/tests/ZfcDatagridTest/Renderer/BootstrapTable/View/Helper/TableRowTest.php
index b173c887..bbad62ee 100644
--- a/tests/ZfcDatagridTest/Renderer/BootstrapTable/View/Helper/TableRowTest.php
+++ b/tests/ZfcDatagridTest/Renderer/BootstrapTable/View/Helper/TableRowTest.php
@@ -36,7 +36,8 @@ public function setUp()
$this->myCol = $myCol;
- $this->serviceLocator = $this->getMock('Zend\ServiceManager\ServiceManager');
+ $this->serviceLocator = $this->getMockBuilder('Zend\ServiceManager\ServiceManager')
+ ->getMock();
}
public function testCanExecute()
@@ -101,6 +102,9 @@ public function testType()
$this->assertContains('First value
', $html);
}
+ /**
+ * @expectedException \InvalidArgumentException
+ */
public function testStyle()
{
$helper = new TableRow();
@@ -166,7 +170,6 @@ public function testStyle()
$myCol,
];
- $this->setExpectedException('InvalidArgumentException');
$html = $helper($this->rowWithId, $cols);
}
diff --git a/tests/ZfcDatagridTest/Renderer/JqGrid/RendererTest.php b/tests/ZfcDatagridTest/Renderer/JqGrid/RendererTest.php
index cea1cf99..8b545e27 100644
--- a/tests/ZfcDatagridTest/Renderer/JqGrid/RendererTest.php
+++ b/tests/ZfcDatagridTest/Renderer/JqGrid/RendererTest.php
@@ -44,11 +44,19 @@ public function testIsHtml()
$this->assertTrue($renderer->isHtml());
}
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage Request must be an instance of Zend\Http\PhpEnvironment\Request for HTML rendering
+ */
public function testGetRequestException()
{
- $request = $this->getMock('Zend\Console\Request', [], [], '', false);
+ $request = $this->getMockBuilder('Zend\Console\Request')
+ ->disableOriginalConstructor()
+ ->getMock();
- $mvcEvent = $this->getMock('Zend\Mvc\MvcEvent', [], [], '', false);
+ $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')
+ ->disableOriginalConstructor()
+ ->getMock();
$mvcEvent->expects($this->any())
->method('getRequest')
->will($this->returnValue($request));
@@ -56,15 +64,18 @@ public function testGetRequestException()
$renderer = new JqGrid\Renderer();
$renderer->setMvcEvent($mvcEvent);
- $this->setExpectedException('Exception', 'Request must be an instance of Zend\Http\PhpEnvironment\Request for HTML rendering');
$renderer->getRequest();
}
public function testGetRequest()
{
- $request = $this->getMock('Zend\Http\PhpEnvironment\Request', [], [], '', false);
+ $request = $this->getMockBuilder('Zend\Http\PhpEnvironment\Request')
+ ->disableOriginalConstructor()
+ ->getMock();
- $mvcEvent = $this->getMock('Zend\Mvc\MvcEvent', [], [], '', false);
+ $mvcEvent = $this->getMockBuilder('Zend\Mvc\MvcEvent')
+ ->disableOriginalConstructor()
+ ->getMock();
$mvcEvent->expects($this->any())
->method('getRequest')
->will($this->returnValue($request));
diff --git a/tests/ZfcDatagridTest/Renderer/JqGrid/View/Helper/ColumnsTest.php b/tests/ZfcDatagridTest/Renderer/JqGrid/View/Helper/ColumnsTest.php
index 6ede97f6..38733466 100644
--- a/tests/ZfcDatagridTest/Renderer/JqGrid/View/Helper/ColumnsTest.php
+++ b/tests/ZfcDatagridTest/Renderer/JqGrid/View/Helper/ColumnsTest.php
@@ -23,7 +23,9 @@ class ColumnsTest extends PHPUnit_Framework_TestCase
public function setUp()
{
- $this->sm = $this->getMock('Zend\View\HelperPluginManager', [], [], '', false);
+ $this->sm = $this->getMockBuilder('Zend\View\HelperPluginManager')
+ ->disableOriginalConstructor()
+ ->getMock();
$myCol = $this->getMockForAbstractClass('ZfcDatagrid\Column\AbstractColumn');
$myCol->setUniqueId('myCol');
@@ -109,6 +111,10 @@ public function testStyleBackgroundColor()
$this->assertStringEndsWith('search: true,searchoptions: {"clearSearch":false}}]', $result);
}
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessageRegExp /Not defined style: \"[a-zA-Z0-9_]+\"/
+ */
public function testStyleException()
{
$styleMock = $this->getMockForAbstractClass('ZfcDatagrid\Column\Style\AbstractStyle');
@@ -120,7 +126,6 @@ public function testStyleException()
$col1,
];
- $this->setExpectedException('Exception', 'Not defined style: "' . get_class($styleMock) . '"');
$result = $helper($cols);
$this->assertStringStartsWith('[{name:', $result);
@@ -183,6 +188,10 @@ public function testStyleByValueNotEqual()
$this->assertStringEndsWith('if (rowObject.myCol != \'123\') {cellvalue = \'\' + cellvalue + \'\';} return cellvalue; },searchoptions: {"clearSearch":false}}]', $result);
}
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage Currently not supported filter operation: "=(%s)"
+ */
public function testStyleByValueNotSupported()
{
$helper = new Helper\Columns();
@@ -197,14 +206,15 @@ public function testStyleByValueNotSupported()
$col1,
];
- $this->setExpectedException('Exception', 'Currently not supported filter operation: "' . Filter::IN . '"');
$result = $helper($cols);
}
public function testTranslate()
{
/** @var \PHPUnit_Framework_MockObject_MockObject|\Zend\ServiceManager\ServiceManager $sm */
- $sm = $this->getMock('Zend\ServiceManager\ServiceManager', null);
+ $sm = $this->getMockBuilder('Zend\ServiceManager\ServiceManager')
+ ->setMethods(null)
+ ->getMock();
$helper = new Helper\Columns();
diff --git a/tests/ZfcDatagridTest/Renderer/ZendTable/RendererTest.php b/tests/ZfcDatagridTest/Renderer/ZendTable/RendererTest.php
index 47531d2a..60a36bf2 100644
--- a/tests/ZfcDatagridTest/Renderer/ZendTable/RendererTest.php
+++ b/tests/ZfcDatagridTest/Renderer/ZendTable/RendererTest.php
@@ -46,8 +46,13 @@ class RendererTest extends PHPUnit_Framework_TestCase
public function setUp()
{
- $this->requestMock = $this->getMock('Zend\Console\Request', [], [], '', false);
- $this->mvcEventMock = $this->getMock('Zend\Mvc\MvcEvent', [], [], '', false);
+ $this->requestMock = $this->getMockBuilder('Zend\Console\Request')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->mvcEventMock = $this->getMockBuilder('Zend\Mvc\MvcEvent')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->colMock = $this->getMockForAbstractClass('ZfcDatagrid\Column\AbstractColumn');
}
@@ -73,9 +78,15 @@ public function testIsHtml()
$this->assertFalse($renderer->isHtml());
}
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage Request must be an instance of Zend\Console\Request for console rendering
+ */
public function testGetRequestException()
{
- $request = $this->getMock('Zend\Http\PhpEnvironment\Request', [], [], '', false);
+ $request = $this->getMockBuilder('Zend\Http\PhpEnvironment\Request')
+ ->disableOriginalConstructor()
+ ->getMock();
$mvcEvent = clone $this->mvcEventMock;
$mvcEvent->expects($this->any())
@@ -85,7 +96,6 @@ public function testGetRequestException()
$renderer = new ZendTable\Renderer();
$renderer->setMvcEvent($mvcEvent);
- $this->setExpectedException('Exception', 'Request must be an instance of Zend\Console\Request for console rendering');
$renderer->getRequest();
}
@@ -307,6 +317,10 @@ public function testGetItemsPerPageUser()
$this->assertEquals(99, $renderer->getItemsPerPage());
}
+ /**
+ * @expectedException \Exception
+ * @expectedExceptionMessage No columns to display available
+ */
public function testGetColumnsToDisplay()
{
$reflection = new ReflectionClass('ZfcDatagrid\Renderer\ZendTable\Renderer');
@@ -319,7 +333,9 @@ public function testGetColumnsToDisplay()
$col2 = $this->getMockForAbstractClass('ZfcDatagrid\Column\AbstractColumn');
$col2->setWidth(20);
- $col3 = $this->getMock('ZfcDatagrid\Column\Action');
+ $col3 = $this->getMockBuilder('ZfcDatagrid\Column\Action')
+ ->disableOriginalConstructor()
+ ->getMock();
$col3->setWidth(20);
$renderer = new ZendTable\Renderer();
@@ -344,7 +360,6 @@ public function testGetColumnsToDisplay()
$col2,
], $result);
- $this->setExpectedException('Exception', 'No columns to display available');
$renderer = new ZendTable\Renderer();
$method->invoke($renderer);
}
diff --git a/tests/ZfcDatagridTest/Service/DatagridFactoryTest.php b/tests/ZfcDatagridTest/Service/DatagridFactoryTest.php
index 7654733b..56b9e6ef 100644
--- a/tests/ZfcDatagridTest/Service/DatagridFactoryTest.php
+++ b/tests/ZfcDatagridTest/Service/DatagridFactoryTest.php
@@ -37,9 +37,12 @@ class DatagridFactoryTest extends PHPUnit_Framework_TestCase
public function setUp()
{
- $mvcEventMock = $this->getMock('Zend\Mvc\MvcEvent');
+ $mvcEventMock = $this->getMockBuilder('Zend\Mvc\MvcEvent')
+ ->getMock();
- $this->applicationMock = $this->getMock('Zend\Mvc\Application', [], [], '', false);
+ $this->applicationMock = $this->getMockBuilder('Zend\Mvc\Application')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->applicationMock->expects($this->any())
->method('getMvcEvent')
->will($this->returnValue($mvcEventMock));
@@ -48,10 +51,12 @@ public function setUp()
->getMock();
}
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage Config key "ZfcDatagrid" is missing
+ */
public function testCreateServiceException()
{
- $this->setExpectedException('InvalidArgumentException', 'Config key "ZfcDatagrid" is missing');
-
$sm = new ServiceManager();
$sm->setService('config', []);
@@ -74,7 +79,9 @@ public function testCanCreateService()
public function testCanCreateServiceWithTranslator()
{
- $translatorMock = $this->getMock('Zend\I18n\Translator\Translator', [], [], '', false);
+ $translatorMock = $this->getMockBuilder('Zend\I18n\Translator\Translator')
+ ->disableOriginalConstructor()
+ ->getMock();
$sm = new ServiceManager();
$sm->setService('config', $this->config);
@@ -91,7 +98,9 @@ public function testCanCreateServiceWithTranslator()
public function testCanCreateServiceWithMvcTranslator()
{
- $mvcTranslatorMock = $this->getMock('Zend\Mvc\I18n\Translator', [], [], '', false);
+ $mvcTranslatorMock = $this->getMockBuilder('Zend\I18n\Translator\Translator')
+ ->disableOriginalConstructor()
+ ->getMock();
$sm = new ServiceManager();
$sm->setService('config', $this->config);