Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: db:table shows db config #7972

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions system/Commands/Database/ShowTableInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
$this->db = Database::connect();
$this->DBPrefix = $this->db->getPrefix();

$this->showDBConfig();

$tables = $this->db->listTables();

if (array_key_exists('desc', $params)) {
Expand Down Expand Up @@ -145,6 +147,22 @@
$this->showDataOfTable($tableName, $limitRows, $limitFieldValue);
}

private function showDBConfig(): void
{
$data = [[
'hostname' => $this->db->hostname,
'database' => $this->db->getDatabase(),
'username' => $this->db->username,

Check failure on line 155 in system/Commands/Database/ShowTableInfo.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Access to protected property CodeIgniter\Database\BaseConnection::$username.

Check failure on line 155 in system/Commands/Database/ShowTableInfo.php

View workflow job for this annotation

GitHub Actions / Psalm Analysis

InaccessibleProperty

system/Commands/Database/ShowTableInfo.php:155:27: InaccessibleProperty: Cannot access protected property CodeIgniter\Database\BaseConnection::$username from context CodeIgniter\Commands\Database\ShowTableInfo (see https://psalm.dev/054)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to protected property username. Although port, hostname are also protected, there is no error for them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a magic getter __get().

'DBDriver' => $this->db->getPlatform(),
'DBPrefix' => $this->DBPrefix,
'port' => $this->db->port,
]];
CLI::table(
$data,
['hostname', 'database', 'username', 'DBDriver', 'DBPrefix', 'port']
);
}

private function removeDBPrefix(): void
{
$this->db->setPrefix('');
Expand Down
14 changes: 14 additions & 0 deletions tests/system/Commands/Database/ShowTableInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ public function testDbTable(): void
$this->assertMatchesRegularExpression($expectedPattern, $result);
}

public function testDbTableShowsDBConfig(): void
{
command('db:table');

$result = $this->getNormalizedResult();

$expected = <<<'EOL'
+-----------+----------+----------+----------+----------+------+
| hostname | database | username | DBDriver | DBPrefix | port |
+-----------+----------+----------+----------+----------+------+
EOL;
$this->assertStringContainsString($expected, $result);
}

public function testDbTableShow(): void
{
command('db:table --show');
Expand Down
Loading