1313
1414use Doctrine \Persistence \Event \LifecycleEventArgs ;
1515use Doctrine \Persistence \Mapping \ClassMetadata ;
16+ use Doctrine \Persistence \ObjectManager ;
1617use PHPUnit \Framework \MockObject \MockObject ;
1718use PHPUnit \Framework \TestCase ;
1819use Xiidea \EasyAuditBundle \Subscriber \DoctrineSubscriber ;
1920use Xiidea \EasyAuditBundle \Tests \Fixtures \ORM \DummyEntity ;
2021use Xiidea \EasyAuditBundle \Tests \Fixtures \ORM \Movie ;
21- use Doctrine \Persistence \ObjectManager ;
2222
2323class DoctrineSubscriberTest extends TestCase
2424{
2525 /** @var MockObject */
2626 private $ dispatcher ;
2727
28-
2928 /** @var MockObject */
3029 private $ entityManager ;
3130
@@ -43,86 +42,77 @@ public function setUp(): void
4342 }
4443
4544
46- public function testCreateEventForAttributedEntity ()
47- {
48- $ subscriber = new DoctrineSubscriber (array ());
49-
50- $ this ->invokeCreatedEventCall ($ subscriber );
51- }
52-
53- public function testCreateEventForEntityNotConfiguredToTrack ()
54- {
55- $ subscriber = new DoctrineSubscriber (array ());
56- $ this ->invokeCreatedEventCall ($ subscriber , new DummyEntity ());
57- }
58-
59- public function testCreateEventForEntityConfiguredToTrack ()
60- {
61- $ subscriber = new DoctrineSubscriber (
62- array ('Xiidea\EasyAuditBundle\Tests\Fixtures\ORM\Movie ' => array ('created ' ))
63- );
64-
65- $ this ->invokeCreatedEventCall ($ subscriber );
66- }
67-
68- public function testCreateEventForEntityConfiguredToTrackAllEvents ()
45+ public function testEntityConfigureToTrackForAttributedEntity ()
6946 {
70- $ subscriber = new DoctrineSubscriber (array ( ' Xiidea\EasyAuditBundle\Tests\Fixtures\ORM\Movie ' => array ()) );
47+ $ subscriber = new DoctrineSubscriber ([] );
7148
72- $ this ->invokeCreatedEventCall ($ subscriber );
49+ $ subscriber ->setDispatcher ($ this ->dispatcher );
50+ $ subscriber ->postPersist (new LifecycleEventArgs (new Movie (), $ this ->entityManager ));
51+ $ subscriber ->postUpdate (new LifecycleEventArgs (new Movie (), $ this ->entityManager ));
52+ $ subscriber ->preRemove (new LifecycleEventArgs (new Movie (), $ this ->entityManager ));
53+ $ subscriber ->postRemove (new LifecycleEventArgs (new Movie (), $ this ->entityManager ));
54+ $ this ->assertTrue (true );
7355 }
7456
75- public function testUpdateEventForEntityNotConfiguredToTrack ()
57+ public function testEntityNotConfiguredToTrack ()
7658 {
77- $ subscriber = new DoctrineSubscriber (array ());
78- $ this ->invokeUpdatedEventCall ($ subscriber , new DummyEntity ());
59+ $ subscriber = new DoctrineSubscriber ([]);
60+ $ subscriber ->setDispatcher ($ this ->dispatcher );
61+ $ subscriber ->postPersist (new LifecycleEventArgs (new DummyEntity (), $ this ->entityManager ));
62+ $ this ->assertTrue (true );
7963 }
8064
8165 public function testRemovedEventForEntityNotConfiguredToTrack ()
8266 {
83- $ subscriber = new DoctrineSubscriber (array () );
67+ $ subscriber = new DoctrineSubscriber ([] );
8468 $ this ->invokeDeletedEventCall ($ subscriber );
69+ $ this ->assertTrue (true );
8570 }
8671
8772 public function testRemovedEventForEntityConfiguredToTrackAllEvent ()
8873 {
8974 $ this ->mockMetaData ();
90- $ subscriber = new DoctrineSubscriber (array ( 'Xiidea\EasyAuditBundle\Tests\Fixtures\ORM\Movie ' => array ()) );
75+ $ subscriber = new DoctrineSubscriber ([ 'Xiidea\EasyAuditBundle\Tests\Fixtures\ORM\Movie ' => []] );
9176 $ this ->invokeDeletedEventCall ($ subscriber );
77+ $ this ->assertTrue (true );
9278 }
9379
94-
9580 /**
96- * @param DoctrineSubscriber $subscriber
81+ * @return void
9782 */
98- private function invokeCreatedEventCall ( $ subscriber , $ entity = null )
83+ public function testCreatedEventTrackEntityViaYaml (): void
9984 {
85+ $ subscriber = new DoctrineSubscriber ([DummyEntity::class => ['created ' ]]);
10086 $ subscriber ->setDispatcher ($ this ->dispatcher );
101- $ subscriber ->postPersist (new LifecycleEventArgs ($ entity ?? new Movie (), $ this ->entityManager ));
87+ $ dummyClass = new DummyEntity ();
88+ $ subscriber ->preRemove (new LifecycleEventArgs ($ dummyClass , $ this ->entityManager ));
89+ $ subscriber ->postRemove (new LifecycleEventArgs ($ dummyClass , $ this ->entityManager ));
10290 $ this ->assertTrue (true );
10391 }
10492
105- /**
106- * @param DoctrineSubscriber $subscriber
107- */
108- private function invokeUpdatedEventCall ($ subscriber , $ entity = null )
93+
94+ public function testAnyEventToTrackConfigureViaYaml (): void
10995 {
96+ $ subscriber = new DoctrineSubscriber ([DummyEntity::class => []]);
11097 $ subscriber ->setDispatcher ($ this ->dispatcher );
111-
112- $ subscriber ->postUpdate (new LifecycleEventArgs ($ entity ?? new Movie (), $ this ->entityManager ));
98+ $ dummyClass = new DummyEntity ();
99+ $ subscriber ->preRemove (new LifecycleEventArgs ($ dummyClass , $ this ->entityManager ));
100+ $ subscriber ->postRemove (new LifecycleEventArgs ($ dummyClass , $ this ->entityManager ));
113101 $ this ->assertTrue (true );
114102 }
115103
104+
105+
116106 /**
117107 * @param DoctrineSubscriber $subscriber
118108 */
119109 private function invokeDeletedEventCall ($ subscriber )
120110 {
121111 $ subscriber ->setDispatcher ($ this ->dispatcher );
112+
122113 $ movie = new Movie ();
123114 $ subscriber ->preRemove (new LifecycleEventArgs ($ movie , $ this ->entityManager ));
124115 $ subscriber ->postRemove (new LifecycleEventArgs ($ movie , $ this ->entityManager ));
125- $ this ->assertTrue (true );
126116 }
127117
128118 private function mockMetaData ($ data = ['id ' => 1 ])
0 commit comments