Skip to content

Commit

Permalink
Fix issue yiisoft#762
Browse files Browse the repository at this point in the history
  • Loading branch information
evil1 committed Dec 25, 2024
1 parent 804c637 commit 13f23c7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
14 changes: 3 additions & 11 deletions src/Schema/AbstractSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,37 +576,29 @@ public function getViewNames(string $schema = '', bool $refresh = false): array
}

/**
* @param string $tableName The table name.
* @param string $schema The schema of the tables.
* @return bool
* @throws Throwable
*/
public function hasTableName(string $tableName, string $schema = ''): bool
public function hasTable(string $tableName, string $schema = ''): bool
{
$tables = $this->getTableNames($schema);

return in_array($tableName, $tables);
}

/**
* @param string $schema The schema name.
* @return bool
* @throws Throwable
*/
public function hasSchemaName(string $schema): bool
public function hasSchema(string $schema): bool
{
$schemas = $this->getSchemaNames();

return in_array($schema, $schemas);
}

/**
* @param string $viewName The view name.
* @param string $schema The schema of the views.
* @return bool
* @throws Throwable
*/
public function hasViewName(string $viewName, string $schema = ''): bool
public function hasView(string $viewName, string $schema = ''): bool
{
$views = $this->getViewNames($schema);

Expand Down
6 changes: 3 additions & 3 deletions src/Schema/SchemaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,15 @@ public function getViewNames(string $schema = '', bool $refresh = false): array;
* name. If not empty, the table will be searched in the specified schema.
* @return bool Whether table exists or not
*/
public function hasTableName(string $tableName, string $schema = ''): bool;
public function hasTable(string $tableName, string $schema = ''): bool;

/**
* Determines if a specified schema exists in the database.
*
* @param string $schema The table name to search for
* @return bool Whether schema exists or not
*/
public function hasSchemaName(string $schema): bool;
public function hasSchema(string $schema): bool;

/**
* Determines if a specified view exists in the database.
Expand All @@ -443,5 +443,5 @@ public function hasSchemaName(string $schema): bool;
* name. If not empty, the table will be searched in the specified schema.
* @return bool Whether view exists or not
*/
public function hasViewName(string $viewName, string $schema = ''): bool;
public function hasView(string $viewName, string $schema = ''): bool;
}
14 changes: 7 additions & 7 deletions tests/Common/CommonSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public function testGetTableNames(array $pdoAttributes): void
$db->close();
}

public function testHasTableName(array $pdoAttributes): void
public function testHasTable(array $pdoAttributes): void
{
$db = $this->getConnection(true);

Expand All @@ -419,9 +419,9 @@ public function testHasTableName(array $pdoAttributes): void

$schema = $db->getSchema();

$this->assertTrue($schema->hasTableName('customer'));
$this->assertTrue($schema->hasTableName('category'));
$this->assertFalse($schema->hasTableName('no_such_table'));
$this->assertTrue($schema->hasTable('customer'));
$this->assertTrue($schema->hasTable('category'));
$this->assertFalse($schema->hasTable('no_such_table'));

$db->close();
}
Expand Down Expand Up @@ -503,14 +503,14 @@ public function testGetViewNames(): void
$db->close();
}

public function hasViewName(): void
public function hasView(): void
{
$db = $this->getConnection(true);

$schema = $db->getSchema();

$this->assertTrue($schema->hasViewName('animal_view'));
$this->assertFalse($schema->hasViewName('no_such_view'));
$this->assertTrue($schema->hasView('animal_view'));
$this->assertFalse($schema->hasView('no_such_view'));

$db->close();
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Db/Schema/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,16 @@ public function testGetSchemaNamesWithSchema(): void
$this->assertSame(['dbo', 'public'], $schema->getSchemaNames());
}

public function testHasSchemaName(): void
public function testHasSchema(): void
{
$db = $this->getConnection();

$schema = $db->getSchema();
Assert::setInaccessibleProperty($schema, 'schemaNames', ['dbo', 'public']);

$this->assertTrue($schema->hasSchemaName('dbo'));
$this->assertTrue($schema->hasSchemaName('public'));
$this->assertFalse($schema->hasSchemaName('no_such_schema'));
$this->assertTrue($schema->hasSchema('dbo'));
$this->assertTrue($schema->hasSchema('public'));
$this->assertFalse($schema->hasSchema('no_such_schema'));

$db->close();
}
Expand Down

0 comments on commit 13f23c7

Please sign in to comment.