@@ 334-414 (lines=81) @@ | ||
331 | $this->domainManager->create($data, 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($data = 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, $data) { |
|
357 | return $event->getResource() === $this->resource |
|
358 | && $event->getData() === $data |
|
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, $data) { |
|
369 | return $event->getResource() === $this->resource |
|
370 | && $event->getData() === $data |
|
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, $data) { |
|
381 | return $event->getResource() === $this->resource |
|
382 | && $event->getData() === $data |
|
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 ($data, $createAction, $statusCode, $message) { |
|
396 | $result = $event->getResource() === $this->resource |
|
397 | && $event->getData() === $data |
|
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($data); |
|
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 | { |
|
@@ 952-1032 (lines=81) @@ | ||
949 | $this->domainManager->delete($data, false); |
|
950 | } |
|
951 | ||
952 | public function testDeleteThrowException() |
|
953 | { |
|
954 | $this->resource |
|
955 | ->expects($this->exactly(4)) |
|
956 | ->method('getName') |
|
957 | ->will($this->returnValue($name = 'name')); |
|
958 | ||
959 | $this->objectManager |
|
960 | ->expects($this->once()) |
|
961 | ->method('remove') |
|
962 | ->with($this->identicalTo($data = new \stdClass())); |
|
963 | ||
964 | $this->objectManager |
|
965 | ->expects($this->once()) |
|
966 | ->method('flush') |
|
967 | ->will($this->throwException(new \Exception())); |
|
968 | ||
969 | $this->eventDispatcher |
|
970 | ->expects($this->at(0)) |
|
971 | ->method('dispatch') |
|
972 | ->with( |
|
973 | $this->identicalTo('lug.'.$name.'.pre_'.($deleteAction = 'delete')), |
|
974 | $this->callback(function (DomainEvent $event) use ($deleteAction, $data) { |
|
975 | return $event->getResource() === $this->resource |
|
976 | && $event->getData() === $data |
|
977 | && $event->getAction() === $deleteAction; |
|
978 | }) |
|
979 | ); |
|
980 | ||
981 | $this->eventDispatcher |
|
982 | ->expects($this->at(1)) |
|
983 | ->method('dispatch') |
|
984 | ->with( |
|
985 | $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')), |
|
986 | $this->callback(function (DomainEvent $event) use ($flushAction, $data) { |
|
987 | return $event->getResource() === $this->resource |
|
988 | && $event->getData() === $data |
|
989 | && $event->getAction() === $flushAction; |
|
990 | }) |
|
991 | ); |
|
992 | ||
993 | $this->eventDispatcher |
|
994 | ->expects($this->at(2)) |
|
995 | ->method('dispatch') |
|
996 | ->with( |
|
997 | $this->identicalTo('lug.'.$name.'.error_'.$flushAction), |
|
998 | $this->callback(function (DomainEvent $event) use ($flushAction, $data) { |
|
999 | return $event->getResource() === $this->resource |
|
1000 | && $event->getData() === $data |
|
1001 | && $event->getAction() === $flushAction; |
|
1002 | }) |
|
1003 | ); |
|
1004 | ||
1005 | $statusCode = Response::HTTP_BAD_REQUEST; |
|
1006 | $message = 'message'; |
|
1007 | ||
1008 | $this->eventDispatcher |
|
1009 | ->expects($this->at(3)) |
|
1010 | ->method('dispatch') |
|
1011 | ->with( |
|
1012 | $this->identicalTo('lug.'.$name.'.error_'.$deleteAction), |
|
1013 | $this->callback(function (DomainEvent $event) use ($data, $deleteAction, $statusCode, $message) { |
|
1014 | $result = $event->getResource() === $this->resource |
|
1015 | && $event->getData() === $data |
|
1016 | && $event->getAction() === $deleteAction; |
|
1017 | ||
1018 | $event->setStatusCode($statusCode); |
|
1019 | $event->setMessage($message); |
|
1020 | ||
1021 | return $result; |
|
1022 | }) |
|
1023 | ); |
|
1024 | ||
1025 | try { |
|
1026 | $this->domainManager->delete($data); |
|
1027 | $this->fail(); |
|
1028 | } catch (DomainException $e) { |
|
1029 | $this->assertSame($statusCode, $e->getStatusCode()); |
|
1030 | $this->assertSame($message, $e->getMessage()); |
|
1031 | } |
|
1032 | } |
|
1033 | ||
1034 | public function testDeleteByPassException() |
|
1035 | { |