1414 */
1515namespace DatabaseBackup \Test \TestCase \Command ;
1616
17- use Cake \Core \Configure ;
1817use DatabaseBackup \TestSuite \TestCase ;
1918use MeTools \TestSuite \ConsoleIntegrationTestTrait ;
2019
@@ -25,51 +24,79 @@ class ExportCommandTest extends TestCase
2524{
2625 use ConsoleIntegrationTestTrait;
2726
27+ /**
28+ * @var string
29+ */
30+ protected $ command = 'database_backup.export -v ' ;
31+
2832 /**
2933 * Test for `execute()` method
3034 * @test
3135 */
3236 public function testExecute ()
3337 {
34- $ command = 'database_backup.export -v ' ;
35- $ targetRegex = preg_quote (Configure::read ('DatabaseBackup.target ' ) . DS , '/ ' );
36-
37- //Exports, without params
38- $ this ->exec ($ command );
38+ $ this ->exec ($ this ->command );
3939 $ this ->assertExitWithSuccess ();
4040 $ this ->assertOutputContains ('Connection: test ' );
4141 $ this ->assertOutputContains ('Driver: Mysql ' );
42- $ this ->assertOutputRegExp ('/Backup ` ' . $ targetRegex . 'backup_test_\d+\.sql` has been exported/ ' );
42+ $ this ->assertOutputRegExp ('/Backup `[\w\-\/]+\/backup_test_\d+\.sql` has been exported/ ' );
43+ }
4344
44- //Exports, with `compression` param
45- sleep (1 );
46- $ this ->exec ($ command . ' --compression bzip2 ' );
45+ /**
46+ * Test for `execute()` method, with `compression` param
47+ * @test
48+ */
49+ public function testExecuteCompressionParam ()
50+ {
51+ $ this ->exec ($ this ->command . ' --compression bzip2 ' );
4752 $ this ->assertExitWithSuccess ();
48- $ this ->assertOutputRegExp ('/Backup ` ' . $ targetRegex . 'backup_test_\d+\.sql\.bz2` has been exported/ ' );
53+ $ this ->assertOutputRegExp ('/Backup `[\w\-\/]+\/backup_test_\d+\.sql\.bz2` has been exported/ ' );
54+ }
4955
50- //Exports, with `filename` param
51- sleep (1 );
52- $ this ->exec ($ command . ' --filename backup.sql ' );
56+ /**
57+ * Test for `execute()` method, with `filename` param
58+ * @test
59+ */
60+ public function testExecuteFilenameParam ()
61+ {
62+ $ this ->exec ($ this ->command . ' --filename backup.sql ' );
5363 $ this ->assertExitWithSuccess ();
54- $ this ->assertOutputRegExp ('/Backup ` ' . $ targetRegex . 'backup.sql` has been exported/ ' );
64+ $ this ->assertOutputRegExp ('/Backup `[\w\-\/]+\/backup.sql` has been exported/ ' );
65+ }
5566
56- //Exports, with `rotate` param
57- sleep (1 );
58- $ this ->exec ($ command . ' --rotate 3 -v ' );
67+ /**
68+ * Test for `execute()` method, with `rotate` param
69+ * @test
70+ */
71+ public function testExecuteRotateParam ()
72+ {
73+ $ files = $ this ->createSomeBackups ();
74+ $ this ->exec ($ this ->command . ' --rotate 3 -v ' );
5975 $ this ->assertExitWithSuccess ();
60- $ this ->assertOutputRegExp ('/Backup ` ' . $ targetRegex . ' backup_test_\d+\.sql` has been exported/ ' );
61- $ this ->assertOutputRegExp ( ' / Backup `backup_test_\d+\.sql ` has been deleted/ ' );
76+ $ this ->assertOutputRegExp ('/Backup `[\w\-\/]+\/ backup_test_\d+\.sql` has been exported/ ' );
77+ $ this ->assertOutputContains ( ' Backup ` ' . basename ( array_value_first ( $ files )) . ' ` has been deleted ' );
6278 $ this ->assertOutputContains ('<success>Deleted backup files: 1</success> ' );
79+ }
6380
64- //Exports, with `send` param
65- sleep (1 );
66- $ this ->exec ($ command . ' --send mymail@example.com ' );
81+ /**
82+ * Test for `execute()` method, with `send` param
83+ * @test
84+ */
85+ public function testExecuteSendParam ()
86+ {
87+ $ this ->exec ($ this ->command . ' --send mymail@example.com ' );
6788 $ this ->assertExitWithSuccess ();
68- $ this ->assertOutputRegExp ('/Backup ` ' . $ targetRegex . 'backup_test_\d+\.sql` has been exported/ ' );
69- $ this ->assertOutputRegExp ('/Backup ` ' . $ targetRegex . 'backup_test_\d+\.sql` was sent via mail/ ' );
89+ $ this ->assertOutputRegExp ('/Backup `[\w\-\/]+\/backup_test_\d+\.sql` has been exported/ ' );
90+ $ this ->assertOutputRegExp ('/Backup `[\w\-\/]+\/backup_test_\d+\.sql` was sent via mail/ ' );
91+ }
7092
71- //With an invalid option value
72- $ this ->exec ($ command . ' --filename /noExistingDir/backup.sql ' );
93+ /**
94+ * Test for `execute()` method, with an invalid option value
95+ * @test
96+ */
97+ public function testExecuteInvalidOptionValue ()
98+ {
99+ $ this ->exec ($ this ->command . ' --filename /noExistingDir/backup.sql ' );
73100 $ this ->assertExitWithError ();
74101 }
75102}
0 commit comments