File tree 2 files changed +23
-2
lines changed
tests/system/Commands/Database
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 17
17
use CodeIgniter \CLI \CLI ;
18
18
use CodeIgniter \Database \BaseConnection ;
19
19
use Config \Database ;
20
+ use InvalidArgumentException ;
20
21
21
22
/**
22
23
* Get table data if it exists in the database.
@@ -83,14 +84,15 @@ class ShowTableInfo extends BaseCommand
83
84
'--desc ' => 'Sorts the table rows in DESC order. ' ,
84
85
'--limit-rows ' => 'Limits the number of rows. Default: 10. ' ,
85
86
'--limit-field-value ' => 'Limits the length of field values. Default: 15. ' ,
87
+ '--dbgroup ' => 'Database group to show. ' ,
86
88
];
87
89
88
90
/**
89
91
* @var list<list<int|string>> Table Data.
90
92
*/
91
93
private array $ tbody ;
92
94
93
- private BaseConnection $ db ;
95
+ private ? BaseConnection $ db = null ;
94
96
95
97
/**
96
98
* @var bool Sort the table rows in DESC order or not.
@@ -101,7 +103,16 @@ class ShowTableInfo extends BaseCommand
101
103
102
104
public function run (array $ params )
103
105
{
104
- $ this ->db = Database::connect ();
106
+ $ dbGroup = $ params ['dbgroup ' ] ?? CLI ::getOption ('dbgroup ' );
107
+
108
+ try {
109
+ $ this ->db = Database::connect ($ dbGroup );
110
+ } catch (InvalidArgumentException $ e ) {
111
+ CLI ::error ($ e ->getMessage ());
112
+
113
+ return EXIT_ERROR ;
114
+ }
115
+
105
116
$ this ->DBPrefix = $ this ->db ->getPrefix ();
106
117
107
118
$ this ->showDBConfig ();
Original file line number Diff line number Diff line change @@ -66,6 +66,16 @@ public function testDbTable(): void
66
66
$ this ->assertMatchesRegularExpression ($ expectedPattern , $ result );
67
67
}
68
68
69
+ public function testDbTableShowsWithInvalidDBGroup (): void
70
+ {
71
+ command ('db:table --show --dbgroup invalid ' );
72
+
73
+ $ result = $ this ->getNormalizedResult ();
74
+
75
+ $ expected = '"invalid" is not a valid database connection group. ' ;
76
+ $ this ->assertStringContainsString ($ expected , $ result );
77
+ }
78
+
69
79
public function testDbTableShowsDBConfig (): void
70
80
{
71
81
command ('db:table --show ' );
You can’t perform that action at this time.
0 commit comments