Assert that the username is specified on the connection when listing DB2 tables

parent 0db36a96
...@@ -6,7 +6,9 @@ use Doctrine\DBAL\Platforms\DB2Platform; ...@@ -6,7 +6,9 @@ use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use const CASE_LOWER; use const CASE_LOWER;
use function array_change_key_case; use function array_change_key_case;
use function assert;
use function is_resource; use function is_resource;
use function is_string;
use function preg_match; use function preg_match;
use function str_replace; use function str_replace;
use function strpos; use function strpos;
...@@ -24,12 +26,14 @@ class DB2SchemaManager extends AbstractSchemaManager ...@@ -24,12 +26,14 @@ class DB2SchemaManager extends AbstractSchemaManager
* Apparently creator is the schema not the user who created it: * Apparently creator is the schema not the user who created it:
* {@link http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z_sysibmsystablestable.htm} * {@link http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z_sysibmsystablestable.htm}
*/ */
public function listTableNames() public function listTableNames() : array
{ {
$sql = $this->_platform->getListTablesSQL(); $username = $this->_conn->getUsername();
$sql .= ' AND CREATOR = UPPER(' . $this->_conn->quote($this->_conn->getUsername()) . ')'; assert(is_string($username));
$tables = $this->_conn->fetchAll($sql); $sql = $this->_platform->getListTablesSQL() . ' AND CREATOR = UPPER(?)';
$tables = $this->_conn->fetchAll($sql, [$username]);
return $this->filterAssetNames($this->_getPortableTablesList($tables)); return $this->filterAssetNames($this->_getPortableTablesList($tables));
} }
......
...@@ -30,9 +30,14 @@ final class DB2SchemaManagerTest extends TestCase ...@@ -30,9 +30,14 @@ final class DB2SchemaManagerTest extends TestCase
$platform = $this->createMock(DB2Platform::class); $platform = $this->createMock(DB2Platform::class);
$this->conn = $this $this->conn = $this
->getMockBuilder(Connection::class) ->getMockBuilder(Connection::class)
->onlyMethods(['fetchAll', 'quote']) ->onlyMethods(['fetchAll', 'getUsername'])
->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager]) ->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager])
->getMock(); ->getMock();
$this->conn->expects($this->any())
->method('getUsername')
->willReturn('db2inst1');
$this->manager = new DB2SchemaManager($this->conn); $this->manager = new DB2SchemaManager($this->conn);
} }
...@@ -95,7 +100,7 @@ final class DB2SchemaManagerTest extends TestCase ...@@ -95,7 +100,7 @@ final class DB2SchemaManagerTest extends TestCase
$this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) {
return in_array($assetName, $accepted); return in_array($assetName, $accepted);
}); });
$this->conn->expects($this->any())->method('quote');
$this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([
['name' => 'FOO'], ['name' => 'FOO'],
['name' => 'T_FOO'], ['name' => 'T_FOO'],
...@@ -120,7 +125,7 @@ final class DB2SchemaManagerTest extends TestCase ...@@ -120,7 +125,7 @@ final class DB2SchemaManagerTest extends TestCase
$this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) {
return in_array($assetName, $accepted); return in_array($assetName, $accepted);
}); });
$this->conn->expects($this->any())->method('quote');
$this->conn->expects($this->atLeastOnce())->method('fetchAll')->will($this->returnValue([ $this->conn->expects($this->atLeastOnce())->method('fetchAll')->will($this->returnValue([
['name' => 'FOO'], ['name' => 'FOO'],
['name' => 'T_FOO'], ['name' => 'T_FOO'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment