11<?php
22namespace webfiori \framework \test \cli ;
33
4- use PHPUnit \ Framework \ TestCase ;
4+ use webfiori \ cli \ CommandTestCase ;
55use webfiori \cli \Runner ;
66use webfiori \file \File ;
77use webfiori \framework \App ;
1313 *
1414 * @author Ibrahim
1515 */
16- class AddCommandTest extends TestCase {
16+ class AddCommandTest extends CommandTestCase {
1717 /**
1818 * @test
1919 */
2020 public function test00 () {
21+ $ output = $ this ->executeSingleCommand (new AddCommand (), [], [
22+ '3 '
23+ ]);
2124 $ runner = new Runner ();
2225 $ runner ->setInputs ([
2326 '3 '
2427 ]);
25- $ this ->assertEquals (0 , $ runner ->runCommand (new AddCommand ()));
2628 $ this ->assertEquals ([
2729 "What would you like to add? \n" ,
2830 "0: New database connection. \n" ,
2931 "1: New SMTP connection. \n" ,
3032 "2: New website language. \n" ,
3133 "3: Quit. <-- \n"
32- ], $ runner ->getOutput ());
34+ ], $ output );
35+ $ this ->assertEquals (0 , $ this ->getExitCode ());
3336 }
3437 /**
3538 * @test
3639 */
3740 public function testAddDBConnection00 () {
38- $ runner = App::getRunner ();
39- $ runner ->setInputs ([
41+ $ output = $ this ->executeSingleCommand (new AddCommand (), [], [
4042 '0 ' ,
4143 '0 ' ,
4244 '127.0.0.1 ' ,
@@ -46,11 +48,8 @@ public function testAddDBConnection00() {
4648 'testing_db ' ,
4749 ''
4850 ]);
49- $ runner ->setArgsVector ([
50- 'webfiori ' ,
51- 'add '
52- ]);
53- $ this ->assertEquals (0 , $ runner ->start ());
51+
52+
5453 $ connName = 'db-connection- ' .(count (App::getConfig ()->getDBConnections ()) - 1 );
5554 $ this ->assertEquals ([
5655 "What would you like to add? \n" ,
@@ -70,7 +69,8 @@ public function testAddDBConnection00() {
7069 "Trying to connect to the database... \n" ,
7170 "Success: Connected. Adding the connection... \n" ,
7271 "Success: Connection information was stored in application configuration. \n"
73- ], $ runner ->getOutput ());
72+ ], $ output );
73+ $ this ->assertEquals (0 , $ this ->getExitCode ());
7474 }
7575 /**
7676 * @test
@@ -111,8 +111,9 @@ public function testAddDBConnection01() {
111111 "Database name: \n" ,
112112 "Give your connection a friendly name: Enter = ' $ connName' \n" ,
113113 "Trying to connect to the database... \n" ,
114+ "Trying with 'localhost'... \n" ,
114115 "Error: Unable to connect to the database. \n" ,
115- "Error: Unable to connect to database: 2002 - No such file or directory \n" ,
116+ "Error: Unable to connect to database: 1045 - Access denied for user 'root'@'localhost' (using password: YES) \n" ,
116117 "Would you like to store connection information anyway?(y/N) \n" ,
117118 "Success: Connection information was stored in application configuration. \n"
118119 ], $ runner ->getOutput ());
@@ -155,8 +156,9 @@ public function testAddDBConnection02() {
155156 "Database name: \n" ,
156157 "Give your connection a friendly name: Enter = ' $ connName' \n" ,
157158 "Trying to connect to the database... \n" ,
159+ "Trying with 'localhost'... \n" ,
158160 "Error: Unable to connect to the database. \n" ,
159- "Error: Unable to connect to database: 2002 - No such file or directory \n" ,
161+ "Error: Unable to connect to database: 1045 - Access denied for user 'root'@'localhost' (using password: YES) \n" ,
160162 "Would you like to store connection information anyway?(y/N) \n" ,
161163 ], $ runner ->getOutput ());
162164 }
0 commit comments