mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
test on members editor post move + listen for event (wip)
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user