test on members editor post move + listen for event (wip)

This commit is contained in:
2022-02-15 00:23:01 +01:00
parent b9dbb1916a
commit 1658fee090
7 changed files with 111 additions and 3 deletions

View File

@@ -14,10 +14,14 @@ namespace Chill\PersonBundle\Tests\Household;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Household\Position;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
use Chill\PersonBundle\Household\MembersEditorFactory;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use function count;
/**
@@ -26,13 +30,56 @@ use function count;
*/
final class MembersEditorTest extends TestCase
{
use ProphecyTrait;
private MembersEditorFactory $factory;
protected function setUp(): void
{
$validator = $this->createMock(ValidatorInterface::class);
$this->factory = $this->buildMembersEditorFactory();
}
$this->factory = new MembersEditorFactory($validator);
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()