@@ 334-414 (lines=81) @@ | ||
331 | $this->domainManager->create($object, false); |
|
332 | } |
|
333 | ||
334 | public function testCreateThrowException() |
|
335 | { |
|
336 | $this->resource |
|
337 | ->expects($this->exactly(4)) |
|
338 | ->method('getName') |
|
339 | ->will($this->returnValue($name = 'name')); |
|
340 | ||
341 | $this->objectManager |
|
342 | ->expects($this->once()) |
|
343 | ->method('persist') |
|
344 | ->with($this->identicalTo($object = new \stdClass())); |
|
345 | ||
346 | $this->objectManager |
|
347 | ->expects($this->once()) |
|
348 | ->method('flush') |
|
349 | ->will($this->throwException(new \Exception())); |
|
350 | ||
351 | $this->eventDispatcher |
|
352 | ->expects($this->at(0)) |
|
353 | ->method('dispatch') |
|
354 | ->with( |
|
355 | $this->identicalTo('lug.'.$name.'.pre_'.($createAction = 'create')), |
|
356 | $this->callback(function (DomainEvent $event) use ($createAction, $object) { |
|
357 | return $event->getResource() === $this->resource |
|
358 | && $event->getObject() === $object |
|
359 | && $event->getAction() === $createAction; |
|
360 | }) |
|
361 | ); |
|
362 | ||
363 | $this->eventDispatcher |
|
364 | ->expects($this->at(1)) |
|
365 | ->method('dispatch') |
|
366 | ->with( |
|
367 | $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')), |
|
368 | $this->callback(function (DomainEvent $event) use ($flushAction, $object) { |
|
369 | return $event->getResource() === $this->resource |
|
370 | && $event->getObject() === $object |
|
371 | && $event->getAction() === $flushAction; |
|
372 | }) |
|
373 | ); |
|
374 | ||
375 | $this->eventDispatcher |
|
376 | ->expects($this->at(2)) |
|
377 | ->method('dispatch') |
|
378 | ->with( |
|
379 | $this->identicalTo('lug.'.$name.'.error_'.$flushAction), |
|
380 | $this->callback(function (DomainEvent $event) use ($flushAction, $object) { |
|
381 | return $event->getResource() === $this->resource |
|
382 | && $event->getObject() === $object |
|
383 | && $event->getAction() === $flushAction; |
|
384 | }) |
|
385 | ); |
|
386 | ||
387 | $statusCode = Response::HTTP_BAD_REQUEST; |
|
388 | $message = 'message'; |
|
389 | ||
390 | $this->eventDispatcher |
|
391 | ->expects($this->at(3)) |
|
392 | ->method('dispatch') |
|
393 | ->with( |
|
394 | $this->identicalTo('lug.'.$name.'.error_'.$createAction), |
|
395 | $this->callback(function (DomainEvent $event) use ($object, $createAction, $statusCode, $message) { |
|
396 | $result = $event->getResource() === $this->resource |
|
397 | && $event->getObject() === $object |
|
398 | && $event->getAction() === $createAction; |
|
399 | ||
400 | $event->setStatusCode($statusCode); |
|
401 | $event->setMessage($message); |
|
402 | ||
403 | return $result; |
|
404 | }) |
|
405 | ); |
|
406 | ||
407 | try { |
|
408 | $this->domainManager->create($object); |
|
409 | $this->fail(); |
|
410 | } catch (DomainException $e) { |
|
411 | $this->assertSame($statusCode, $e->getStatusCode()); |
|
412 | $this->assertSame($message, $e->getMessage()); |
|
413 | } |
|
414 | } |
|
415 | ||
416 | public function testCreateByPassException() |
|
417 | { |
|
@@ 676-756 (lines=81) @@ | ||
673 | $this->domainManager->update($object, false); |
|
674 | } |
|
675 | ||
676 | public function testUpdateThrowException() |
|
677 | { |
|
678 | $this->resource |
|
679 | ->expects($this->exactly(4)) |
|
680 | ->method('getName') |
|
681 | ->will($this->returnValue($name = 'name')); |
|
682 | ||
683 | $this->objectManager |
|
684 | ->expects($this->once()) |
|
685 | ->method('persist') |
|
686 | ->with($this->identicalTo($object = new \stdClass())); |
|
687 | ||
688 | $this->objectManager |
|
689 | ->expects($this->once()) |
|
690 | ->method('flush') |
|
691 | ->will($this->throwException(new \Exception())); |
|
692 | ||
693 | $this->eventDispatcher |
|
694 | ->expects($this->at(0)) |
|
695 | ->method('dispatch') |
|
696 | ->with( |
|
697 | $this->identicalTo('lug.'.$name.'.pre_'.($updateAction = 'update')), |
|
698 | $this->callback(function (DomainEvent $event) use ($updateAction, $object) { |
|
699 | return $event->getResource() === $this->resource |
|
700 | && $event->getObject() === $object |
|
701 | && $event->getAction() === $updateAction; |
|
702 | }) |
|
703 | ); |
|
704 | ||
705 | $this->eventDispatcher |
|
706 | ->expects($this->at(1)) |
|
707 | ->method('dispatch') |
|
708 | ->with( |
|
709 | $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')), |
|
710 | $this->callback(function (DomainEvent $event) use ($flushAction, $object) { |
|
711 | return $event->getResource() === $this->resource |
|
712 | && $event->getObject() === $object |
|
713 | && $event->getAction() === $flushAction; |
|
714 | }) |
|
715 | ); |
|
716 | ||
717 | $this->eventDispatcher |
|
718 | ->expects($this->at(2)) |
|
719 | ->method('dispatch') |
|
720 | ->with( |
|
721 | $this->identicalTo('lug.'.$name.'.error_'.$flushAction), |
|
722 | $this->callback(function (DomainEvent $event) use ($flushAction, $object) { |
|
723 | return $event->getResource() === $this->resource |
|
724 | && $event->getObject() === $object |
|
725 | && $event->getAction() === $flushAction; |
|
726 | }) |
|
727 | ); |
|
728 | ||
729 | $statusCode = Response::HTTP_BAD_REQUEST; |
|
730 | $message = 'message'; |
|
731 | ||
732 | $this->eventDispatcher |
|
733 | ->expects($this->at(3)) |
|
734 | ->method('dispatch') |
|
735 | ->with( |
|
736 | $this->identicalTo('lug.'.$name.'.error_'.$updateAction), |
|
737 | $this->callback(function (DomainEvent $event) use ($object, $updateAction, $statusCode, $message) { |
|
738 | $result = $event->getResource() === $this->resource |
|
739 | && $event->getObject() === $object |
|
740 | && $event->getAction() === $updateAction; |
|
741 | ||
742 | $event->setStatusCode($statusCode); |
|
743 | $event->setMessage($message); |
|
744 | ||
745 | return $result; |
|
746 | }) |
|
747 | ); |
|
748 | ||
749 | try { |
|
750 | $this->domainManager->update($object); |
|
751 | $this->fail(); |
|
752 | } catch (DomainException $e) { |
|
753 | $this->assertSame($statusCode, $e->getStatusCode()); |
|
754 | $this->assertSame($message, $e->getMessage()); |
|
755 | } |
|
756 | } |
|
757 | ||
758 | public function testUpdateByPassException() |
|
759 | { |
|
@@ 940-1020 (lines=81) @@ | ||
937 | $this->domainManager->delete($object, false); |
|
938 | } |
|
939 | ||
940 | public function testDeleteThrowException() |
|
941 | { |
|
942 | $this->resource |
|
943 | ->expects($this->exactly(4)) |
|
944 | ->method('getName') |
|
945 | ->will($this->returnValue($name = 'name')); |
|
946 | ||
947 | $this->objectManager |
|
948 | ->expects($this->once()) |
|
949 | ->method('remove') |
|
950 | ->with($this->identicalTo($object = new \stdClass())); |
|
951 | ||
952 | $this->objectManager |
|
953 | ->expects($this->once()) |
|
954 | ->method('flush') |
|
955 | ->will($this->throwException(new \Exception())); |
|
956 | ||
957 | $this->eventDispatcher |
|
958 | ->expects($this->at(0)) |
|
959 | ->method('dispatch') |
|
960 | ->with( |
|
961 | $this->identicalTo('lug.'.$name.'.pre_'.($deleteAction = 'delete')), |
|
962 | $this->callback(function (DomainEvent $event) use ($deleteAction, $object) { |
|
963 | return $event->getResource() === $this->resource |
|
964 | && $event->getObject() === $object |
|
965 | && $event->getAction() === $deleteAction; |
|
966 | }) |
|
967 | ); |
|
968 | ||
969 | $this->eventDispatcher |
|
970 | ->expects($this->at(1)) |
|
971 | ->method('dispatch') |
|
972 | ->with( |
|
973 | $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')), |
|
974 | $this->callback(function (DomainEvent $event) use ($flushAction, $object) { |
|
975 | return $event->getResource() === $this->resource |
|
976 | && $event->getObject() === $object |
|
977 | && $event->getAction() === $flushAction; |
|
978 | }) |
|
979 | ); |
|
980 | ||
981 | $this->eventDispatcher |
|
982 | ->expects($this->at(2)) |
|
983 | ->method('dispatch') |
|
984 | ->with( |
|
985 | $this->identicalTo('lug.'.$name.'.error_'.$flushAction), |
|
986 | $this->callback(function (DomainEvent $event) use ($flushAction, $object) { |
|
987 | return $event->getResource() === $this->resource |
|
988 | && $event->getObject() === $object |
|
989 | && $event->getAction() === $flushAction; |
|
990 | }) |
|
991 | ); |
|
992 | ||
993 | $statusCode = Response::HTTP_BAD_REQUEST; |
|
994 | $message = 'message'; |
|
995 | ||
996 | $this->eventDispatcher |
|
997 | ->expects($this->at(3)) |
|
998 | ->method('dispatch') |
|
999 | ->with( |
|
1000 | $this->identicalTo('lug.'.$name.'.error_'.$deleteAction), |
|
1001 | $this->callback(function (DomainEvent $event) use ($object, $deleteAction, $statusCode, $message) { |
|
1002 | $result = $event->getResource() === $this->resource |
|
1003 | && $event->getObject() === $object |
|
1004 | && $event->getAction() === $deleteAction; |
|
1005 | ||
1006 | $event->setStatusCode($statusCode); |
|
1007 | $event->setMessage($message); |
|
1008 | ||
1009 | return $result; |
|
1010 | }) |
|
1011 | ); |
|
1012 | ||
1013 | try { |
|
1014 | $this->domainManager->delete($object); |
|
1015 | $this->fail(); |
|
1016 | } catch (DomainException $e) { |
|
1017 | $this->assertSame($statusCode, $e->getStatusCode()); |
|
1018 | $this->assertSame($message, $e->getMessage()); |
|
1019 | } |
|
1020 | } |
|
1021 | ||
1022 | public function testDeleteByPassException() |
|
1023 | { |