Skip to content

Commit 09fe584

Browse files
committed
Introduce additional tests for the validate method
1 parent a791e83 commit 09fe584

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

tests/InvalidModelTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,13 @@ public function testSaveThrowsAValidationException()
4343
$model = new InvalidModel();
4444
$model->save();
4545
}
46+
47+
/**
48+
* @expectedException \Illuminate\Validation\ValidationException
49+
*/
50+
public function testValidateThrowsAValidationException()
51+
{
52+
$model = new InvalidModel();
53+
$model->validate();
54+
}
4655
}

tests/TestCase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,15 @@ protected function setUpContainer()
4141
return $validator;
4242
});
4343
}
44+
45+
/**
46+
* A simple helper so our test case expectations are a little more clear.
47+
*
48+
* @param mixed $value
49+
* The value that we are asserting is void.
50+
*/
51+
protected function assertVoid($value)
52+
{
53+
$this->assertNull($value);
54+
}
4455
}

tests/ModelTest.php renamed to tests/ValidModelTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Database\Eloquent\Model as EloquentModel;
77
use Jaspaul\EloquentModelValidation\Contracts\Validatable;
88

9-
class ModelTest extends TestCase
9+
class ValidModelTest extends TestCase
1010
{
1111
public function testItCanBeConstructed()
1212
{
@@ -27,4 +27,10 @@ public function testGetErrorsReturnsAnEmptyMessageBag()
2727
$errors = $model->getErrors();
2828
$this->assertTrue($errors->isEmpty());
2929
}
30+
31+
public function testValidateDoesNotThrowAValidationException()
32+
{
33+
$model = new ValidModel();
34+
$this->assertVoid($model->validate());
35+
}
3036
}

0 commit comments

Comments
 (0)