Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
adding test for failure states when validating
Browse files Browse the repository at this point in the history
  • Loading branch information
thepsion5 committed Feb 26, 2016
1 parent f53db3d commit 386e9bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/CrudKit/Data/SQLDataProvider.php
Expand Up @@ -179,6 +179,7 @@ protected function processColumns () {
$target = new ExternalColumn ($id, $category, $opts);
break;
default:
//TODO: Throw library-specific exceptions
throw new \Exception("Unknown category for column $category");
}

Expand Down Expand Up @@ -264,6 +265,7 @@ protected function queryColumns ($queryType, $queryValues, $valueType, $keyValue
$resultItem = $column->getSummaryConfig();
break;
default:
//TODO: Throw library-specific exceptions
throw new \Exception("Unknown value type $valueType");
}

Expand Down Expand Up @@ -441,6 +443,7 @@ public function setRow($id = null, array $values = [])
/** @var SQLColumn $col */
$col = null;
if(!isset($this->columns[$formKey])) {
//TODO: Throw library-specific exceptions
throw new \Exception ("Unknown column");
}
$col = $this->columns[$formKey];
Expand Down Expand Up @@ -473,6 +476,7 @@ public function createItem(array $values)
/** @var SQLColumn $col */
$col = null;
if(!isset($this->columns[$formKey])) {
//TODO: Throw library-specific exceptions
throw new \Exception ("Unknown column");
}
$col = $this->columns[$formKey];
Expand Down Expand Up @@ -560,6 +564,7 @@ public function getRelationshipValues ($id, $foreign) {
return $extProvider->getForeignValues($forOpts['fk_extKey'], $id);
}
else {
//TODO: Throw library-specific exceptions
throw new \Exception("Unknown relationship value");
}
return array();
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/Data/SQLDataProviderTest.php
Expand Up @@ -265,6 +265,17 @@ public function it_validates_a_row_of_data_for_missing_fields()
$this->assertArrayHasKey('LastName', $errorsForInvalidData);
}


/**
* @test
* @expectedException \Exception
*/
public function it_throws_an_exception_if_validating_a_row_for_missing_fields_with_unknown_columns()
{
$unknownColumn = ['Foo' => 'Bar'];
SqlDataProviderFactory::defaultSqlDataProvider()->validateRequiredRow($unknownColumn);
}

/** @test */
public function it_validates_a_row_of_data_using_a_custom_validator()
{
Expand Down Expand Up @@ -292,6 +303,17 @@ public function it_validates_a_row_of_data_using_a_custom_validator()
$this->assertEquals($invalidData['Email'], $failuresForInvalidData['Email']);
}

/**
* @test
* @expectedException \Exception
*/
public function it_throws_an_exception_if_validating_a_row_with_unknown_columns()
{
$unknownColumn = ['Foo' => 'Bar'];

SqlDataProviderFactory::defaultSqlDataProvider()->validateRow($unknownColumn);
}

public function tearDown()
{
parent::tearDown();
Expand Down

0 comments on commit 386e9bb

Please sign in to comment.