Answer the question
In order to leave comments, you need to log in
How to make a unit test for the method of sending messages to Email?
You need to write a unit test for the mail.php file, which contains a method for sending a message to Email.
header("Location: http://landingtaxi/");
$name = $_POST['firstname'];
$email = $_POST['email_box'];
$col = $_POST['select_col'];
if(isset($name) && isset($email) && isset($col)){
switch ($col) {
case 2:
$col_name = "ГОСТ";
break;
case 3:
$col_name = "Яндекс";
break;
case 4:
$col_name = "Яндекс + Light Box";
break;
default:
$col_name = "Не выбрана";
break;
}
require_once "SendMailSmtpClass.php"; // подключаем класс
$mailSMTP = new SendMailSmtpClass('[email protected]', '***', 'ssl://smtp.mail.ru', 465, "UTF-8");
// $mailSMTP = new SendMailSmtpClass('логин', 'пароль', 'хост', 'порт', 'кодировка письма');
// от кого
$from = array(
"Иван", // Имя отправителя
"[email protected]" // почта отправителя
);
// кому
$to = '[email protected]';
$result = $mailSMTP->send($to, 'Заказ на оклейку', "Поступил заказ на оклейку автомобиля. Выбранная опция: " . $col_name . ". Имя заказчика: " . $name . ". Почта заказчика: " . $email, $from);
// $result = $mailSMTP->send('Кому письмо', 'Тема письма', 'Текст письма', 'Отправитель письма');
if($result === true){
echo "Done";
}else{
echo "Error: " . $result;
}
$to = $email;
$result = $mailSMTP->send($to, 'Оклейка автомобиля', "Благодарим вас за выбор нашей компании! Вам скоро перезвонят для уточнения деталей. С уважением, Батурин Иван!", $from);
}
exit;
Answer the question
In order to leave comments, you need to log in
Unit test:
A unit test is not possible in this case, because there is no unit test in the form of a pure function (without side effects). There is a solid side effect here: sending to SMTP, listening to HTTP, that is, you don’t really test with units.
The unit test object is either a function or an object. And you also have no function/procedure even at least.
It will be functional (if you call it from the code) or acceptance (if you pull your application via HTTP) in any case.
How to finally test it:
Such functionality is usually tested like this:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question