/** * @param Rental $rental */ public function penalizeRental(Rental $rental) { $comment = 'Penalización automática por retraso al entregar la taquilla ' . $rental->getLocker()->getCode(); /** @var FinancialPenalty $penalty */ $penalty = $this->penaltyRepository->createNew(); $penalty->setUser($rental->getUser()); $penalty->setAmount($this->amount); $penalty->setComment($comment); $penalty->setRental($rental); $this->manager->persist($penalty); $this->manager->flush(); $event = new PenaltyEvent($penalty); $this->dispatcher->dispatch(PenaltyEvents::PENALTY_CREATED, $event); }
public function it_can_add_a_penalty_from_a_rent(EventDispatcherInterface $dispatcher, ObjectManager $manager, Locker $locker, FinancialPenalty $penalty, FinancialPenaltyRepository $penaltyRepository, Rental $rental, User $user) { $rental->getLocker()->shouldBeCalled(); $locker->getCode()->shouldBeCalled(); $comment = 'Penalización automática por retraso al entregar la taquilla 100'; $rental->getUser()->shouldBeCalled(); $penaltyRepository->createNew()->shouldBeCalled()->willReturn($penalty); $penalty->setUser($user)->shouldBeCalled(); $penalty->setAmount($this->amount)->shouldBeCalled(); $penalty->setComment($comment)->shouldBeCalled(); $penalty->setRental($rental)->shouldBeCalled(); $manager->persist($penalty)->shouldBeCalled(); $manager->flush()->shouldBeCalled(); $dispatcher->dispatch(PenaltyEvents::PENALTY_CREATED, Argument::type(PenaltyEvent::class))->shouldBeCalled(); $this->penalizeRental($rental); }