22namespace phpbu \App \Log ;
33
44/**
5- * Array utility test
5+ * Mail Test
66 *
77 * @package phpbu
88 * @subpackage tests
@@ -103,10 +103,8 @@ public function testSetupSendmailOk()
103103 */
104104 public function testSequenceOk ()
105105 {
106- $ appResult = $ this ->getAppResultMock (true );
107- $ appResult ->expects ($ this ->once ())->method ('wasSuccessful ' )->willReturn (true );
108- $ appResult ->expects ($ this ->once ())->method ('noneSkipped ' )->willReturn (true );
109- $ appResult ->expects ($ this ->once ())->method ('wasSuccessful ' )->willReturn (true );
106+ $ appResult = $ this ->getAppResultMock ();
107+ $ appResult ->expects ($ this ->once ())->method ('allOk ' )->willReturn (true );
110108 $ appResult ->method ('getBackups ' )->willReturn (array ());
111109 $ appResult ->expects ($ this ->once ())->method ('getErrors ' )->willReturn (array ());
112110
@@ -132,11 +130,146 @@ public function testSequenceOk()
132130 $ mail ->phpbuEnd ($ appResult );
133131 }
134132
133+ /**
134+ * Tests Mail with a successful backup.
135+ */
136+ public function testBackupOk ()
137+ {
138+ $ backup = $ this ->getBackupResultMock ();
139+ $ backup ->method ('getName ' )->willReturn ('backup ' );
140+ $ backup ->method ('allOk ' )->willReturn (true );
141+ $ backup ->method ('checkCount ' )->willReturn (0 );
142+ $ backup ->method ('checkCountFailed ' )->willReturn (0 );
143+ $ backup ->method ('syncCount ' )->willReturn (0 );
144+ $ backup ->method ('syncCountSkipped ' )->willReturn (0 );
145+ $ backup ->method ('syncCountFailed ' )->willReturn (0 );
146+ $ backup ->method ('cleanupCount ' )->willReturn (0 );
147+ $ backup ->method ('cleanupCountSkipped ' )->willReturn (0 );
148+ $ backup ->method ('cleanupCountFailed ' )->willReturn (0 );
149+
150+ $ app = $ this ->getAppResultMock ();
151+ $ app ->expects ($ this ->exactly (2 ))->method ('allOk ' )->willReturn (true );
152+ $ app ->method ('getBackups ' )->willReturn (array ($ backup ));
153+ $ app ->expects ($ this ->once ())->method ('getErrors ' )->willReturn (array ());
154+
155+ $ mail = new Mail ();
156+ $ mail ->setup (array ('recipients ' => 'test@example.com ' , 'transport ' => 'null ' ));
157+
158+ $ mail ->phpbuStart (array ());
159+ $ mail ->backupStart (array ());
160+ $ mail ->backupEnd (array ());
161+ $ mail ->phpbuEnd ($ app );
162+ }
163+
164+ /**
165+ * Tests Mail with skipped or failed Syncs or Cleanups.
166+ */
167+ public function testBackupOkButSkipsOrFails ()
168+ {
169+ $ backup = $ this ->getBackupResultMock ();
170+ $ backup ->method ('getName ' )->willReturn ('backup ' );
171+ $ backup ->method ('allOk ' )->willReturn (false );
172+ $ backup ->method ('okButSkipsOrFails ' )->willReturn (true );
173+ $ backup ->method ('checkCount ' )->willReturn (0 );
174+ $ backup ->method ('checkCountFailed ' )->willReturn (0 );
175+ $ backup ->method ('syncCount ' )->willReturn (1 );
176+ $ backup ->method ('syncCountSkipped ' )->willReturn (0 );
177+ $ backup ->method ('syncCountFailed ' )->willReturn (1 );
178+ $ backup ->method ('cleanupCount ' )->willReturn (0 );
179+ $ backup ->method ('cleanupCountSkipped ' )->willReturn (0 );
180+ $ backup ->method ('cleanupCountFailed ' )->willReturn (0 );
181+
182+ $ app = $ this ->getAppResultMock ();
183+ $ app ->expects ($ this ->exactly (2 ))->method ('allOk ' )->willReturn (false );
184+ $ app ->expects ($ this ->once ())->method ('backupOkButSkipsOrFails ' )->willReturn (true );
185+ $ app ->method ('getBackups ' )->willReturn (array ($ backup ));
186+ $ app ->expects ($ this ->once ())->method ('getErrors ' )->willReturn (array ());
187+
188+ $ mail = new Mail ();
189+ $ mail ->setup (array ('recipients ' => 'test@example.com ' , 'transport ' => 'null ' ));
190+
191+ $ mail ->phpbuStart (array ());
192+ $ mail ->backupStart (array ());
193+ $ mail ->backupEnd (array ());
194+ $ mail ->phpbuEnd ($ app );
195+ }
196+
197+ /**
198+ * Tests Mail failed Backup.
199+ */
200+ public function testBackupFailed ()
201+ {
202+ $ backup = $ this ->getBackupResultMock ();
203+ $ backup ->method ('getName ' )->willReturn ('backup ' );
204+ $ backup ->method ('allOk ' )->willReturn (false );
205+ $ backup ->method ('okButSkipsOrFails ' )->willReturn (false );
206+ $ backup ->method ('checkCount ' )->willReturn (0 );
207+ $ backup ->method ('checkCountFailed ' )->willReturn (0 );
208+ $ backup ->method ('syncCount ' )->willReturn (1 );
209+ $ backup ->method ('syncCountSkipped ' )->willReturn (0 );
210+ $ backup ->method ('syncCountFailed ' )->willReturn (1 );
211+ $ backup ->method ('cleanupCount ' )->willReturn (0 );
212+ $ backup ->method ('cleanupCountSkipped ' )->willReturn (0 );
213+ $ backup ->method ('cleanupCountFailed ' )->willReturn (0 );
214+
215+ $ e = $ this ->getExceptionMock ('test ' , 0 );
216+
217+ $ app = $ this ->getAppResultMock ();
218+ $ app ->expects ($ this ->exactly (2 ))->method ('allOk ' )->willReturn (false );
219+ $ app ->expects ($ this ->once ())->method ('backupOkButSkipsOrFails ' )->willReturn (false );
220+ $ app ->method ('getBackups ' )->willReturn (array ($ backup ));
221+ $ app ->expects ($ this ->once ())->method ('getErrors ' )->willReturn (array ($ e ));
222+
223+ $ mail = new Mail ();
224+ $ mail ->setup (array ('recipients ' => 'test@example.com ' , 'transport ' => 'null ' ));
225+
226+ $ mail ->phpbuStart (array ());
227+ $ mail ->backupStart (array ());
228+ $ mail ->backupEnd (array ());
229+ $ mail ->phpbuEnd ($ app );
230+ }
231+
232+ /**
233+ * Return App Result mock.
234+ *
235+ * @return \phpbu\App\Result
236+ */
135237 public function getAppResultMock ()
136238 {
137239 $ appResult = $ this ->getMockBuilder ('\\phpbu \\App \\Result ' )
138240 ->disableOriginalConstructor ()
139241 ->getMock ();
140242 return $ appResult ;
141243 }
244+
245+ /**
246+ * Return Backup Result mock.
247+ *
248+ * @return \phpbu\App\Result\Backup
249+ */
250+ public function getBackupResultMock ()
251+ {
252+ $ backup = $ this ->getMockBuilder ('\\phpbu \\App \\Result \\Backup ' )
253+ ->disableOriginalConstructor ()
254+ ->getMock ();
255+ return $ backup ;
256+ }
257+
258+ /**
259+ * Return Backup Result mock.
260+ *
261+ * @param string $msg
262+ * @param string $code
263+ * @return \phpbu\App\Result\Backup
264+ */
265+ public function getExceptionMock ($ msg , $ code )
266+ {
267+ $ e = $ this ->getMockBuilder ('\\Exception ' )
268+ ->disableOriginalConstructor ()
269+ ->getMock ();
270+
271+ $ e ->method ('getMessage ' )->willReturn ($ msg );
272+ $ e ->method ('getCode ' )->willReturn ($ code );
273+ return $ e ;
274+ }
142275}
0 commit comments