Skip to content

Commit b7ebf65

Browse files
authored
Adds ValidationException::getEntity() (#111)
1 parent 193530c commit b7ebf65

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

plugins/exception-render/src/ValidationException.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ public function getErrors(): array
4646

4747
return $return;
4848
}
49+
50+
/**
51+
* @return \Cake\Datasource\EntityInterface|null
52+
*/
53+
public function getEntity(): ?EntityInterface
54+
{
55+
return $this->entity;
56+
}
4957
}

plugins/exception-render/tests/TestCase/EntityValidationTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ public function test_validation_exception(): void
5151
]);
5252
}
5353

54+
public function test_validation_exception_get_entity(): void
55+
{
56+
$this->expectException(ValidationException::class);
57+
58+
new EntityValidationListener();
59+
60+
$actorsTable = new ActorsTable();
61+
$entity = $actorsTable->patchEntity($actorsTable->newEmptyEntity(), [
62+
'first_name' => '',
63+
'last_name' => ''
64+
]);
65+
$this->assertInstanceOf(EntityInterface::class, $entity);
66+
}
67+
5468
public function test_validation_exception_does_not_run_when_cli(): void
5569
{
5670
Configure::write('MixerApi.ExceptionRender.entity_validation', false);

plugins/exception-render/tests/TestCase/ValidationExceptionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ class ValidationExceptionTest extends TestCase
1010
public function test_get_errors_returns_empty_array_on_null_entity(): void
1111
{
1212
$this->assertCount(0, (new ValidationException())->getErrors());
13+
$this->assertNull((new ValidationException())->getEntity());
1314
}
1415
}

0 commit comments

Comments
 (0)