handle event PersonMoveEvent on Period

This commit is contained in:
2022-02-15 23:52:15 +01:00
parent 1658fee090
commit 0a4913f341
8 changed files with 495 additions and 63 deletions

View File

@@ -39,49 +39,6 @@ final class MembersEditorTest extends TestCase
$this->factory = $this->buildMembersEditorFactory();
}
private function buildMembersEditorFactory(
?EventDispatcherInterface $eventDispatcher = null,
?ValidatorInterface $validator = null
) {
if ($eventDispatcher === null) {
$double = $this->getProphet()->prophesize();
$double->willImplement(EventDispatcherInterface::class);
$double->dispatch(Argument::type(PersonAddressMoveEvent::class));
$eventDispatcher = $double->reveal();
}
if ($validator === null) {
$double = $this->getProphet()->prophesize();
$double->willImplement(ValidatorInterface::class);
$validator = $double->reveal();
}
return new MembersEditorFactory(
$eventDispatcher, $validator
);
}
public function testPostMove()
{
$person = new Person();
$position = (new Position())
->setShareHousehold(false);
$household1 = new Household();
$household2 = new Household();
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
$eventDispatcher
->dispatch(Argument::type(PersonAddressMoveEvent::class))
->shouldBeCalled();
$factory = $this->buildMembersEditorFactory(
$eventDispatcher->reveal(), null
);
$editor = $factory->createEditor($household1);
$editor->addMovement(new DateTimeImmutable('now'), $person, $position);
$editor->postMove();
}
public function testMovePersonWithoutSharedHousehold()
{
$person = new Person();
@@ -168,4 +125,49 @@ final class MembersEditorTest extends TestCase
);
$this->assertEquals($date, $membership1->getEndDate());
}
public function testPostMove()
{
$person = new Person();
$position = (new Position())
->setShareHousehold(false);
$household1 = new Household();
$household2 = new Household();
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
$eventDispatcher
->dispatch(Argument::type(PersonAddressMoveEvent::class))
->shouldBeCalled();
$factory = $this->buildMembersEditorFactory(
$eventDispatcher->reveal(),
null
);
$editor = $factory->createEditor($household1);
$editor->addMovement(new DateTimeImmutable('now'), $person, $position);
$editor->postMove();
}
private function buildMembersEditorFactory(
?EventDispatcherInterface $eventDispatcher = null,
?ValidatorInterface $validator = null
) {
if (null === $eventDispatcher) {
$double = $this->getProphet()->prophesize();
$double->willImplement(EventDispatcherInterface::class);
$double->dispatch(Argument::type(PersonAddressMoveEvent::class));
$eventDispatcher = $double->reveal();
}
if (null === $validator) {
$double = $this->getProphet()->prophesize();
$double->willImplement(ValidatorInterface::class);
$validator = $double->reveal();
}
return new MembersEditorFactory(
$eventDispatcher,
$validator
);
}
}