Skip to content

Commit

Permalink
Enhance expected exception tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed Oct 23, 2019
1 parent 560948f commit 5ea6742
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions tests/DataGridFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function testCreateGrids()
$this->assertSame('grid',$grid->getName());

$this->expectException(DataGridColumnException::class);
$this->expectExceptionMessage('Datagrid name "grid" is not uniqe, it was used before to create datagrid');
$this->factory->createDataGrid('grid');
}

Expand All @@ -58,6 +59,7 @@ public function testGetColumnType()
$this->assertInstanceOf(FooType::class, $this->factory->getColumnType('foo'));

$this->expectException(UnexpectedTypeException::class);
$this->expectExceptionMessage('There is no column with type "bar" registered in factory.');
$this->factory->getColumnType('bar');
}

Expand Down
1 change: 1 addition & 0 deletions tests/DataGridTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function testHasAddGetRemoveClearColumn()
$this->assertCount(0, $this->datagrid->getColumns());

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Column "bar" does not exist in data grid.');
$this->datagrid->getColumn('bar');
}

Expand Down
2 changes: 2 additions & 0 deletions tests/DataMapper/ChainMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ChainMapperTest extends TestCase
public function testMappersInChainWithInvalidMappers()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf('Mapper needs to implement "%s"', DataMapperInterface::class));
new ChainMapper([
'foo',
'bar'
Expand All @@ -31,6 +32,7 @@ public function testMappersInChainWithInvalidMappers()
public function testMappersInChainWithEmptyMappersArray()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf('Mapper needs to implement "%s"', DataMapperInterface::class));
new ChainMapper([
'foo',
'bar'
Expand Down
6 changes: 6 additions & 0 deletions tests/DataMapper/ReflectionMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function testProtectedGetter()
$entity->setSurname('foosurname');

$this->expectException(DataMappingException::class);
$this->expectExceptionMessage(sprintf('Method "getSurname()" is not public in class "%s"', EntityMapper::class));
$mapper->getData('surname', $entity);
}

Expand All @@ -53,6 +54,7 @@ public function testProtectedHaser()
$entity->setPrivateCollection('collection');

$this->expectException(DataMappingException::class);
$this->expectExceptionMessage(sprintf('Method "hasPrivateCollection()" is not public in class "%s"', EntityMapper::class));
$mapper->getData('private_collection', $entity);
}

Expand All @@ -72,6 +74,7 @@ public function testProtectedIser()
$entity->setProtectedReady(true);

$this->expectException(DataMappingException::class);
$this->expectExceptionMessage(sprintf('Method "isProtectedReady()" is not public in class "%s"', EntityMapper::class));
$mapper->getData('protected_ready', $entity);
}

Expand All @@ -91,6 +94,7 @@ public function testPrivateProperty()
$entity->setPrivateId('bar');

$this->expectException(DataMappingException::class);
$this->expectExceptionMessage(sprintf('Property "private_id" is not public in class "%s"', EntityMapper::class));
$mapper->getData('private_id', $entity);
}

Expand All @@ -109,6 +113,7 @@ public function testProtectedSetter()
$entity = new EntityMapper();

$this->expectException(DataMappingException::class);
$this->expectExceptionMessage(sprintf('Method "setProtectedName()" is not public in class "%s"', EntityMapper::class));
$mapper->setData('protected_name', $entity, 'fooname');
}

Expand All @@ -127,6 +132,7 @@ public function testProtectedAdder()
$entity = new EntityMapper();

$this->expectException(DataMappingException::class);
$this->expectExceptionMessage(sprintf('Method "addProtectedTag()" is not public in class "%s"', EntityMapper::class));
$mapper->setData('protected_tag', $entity, 'bar');
}
}
3 changes: 2 additions & 1 deletion tests/Extension/Core/ColumnType/ActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ActionTest extends TestCase
*/
private $column;

public function setUp()
protected function setUp()
{
$column = new Action();
$column->setName('action');
Expand All @@ -39,6 +39,7 @@ public function setUp()
public function testFilterValueEmptyActionsOptionType()
{
$this->expectException(InvalidOptionsException::class);
$this->expectExceptionMessage('The option "actions" with value "boo" is expected to be of type "array", but is of type "string".');
$this->column->setOption('actions', 'boo');
$this->column->filterValue([]);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Extension/Core/ColumnType/BooleanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BooleanTest extends TestCase
*/
private $column;

public function setUp()
protected function setUp()
{
$column = new Boolean();
$column->setName('available');
Expand Down
8 changes: 7 additions & 1 deletion tests/Extension/Core/ColumnType/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DateTimeTest extends TestCase
*/
private $column;

public function setUp()
protected function setUp()
{
$column = new DateTime();
$column->setName('datetime');
Expand Down Expand Up @@ -180,6 +180,7 @@ public function testMappingFieldsOptionInputTimestamp()
);

$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Value in column "datetime" should be timestamp but "object" type was detected. Maybe you should consider using different "input" opition value?');
$this->column->filterValue($brokenValue);
}

Expand All @@ -193,6 +194,7 @@ public function testMappingFieldsOptionInputStringMissingMappingFieldsFormat()
$this->column->setOption('input_type', 'string');

$this->expectException(DataGridColumnException::class);
$this->expectExceptionMessage('"mapping_fields_format" option is missing. Example: "mapping_fields_format" => "Y-m-d H:i:s"');
$this->column->filterValue($value);
}

Expand Down Expand Up @@ -221,6 +223,7 @@ public function testMappingFieldsOptionInputString()
);

$this->expectException(DataGridColumnException::class);
$this->expectExceptionMessage('Value in field "datetime" is not a valid string.');
$this->column->filterValue($brokenValue);
}

Expand All @@ -236,6 +239,7 @@ public function testMappingFieldsOptionInputArrayMissingMappingFieldsFormat()

$this->column->setOption('input_type', 'array');
$this->expectException(DataGridColumnException::class);
$this->expectExceptionMessage('"input_field_format" option is missing. Example: "input_field_format" => array("mapping_field_name" => array("input" => "datetime"))');
$this->column->filterValue($value);
}

Expand All @@ -256,6 +260,7 @@ public function testMappingFieldsOptionInputArrayMissingMappingFieldsFormatForDa
$this->column->setOption('input_type', 'array');

$this->expectException(DataGridColumnException::class);
$this->expectExceptionMessage('"input_field_format" option is missing. Example: "input_field_format" => array("mapping_field_name" => array("input" => "datetime"))');
$this->column->filterValue($value);
}

Expand All @@ -277,6 +282,7 @@ public function testMappingFieldsOptionInputArrayWrongMappingFieldsFormat()
]);

$this->expectException(DataGridColumnException::class);
$this->expectExceptionMessage('When using input type "string", "mapping_fields_format" option must be an string that contains valid data format');
$this->column->filterValue($value);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Extension/Core/ColumnType/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MoneyTest extends TestCase
*/
private $column;

public function setUp()
protected function setUp()
{
$column = new Money();
$column->setName('money');
Expand Down
2 changes: 1 addition & 1 deletion tests/Extension/Core/ColumnType/NumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class NumberTest extends TestCase
*/
private $column;

public function setUp()
protected function setUp()
{
$column = new Number();
$column->setName('number');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public function test_build_cell_view_without_format_and_glue_with_value_array()
->will($this->returnValue(['foo', 'bar']));

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('At least one of "value_format" or "value_glue" option is missing in column: "".');
$extension->buildCellView($column, $view);
}

Expand Down Expand Up @@ -492,6 +493,7 @@ public function test_build_cell_view_with_empty_value_that_not_exists_in_mapping
}));

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Mapping field "fo" doesn\'t exist in column: "".');
$extension->buildCellView($column, $view);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public function testBuildCellViewWithGlueAndEmptyValueAsArrayAndNotFoundKeyInEmp
->will($this->returnValue(['id2' => 'no','name' => 'no']));

$this->expectException(DataGridException::class);
$this->expectExceptionMessage('Not found key "id" in empty_value array');
$extension->buildCellView($column, $view);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Extension/Gedmo/ColumnType/Tree/TreeTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function testWrongValue()

$object = 'This is string, not object';

$this->expectException('InvalidArgumentException');
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Column "gedmo_tree" must read value from object.');
$column->getValue($object);
}

Expand Down

0 comments on commit 5ea6742

Please sign in to comment.