| 1 | <?php |
||
| 14 | class SmtpCredentialsValidatorTest extends PHPUnit_Framework_TestCase |
||
| 15 | { |
||
| 16 | public function testValidationPassed() |
||
| 17 | { |
||
| 18 | $mock = Mockery::mock('overload:' . Swift_SmtpTransport::class); |
||
| 19 | $mock->shouldReceive('start')->once()->andReturn(true); |
||
| 20 | $mock->shouldReceive('setUsername')->once()->with('Obiwoan'); |
||
| 21 | $mock->shouldReceive('setPassword')->once()->with('Kenovi'); |
||
| 22 | $mock->shouldReceive('setEncryption')->once()->with('ssl'); |
||
| 23 | $mock->shouldReceive('setAuthMode')->once()->with('Plain'); |
||
| 24 | |||
| 25 | $validator = SmtpCredentialsValidator::fromArray( |
||
| 26 | [ |
||
| 27 | 'host' => 'localhost', |
||
| 28 | 'port' => 587, |
||
| 29 | 'username' => 'Obiwoan', |
||
| 30 | 'password' => 'Kenovi', |
||
| 31 | 'encryption' => 'ssl', |
||
| 32 | 'authMode' => 'Plain', |
||
| 33 | ] |
||
| 34 | ); |
||
| 35 | |||
| 36 | $this->assertTrue($validator->validate()); |
||
| 37 | } |
||
| 38 | |||
| 39 | public function testValidationThrowsException() |
||
| 40 | { |
||
| 41 | $mock = Mockery::mock('overload:' . Swift_SmtpTransport::class); |
||
| 42 | |||
| 43 | $mock->shouldReceive('start')->once()->andThrow(Exception::class); |
||
| 44 | $mock->shouldReceive('setUsername')->once()->with('Obiwoan'); |
||
| 45 | $mock->shouldReceive('setPassword')->once()->with('Kenovi'); |
||
| 46 | $mock->shouldReceive('setEncryption')->once()->with('ssl'); |
||
| 47 | $mock->shouldReceive('setAuthMode')->once()->with('Plain'); |
||
| 48 | |||
| 49 | $validator = SmtpCredentialsValidator::fromArray( |
||
| 50 | [ |
||
| 51 | 'host' => 'localhost', |
||
| 52 | 'port' => 587, |
||
| 53 | 'username' => 'Obiwoan', |
||
| 54 | 'password' => 'Kenovi', |
||
| 55 | 'encryption' => 'ssl', |
||
| 56 | 'authMode' => 'Plain', |
||
| 57 | ] |
||
| 58 | ); |
||
| 59 | |||
| 60 | $this->assertTrue($validator->validate() === false); |
||
| 61 | } |
||
| 62 | } |
||
| 63 |