Code Duplication    Length = 66-66 lines in 2 locations

src/Component/Resource/Tests/Domain/DomainManagerTest.php 2 locations

@@ 224-289 (lines=66) @@
221
        $this->assertNull($this->domainManager->find($action, $repositoryMethod, $criteria, $sorting));
222
    }
223
224
    public function testCreate()
225
    {
226
        $this->resource
227
            ->expects($this->exactly(4))
228
            ->method('getName')
229
            ->will($this->returnValue($name = 'name'));
230
231
        $this->objectManager
232
            ->expects($this->once())
233
            ->method('persist')
234
            ->with($this->identicalTo($data = new \stdClass()));
235
236
        $this->objectManager
237
            ->expects($this->once())
238
            ->method('flush');
239
240
        $this->eventDispatcher
241
            ->expects($this->at(0))
242
            ->method('dispatch')
243
            ->with(
244
                $this->identicalTo('lug.'.$name.'.pre_'.($createAction = 'create')),
245
                $this->callback(function (DomainEvent $event) use ($createAction, $data) {
246
                    return $event->getResource() === $this->resource
247
                        && $event->getData() === $data
248
                        && $event->getAction() === $createAction;
249
                })
250
            );
251
252
        $this->eventDispatcher
253
            ->expects($this->at(1))
254
            ->method('dispatch')
255
            ->with(
256
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
257
                $this->callback(function (DomainEvent $event) use ($flushAction, $data) {
258
                    return $event->getResource() === $this->resource
259
                        && $event->getData() === $data
260
                        && $event->getAction() === $flushAction;
261
                })
262
            );
263
264
        $this->eventDispatcher
265
            ->expects($this->at(2))
266
            ->method('dispatch')
267
            ->with(
268
                $this->identicalTo('lug.'.$name.'.post_'.$flushAction),
269
                $this->callback(function (DomainEvent $event) use ($flushAction, $data) {
270
                    return $event->getResource() === $this->resource
271
                        && $event->getData() === $data
272
                        && $event->getAction() === $flushAction;
273
                })
274
            );
275
276
        $this->eventDispatcher
277
            ->expects($this->at(3))
278
            ->method('dispatch')
279
            ->with(
280
                $this->identicalTo('lug.'.$name.'.post_'.$createAction),
281
                $this->callback(function (DomainEvent $event) use ($data, $createAction) {
282
                    return $event->getResource() === $this->resource
283
                        && $event->getData() === $data
284
                        && $event->getAction() === $createAction;
285
                })
286
            );
287
288
        $this->domainManager->create($data);
289
    }
290
291
    public function testCreateWithoutFlush()
292
    {
@@ 842-907 (lines=66) @@
839
        $this->domainManager->update($data);
840
    }
841
842
    public function testDelete()
843
    {
844
        $this->resource
845
            ->expects($this->exactly(4))
846
            ->method('getName')
847
            ->will($this->returnValue($name = 'name'));
848
849
        $this->objectManager
850
            ->expects($this->once())
851
            ->method('remove')
852
            ->with($this->identicalTo($data = new \stdClass()));
853
854
        $this->objectManager
855
            ->expects($this->once())
856
            ->method('flush');
857
858
        $this->eventDispatcher
859
            ->expects($this->at(0))
860
            ->method('dispatch')
861
            ->with(
862
                $this->identicalTo('lug.'.$name.'.pre_'.($deleteAction = 'delete')),
863
                $this->callback(function (DomainEvent $event) use ($deleteAction, $data) {
864
                    return $event->getResource() === $this->resource
865
                    && $event->getData() === $data
866
                    && $event->getAction() === $deleteAction;
867
                })
868
            );
869
870
        $this->eventDispatcher
871
            ->expects($this->at(1))
872
            ->method('dispatch')
873
            ->with(
874
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
875
                $this->callback(function (DomainEvent $event) use ($flushAction, $data) {
876
                    return $event->getResource() === $this->resource
877
                    && $event->getData() === $data
878
                    && $event->getAction() === $flushAction;
879
                })
880
            );
881
882
        $this->eventDispatcher
883
            ->expects($this->at(2))
884
            ->method('dispatch')
885
            ->with(
886
                $this->identicalTo('lug.'.$name.'.post_'.$flushAction),
887
                $this->callback(function (DomainEvent $event) use ($flushAction, $data) {
888
                    return $event->getResource() === $this->resource
889
                    && $event->getData() === $data
890
                    && $event->getAction() === $flushAction;
891
                })
892
            );
893
894
        $this->eventDispatcher
895
            ->expects($this->at(3))
896
            ->method('dispatch')
897
            ->with(
898
                $this->identicalTo('lug.'.$name.'.post_'.$deleteAction),
899
                $this->callback(function (DomainEvent $event) use ($data, $deleteAction) {
900
                    return $event->getResource() === $this->resource
901
                    && $event->getData() === $data
902
                    && $event->getAction() === $deleteAction;
903
                })
904
            );
905
906
        $this->domainManager->delete($data);
907
    }
908
909
    public function testDeleteWithoutFlush()
910
    {