Replace PhoneNumberUtil with PhonenumberHelper

The PhoneNumberUtil has been replaced with PhonenumberHelper in AssociateByPhonenumberCommandHandler and its test class. The purpose of this change is to improve phone number parsing which is now delegated to the PhonenumberHelper class in the Chill\MainBundle\Phonenumber namespace. As a consequence, the related dependencies in both the service and the test class have been updated accordingly.
This commit is contained in:
Julien Fastré 2024-05-17 12:17:00 +02:00
parent c81828e04f
commit 3a8154ecce
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 17 additions and 5 deletions

View File

@ -11,26 +11,26 @@ declare(strict_types=1);
namespace Chill\TicketBundle\Action\Ticket\Handler; namespace Chill\TicketBundle\Action\Ticket\Handler;
use Chill\MainBundle\Phonenumber\PhonenumberHelper;
use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface; use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
use Chill\TicketBundle\Action\Ticket\AssociateByPhonenumberCommand; use Chill\TicketBundle\Action\Ticket\AssociateByPhonenumberCommand;
use Chill\TicketBundle\Entity\PersonHistory; use Chill\TicketBundle\Entity\PersonHistory;
use Chill\TicketBundle\Entity\Ticket; use Chill\TicketBundle\Entity\Ticket;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use libphonenumber\PhoneNumberUtil;
use Symfony\Component\Clock\ClockInterface; use Symfony\Component\Clock\ClockInterface;
class AssociateByPhonenumberCommandHandler class AssociateByPhonenumberCommandHandler
{ {
public function __construct( public function __construct(
private PersonACLAwareRepositoryInterface $personRepository, private PersonACLAwareRepositoryInterface $personRepository,
private PhoneNumberUtil $phoneNumberUtil, private PhonenumberHelper $phonenumberHelper,
private ClockInterface $clock, private ClockInterface $clock,
private EntityManagerInterface $entityManager, private EntityManagerInterface $entityManager,
) {} ) {}
public function __invoke(Ticket $ticket, AssociateByPhonenumberCommand $command): void public function __invoke(Ticket $ticket, AssociateByPhonenumberCommand $command): void
{ {
$phone = $this->phoneNumberUtil->parse($command->phonenumber); $phone = $this->phonenumberHelper->parse($command->phonenumber);
$persons = $this->personRepository->findByPhone($phone); $persons = $this->personRepository->findByPhone($phone);
foreach ($persons as $person) { foreach ($persons as $person) {

View File

@ -11,17 +11,20 @@ declare(strict_types=1);
namespace Chill\TicketBundle\Tests\Action\Ticket\Handler; namespace Chill\TicketBundle\Tests\Action\Ticket\Handler;
use Chill\MainBundle\Phonenumber\PhonenumberHelper;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface; use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
use Chill\TicketBundle\Action\Ticket\AssociateByPhonenumberCommand; use Chill\TicketBundle\Action\Ticket\AssociateByPhonenumberCommand;
use Chill\TicketBundle\Action\Ticket\Handler\AssociateByPhonenumberCommandHandler; use Chill\TicketBundle\Action\Ticket\Handler\AssociateByPhonenumberCommandHandler;
use Chill\TicketBundle\Entity\Ticket; use Chill\TicketBundle\Entity\Ticket;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use libphonenumber\PhoneNumberUtil;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\NullLogger;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Clock\MockClock; use Symfony\Component\Clock\MockClock;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/** /**
* @internal * @internal
@ -36,10 +39,19 @@ class AssociateByPhonenumberCommandHandlerTest extends TestCase
PersonACLAwareRepositoryInterface $personACLAwareRepository, PersonACLAwareRepositoryInterface $personACLAwareRepository,
): AssociateByPhonenumberCommandHandler { ): AssociateByPhonenumberCommandHandler {
$entityManager = $this->prophesize(EntityManagerInterface::class); $entityManager = $this->prophesize(EntityManagerInterface::class);
$phonenumberHelper = new PhonenumberHelper(
new ArrayAdapter(),
new ParameterBag([
'chill_main.phone_helper' => [
'default_carrier_code' => 'BE',
],
]),
new NullLogger()
);
return new AssociateByPhonenumberCommandHandler( return new AssociateByPhonenumberCommandHandler(
$personACLAwareRepository, $personACLAwareRepository,
PhoneNumberUtil::getInstance(), $phonenumberHelper,
new MockClock(), new MockClock(),
$entityManager->reveal() $entityManager->reveal()
); );