1 | <?php declare(strict_types = 1); |
||||
2 | |||||
3 | namespace Bukashk0zzz\FilterBundle\Tests\EventListener; |
||||
4 | |||||
5 | use Bukashk0zzz\FilterBundle\EventListener\FilterSubscriber; |
||||
6 | use Bukashk0zzz\FilterBundle\Service\Filter; |
||||
7 | use Bukashk0zzz\FilterBundle\Tests\Fixtures\User; |
||||
8 | use Doctrine\Common\Annotations\AnnotationReader; |
||||
9 | use Doctrine\Common\Annotations\CachedReader; |
||||
10 | use Doctrine\Common\Cache\Psr6\DoctrineProvider; |
||||
11 | use Doctrine\ORM\Event\LifecycleEventArgs; |
||||
12 | use PHPUnit\Framework\MockObject\MockObject; |
||||
13 | use PHPUnit\Framework\TestCase; |
||||
14 | use Symfony\Component\Cache\Adapter\ArrayAdapter; |
||||
15 | |||||
16 | /** |
||||
17 | * FilterSubscriberTest. |
||||
18 | * |
||||
19 | * @internal |
||||
20 | */ |
||||
21 | final class FilterSubscriberTest extends TestCase |
||||
22 | { |
||||
23 | /** |
||||
24 | * Test persist event. |
||||
25 | */ |
||||
26 | public function testPersist(): void |
||||
27 | { |
||||
28 | $user = new User(); |
||||
29 | $cache = DoctrineProvider::wrap( |
||||
30 | new ArrayAdapter() |
||||
31 | ); |
||||
32 | $filter = new Filter(new CachedReader(new AnnotationReader(), $cache)); |
||||
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||||
33 | |||||
34 | $lifeCycleEvent = $this->mockEvent('LifecycleEventArgs'); |
||||
35 | $lifeCycleEvent->expects(static::once())->method('getEntity')->willReturn($user); |
||||
36 | |||||
37 | /** @var LifecycleEventArgs $lifeCycleEvent */ |
||||
38 | $subscriber = new FilterSubscriber($filter); |
||||
39 | $subscriber->prePersist($lifeCycleEvent); |
||||
40 | } |
||||
41 | |||||
42 | /** |
||||
43 | * Test update event. |
||||
44 | */ |
||||
45 | public function testUpdate(): void |
||||
46 | { |
||||
47 | $user = new User(); |
||||
48 | $cache = DoctrineProvider::wrap( |
||||
49 | new ArrayAdapter() |
||||
50 | ); |
||||
51 | $filter = new Filter(new CachedReader(new AnnotationReader(), $cache)); |
||||
0 ignored issues
–
show
The class
Doctrine\Common\Annotations\CachedReader has been deprecated: the CachedReader is deprecated and will be removed in version 2.0.0 of doctrine/annotations. Please use the {@see \Doctrine\Common\Annotations\PsrCachedReader} instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
52 | |||||
53 | $lifeCycleEvent = $this->mockEvent('LifecycleEventArgs'); |
||||
54 | $lifeCycleEvent->expects(static::once())->method('getEntity')->willReturn($user); |
||||
55 | |||||
56 | /** @var LifecycleEventArgs $lifeCycleEvent */ |
||||
57 | $subscriber = new FilterSubscriber($filter); |
||||
58 | $subscriber->preUpdate($lifeCycleEvent); |
||||
59 | } |
||||
60 | |||||
61 | /** |
||||
62 | * Test get subscribed events. |
||||
63 | */ |
||||
64 | public function testSubscription(): void |
||||
65 | { |
||||
66 | $cache = DoctrineProvider::wrap( |
||||
67 | new ArrayAdapter() |
||||
68 | ); |
||||
69 | $filter = new Filter(new CachedReader(new AnnotationReader(), $cache)); |
||||
0 ignored issues
–
show
The class
Doctrine\Common\Annotations\CachedReader has been deprecated: the CachedReader is deprecated and will be removed in version 2.0.0 of doctrine/annotations. Please use the {@see \Doctrine\Common\Annotations\PsrCachedReader} instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
70 | $subscriber = new FilterSubscriber($filter); |
||||
71 | static::assertSame([ |
||||
72 | 'prePersist', |
||||
73 | 'preUpdate', |
||||
74 | ], $subscriber->getSubscribedEvents()); |
||||
75 | } |
||||
76 | |||||
77 | /** |
||||
78 | * Mock a lifeCycleEventArgs Object. |
||||
79 | */ |
||||
80 | private function mockEvent(string $eventType): MockObject |
||||
81 | { |
||||
82 | return $this->createPartialMock( |
||||
83 | '\Doctrine\ORM\Event\\'.$eventType, |
||||
84 | ['getEntityManager', 'getEntity'], |
||||
85 | ); |
||||
86 | } |
||||
87 | } |
||||
88 |