| @@ 488-558 (lines=71) @@ | ||
| 485 | $this->domainManager->create($object); |
|
| 486 | } |
|
| 487 | ||
| 488 | public function testUpdateWithManagedObject() |
|
| 489 | { |
|
| 490 | $this->resource |
|
| 491 | ->expects($this->exactly(4)) |
|
| 492 | ->method('getName') |
|
| 493 | ->will($this->returnValue($name = 'name')); |
|
| 494 | ||
| 495 | $this->objectManager |
|
| 496 | ->expects($this->once()) |
|
| 497 | ->method('contains') |
|
| 498 | ->with($this->identicalTo($object = new \stdClass())) |
|
| 499 | ->will($this->returnValue(true)); |
|
| 500 | ||
| 501 | $this->objectManager |
|
| 502 | ->expects($this->never()) |
|
| 503 | ->method('persist'); |
|
| 504 | ||
| 505 | $this->objectManager |
|
| 506 | ->expects($this->once()) |
|
| 507 | ->method('flush'); |
|
| 508 | ||
| 509 | $this->eventDispatcher |
|
| 510 | ->expects($this->at(0)) |
|
| 511 | ->method('dispatch') |
|
| 512 | ->with( |
|
| 513 | $this->identicalTo('lug.'.$name.'.pre_'.($updateAction = 'update')), |
|
| 514 | $this->callback(function (DomainEvent $event) use ($updateAction, $object) { |
|
| 515 | return $event->getResource() === $this->resource |
|
| 516 | && $event->getObject() === $object |
|
| 517 | && $event->getAction() === $updateAction; |
|
| 518 | }) |
|
| 519 | ); |
|
| 520 | ||
| 521 | $this->eventDispatcher |
|
| 522 | ->expects($this->at(1)) |
|
| 523 | ->method('dispatch') |
|
| 524 | ->with( |
|
| 525 | $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')), |
|
| 526 | $this->callback(function (DomainEvent $event) use ($flushAction, $object) { |
|
| 527 | return $event->getResource() === $this->resource |
|
| 528 | && $event->getObject() === $object |
|
| 529 | && $event->getAction() === $flushAction; |
|
| 530 | }) |
|
| 531 | ); |
|
| 532 | ||
| 533 | $this->eventDispatcher |
|
| 534 | ->expects($this->at(2)) |
|
| 535 | ->method('dispatch') |
|
| 536 | ->with( |
|
| 537 | $this->identicalTo('lug.'.$name.'.post_'.$flushAction), |
|
| 538 | $this->callback(function (DomainEvent $event) use ($flushAction, $object) { |
|
| 539 | return $event->getResource() === $this->resource |
|
| 540 | && $event->getObject() === $object |
|
| 541 | && $event->getAction() === $flushAction; |
|
| 542 | }) |
|
| 543 | ); |
|
| 544 | ||
| 545 | $this->eventDispatcher |
|
| 546 | ->expects($this->at(3)) |
|
| 547 | ->method('dispatch') |
|
| 548 | ->with( |
|
| 549 | $this->identicalTo('lug.'.$name.'.post_'.$updateAction), |
|
| 550 | $this->callback(function (DomainEvent $event) use ($object, $updateAction) { |
|
| 551 | return $event->getResource() === $this->resource |
|
| 552 | && $event->getObject() === $object |
|
| 553 | && $event->getAction() === $updateAction; |
|
| 554 | }) |
|
| 555 | ); |
|
| 556 | ||
| 557 | $this->domainManager->update($object); |
|
| 558 | } |
|
| 559 | ||
| 560 | public function testUpdateWithoutManagedObject() |
|
| 561 | { |
|
| @@ 560-631 (lines=72) @@ | ||
| 557 | $this->domainManager->update($object); |
|
| 558 | } |
|
| 559 | ||
| 560 | public function testUpdateWithoutManagedObject() |
|
| 561 | { |
|
| 562 | $this->resource |
|
| 563 | ->expects($this->exactly(4)) |
|
| 564 | ->method('getName') |
|
| 565 | ->will($this->returnValue($name = 'name')); |
|
| 566 | ||
| 567 | $this->objectManager |
|
| 568 | ->expects($this->once()) |
|
| 569 | ->method('contains') |
|
| 570 | ->with($this->identicalTo($object = new \stdClass())) |
|
| 571 | ->will($this->returnValue(false)); |
|
| 572 | ||
| 573 | $this->objectManager |
|
| 574 | ->expects($this->once()) |
|
| 575 | ->method('persist') |
|
| 576 | ->with($this->identicalTo($object)); |
|
| 577 | ||
| 578 | $this->objectManager |
|
| 579 | ->expects($this->once()) |
|
| 580 | ->method('flush'); |
|
| 581 | ||
| 582 | $this->eventDispatcher |
|
| 583 | ->expects($this->at(0)) |
|
| 584 | ->method('dispatch') |
|
| 585 | ->with( |
|
| 586 | $this->identicalTo('lug.'.$name.'.pre_'.($updateAction = 'update')), |
|
| 587 | $this->callback(function (DomainEvent $event) use ($updateAction, $object) { |
|
| 588 | return $event->getResource() === $this->resource |
|
| 589 | && $event->getObject() === $object |
|
| 590 | && $event->getAction() === $updateAction; |
|
| 591 | }) |
|
| 592 | ); |
|
| 593 | ||
| 594 | $this->eventDispatcher |
|
| 595 | ->expects($this->at(1)) |
|
| 596 | ->method('dispatch') |
|
| 597 | ->with( |
|
| 598 | $this->identicalTo('lug.'.$name.'.pre_'.($flushAction = 'flush')), |
|
| 599 | $this->callback(function (DomainEvent $event) use ($flushAction, $object) { |
|
| 600 | return $event->getResource() === $this->resource |
|
| 601 | && $event->getObject() === $object |
|
| 602 | && $event->getAction() === $flushAction; |
|
| 603 | }) |
|
| 604 | ); |
|
| 605 | ||
| 606 | $this->eventDispatcher |
|
| 607 | ->expects($this->at(2)) |
|
| 608 | ->method('dispatch') |
|
| 609 | ->with( |
|
| 610 | $this->identicalTo('lug.'.$name.'.post_'.$flushAction), |
|
| 611 | $this->callback(function (DomainEvent $event) use ($flushAction, $object) { |
|
| 612 | return $event->getResource() === $this->resource |
|
| 613 | && $event->getObject() === $object |
|
| 614 | && $event->getAction() === $flushAction; |
|
| 615 | }) |
|
| 616 | ); |
|
| 617 | ||
| 618 | $this->eventDispatcher |
|
| 619 | ->expects($this->at(3)) |
|
| 620 | ->method('dispatch') |
|
| 621 | ->with( |
|
| 622 | $this->identicalTo('lug.'.$name.'.post_'.$updateAction), |
|
| 623 | $this->callback(function (DomainEvent $event) use ($object, $updateAction) { |
|
| 624 | return $event->getResource() === $this->resource |
|
| 625 | && $event->getObject() === $object |
|
| 626 | && $event->getAction() === $updateAction; |
|
| 627 | }) |
|
| 628 | ); |
|
| 629 | ||
| 630 | $this->domainManager->update($object); |
|
| 631 | } |
|
| 632 | ||
| 633 | public function testUpdateWithoutFlush() |
|
| 634 | { |
|