public function testWriteAsynchronousReport() { $this->if($mailer = new atoum\mailers\mail())->and($writer = new \mock\mageekguy\atoum\writers\mail($mailer, $locale = new \mock\mageekguy\atoum\locale(), $adapter = new atoum\test\adapter()))->and($writer->getMockController()->write = $writer)->and($adapter->date = function ($arg) { return $arg; })->then->object($writer->writeAsynchronousReport($report = new \mock\mageekguy\atoum\reports\asynchronous()))->isIdenticalTo($writer)->mock($writer)->call('write')->withArguments((string) $report)->once()->string($mailer->getSubject())->isEqualTo('Unit tests report, the Y-m-d at H:i:s')->mock($locale)->call('_')->withArguments('Unit tests report, the %1$s at %2$s')->once()->call('_')->withArguments('Y-m-d')->once()->call('_')->withArguments('H:i:s')->once()->if($mailer = new atoum\mailers\mail())->and($writer = new \mock\mageekguy\atoum\writers\mail($mailer, $locale = new \mock\mageekguy\atoum\locale(), $adapter = new atoum\test\adapter()))->and($writer->getMockController()->write = $writer)->then->object($writer->writeAsynchronousReport($report->setTitle($title = uniqid())))->isIdenticalTo($writer)->mock($writer)->call('write')->withArguments((string) $report)->once()->string($mailer->getSubject())->isEqualTo($title)->mock($locale)->call('_')->never()->if($mailer->setSubject($mailerSubject = uniqid()))->and($this->resetMock($writer))->then->object($writer->writeAsynchronousReport($report))->isIdenticalTo($writer)->mock($writer)->call('write')->withArguments((string) $report)->once()->string($mailer->getSubject())->isEqualTo($mailerSubject); }
public function testSend() { $adapter = new atoum\test\adapter(); $adapter->mail = function () { }; $mail = new mailers\mail($adapter); $this->assert->exception(function () use($mail) { $mail->send(uniqid()); })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('To is undefined'); $mail->addTo($to = uniqid()); $this->assert->exception(function () use($mail) { $mail->send(uniqid()); })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Subject is undefined'); $mail->setSubject($subject = uniqid()); $this->assert->exception(function () use($mail) { $mail->send(uniqid()); })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('From is undefined'); $mail->setFrom($from = uniqid()); $this->assert->exception(function () use($mail) { $mail->send(uniqid()); })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Reply to is undefined'); $mail->setReplyTo($replyTo = uniqid()); $this->assert->exception(function () use($mail) { $mail->send(uniqid()); })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('X-mailer is undefined'); $mail->setXMailer($mailer = uniqid()); $this->assert->object($mail->send($message = uniqid()))->isIdenticalTo($mail)->adapter($adapter)->call('mail')->withArguments($mail->getTo(), $mail->getSubject(), $message, 'From: ' . $from . "\r\n" . 'Reply-To: ' . $replyTo . "\r\n" . 'X-Mailer: ' . $mailer)->once(); $mail->setContentType($type = uniqid(), $charset = uniqid()); $this->assert->object($mail->send($message = uniqid()))->isIdenticalTo($mail)->adapter($adapter)->call('mail')->withArguments($mail->getTo(), $mail->getSubject(), $message, 'From: ' . $from . "\r\n" . 'Reply-To: ' . $replyTo . "\r\n" . 'X-Mailer: ' . $mailer . "\r\n" . 'Content-Type: ' . $type . '; charset="' . $charset . '"')->once(); }