|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) |
| 4 | + * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
| 5 | + * |
| 6 | + * Licensed under The MIT License |
| 7 | + * Redistributions of files must retain the above copyright notice. |
| 8 | + * |
| 9 | + * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
| 10 | + * @link http://cakephp.org CakePHP(tm) Project |
| 11 | + * @license http://www.opensource.org/licenses/mit-license.php MIT License |
| 12 | + */ |
| 13 | +namespace DebugKit\Test\TestCase\Mailer\Transport; |
| 14 | + |
| 15 | +use Cake\Mailer\Email; |
| 16 | +use Cake\Mailer\AbstractTransport; |
| 17 | +use Cake\TestSuite\TestCase; |
| 18 | +use DebugKit\Mailer\Transport\DebugKitTransport; |
| 19 | + |
| 20 | +class DebugKitTransportTest extends TestCase |
| 21 | +{ |
| 22 | + public function setUp() |
| 23 | + { |
| 24 | + $this->log = new \ArrayObject(); |
| 25 | + $this->wrapped = $this->getMockBuilder(AbstractTransport::class) |
| 26 | + ->setMethods(['send', 'customMethod']) |
| 27 | + ->getMock(); |
| 28 | + $this->transport = new DebugKitTransport( |
| 29 | + ['debugKitLog' => $this->log], |
| 30 | + $this->wrapped |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + public function testPropertyProxies() |
| 35 | + { |
| 36 | + $this->wrapped->property = 'value'; |
| 37 | + $this->assertTrue(isset($this->transport->property)); |
| 38 | + $this->assertSame('value', $this->transport->property); |
| 39 | + |
| 40 | + $this->transport->property = 'new value'; |
| 41 | + $this->assertSame('new value', $this->wrapped->property); |
| 42 | + unset($this->transport->property); |
| 43 | + $this->assertFalse(isset($this->wrapped->property)); |
| 44 | + } |
| 45 | + |
| 46 | + public function testMethodProxy() |
| 47 | + { |
| 48 | + $this->wrapped->method('customMethod') |
| 49 | + ->will($this->returnValue('bloop')); |
| 50 | + $this->assertSame('bloop', $this->transport->customMethod()); |
| 51 | + } |
| 52 | + |
| 53 | + public function testEmailCapture() |
| 54 | + { |
| 55 | + $email = new Email(); |
| 56 | + $email->setSubject('Testing 123') |
| 57 | + |
| 58 | + |
| 59 | + $this->transport->send($email); |
| 60 | + $this->assertCount(1, $this->log); |
| 61 | + |
| 62 | + $result = $this->log[0]; |
| 63 | + $this->assertArrayHasKey('headers', $result); |
| 64 | + $this->assertArrayHasKey('message', $result); |
| 65 | + } |
| 66 | +} |
0 commit comments