Code Duplication    Length = 42-42 lines in 3 locations

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

@@ 291-332 (lines=42) @@
288
        $this->domainManager->create($object);
289
    }
290
291
    public function testCreateWithoutFlush()
292
    {
293
        $this->resource
294
            ->expects($this->exactly(2))
295
            ->method('getName')
296
            ->will($this->returnValue($name = 'name'));
297
298
        $this->objectManager
299
            ->expects($this->once())
300
            ->method('persist')
301
            ->with($this->identicalTo($object = new \stdClass()));
302
303
        $this->objectManager
304
            ->expects($this->never())
305
            ->method('flush');
306
307
        $this->eventDispatcher
308
            ->expects($this->at(0))
309
            ->method('dispatch')
310
            ->with(
311
                $this->identicalTo('lug.'.$name.'.pre_'.($createAction = 'create')),
312
                $this->callback(function (DomainEvent $event) use ($createAction, $object) {
313
                    return $event->getResource() === $this->resource
314
                    && $event->getObject() === $object
315
                    && $event->getAction() === $createAction;
316
                })
317
            );
318
319
        $this->eventDispatcher
320
            ->expects($this->at(1))
321
            ->method('dispatch')
322
            ->with(
323
                $this->identicalTo('lug.'.$name.'.post_'.$createAction),
324
                $this->callback(function (DomainEvent $event) use ($object, $createAction) {
325
                    return $event->getResource() === $this->resource
326
                    && $event->getObject() === $object
327
                    && $event->getAction() === $createAction;
328
                })
329
            );
330
331
        $this->domainManager->create($object, false);
332
    }
333
334
    public function testCreateThrowException()
335
    {
@@ 633-674 (lines=42) @@
630
        $this->domainManager->update($object);
631
    }
632
633
    public function testUpdateWithoutFlush()
634
    {
635
        $this->resource
636
            ->expects($this->exactly(2))
637
            ->method('getName')
638
            ->will($this->returnValue($name = 'name'));
639
640
        $this->objectManager
641
            ->expects($this->once())
642
            ->method('persist')
643
            ->with($this->identicalTo($object = new \stdClass()));
644
645
        $this->objectManager
646
            ->expects($this->never())
647
            ->method('flush');
648
649
        $this->eventDispatcher
650
            ->expects($this->at(0))
651
            ->method('dispatch')
652
            ->with(
653
                $this->identicalTo('lug.'.$name.'.pre_'.($updateAction = 'update')),
654
                $this->callback(function (DomainEvent $event) use ($updateAction, $object) {
655
                    return $event->getResource() === $this->resource
656
                    && $event->getObject() === $object
657
                    && $event->getAction() === $updateAction;
658
                })
659
            );
660
661
        $this->eventDispatcher
662
            ->expects($this->at(1))
663
            ->method('dispatch')
664
            ->with(
665
                $this->identicalTo('lug.'.$name.'.post_'.$updateAction),
666
                $this->callback(function (DomainEvent $event) use ($object, $updateAction) {
667
                    return $event->getResource() === $this->resource
668
                    && $event->getObject() === $object
669
                    && $event->getAction() === $updateAction;
670
                })
671
            );
672
673
        $this->domainManager->update($object, false);
674
    }
675
676
    public function testUpdateThrowException()
677
    {
@@ 897-938 (lines=42) @@
894
        $this->domainManager->delete($object);
895
    }
896
897
    public function testDeleteWithoutFlush()
898
    {
899
        $this->resource
900
            ->expects($this->exactly(2))
901
            ->method('getName')
902
            ->will($this->returnValue($name = 'name'));
903
904
        $this->objectManager
905
            ->expects($this->once())
906
            ->method('remove')
907
            ->with($this->identicalTo($object = new \stdClass()));
908
909
        $this->objectManager
910
            ->expects($this->never())
911
            ->method('flush');
912
913
        $this->eventDispatcher
914
            ->expects($this->at(0))
915
            ->method('dispatch')
916
            ->with(
917
                $this->identicalTo('lug.'.$name.'.pre_'.($deleteAction = 'delete')),
918
                $this->callback(function (DomainEvent $event) use ($deleteAction, $object) {
919
                    return $event->getResource() === $this->resource
920
                    && $event->getObject() === $object
921
                    && $event->getAction() === $deleteAction;
922
                })
923
            );
924
925
        $this->eventDispatcher
926
            ->expects($this->at(1))
927
            ->method('dispatch')
928
            ->with(
929
                $this->identicalTo('lug.'.$name.'.post_'.$deleteAction),
930
                $this->callback(function (DomainEvent $event) use ($object, $deleteAction) {
931
                    return $event->getResource() === $this->resource
932
                    && $event->getObject() === $object
933
                    && $event->getAction() === $deleteAction;
934
                })
935
            );
936
937
        $this->domainManager->delete($object, false);
938
    }
939
940
    public function testDeleteThrowException()
941
    {