PageRenderTime 51ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/ZendTest/Mail/Transport/FileTest.php

https://bitbucket.org/gencer/zf2
PHP | 79 lines | 59 code | 10 blank | 10 comment | 2 complexity | 70a3676e969d6a027d7598b9c64f89b1 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace ZendTest\Mail\Transport;
  10. use Zend\Mail\Message;
  11. use Zend\Mail\Transport\File;
  12. use Zend\Mail\Transport\FileOptions;
  13. /**
  14. * @group Zend_Mail
  15. */
  16. class FileTest extends \PHPUnit_Framework_TestCase
  17. {
  18. public function setUp()
  19. {
  20. $this->tempDir = sys_get_temp_dir() . '/mail_file_transport';
  21. if (!is_dir($this->tempDir)) {
  22. mkdir($this->tempDir);
  23. } else {
  24. $this->cleanup($this->tempDir);
  25. }
  26. $fileOptions = new FileOptions(array(
  27. 'path' => $this->tempDir,
  28. ));
  29. $this->transport = new File($fileOptions);
  30. }
  31. public function tearDown()
  32. {
  33. $this->cleanup($this->tempDir);
  34. rmdir($this->tempDir);
  35. }
  36. protected function cleanup($dir)
  37. {
  38. foreach (glob($dir . '/*.*') as $file) {
  39. unlink($file);
  40. }
  41. }
  42. public function getMessage()
  43. {
  44. $message = new Message();
  45. $message->addTo('zf-devteam@zend.com', 'ZF DevTeam')
  46. ->addCc('matthew@zend.com')
  47. ->addBcc('zf-crteam@lists.zend.com', 'CR-Team, ZF Project')
  48. ->addFrom(array(
  49. 'zf-devteam@zend.com',
  50. 'Matthew' => 'matthew@zend.com',
  51. ))
  52. ->setSender('ralph.schindler@zend.com', 'Ralph Schindler')
  53. ->setSubject('Testing Zend\Mail\Transport\Sendmail')
  54. ->setBody('This is only a test.');
  55. $message->getHeaders()->addHeaders(array(
  56. 'X-Foo-Bar' => 'Matthew',
  57. ));
  58. return $message;
  59. }
  60. public function testReceivesMailArtifacts()
  61. {
  62. $message = $this->getMessage();
  63. $this->transport->send($message);
  64. $this->assertNotNull($this->transport->getLastFile());
  65. $file = $this->transport->getLastFile();
  66. $test = file_get_contents($file);
  67. $this->assertEquals($message->toString(), $test);
  68. }
  69. }