Skip to content

Commit

Permalink
- unittests update, removed deprecated method getMock (#238)
Browse files Browse the repository at this point in the history
- also removed deprecated method setExpectedException
- run cs fix
- update composer for cs-fix
  • Loading branch information
kokspflanze authored and ThaDafinser committed Jun 13, 2016
1 parent 460994a commit f85a180
Show file tree
Hide file tree
Showing 38 changed files with 299 additions and 154 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

"require-dev": {
"phpunit/phpunit": "^4.8|^5.2",
"fabpot/php-cs-fixer": "^1.11",
"friendsofphp/php-cs-fixer": "^1.11",

"doctrine/orm": ">=2.5,<2.7",
"doctrine/dbal": ">=2.5,<2.7",
Expand Down
1 change: 0 additions & 1 deletion src/ZfcDatagrid/Column/Style/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* general or based on a value
*
*/

namespace ZfcDatagrid\Column\Style;

class Color extends AbstractColor
Expand Down
1 change: 0 additions & 1 deletion src/ZfcDatagrid/Column/Type/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/**
* Image type
*/

namespace ZfcDatagrid\Column\Type;

use InvalidArgumentException;
Expand Down
1 change: 0 additions & 1 deletion src/ZfcDatagrid/DataSource/Doctrine2/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* or if we use the "safe" variant by Doctrine2
*
*/

namespace ZfcDatagrid\DataSource\Doctrine2;

use Doctrine\ORM\QueryBuilder;
Expand Down
2 changes: 1 addition & 1 deletion src/ZfcDatagrid/PrepareData.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function prepare()
*/
if (is_array($row[$col->getUniqueId()])) {
array_walk_recursive($row[$col->getUniqueId()], function (&$value) {
if(!is_object($value)){
if (!is_object($value)) {
$value = trim($value);
}
});
Expand Down
1 change: 0 additions & 1 deletion src/ZfcDatagrid/Renderer/AbstractExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Methods which can be used in (all) export renderer
*
*/

namespace ZfcDatagrid\Renderer;

use ZfcDatagrid\Column;
Expand Down
1 change: 0 additions & 1 deletion src/ZfcDatagrid/Renderer/Csv/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Render datagrid as CSV
*
*/

namespace ZfcDatagrid\Renderer\Csv;

use Zend\Http\Headers;
Expand Down
1 change: 0 additions & 1 deletion src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/**
* Output as an excel file
*/

namespace ZfcDatagrid\Renderer\PHPExcel;

use PHPExcel;
Expand Down
1 change: 0 additions & 1 deletion src/ZfcDatagrid/Renderer/TCPDF/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/**
* Output as a PDF file
*/

namespace ZfcDatagrid\Renderer\TCPDF;

use TCPDF;
Expand Down
8 changes: 6 additions & 2 deletions tests/ZfcDatagridTest/Column/Action/AbstractActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion tests/ZfcDatagridTest/Column/Action/ButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
}
}
5 changes: 3 additions & 2 deletions tests/ZfcDatagridTest/Column/Action/IconTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ public function testIconLink()
$this->assertEquals('<a href="#"><img src="/images/21/add.png" /></a>', $icon->toHtml([]));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testException()
{
$icon = new Icon();

$this->setExpectedException('InvalidArgumentException');

$icon->toHtml([]);
}
}
10 changes: 5 additions & 5 deletions tests/ZfcDatagridTest/Column/ActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
4 changes: 2 additions & 2 deletions tests/ZfcDatagridTest/Column/DataPopulation/ObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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'));
Expand Down
9 changes: 6 additions & 3 deletions tests/ZfcDatagridTest/Column/ExternalDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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);
}
}
10 changes: 6 additions & 4 deletions tests/ZfcDatagridTest/Column/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 3 additions & 1 deletion tests/ZfcDatagridTest/Column/Style/AbstractStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
6 changes: 4 additions & 2 deletions tests/ZfcDatagridTest/DataSource/AbstractDataSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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());
Expand Down
7 changes: 5 additions & 2 deletions tests/ZfcDatagridTest/DataSource/Doctrine2/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -329,7 +333,6 @@ public function testException()
->method('getOperator')
->will($this->returnValue(' () '));

$this->setExpectedException('InvalidArgumentException');
$filterDoctrine2 = clone $this->filterDoctrine2;
$filterDoctrine2->applyFilter($filter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace ZfcDatagridTest\DataSource\Doctrine2\Mocks;

/**
Expand Down
14 changes: 11 additions & 3 deletions tests/ZfcDatagridTest/DataSource/Doctrine2CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion tests/ZfcDatagridTest/DataSource/Doctrine2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ public function setUp()
]);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testConstruct()
{
$source = clone $this->source;

$this->assertInstanceOf('Doctrine\ORM\QueryBuilder', $source->getData());
$this->assertSame($this->qb, $source->getData());

$this->setExpectedException('InvalidArgumentException');
$source = new Doctrine2(new \stdClass('something'));
}

Expand Down
Loading

0 comments on commit f85a180

Please sign in to comment.