File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -2144,7 +2144,13 @@ protected function mimeTypes($ext = '')
21442144 public function __destruct ()
21452145 {
21462146 if (is_resource ($ this ->SMTPConnect )) {
2147- $ this ->sendCommand ('quit ' );
2147+ try {
2148+ $ this ->sendCommand ('quit ' );
2149+ } catch (ErrorException $ e ) {
2150+ $ protocol = $ this ->getProtocol ();
2151+ $ method = 'sendWith ' . ucfirst ($ protocol );
2152+ log_message ('error ' , 'Email: ' . $ method . ' throwed ' . $ e );
2153+ }
21482154 }
21492155 }
21502156
Original file line number Diff line number Diff line change 1414use CodeIgniter \Events \Events ;
1515use CodeIgniter \Test \CIUnitTestCase ;
1616use CodeIgniter \Test \Mock \MockEmail ;
17+ use ErrorException ;
1718
1819/**
1920 * @internal
@@ -136,6 +137,24 @@ public function testFailureDoesNotTriggerEvent()
136137 $ this ->assertNull ($ result );
137138 }
138139
140+ public function testDestructDoesNotThrowException ()
141+ {
142+ $ email = $ this ->getMockBuilder (Email::class)
143+ ->disableOriginalConstructor ()
144+ ->onlyMethods (['sendCommand ' ])
145+ ->getMock ();
146+ $ email ->method ('sendCommand ' )
147+ ->willThrowException (new ErrorException ('SMTP Error. ' ));
148+
149+ // Force resource to be injected into the property
150+ $ SMTPConnect = fopen (__FILE__ , 'rb ' );
151+ $ this ->setPrivateProperty ($ email , 'SMTPConnect ' , $ SMTPConnect );
152+
153+ $ email ->__destruct ();
154+
155+ $ this ->assertTrue (true );
156+ }
157+
139158 private function createMockEmail (): MockEmail
140159 {
141160 $ config = config ('Email ' );
You can’t perform that action at this time.
0 commit comments