| @@ 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($data = 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, $data) { |
|
| 439 | return $event->getResource() === $this->resource |
|
| 440 | && $event->getData() === $data |
|
| 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, $data) { |
|
| 451 | return $event->getResource() === $this->resource |
|
| 452 | && $event->getData() === $data |
|
| 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, $data) { |
|
| 463 | return $event->getResource() === $this->resource |
|
| 464 | && $event->getData() === $data |
|
| 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 ($data, $createAction) { |
|
| 475 | $result = $event->getResource() === $this->resource |
|
| 476 | && $event->getData() === $data |
|
| 477 | && $event->getAction() === $createAction; |
|
| 478 | ||
| 479 | $event->setStopped(false); |
|
| 480 | ||
| 481 | return $result; |
|
| 482 | }) |
|
| 483 | ); |
|
| 484 | ||
| 485 | $this->domainManager->create($data); |
|
| 486 | } |
|
| 487 | ||
| 488 | public function testUpdateWithManagedObject() |
|
| 489 | { |
|
| @@ 1034-1104 (lines=71) @@ | ||
| 1031 | } |
|
| 1032 | } |
|
| 1033 | ||
| 1034 | public function testDeleteByPassException() |
|
| 1035 | { |
|
| 1036 | $this->resource |
|
| 1037 | ->expects($this->exactly(4)) |
|
| 1038 | ->method('getName') |
|
| 1039 | ->will($this->returnValue($name = 'name')); |
|
| 1040 | ||
| 1041 | $this->objectManager |
|
| 1042 | ->expects($this->once()) |
|
| 1043 | ->method('remove') |
|
| 1044 | ->with($this->identicalTo($data = new \stdClass())); |
|
| 1045 | ||
| 1046 | $this->objectManager |
|
| 1047 | ->expects($this->once()) |
|
| 1048 | ->method('flush') |
|
| 1049 | ->will($this->throwException(new \Exception())); |
|
| 1050 | ||
| 1051 | $this->eventDispatcher |
|
| 1052 | ->expects($this->at(0)) |
|
| 1053 | ->method('dispatch') |
|
| 1054 | ->with( |
|
| 1055 | $this->identicalTo('lug.'.$name.'.pre_'.($deleteAction = 'delete')), |
|
| 1056 | $this->callback(function (DomainEvent $event) use ($deleteAction, $data) { |
|
| 1057 | return $event->getResource() === $this->resource |
|
| 1058 | && $event->getData() === $data |
|
| 1059 | && $event->getAction() === $deleteAction; |
|
| 1060 | }) |
|
| 1061 | ); |
|
| 1062 | ||
| 1063 | $this->eventDispatcher |
|
| 1064 | ->expects($this->at(1)) |
|
| 1065 | ->method('dispatch') |
|
| 1066 | ->with( |
|
| 1067 | $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')), |
|
| 1068 | $this->callback(function (DomainEvent $event) use ($flushAction, $data) { |
|
| 1069 | return $event->getResource() === $this->resource |
|
| 1070 | && $event->getData() === $data |
|
| 1071 | && $event->getAction() === $flushAction; |
|
| 1072 | }) |
|
| 1073 | ); |
|
| 1074 | ||
| 1075 | $this->eventDispatcher |
|
| 1076 | ->expects($this->at(2)) |
|
| 1077 | ->method('dispatch') |
|
| 1078 | ->with( |
|
| 1079 | $this->identicalTo('lug.'.$name.'.error_'.$flushAction), |
|
| 1080 | $this->callback(function (DomainEvent $event) use ($flushAction, $data) { |
|
| 1081 | return $event->getResource() === $this->resource |
|
| 1082 | && $event->getData() === $data |
|
| 1083 | && $event->getAction() === $flushAction; |
|
| 1084 | }) |
|
| 1085 | ); |
|
| 1086 | ||
| 1087 | $this->eventDispatcher |
|
| 1088 | ->expects($this->at(3)) |
|
| 1089 | ->method('dispatch') |
|
| 1090 | ->with( |
|
| 1091 | $this->identicalTo('lug.'.$name.'.error_'.$deleteAction), |
|
| 1092 | $this->callback(function (DomainEvent $event) use ($data, $deleteAction) { |
|
| 1093 | $result = $event->getResource() === $this->resource |
|
| 1094 | && $event->getData() === $data |
|
| 1095 | && $event->getAction() === $deleteAction; |
|
| 1096 | ||
| 1097 | $event->setStopped(false); |
|
| 1098 | ||
| 1099 | return $result; |
|
| 1100 | }) |
|
| 1101 | ); |
|
| 1102 | ||
| 1103 | $this->domainManager->delete($data); |
|
| 1104 | } |
|
| 1105 | ||
| 1106 | public function testFlush() |
|
| 1107 | { |
|