├── .gitignore ├── LICENSE ├── README.md ├── behat.yml.dist ├── composer.json ├── phpspec.yml.dist ├── src └── TweedeGolf │ └── SwiftmailerLoggerBundle │ ├── DependencyInjection │ ├── Configuration.php │ ├── RegisterSendListenerCompilerPass.php │ └── TweedeGolfSwiftmailerLoggerExtension.php │ ├── Entity │ ├── LoggedMessage.php │ └── Repository │ │ └── LoggedMessageRepository.php │ ├── EventListener │ └── SendListener.php │ ├── Logger │ ├── EntityLogger.php │ ├── LoggerInterface.php │ └── SymfonyLogger.php │ ├── Resources │ └── config │ │ └── services.yml │ └── TweedeGolfSwiftmailerLoggerBundle.php └── test └── spec └── TweedeGolf └── SwiftmailerLoggerBundle └── Entity └── LoggedMessageSpec.php /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /vendor/ 3 | .idea 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 tweede golf 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwiftmailerLoggerBundle 2 | 3 | The tweedegolf SwiftmailerLoggerBundle provides an easy way to log messages sent with Swift Mailer. Currently 4 | the bundle only provides an 'entity logger', which uses its `LoggedMessage` Doctrine entity to store 5 | the details of a message that was sent. In the near future, a file logger will be added. Please note that the bundle is a work in progress and pay attention to the issue that was reported on 10-9-2014 about using lifecycle events. 6 | 7 | ## Installation and configuration 8 | 9 | Using [Composer][composer], please run the following command to add the bundle to your composer.json and to install it 10 | immediately: 11 | 12 | ``` 13 | composer require tweedegolf/swiftmailer-logger-bundle:dev-master 14 | ``` 15 | 16 | ### Basic configuration 17 | Add the following configuration to your configuration file `app/config/config.yml`: 18 | 19 | ``` 20 | tweede_golf_swiftmailer_logger: 21 | loggers: 22 | entity_logger: 23 | enabled: true 24 | symfony_logger: 25 | enabled: true 26 | ``` 27 | 28 | This will enable the only logger that is currently available: the entity logger. 29 | 30 | ### Add the bundle to your AppKernel 31 | Add the bundle in `app/AppKernel.php`, as shown below: 32 | 33 | ```php 34 | public function registerBundles() 35 | { 36 | return array( 37 | // ... 38 | new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(), 39 | new TweedeGolf\SwiftmailerLoggerBundle\TweedeGolfSwiftmailerLoggerBundle(), 40 | // ... 41 | ); 42 | } 43 | ``` 44 | 45 | ### Update your database schema 46 | Finally, update your database schema such that `LoggedMessage` entities can be stored by Doctrine. 47 | 48 | ## Usage 49 | With the above all set up, logging is automatic. The bundle provides a listener that listens to the 50 | `Swift_Events_SendEvent sendPerformed` event on which it passes on the data to be logged to any loggers configured. 51 | 52 | 53 | ### What is being logged? 54 | Every time an email is sent in your app with Swiftmailer, an LoggedMessage record is written to the database. This record contains the following info 55 | - the from, to, replyTo, cc and bcc address fields, all stored as array type 56 | - the return path (string) 57 | - the subject of the message 58 | - the body of the message 59 | - the date and time that the message was sent 60 | - the sending result 61 | - any failed recipients 62 | 63 | Of these, the sending result and failed recipients require some explanation. The sending result always contains one of the following strings "pending", "success", "tentative", "failed" or "unknown" 64 | representing the results (except for "spooled") that a Swift_Events_SendEvent can have. In the failed recipients field recipients are logged for which a 65 | Swift_RfcComplianceException or Swift_TransportException was thrown during sending. Note that a "success" result and no failed recipients *does not mean* that all recipients actually received the 66 | email that was logged: we only no that there were no problems during sending. 67 | 68 | ### Retrieving logged messages 69 | The bundle provides an empty `LoggedMessage` repository that can be used to retrieve messages logged by the entity logger. 70 | Retrieve it for example in one of your controllers by using: 71 | 72 | ``` 73 | $repo = $this->getDoctrine()->getRepository("TweedeGolfSwiftmailerLoggerBundle:LoggedMessage"); 74 | 75 | ``` 76 | 77 | ### Use multiple or custom instances of Swift mailer 78 | If you are using multiple Swift instances on your application or if you have overwritten the name of your Swift instance, modify your `app/config.yml` as shown below: 79 | ``` 80 | tweede_golf_swiftmailer_logger: 81 | swift_instances: 82 | - default 83 | - secondary_smtp 84 | 85 | loggers: 86 | entity_logger: 87 | enabled: true 88 | ``` 89 | 90 | Using multiple Swift instances, your Swiftmailer configuration will look something like this: 91 | 92 | ``` 93 | swiftmailer: 94 | default_mailer: default 95 | mailers: 96 | default: 97 | transport: %swift_transport% 98 | username: %swift_username% 99 | password: %swift_password% 100 | 101 | secondary_smtp: 102 | transport: %swift_transport2% 103 | username: %swift_username2% 104 | password: %swift_password2% 105 | 106 | ``` 107 | 108 | [composer]: https://getcomposer.org/ 109 | -------------------------------------------------------------------------------- /behat.yml.dist: -------------------------------------------------------------------------------- 1 | default: 2 | extensions: ~ 3 | #Behat\Symfony2Extension: ~ 4 | #VIPSoft\DoctrineDataFixturesExtension\Extension: 5 | # lifetime: scenario 6 | # autoload: false 7 | # migrations: ~ 8 | autoload: 9 | '': %paths.base%/test/features/bootstrap 10 | suites: 11 | base: 12 | paths: [%paths.base%/test/features] 13 | filters: { tags: "~@tbd" } 14 | contexts: 15 | - FeatureContext 16 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tweedegolf/swiftmailer-logger-bundle", 3 | "description": "Log emails sent with Swift Mailer", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "Hugo van de Pol", 8 | "email": "hugo@tweedegolf.com" 9 | } 10 | ], 11 | "require": { 12 | "php": ">=7.0", 13 | "symfony/framework-bundle": "*", 14 | "symfony/monolog-bundle": "*", 15 | "symfony/orm-pack": "*", 16 | "symfony/swiftmailer-bundle": "^2.3 || ^3.1" 17 | }, 18 | "require-dev": { 19 | "fzaninotto/faker": "~1.4", 20 | "behat/behat": "~3.0", 21 | "behat/symfony2-extension": "~2.0@dev", 22 | "vipsoft/doctrine-data-fixtures-extension": "~3.0@dev", 23 | "phpspec/phpspec": "~2.0", 24 | "bravesheep/phpspec-expect": "~0.1", 25 | "bravesheep/phpspec-extra-matchers": "~0.1", 26 | "henrikbjorn/phpspec-code-coverage": "dev-master" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "TweedeGolf\\SwiftmailerLoggerBundle\\": "src/TweedeGolf/SwiftmailerLoggerBundle/" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /phpspec.yml.dist: -------------------------------------------------------------------------------- 1 | extensions: 2 | - PhpSpec\Extension\CodeCoverageExtension 3 | 4 | code_coverage: 5 | format: html 6 | output: build/coverage 7 | 8 | suites: 9 | default: 10 | spec_path: ./test -------------------------------------------------------------------------------- /src/TweedeGolf/SwiftmailerLoggerBundle/DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | root('tweedegolf_swiftmailer_logger'); 22 | 23 | 24 | $rootNode 25 | ->children() 26 | ->arrayNode('swift_instances') 27 | ->prototype('scalar')->end() 28 | ->end() 29 | ->arrayNode('loggers') 30 | ->children() 31 | ->arrayNode('entity_logger') 32 | ->children() 33 | ->booleanNode('enabled')->defaultTrue()->end() 34 | ->end() 35 | ->end() 36 | ->arrayNode('symfony_logger') 37 | ->children() 38 | ->booleanNode('enabled')->defaultFalse()->end() 39 | ->end() 40 | ->end() 41 | ->end() 42 | ->end() 43 | ->end() 44 | ; 45 | 46 | return $treeBuilder; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/TweedeGolf/SwiftmailerLoggerBundle/DependencyInjection/RegisterSendListenerCompilerPass.php: -------------------------------------------------------------------------------- 1 | hasParameter('tweedegolf_swiftmailer_logger.swift_instances')){ // if instances are explicitly declared 22 | 23 | $instances = $container->getParameter('tweedegolf_swiftmailer_logger.swift_instances'); 24 | foreach($instances as $instance){ 25 | if($container->hasDefinition('swiftmailer.mailer.' . $instance)){ 26 | $def = $container->getDefinition('swiftmailer.mailer.' . $instance); 27 | $def->addMethodCall('registerPlugin', array(new Reference('tweedegolf_swiftmailer_logger.send_listener'))); 28 | unset($def); 29 | } 30 | } 31 | 32 | }else if ($container->hasDefinition('swiftmailer.mailer.default')) { // default instance only 33 | 34 | $def = $container->getDefinition('swiftmailer.mailer.default'); 35 | $def->addMethodCall('registerPlugin', array(new Reference('tweedegolf_swiftmailer_logger.send_listener'))); 36 | unset($def); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/TweedeGolf/SwiftmailerLoggerBundle/DependencyInjection/TweedeGolfSwiftmailerLoggerExtension.php: -------------------------------------------------------------------------------- 1 | processConfiguration($configuration, $configs); 25 | 26 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 27 | $loader->load('services.yml'); 28 | 29 | // add loggers to send listener 30 | if ($container->hasDefinition('tweedegolf_swiftmailer_logger.send_listener')) { 31 | $def = $container->getDefinition('tweedegolf_swiftmailer_logger.send_listener'); 32 | 33 | if ($config['loggers']['entity_logger']['enabled']) { 34 | $def->addMethodCall('addLogger', array(new Reference('tweedegolf_swiftmailer_logger.entity_logger'))); 35 | } 36 | 37 | if ($config['loggers']['symfony_logger']['enabled']) { 38 | $def->addMethodCall('addLogger', array(new Reference('tweedegolf_swiftmailer_logger.symfony_logger'))); 39 | } 40 | 41 | unset($def); 42 | } 43 | 44 | // store the name of the swift instances we want to watch 45 | if($config[ 'swift_instances' ]){ 46 | $container->setParameter( 'tweedegolf_swiftmailer_logger.swift_instances', $config[ 'swift_instances' ]); 47 | } 48 | 49 | // add monolog channel 50 | $channels = $container->getParameter('monolog.additional_channels'); 51 | $channels[] = 'mailer'; 52 | 53 | $container->setParameter( 'monolog.additional_channels', $channels); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/TweedeGolf/SwiftmailerLoggerBundle/Entity/LoggedMessage.php: -------------------------------------------------------------------------------- 1 | id; 133 | } 134 | 135 | /** 136 | * @param array $bcc 137 | */ 138 | public function setBcc($bcc) 139 | { 140 | $this->bcc = $bcc; 141 | } 142 | 143 | /** 144 | * @return array 145 | */ 146 | public function getBcc() 147 | { 148 | return $this->bcc; 149 | } 150 | 151 | /** 152 | * @param string $body 153 | */ 154 | public function setBody($body) 155 | { 156 | $this->body = $body; 157 | } 158 | 159 | /** 160 | * @return string 161 | */ 162 | public function getBody() 163 | { 164 | return $this->body; 165 | } 166 | 167 | /** 168 | * @param array $cc 169 | */ 170 | public function setCc($cc) 171 | { 172 | $this->cc = $cc; 173 | } 174 | 175 | /** 176 | * @return array 177 | */ 178 | public function getCc() 179 | { 180 | return $this->cc; 181 | } 182 | 183 | /** 184 | * @param \DateTime $date 185 | */ 186 | public function setDate($date) 187 | { 188 | $this->date = $date; 189 | } 190 | 191 | /** 192 | * @return \DateTime 193 | */ 194 | public function getDate() 195 | { 196 | return $this->date; 197 | } 198 | 199 | /** 200 | * @param string $from 201 | */ 202 | public function setFrom($from) 203 | { 204 | $this->from = $from; 205 | } 206 | 207 | /** 208 | * @return string 209 | */ 210 | public function getFrom() 211 | { 212 | return $this->from; 213 | } 214 | 215 | /** 216 | * @param string $generatedId 217 | */ 218 | public function setGeneratedId($generatedId) 219 | { 220 | $this->generatedId = $generatedId; 221 | } 222 | 223 | /** 224 | * @return string 225 | */ 226 | public function getGeneratedId() 227 | { 228 | return $this->generatedId; 229 | } 230 | 231 | /** 232 | * @param string $replyTo 233 | */ 234 | public function setReplyTo($replyTo) 235 | { 236 | $this->replyTo = $replyTo; 237 | } 238 | 239 | /** 240 | * @return string 241 | */ 242 | public function getReplyTo() 243 | { 244 | return $this->replyTo; 245 | } 246 | 247 | /** 248 | * @param string $result 249 | */ 250 | public function setResult($result) 251 | { 252 | $this->result = $result; 253 | } 254 | 255 | /** 256 | * @return string 257 | */ 258 | public function getResult() 259 | { 260 | return $this->result; 261 | } 262 | 263 | /** 264 | * @param string $returnPath 265 | */ 266 | public function setReturnPath($returnPath) 267 | { 268 | $this->returnPath = $returnPath; 269 | } 270 | 271 | /** 272 | * @return string 273 | */ 274 | public function getReturnPath() 275 | { 276 | return $this->returnPath; 277 | } 278 | 279 | /** 280 | * @param string $subject 281 | */ 282 | public function setSubject($subject) 283 | { 284 | $this->subject = $subject; 285 | } 286 | 287 | /** 288 | * @return string 289 | */ 290 | public function getSubject() 291 | { 292 | return $this->subject; 293 | } 294 | 295 | /** 296 | * @param array $to 297 | */ 298 | public function setTo($to) 299 | { 300 | $this->to = $to; 301 | } 302 | 303 | /** 304 | * @return array 305 | */ 306 | public function getTo() 307 | { 308 | return $this->to; 309 | } 310 | 311 | /** 312 | * @return array 313 | */ 314 | public function getFailedRecipients() 315 | { 316 | return $this->failedRecipients; 317 | } 318 | 319 | /** 320 | * @param array $failedRecipients 321 | */ 322 | public function setFailedRecipients($failedRecipients) 323 | { 324 | $this->failedRecipients = $failedRecipients; 325 | } 326 | 327 | /** 328 | * Sets all fields from the passed Swift_Mime_Message instance that will be logged 329 | * 330 | * @param Swift_Mime_Message $message 331 | */ 332 | public function setMessageFields(\Swift_Message $message) 333 | { 334 | $date = new DateTime(); 335 | 336 | // To prevent a lot of warnings 337 | $messageDate = $message->getDate(); 338 | if (is_object($messageDate)) { 339 | $messageDate = $messageDate->getTimestamp(); 340 | } 341 | 342 | $this->setDate($date->setTimestamp($messageDate)); 343 | $this->setFrom($message->getFrom()); 344 | $this->setReplyTo($message->getReplyTo()); 345 | $this->setReturnPath($message->getReturnPath()); 346 | $this->setTo($message->getTo()); 347 | $this->setCc($message->getCc()); 348 | $this->setBcc($message->getBcc()); 349 | $this->setSubject($message->getSubject()); 350 | $this->setBody($message->getBody()); 351 | $this->setGeneratedId($message->getId()); 352 | } 353 | 354 | /** 355 | * Returns a Swift_Message instance that can be sent 356 | * 357 | * @return \Swift_Message 358 | */ 359 | public function getSwiftMessage(){ 360 | $message = new \Swift_Message(); 361 | $message->setDate($this->getDate()->getTimestamp()); 362 | $message->setFrom($this->getFrom()); 363 | $message->setReplyTo($this->getReplyTo()); 364 | $message->setReturnPath($this->getReturnPath()); 365 | $message->setTo($this->getTo()); 366 | $message->setCc($this->getCc()); 367 | $message->setBcc($this->getBcc()); 368 | $message->setSubject($this->getSubject()); 369 | $message->setBody($this->getBody()); 370 | 371 | return $message; 372 | } 373 | } 374 | -------------------------------------------------------------------------------- /src/TweedeGolf/SwiftmailerLoggerBundle/Entity/Repository/LoggedMessageRepository.php: -------------------------------------------------------------------------------- 1 | loggers[] = $logger; 26 | } 27 | 28 | /** 29 | * Invoked immediately before the Message is sent. 30 | * 31 | * @param Swift_Events_SendEvent $evt 32 | */ 33 | public function beforeSendPerformed(Swift_Events_SendEvent $evt) 34 | { 35 | // not used 36 | } 37 | 38 | /** 39 | * Log the event with each logger that was passed to this service. When spooling, Swift Mailer 40 | * dispatches the sendPerformed event twice, in that case, only log the second sendPerformed event 41 | * 42 | * @param Swift_Events_SendEvent $evt 43 | * @return bool 44 | */ 45 | public function sendPerformed(Swift_Events_SendEvent $evt) 46 | { 47 | $message = $evt->getMessage(); 48 | 49 | // do nothing with a spooled messages, there comes a second send event 50 | if ($this->getReadableResult($evt) === 'spooled') { 51 | return false; 52 | } 53 | 54 | $data = [ 55 | 'message' => $message, 56 | 'result' => $this->getReadableResult($evt), 57 | 'failed_recipients' => $evt->getFailedRecipients() 58 | ]; 59 | 60 | /** @var $logger LoggerInterface */ 61 | foreach($this->loggers as $logger) { 62 | $logger->log($data); 63 | } 64 | } 65 | 66 | /** 67 | * Turns the event result into a human readable string 68 | * 69 | * @param Swift_Events_SendEvent $evt 70 | * @return string 71 | */ 72 | private function getReadableResult(Swift_Events_SendEvent $evt) 73 | { 74 | $result = $evt->getResult(); 75 | 76 | if ($result === 1) { 77 | return 'pending'; 78 | } 79 | 80 | if ($result === 16) { 81 | return 'success'; 82 | } 83 | 84 | if ($result === 17) { 85 | return 'spooled'; 86 | } 87 | 88 | if ($result === 256) { 89 | return 'tentative'; 90 | } 91 | 92 | if ($result === 4096) { 93 | return 'failed'; 94 | } 95 | 96 | return 'unknown'; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/TweedeGolf/SwiftmailerLoggerBundle/Logger/EntityLogger.php: -------------------------------------------------------------------------------- 1 | doctrine = $doctrine; 34 | $this->logger = $logger; 35 | } 36 | 37 | /** 38 | * @param array $data 39 | */ 40 | public function log(array $data) 41 | { 42 | $loggedMessage = new LoggedMessage(); 43 | $loggedMessage->setMessageFields($data['message']); 44 | $loggedMessage->setResult($data['result']); 45 | $loggedMessage->setFailedRecipients($data['failed_recipients']); 46 | 47 | $em = $this->doctrine->getManager(); 48 | 49 | // application should not crash when logging fails 50 | try { 51 | $em->persist($loggedMessage); 52 | $em->flush($loggedMessage); 53 | } catch (\Exception $e) { 54 | $message = 'Logging sent message with TweedeGolf\SwiftmailerLoggerBundle\Logger\EntityLogger failed: ' . 55 | $e->getMessage(); 56 | $this->logger->addError($message); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/TweedeGolf/SwiftmailerLoggerBundle/Logger/LoggerInterface.php: -------------------------------------------------------------------------------- 1 | logger = $mailerLogger; 26 | } 27 | 28 | 29 | /** 30 | * @param array $data 31 | */ 32 | public function log(array $data) 33 | { 34 | /** @var \Swift_Message $swiftMessage */ 35 | $swiftMessage = $data['message']; 36 | 37 | $this->logger->addInfo(\sprintf( 38 | 'MAIL SENT - from: %s; reply-to: %s; return-path: %s; to: %s; cc: %s; bcc: %s; subject: %s; date: %s', 39 | $this->getStringValue($swiftMessage->getFrom()), 40 | $this->getStringValue($swiftMessage->getReplyTo()), 41 | $this->getStringValue($swiftMessage->getReturnPath()), 42 | $this->getStringValue($swiftMessage->getTo()), 43 | $this->getStringValue($swiftMessage->getCc()), 44 | $this->getStringValue($swiftMessage->getBcc()), 45 | $data['message']->getSubject(), 46 | $data['message']->getDate()->format('d.m.Y - H:i:s') 47 | )); 48 | } 49 | 50 | /** 51 | * @param mixed $fieldValue 52 | * @return string 53 | */ 54 | private function getStringValue($fieldValue) 55 | { 56 | if (\is_string($fieldValue)) { 57 | return $fieldValue; 58 | } else if (\is_array($fieldValue)) { 59 | $fromStrings = []; 60 | 61 | foreach ($fieldValue as $prefix => $suffix) { 62 | $fromStrings[] = (empty($suffix)) ? $prefix : $prefix.'<'.$suffix.'>'; 63 | } 64 | 65 | return \implode(', ', $fromStrings); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/TweedeGolf/SwiftmailerLoggerBundle/Resources/config/services.yml: -------------------------------------------------------------------------------- 1 | services: 2 | tweedegolf_swiftmailer_logger.send_listener: 3 | class: TweedeGolf\SwiftmailerLoggerBundle\EventListener\SendListener 4 | 5 | # loggers 6 | tweedegolf_swiftmailer_logger.entity_logger: 7 | class: TweedeGolf\SwiftmailerLoggerBundle\Logger\EntityLogger 8 | arguments: 9 | - "@doctrine" 10 | - "@logger" 11 | 12 | tweedegolf_swiftmailer_logger.symfony_logger: 13 | class: TweedeGolf\SwiftmailerLoggerBundle\Logger\SymfonyLogger 14 | arguments: 15 | - "@monolog.logger.mailer" 16 | 17 | # todo add a file logger 18 | 19 | -------------------------------------------------------------------------------- /src/TweedeGolf/SwiftmailerLoggerBundle/TweedeGolfSwiftmailerLoggerBundle.php: -------------------------------------------------------------------------------- 1 | addCompilerPass(new RegisterSendListenerCompilerPass()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/spec/TweedeGolf/SwiftmailerLoggerBundle/Entity/LoggedMessageSpec.php: -------------------------------------------------------------------------------- 1 | shouldHaveType('tweedegolf\SwiftMailerLoggerBundle\Entity\LoggedMessage'); 14 | } 15 | 16 | function its_from_email_should_be_modifiable() 17 | { 18 | $email = 'hugo@tweedegolf.com'; 19 | $this->setFrom($email); 20 | $this->getFrom()->shouldReturn($email); 21 | } 22 | 23 | function its_to_email_should_be_modifiable() 24 | { 25 | $email = ['hugo@tweedegolf.com']; 26 | $this->setTo($email); 27 | $this->getTo()->shouldReturn($email); 28 | } 29 | 30 | function its_generated_id_should_be_modifiable() 31 | { 32 | $id = ''; 33 | $this->setGeneratedId($id); 34 | $this->getGeneratedId()->shouldReturn($id); 35 | } 36 | 37 | function its_return_path_should_be_modifiable() 38 | { 39 | $email = 'hugo@tweedegolf.com'; 40 | $this->setReturnPath($email); 41 | $this->getReturnPath()->shouldReturn($email); 42 | } 43 | 44 | function its_reply_to_email_should_be_modifiable() 45 | { 46 | $email = 'hugo@tweedegolf.com'; 47 | $this->setReplyTo($email); 48 | $this->getReplyTo()->shouldReturn($email); 49 | } 50 | 51 | function its_cc_should_be_modifiable() 52 | { 53 | $email = ['hugo@tweedegolf.com']; 54 | $this->setCc($email); 55 | $this->getCc()->shouldReturn($email); 56 | } 57 | 58 | function its_bcc_should_be_modifiable() 59 | { 60 | $email = ['hugo@tweedegolf.com']; 61 | $this->setBcc($email); 62 | $this->getBcc()->shouldReturn($email); 63 | } 64 | 65 | function its_subject_should_be_modifiable() 66 | { 67 | $subject = 'This could be a really long subject too'; 68 | $this->setSubject($subject); 69 | $this->getSubject()->shouldReturn($subject); 70 | } 71 | 72 | function its_date_should_be_modifiable() 73 | { 74 | $date = new \DateTime(); 75 | $this->setDate($date); 76 | $this->getDate()->shouldReturn($date); 77 | } 78 | 79 | function its_body_should_be_modifieable() 80 | { 81 | $body = 'some body'; 82 | $this->setBody($body); 83 | $this->getBody()->shouldReturn($body); 84 | } 85 | 86 | function its_result_should_be_modifiable() 87 | { 88 | $result = 'success'; 89 | $this->setResult($result); 90 | $this->getResult()->shouldReturn($result); 91 | } 92 | } 93 | --------------------------------------------------------------------------------