Code Duplication    Length = 71-71 lines in 3 locations

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

@@ 416-486 (lines=71) @@
413
        }
414
    }
415
416
    public function testCreateByPassException()
417
    {
418
        $this->resource
419
            ->expects($this->exactly(4))
420
            ->method('getName')
421
            ->will($this->returnValue($name = 'name'));
422
423
        $this->objectManager
424
            ->expects($this->once())
425
            ->method('persist')
426
            ->with($this->identicalTo($object = new \stdClass()));
427
428
        $this->objectManager
429
            ->expects($this->once())
430
            ->method('flush')
431
            ->will($this->throwException(new \Exception()));
432
433
        $this->eventDispatcher
434
            ->expects($this->at(0))
435
            ->method('dispatch')
436
            ->with(
437
                $this->identicalTo('lug.'.$name.'.pre_'.($createAction = 'create')),
438
                $this->callback(function (DomainEvent $event) use ($createAction, $object) {
439
                    return $event->getResource() === $this->resource
440
                    && $event->getObject() === $object
441
                    && $event->getAction() === $createAction;
442
                })
443
            );
444
445
        $this->eventDispatcher
446
            ->expects($this->at(1))
447
            ->method('dispatch')
448
            ->with(
449
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
450
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
451
                    return $event->getResource() === $this->resource
452
                    && $event->getObject() === $object
453
                    && $event->getAction() === $flushAction;
454
                })
455
            );
456
457
        $this->eventDispatcher
458
            ->expects($this->at(2))
459
            ->method('dispatch')
460
            ->with(
461
                $this->identicalTo('lug.'.$name.'.error_'.$flushAction),
462
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
463
                    return $event->getResource() === $this->resource
464
                    && $event->getObject() === $object
465
                    && $event->getAction() === $flushAction;
466
                })
467
            );
468
469
        $this->eventDispatcher
470
            ->expects($this->at(3))
471
            ->method('dispatch')
472
            ->with(
473
                $this->identicalTo('lug.'.$name.'.error_'.$createAction),
474
                $this->callback(function (DomainEvent $event) use ($object, $createAction) {
475
                    $result = $event->getResource() === $this->resource
476
                        && $event->getObject() === $object
477
                        && $event->getAction() === $createAction;
478
479
                    $event->setStopped(false);
480
481
                    return $result;
482
                })
483
            );
484
485
        $this->domainManager->create($object);
486
    }
487
488
    public function testUpdateWithManagedObject()
489
    {
@@ 758-828 (lines=71) @@
755
        }
756
    }
757
758
    public function testUpdateByPassException()
759
    {
760
        $this->resource
761
            ->expects($this->exactly(4))
762
            ->method('getName')
763
            ->will($this->returnValue($name = 'name'));
764
765
        $this->objectManager
766
            ->expects($this->once())
767
            ->method('persist')
768
            ->with($this->identicalTo($object = new \stdClass()));
769
770
        $this->objectManager
771
            ->expects($this->once())
772
            ->method('flush')
773
            ->will($this->throwException(new \Exception()));
774
775
        $this->eventDispatcher
776
            ->expects($this->at(0))
777
            ->method('dispatch')
778
            ->with(
779
                $this->identicalTo('lug.'.$name.'.pre_'.($updateAction = 'update')),
780
                $this->callback(function (DomainEvent $event) use ($updateAction, $object) {
781
                    return $event->getResource() === $this->resource
782
                    && $event->getObject() === $object
783
                    && $event->getAction() === $updateAction;
784
                })
785
            );
786
787
        $this->eventDispatcher
788
            ->expects($this->at(1))
789
            ->method('dispatch')
790
            ->with(
791
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
792
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
793
                    return $event->getResource() === $this->resource
794
                    && $event->getObject() === $object
795
                    && $event->getAction() === $flushAction;
796
                })
797
            );
798
799
        $this->eventDispatcher
800
            ->expects($this->at(2))
801
            ->method('dispatch')
802
            ->with(
803
                $this->identicalTo('lug.'.$name.'.error_'.$flushAction),
804
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
805
                    return $event->getResource() === $this->resource
806
                    && $event->getObject() === $object
807
                    && $event->getAction() === $flushAction;
808
                })
809
            );
810
811
        $this->eventDispatcher
812
            ->expects($this->at(3))
813
            ->method('dispatch')
814
            ->with(
815
                $this->identicalTo('lug.'.$name.'.error_'.$updateAction),
816
                $this->callback(function (DomainEvent $event) use ($object, $updateAction) {
817
                    $result = $event->getResource() === $this->resource
818
                        && $event->getObject() === $object
819
                        && $event->getAction() === $updateAction;
820
821
                    $event->setStopped(false);
822
823
                    return $result;
824
                })
825
            );
826
827
        $this->domainManager->update($object);
828
    }
829
830
    public function testDelete()
831
    {
@@ 1022-1092 (lines=71) @@
1019
        }
1020
    }
1021
1022
    public function testDeleteByPassException()
1023
    {
1024
        $this->resource
1025
            ->expects($this->exactly(4))
1026
            ->method('getName')
1027
            ->will($this->returnValue($name = 'name'));
1028
1029
        $this->objectManager
1030
            ->expects($this->once())
1031
            ->method('remove')
1032
            ->with($this->identicalTo($object = new \stdClass()));
1033
1034
        $this->objectManager
1035
            ->expects($this->once())
1036
            ->method('flush')
1037
            ->will($this->throwException(new \Exception()));
1038
1039
        $this->eventDispatcher
1040
            ->expects($this->at(0))
1041
            ->method('dispatch')
1042
            ->with(
1043
                $this->identicalTo('lug.'.$name.'.pre_'.($deleteAction = 'delete')),
1044
                $this->callback(function (DomainEvent $event) use ($deleteAction, $object) {
1045
                    return $event->getResource() === $this->resource
1046
                    && $event->getObject() === $object
1047
                    && $event->getAction() === $deleteAction;
1048
                })
1049
            );
1050
1051
        $this->eventDispatcher
1052
            ->expects($this->at(1))
1053
            ->method('dispatch')
1054
            ->with(
1055
                $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')),
1056
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
1057
                    return $event->getResource() === $this->resource
1058
                    && $event->getObject() === $object
1059
                    && $event->getAction() === $flushAction;
1060
                })
1061
            );
1062
1063
        $this->eventDispatcher
1064
            ->expects($this->at(2))
1065
            ->method('dispatch')
1066
            ->with(
1067
                $this->identicalTo('lug.'.$name.'.error_'.$flushAction),
1068
                $this->callback(function (DomainEvent $event) use ($flushAction, $object) {
1069
                    return $event->getResource() === $this->resource
1070
                    && $event->getObject() === $object
1071
                    && $event->getAction() === $flushAction;
1072
                })
1073
            );
1074
1075
        $this->eventDispatcher
1076
            ->expects($this->at(3))
1077
            ->method('dispatch')
1078
            ->with(
1079
                $this->identicalTo('lug.'.$name.'.error_'.$deleteAction),
1080
                $this->callback(function (DomainEvent $event) use ($object, $deleteAction) {
1081
                    $result = $event->getResource() === $this->resource
1082
                        && $event->getObject() === $object
1083
                        && $event->getAction() === $deleteAction;
1084
1085
                    $event->setStopped(false);
1086
1087
                    return $result;
1088
                })
1089
            );
1090
1091
        $this->domainManager->delete($object);
1092
    }
1093
1094
    public function testFlush()
1095
    {