我已經開始爲我的項目編寫單元測試(在使用PHPUnit of course的symfony中)。 我正在嘗試爲此功能編寫一個功能/單元測試。 ,我不知道我應該怎麼做。 我知道我可以使用「測試雙打」(模擬)發送郵件/發送短信功能。 但是我需要在測試中檢查什麼?郵件功能的單元/功能測試
我的功能:
所有的public function notifyAlerts()
{
$alertSettings = $this->entity_manager->getRepository('TravelyoCoreBundle:Alert')->getActive();
$notifiedIdsObject = array(); // Will store the ids of the AlertLog that has been notified.
foreach($alertSettings as $alert)
{
$code = $alert->getEventCode();
$agencyId = $alert->getAgencyId();
$agency = $this->entity_manager->getRepository('TravelyoCoreBundle:Agency')->findOneBy(array('id'=>$agencyId));
$site= $agency->getSite();
$alertsToNotify = $this->entity_manager->getRepository('TravelyoCoreBundle:AlertLog')->getForCodeAgencyDate($code, $agencyId);
$messageArrays = array();
foreach($alertsToNotify as $notifyMe)
{
$notifiedIdsObject[$notifyMe->getId()] = $notifyMe->getId();
$methods = $alert->getMethods();
$routeParams = $notifyMe->getRouteParam();
$routeParams['trav_host'] = $site->getFullUrl(); //We need to know on which backoffice we need to send him
$url = $this->router->generate($notifyMe->getRoute(),$routeParams,true);
$shortUrl = GooglesShortUrl::generateUrl($url);
$messageParam = $notifyMe->getMessageParam();
$messageParam['%link%'] = $shortUrl;
if(in_array('sms', $methods))
{
$this->messageSender->sendSms($recipientsArray, $notifyMe->getMessage(),$messageParam, 'alert',strtolower($alert->getLanguage()), false, $agency->getSmsSettings());
}
if(in_array('email', $methods))
{
$recipients = $alert->getEmail();
$recipientsArray = explode(";",$recipients);
$messageArrays[] = array(
"message" => $notifyMe->getMessage(),
"messageParam" => $messageParam,
"domain" => "alert"
);
}
$notifyMe->setProcessed(1);
$this->entity_manager->persist($notifyMe);
}
if(count($messageArrays)>0)
{
$comType = array(MessageSenderManager::COMMUNICATION_TYPE_EMAIL);
$options = array('mail-settings'=> $agency->getMailSettings(),'subject'=>'Alert System : '. $notifyMe->getEventCode(), "template"=> "TravelyoAdminBundle:Admin/Mail:alert.html.twig");
$this->messageSender->send($agency->getMailSettingEmailAddress(),join(',',$recipientsArray), $messageArrays, $comType, $options);
}
}
$this->entity_manager->flush();
}