|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Small\Exception; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Exception\ValidationException; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\MockEntityFactory; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Symfony\Component\Validator\ConstraintViolationList; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class ValidationExceptionTest |
|
12
|
|
|
* |
|
13
|
|
|
* @package EdmondsCommerce\DoctrineStaticMeta\Exception |
|
14
|
|
|
* @SuppressWarnings(PHPMD.UnusedLocalVariable) |
|
15
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
16
|
|
|
* @coversDefaultClass \EdmondsCommerce\DoctrineStaticMeta\Exception\ValidationException |
|
17
|
|
|
*/ |
|
18
|
|
|
class ValidationExceptionTest extends TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var ValidationException |
|
22
|
|
|
*/ |
|
23
|
|
|
private $exception; |
|
24
|
|
|
|
|
25
|
|
|
private $errors; |
|
26
|
|
|
|
|
27
|
|
|
private $entity; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
|
31
|
|
|
*/ |
|
32
|
|
|
public function setup() |
|
33
|
|
|
{ |
|
34
|
|
|
try { |
|
35
|
|
|
$this->errors = new ConstraintViolationList(); |
|
36
|
|
|
$this->entity = MockEntityFactory::createMockEntity(); |
|
37
|
|
|
throw new ValidationException($this->errors, $this->entity); |
|
38
|
|
|
} catch (ValidationException $e) { |
|
39
|
|
|
$this->exception = $e; |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @test |
|
45
|
|
|
* @small |
|
46
|
|
|
* @covers ::getInvalidEntity |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getInvalidEntity(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$expected = $this->entity; |
|
51
|
|
|
$actual = $this->exception->getInvalidEntity(); |
|
52
|
|
|
self::assertSame($expected, $actual); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @test |
|
57
|
|
|
* @small |
|
58
|
|
|
* @covers ::getValidationErrors |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getValidationErrors(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$expected = $this->errors; |
|
63
|
|
|
$actual = $this->exception->getValidationErrors(); |
|
64
|
|
|
self::assertSame($expected, $actual); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|