minor changes review: comments removed, logicexception, more test cases passed

This commit is contained in:
Julie Lenaerts 2021-10-07 11:13:38 +02:00
parent 7dd42c3fa2
commit aa852ec924
2 changed files with 7 additions and 12 deletions

View File

@ -7,14 +7,13 @@ namespace Chill\PersonBundle\EventListener;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\PersonAltName;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use LogicException;
use Symfony\Component\Validator\Exception\LogicException as ExceptionLogicException;
class PersonEventListener
{
public function onPrePersist(LifecycleEventArgs $event): void
{
// $em = $event->getObjectManager();
if($event->getObject() instanceof Person){
$person = $event->getObject();
@ -25,22 +24,16 @@ class PersonEventListener
$lastnameCaps = mb_strtoupper($person->getLastName(), 'UTF-8');
$person->setLastName($lastnameCaps);
// $em->persist($person);
// $em->flush();
} elseif ($event->getObject() instanceof PersonAltName){
$altname = $event->getObject();
$altnameCaps = ucwords(strtolower($altname->getLabel()), " \t\r\n\f\v'-");
$altnameCaps = mb_convert_case(mb_strtolower($altname->getLabel()), MB_CASE_TITLE, 'UTF-8');
$altnameCaps = ucwords(strtolower($altnameCaps), " \t\r\n\f\v'-");
$altname->setLabel($altnameCaps);
// $em->persist($altname);
// $em->flush();
} else {
throw new NotFoundHttpException('Entity must be a person or an altname');
throw new LogicException('Entity must be a person or an altname');
}
}

View File

@ -63,6 +63,8 @@ class PersonCreateEventTest extends TestCase
{
yield ['vinCENT', 'Vincent'];
yield ['jean-marie', 'Jean-Marie'];
yield ['fastré', 'Fastré'];
yield ['émile', 'Émile'];
}
}