mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 22:04:23 +00:00
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:
parent
c81828e04f
commit
3a8154ecce
@ -11,26 +11,26 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\TicketBundle\Action\Ticket\Handler;
|
||||
|
||||
use Chill\MainBundle\Phonenumber\PhonenumberHelper;
|
||||
use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
|
||||
use Chill\TicketBundle\Action\Ticket\AssociateByPhonenumberCommand;
|
||||
use Chill\TicketBundle\Entity\PersonHistory;
|
||||
use Chill\TicketBundle\Entity\Ticket;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
|
||||
class AssociateByPhonenumberCommandHandler
|
||||
{
|
||||
public function __construct(
|
||||
private PersonACLAwareRepositoryInterface $personRepository,
|
||||
private PhoneNumberUtil $phoneNumberUtil,
|
||||
private PhonenumberHelper $phonenumberHelper,
|
||||
private ClockInterface $clock,
|
||||
private EntityManagerInterface $entityManager,
|
||||
) {}
|
||||
|
||||
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);
|
||||
|
||||
foreach ($persons as $person) {
|
||||
|
@ -11,17 +11,20 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\TicketBundle\Tests\Action\Ticket\Handler;
|
||||
|
||||
use Chill\MainBundle\Phonenumber\PhonenumberHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
|
||||
use Chill\TicketBundle\Action\Ticket\AssociateByPhonenumberCommand;
|
||||
use Chill\TicketBundle\Action\Ticket\Handler\AssociateByPhonenumberCommandHandler;
|
||||
use Chill\TicketBundle\Entity\Ticket;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Psr\Log\NullLogger;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Clock\MockClock;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@ -36,10 +39,19 @@ class AssociateByPhonenumberCommandHandlerTest extends TestCase
|
||||
PersonACLAwareRepositoryInterface $personACLAwareRepository,
|
||||
): AssociateByPhonenumberCommandHandler {
|
||||
$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(
|
||||
$personACLAwareRepository,
|
||||
PhoneNumberUtil::getInstance(),
|
||||
$phonenumberHelper,
|
||||
new MockClock(),
|
||||
$entityManager->reveal()
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user