Test Failed
Pull Request — master (#8)
by Alex
03:59
created

EntityErrorEventTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArpTest\DoctrineEntityRepository\Persistence;
6
7
use Arp\DoctrineEntityRepository\Constant\EntityEventName;
8
use Arp\DoctrineEntityRepository\Persistence\Event\EntityErrorEvent;
9
use Arp\Entity\EntityInterface;
10
use Arp\EventDispatcher\Resolver\EventNameAwareInterface;
11
use Doctrine\ORM\EntityManagerInterface;
12
use PHPUnit\Framework\MockObject\MockObject;
13
use PHPUnit\Framework\TestCase;
14
15
/**
16
 * @covers  \Arp\DoctrineEntityRepository\Persistence\Event\EntityErrorEvent
17
 *
18
 * @author  Alex Patterson <[email protected]>
19
 * @package ArpTest\DoctrineEntityRepository\Persistence
20
 */
21
final class EntityErrorEventTest extends TestCase
22
{
23
    /**
24
     * @var string
25
     */
26
    private string $eventName;
27
28
    /**
29
     * @var string
30
     */
31
    private string $entityName = EntityInterface::class;
32
33
    /**
34
     * @var EntityManagerInterface&MockObject
35
     */
36
    private $entityManager;
37
38
    /**
39
     * @var \Throwable
40
     */
41
    private \Throwable $exception;
42
43
    /**
44
     * @var array<mixed>
45
     */
46
    private array $params = [];
47
48
    /**
49
     * Prepare the test case dependencies
50
     */
51
    public function setUp(): void
52
    {
53
        $this->eventName = EntityEventName::CREATE_ERROR;
54
55
        $this->entityManager = $this->createMock(EntityManagerInterface::class);
56
57
        $this->exception = new \Exception('This is a test exception message');
58
    }
59
60
    /**
61
     * Assert that the event implement EventNameAwareInterface
62
     */
63
    public function testIsInstanceOfEventNameAwareInterface(): void
64
    {
65
        $event = new EntityErrorEvent(
66
            $this->eventName,
67
            $this->entityName,
0 ignored issues
show
Bug introduced by
$this->entityName of type string is incompatible with the type Arp\DoctrineEntityReposi...PersistServiceInterface expected by parameter $persistService of Arp\DoctrineEntityReposi...rorEvent::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
            /** @scrutinizer ignore-type */ $this->entityName,
Loading history...
68
            $this->entityManager,
69
            $this->exception,
0 ignored issues
show
Bug introduced by
$this->exception of type Throwable is incompatible with the type Psr\Log\LoggerInterface expected by parameter $logger of Arp\DoctrineEntityReposi...rorEvent::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

69
            /** @scrutinizer ignore-type */ $this->exception,
Loading history...
70
            $this->params
0 ignored issues
show
Bug introduced by
$this->params of type array is incompatible with the type Throwable|null expected by parameter $exception of Arp\DoctrineEntityReposi...rorEvent::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

70
            /** @scrutinizer ignore-type */ $this->params
Loading history...
71
        );
72
73
        $this->assertInstanceOf(EventNameAwareInterface::class, $event);
74
    }
75
76
    /**
77
     * Assert the constructor set exception class is returned from getException()
78
     */
79
    public function testGetExceptionWillReturnException(): void
80
    {
81
        $event = new EntityErrorEvent(
82
            $this->eventName,
83
            $this->entityName,
0 ignored issues
show
Bug introduced by
$this->entityName of type string is incompatible with the type Arp\DoctrineEntityReposi...PersistServiceInterface expected by parameter $persistService of Arp\DoctrineEntityReposi...rorEvent::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

83
            /** @scrutinizer ignore-type */ $this->entityName,
Loading history...
84
            $this->entityManager,
85
            $this->exception,
0 ignored issues
show
Bug introduced by
$this->exception of type Throwable is incompatible with the type Psr\Log\LoggerInterface expected by parameter $logger of Arp\DoctrineEntityReposi...rorEvent::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

85
            /** @scrutinizer ignore-type */ $this->exception,
Loading history...
86
            $this->params
0 ignored issues
show
Bug introduced by
$this->params of type array is incompatible with the type Throwable|null expected by parameter $exception of Arp\DoctrineEntityReposi...rorEvent::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

86
            /** @scrutinizer ignore-type */ $this->params
Loading history...
87
        );
88
89
        $this->assertSame($this->exception, $event->getException());
90
    }
91
92
    /**
93
     * Assert that the exception can be set and get via setException() and getException()
94
     */
95
    public function testSetAndGetException(): void
96
    {
97
        $event = new EntityErrorEvent(
98
            $this->eventName,
99
            $this->entityName,
0 ignored issues
show
Bug introduced by
$this->entityName of type string is incompatible with the type Arp\DoctrineEntityReposi...PersistServiceInterface expected by parameter $persistService of Arp\DoctrineEntityReposi...rorEvent::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

99
            /** @scrutinizer ignore-type */ $this->entityName,
Loading history...
100
            $this->entityManager,
101
            $this->exception,
0 ignored issues
show
Bug introduced by
$this->exception of type Throwable is incompatible with the type Psr\Log\LoggerInterface expected by parameter $logger of Arp\DoctrineEntityReposi...rorEvent::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

101
            /** @scrutinizer ignore-type */ $this->exception,
Loading history...
102
            $this->params
0 ignored issues
show
Bug introduced by
$this->params of type array is incompatible with the type Throwable|null expected by parameter $exception of Arp\DoctrineEntityReposi...rorEvent::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

102
            /** @scrutinizer ignore-type */ $this->params
Loading history...
103
        );
104
105
        $newException = new \Exception('This is a new exception message');
106
107
        $event->setException($newException);
108
109
        $this->assertSame($newException, $event->getException());
110
    }
111
}
112