Unverified Commit f9b3e790 authored by Michael Moravec's avatar Michael Moravec Committed by Sergei Morozov

Enable PHPStan in tests

parent be458b5d
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "c80faa771bd92a02a1deef849df31e83", "content-hash": "b8d34165a2e5fbd1c74f7a5125e7d9f1",
"packages": [ "packages": [
{ {
"name": "doctrine/cache", "name": "doctrine/cache",
...@@ -1582,6 +1582,63 @@ ...@@ -1582,6 +1582,63 @@
"description": "PHPStan - PHP Static Analysis Tool", "description": "PHPStan - PHP Static Analysis Tool",
"time": "2019-08-18T20:51:53+00:00" "time": "2019-08-18T20:51:53+00:00"
}, },
{
"name": "phpstan/phpstan-phpunit",
"version": "0.11.2",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-phpunit.git",
"reference": "fbf2ad56c3b13189d29655e226c9b1da47c2fad9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/fbf2ad56c3b13189d29655e226c9b1da47c2fad9",
"reference": "fbf2ad56c3b13189d29655e226c9b1da47c2fad9",
"shasum": ""
},
"require": {
"nikic/php-parser": "^4.0",
"php": "~7.1",
"phpstan/phpdoc-parser": "^0.3",
"phpstan/phpstan": "^0.11.4"
},
"conflict": {
"phpunit/phpunit": "<7.0"
},
"require-dev": {
"consistence/coding-standard": "^3.0.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
"jakub-onderka/php-parallel-lint": "^1.0",
"phing/phing": "^2.16.0",
"phpstan/phpstan-strict-rules": "^0.11",
"phpunit/phpunit": "^7.0",
"satooshi/php-coveralls": "^1.0",
"slevomat/coding-standard": "^4.5.2"
},
"type": "phpstan-extension",
"extra": {
"branch-alias": {
"dev-master": "0.11-dev"
},
"phpstan": {
"includes": [
"extension.neon",
"rules.neon"
]
}
},
"autoload": {
"psr-4": {
"PHPStan\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPUnit extensions and rules for PHPStan",
"time": "2019-05-17T17:50:16+00:00"
},
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "7.0.8", "version": "7.0.8",
......
...@@ -2,6 +2,7 @@ parameters: ...@@ -2,6 +2,7 @@ parameters:
level: 7 level: 7
paths: paths:
- %currentWorkingDirectory%/lib - %currentWorkingDirectory%/lib
- %currentWorkingDirectory%/tests
autoload_files: autoload_files:
- %currentWorkingDirectory%/tests/phpstan-polyfill.php - %currentWorkingDirectory%/tests/phpstan-polyfill.php
reportUnmatchedIgnoredErrors: false reportUnmatchedIgnoredErrors: false
...@@ -63,3 +64,26 @@ parameters: ...@@ -63,3 +64,26 @@ parameters:
- -
message: '~^Strict comparison using === between string|false and null will always evaluate to false\.~' message: '~^Strict comparison using === between string|false and null will always evaluate to false\.~'
path: %currentWorkingDirectory%/lib/Doctrine/DBAL/Driver/PDOStatement.php path: %currentWorkingDirectory%/lib/Doctrine/DBAL/Driver/PDOStatement.php
# impossible inference for covariance
- '~^Property Doctrine\\Tests\\DBAL\\Types\\\S+Test::\$type \(Doctrine\\DBAL\\Types\\\S+Type\) does not accept Doctrine\\DBAL\\Types\\Type\.\z~'
- '~^Property Doctrine\\Tests\\DBAL\\Tools\\Console\\RunSqlCommandTest::\$command \(Doctrine\\DBAL\\Tools\\Console\\Command\\RunSqlCommand\) does not accept Symfony\\Component\\Console\\Command\\Command\.\z~'
# https://github.com/phpstan/phpstan-phpunit/pull/28
-
message: '~Call to method expects\(\) on an unknown class \S+~'
path: %currentWorkingDirectory%/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
-
message: '~Call to method expects\(\) on an unknown class \S+~'
path: %currentWorkingDirectory%/tests/Doctrine/Tests/DBAL/ConnectionTest.php
-
message: '~Call to method expects\(\) on an unknown class \S+~'
path: %currentWorkingDirectory%/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
# https://github.com/doctrine/dbal/pull/3582/files#r290847062
-
message: '~Parameter #3 \$type of method Doctrine\\DBAL\\Driver\\Statement::bindValue\(\) expects int, string given\.~'
path: %currentWorkingDirectory%/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
...@@ -136,8 +136,8 @@ class ArrayStatementTest extends TestCase ...@@ -136,8 +136,8 @@ class ArrayStatementTest extends TestCase
$statement = $this->createTestArrayStatement(); $statement = $this->createTestArrayStatement();
self::assertSame(true, $statement->fetchColumn(1)); self::assertTrue($statement->fetchColumn(1));
self::assertSame(false, $statement->fetchColumn(1)); self::assertFalse($statement->fetchColumn(1));
} }
private function createTestArrayStatement() : ArrayStatement private function createTestArrayStatement() : ArrayStatement
......
...@@ -23,7 +23,7 @@ class QueryCacheProfileTest extends DbalTestCase ...@@ -23,7 +23,7 @@ class QueryCacheProfileTest extends DbalTestCase
/** @var int[] */ /** @var int[] */
private $params = [666]; private $params = [666];
/** @var string[] */ /** @var int[] */
private $types = [ParameterType::INTEGER]; private $types = [ParameterType::INTEGER];
/** @var string[] */ /** @var string[] */
......
...@@ -198,6 +198,9 @@ abstract class AbstractDriverTest extends DbalTestCase ...@@ -198,6 +198,9 @@ abstract class AbstractDriverTest extends DbalTestCase
*/ */
abstract protected function createSchemaManager(Connection $connection) : AbstractSchemaManager; abstract protected function createSchemaManager(Connection $connection) : AbstractSchemaManager;
/**
* @return Connection|MockObject
*/
protected function getConnectionMock() : Connection protected function getConnectionMock() : Connection
{ {
return $this->getMockBuilder(Connection::class) return $this->getMockBuilder(Connection::class)
......
...@@ -58,7 +58,7 @@ class MysqliConnectionTest extends DbalFunctionalTestCase ...@@ -58,7 +58,7 @@ class MysqliConnectionTest extends DbalFunctionalTestCase
// Do nothing // Do nothing
} }
self::assertSame($handler, set_error_handler($default_handler), 'Restoring error handler failed.'); self::assertSame($handler, set_error_handler($handler), 'Restoring error handler failed.');
restore_error_handler(); restore_error_handler();
restore_error_handler(); restore_error_handler();
} }
......
...@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Driver; ...@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Driver;
use Doctrine\DBAL\Driver\PDOException; use Doctrine\DBAL\Driver\PDOException;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
/** /**
* @requires extension pdo * @requires extension pdo
...@@ -29,7 +28,7 @@ class PDOExceptionTest extends DbalTestCase ...@@ -29,7 +28,7 @@ class PDOExceptionTest extends DbalTestCase
/** /**
* The wrapped PDO exception mock. * The wrapped PDO exception mock.
* *
* @var \PDOException|MockObject * @var \PDOException
*/ */
private $wrappedException; private $wrappedException;
......
...@@ -15,8 +15,9 @@ use Doctrine\DBAL\Portability\Statement as PortabilityStatement; ...@@ -15,8 +15,9 @@ use Doctrine\DBAL\Portability\Statement as PortabilityStatement;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use IteratorAggregate; use IteratorAggregate;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Traversable; use function assert;
use function extension_loaded; use function extension_loaded;
use function is_iterable;
class StatementIteratorTest extends DbalTestCase class StatementIteratorTest extends DbalTestCase
{ {
...@@ -43,7 +44,9 @@ class StatementIteratorTest extends DbalTestCase ...@@ -43,7 +44,9 @@ class StatementIteratorTest extends DbalTestCase
$stmtIterator = new StatementIterator($stmt); $stmtIterator = new StatementIterator($stmt);
$this->assertIterationCallsFetchOncePerStep($stmtIterator, $calls); foreach ($stmtIterator as $i => $_) {
$this->assertEquals($i + 1, $calls);
}
} }
/** /**
...@@ -52,10 +55,14 @@ class StatementIteratorTest extends DbalTestCase ...@@ -52,10 +55,14 @@ class StatementIteratorTest extends DbalTestCase
public function testStatementIterationCallsFetchOncePerStep(string $class) : void public function testStatementIterationCallsFetchOncePerStep(string $class) : void
{ {
$stmt = $this->createPartialMock($class, ['fetch']); $stmt = $this->createPartialMock($class, ['fetch']);
assert(is_iterable($stmt));
$calls = 0; $calls = 0;
$this->configureStatement($stmt, $calls); $this->configureStatement($stmt, $calls);
$this->assertIterationCallsFetchOncePerStep($stmt, $calls);
foreach ($stmt as $i => $_) {
$this->assertEquals($i + 1, $calls);
}
} }
private function configureStatement(MockObject $stmt, int &$calls) : void private function configureStatement(MockObject $stmt, int &$calls) : void
...@@ -73,13 +80,6 @@ class StatementIteratorTest extends DbalTestCase ...@@ -73,13 +80,6 @@ class StatementIteratorTest extends DbalTestCase
}); });
} }
private function assertIterationCallsFetchOncePerStep(Traversable $iterator, int &$calls) : void
{
foreach ($iterator as $i => $_) {
$this->assertEquals($i + 1, $calls);
}
}
/** /**
* @return string[][] * @return string[][]
*/ */
......
...@@ -196,7 +196,7 @@ class DriverManagerTest extends DbalTestCase ...@@ -196,7 +196,7 @@ class DriverManagerTest extends DbalTestCase
} }
/** /**
* @return array<string, array<int, mixed>> * @return array<string, mixed>
*/ */
public function databaseUrls() : iterable public function databaseUrls() : iterable
{ {
......
...@@ -28,9 +28,11 @@ use const PHP_EOL; ...@@ -28,9 +28,11 @@ use const PHP_EOL;
use function array_change_key_case; use function array_change_key_case;
use function array_filter; use function array_filter;
use function array_keys; use function array_keys;
use function assert;
use function count; use function count;
use function date; use function date;
use function implode; use function implode;
use function is_array;
use function is_numeric; use function is_numeric;
use function json_encode; use function json_encode;
use function property_exists; use function property_exists;
...@@ -521,6 +523,8 @@ class DataAccessTest extends DbalFunctionalTestCase ...@@ -521,6 +523,8 @@ class DataAccessTest extends DbalFunctionalTestCase
'FROM fetch_table'; 'FROM fetch_table';
$row = $this->connection->fetchAssoc($sql); $row = $this->connection->fetchAssoc($sql);
self::assertIsArray($row);
$row = array_change_key_case($row, CASE_LOWER); $row = array_change_key_case($row, CASE_LOWER);
self::assertEquals($expectedResult, $row['trimmed']); self::assertEquals($expectedResult, $row['trimmed']);
...@@ -931,6 +935,8 @@ class DataAccessTest extends DbalFunctionalTestCase ...@@ -931,6 +935,8 @@ class DataAccessTest extends DbalFunctionalTestCase
$sql .= 'FROM fetch_table'; $sql .= 'FROM fetch_table';
$row = $this->connection->fetchAssoc($sql); $row = $this->connection->fetchAssoc($sql);
assert(is_array($row));
$row = array_change_key_case($row, CASE_LOWER); $row = array_change_key_case($row, CASE_LOWER);
self::assertEquals(2, $row['locate1']); self::assertEquals(2, $row['locate1']);
......
...@@ -5,8 +5,10 @@ declare(strict_types=1); ...@@ -5,8 +5,10 @@ declare(strict_types=1);
namespace Doctrine\Tests\DBAL\Functional\Driver\IBMDB2; namespace Doctrine\Tests\DBAL\Functional\Driver\IBMDB2;
use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; use Doctrine\DBAL\Driver\IBMDB2\DB2Driver;
use Doctrine\DBAL\Statement;
use Doctrine\Tests\DbalFunctionalTestCase; use Doctrine\Tests\DbalFunctionalTestCase;
use PHPUnit\Framework\Error\Notice; use PHPUnit\Framework\Error\Notice;
use function assert;
use function extension_loaded; use function extension_loaded;
class DB2StatementTest extends DbalFunctionalTestCase class DB2StatementTest extends DbalFunctionalTestCase
...@@ -29,6 +31,7 @@ class DB2StatementTest extends DbalFunctionalTestCase ...@@ -29,6 +31,7 @@ class DB2StatementTest extends DbalFunctionalTestCase
public function testExecutionErrorsAreNotSuppressed() : void public function testExecutionErrorsAreNotSuppressed() : void
{ {
$stmt = $this->connection->prepare('SELECT * FROM SYSIBM.SYSDUMMY1 WHERE \'foo\' = ?'); $stmt = $this->connection->prepare('SELECT * FROM SYSIBM.SYSDUMMY1 WHERE \'foo\' = ?');
assert($stmt instanceof Statement);
// unwrap the statement to prevent the wrapper from handling the PHPUnit-originated exception // unwrap the statement to prevent the wrapper from handling the PHPUnit-originated exception
$wrappedStmt = $stmt->getWrappedStatement(); $wrappedStmt = $stmt->getWrappedStatement();
......
...@@ -8,6 +8,7 @@ use Doctrine\DBAL\Driver\OCI8\Driver; ...@@ -8,6 +8,7 @@ use Doctrine\DBAL\Driver\OCI8\Driver;
use Doctrine\DBAL\Driver\OCI8\OCI8Connection; use Doctrine\DBAL\Driver\OCI8\OCI8Connection;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalFunctionalTestCase; use Doctrine\Tests\DbalFunctionalTestCase;
use function assert;
use function extension_loaded; use function extension_loaded;
class OCI8ConnectionTest extends DbalFunctionalTestCase class OCI8ConnectionTest extends DbalFunctionalTestCase
...@@ -27,7 +28,10 @@ class OCI8ConnectionTest extends DbalFunctionalTestCase ...@@ -27,7 +28,10 @@ class OCI8ConnectionTest extends DbalFunctionalTestCase
$this->markTestSkipped('oci8 only test.'); $this->markTestSkipped('oci8 only test.');
} }
$this->driverConnection = $this->connection->getWrappedConnection(); $wrappedConnection = $this->connection->getWrappedConnection();
assert($wrappedConnection instanceof OCI8Connection);
$this->driverConnection = $wrappedConnection;
} }
/** /**
......
...@@ -30,13 +30,13 @@ class PDOConnectionTest extends DbalFunctionalTestCase ...@@ -30,13 +30,13 @@ class PDOConnectionTest extends DbalFunctionalTestCase
{ {
parent::setUp(); parent::setUp();
$this->driverConnection = $this->connection->getWrappedConnection(); $wrappedConnection = $this->connection->getWrappedConnection();
if ($this->driverConnection instanceof PDOConnection) { if (! $wrappedConnection instanceof PDOConnection) {
return; $this->markTestSkipped('PDO connection only test.');
} }
$this->markTestSkipped('PDO connection only test.'); $this->driverConnection = $wrappedConnection;
} }
protected function tearDown() : void protected function tearDown() : void
......
...@@ -38,7 +38,7 @@ class StatementTest extends DbalFunctionalTestCase ...@@ -38,7 +38,7 @@ class StatementTest extends DbalFunctionalTestCase
self::assertTrue($conn->isConnected(), 'No SQLAnywhere-Connection established'); self::assertTrue($conn->isConnected(), 'No SQLAnywhere-Connection established');
$prepStmt = $conn->prepare('SELECT 1'); $prepStmt = $conn->prepare('SELECT 1');
self::assertTrue($prepStmt->execute(), ' Statement non-persistent failed'); $prepStmt->execute();
} }
public function testPersistentStatement() : void public function testPersistentStatement() : void
...@@ -53,6 +53,6 @@ class StatementTest extends DbalFunctionalTestCase ...@@ -53,6 +53,6 @@ class StatementTest extends DbalFunctionalTestCase
self::assertTrue($conn->isConnected(), 'No SQLAnywhere-Connection established'); self::assertTrue($conn->isConnected(), 'No SQLAnywhere-Connection established');
$prepStmt = $conn->prepare('SELECT 1'); $prepStmt = $conn->prepare('SELECT 1');
self::assertTrue($prepStmt->execute(), ' Statement persistent failed'); $prepStmt->execute();
} }
} }
...@@ -12,6 +12,7 @@ use Doctrine\Tests\DbalFunctionalTestCase; ...@@ -12,6 +12,7 @@ use Doctrine\Tests\DbalFunctionalTestCase;
use Throwable; use Throwable;
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 sprintf; use function sprintf;
use function strlen; use function strlen;
use function strtolower; use function strtolower;
...@@ -49,7 +50,10 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase ...@@ -49,7 +50,10 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
private function createMasterSlaveConnection(bool $keepSlave = false) : MasterSlaveConnection private function createMasterSlaveConnection(bool $keepSlave = false) : MasterSlaveConnection
{ {
return DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave)); $connection = DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave));
assert($connection instanceof MasterSlaveConnection);
return $connection;
} }
/** /**
......
...@@ -21,11 +21,16 @@ class PortabilityTest extends DbalFunctionalTestCase ...@@ -21,11 +21,16 @@ class PortabilityTest extends DbalFunctionalTestCase
/** @var Connection */ /** @var Connection */
private $portableConnection; private $portableConnection;
protected function setUp() : void
{
parent::setUp();
$this->portableConnection = $this->getPortableConnection();
}
protected function tearDown() : void protected function tearDown() : void
{ {
if ($this->portableConnection) { $this->portableConnection->close();
$this->portableConnection->close();
}
parent::tearDown(); parent::tearDown();
} }
...@@ -34,64 +39,62 @@ class PortabilityTest extends DbalFunctionalTestCase ...@@ -34,64 +39,62 @@ class PortabilityTest extends DbalFunctionalTestCase
int $portabilityMode = ConnectionPortability::PORTABILITY_ALL, int $portabilityMode = ConnectionPortability::PORTABILITY_ALL,
int $case = ColumnCase::LOWER int $case = ColumnCase::LOWER
) : Connection { ) : Connection {
if (! $this->portableConnection) { $params = $this->connection->getParams();
$params = $this->connection->getParams();
$params['wrapperClass'] = ConnectionPortability::class;
$params['wrapperClass'] = ConnectionPortability::class; $params['portability'] = $portabilityMode;
$params['portability'] = $portabilityMode; $params['fetch_case'] = $case;
$params['fetch_case'] = $case;
$portableConnection = DriverManager::getConnection($params, $this->connection->getConfiguration(), $this->connection->getEventManager());
$this->portableConnection = DriverManager::getConnection($params, $this->connection->getConfiguration(), $this->connection->getEventManager());
$table = new Table('portability_table');
$table = new Table('portability_table'); $table->addColumn('Test_Int', 'integer');
$table->addColumn('Test_Int', 'integer'); $table->addColumn('Test_String', 'string', [
$table->addColumn('Test_String', 'string', [ 'length' => 8,
'length' => 8, 'fixed' => true,
'fixed' => true, ]);
]); $table->addColumn('Test_Null', 'string', [
$table->addColumn('Test_Null', 'string', [ 'length' => 1,
'length' => 1, 'notnull' => false,
'notnull' => false, ]);
]); $table->setPrimaryKey(['Test_Int']);
$table->setPrimaryKey(['Test_Int']);
$sm = $portableConnection->getSchemaManager();
$sm = $this->portableConnection->getSchemaManager(); $sm->dropAndCreateTable($table);
$sm->dropAndCreateTable($table);
$portableConnection->insert('portability_table', [
$this->portableConnection->insert('portability_table', [ 'Test_Int' => 1,
'Test_Int' => 1, 'Test_String' => 'foo',
'Test_String' => 'foo', 'Test_Null' => '',
'Test_Null' => '', ]);
]); $portableConnection->insert('portability_table', [
$this->portableConnection->insert('portability_table', [ 'Test_Int' => 2,
'Test_Int' => 2, 'Test_String' => 'foo ',
'Test_String' => 'foo ', 'Test_Null' => null,
'Test_Null' => null, ]);
]);
} return $portableConnection;
return $this->portableConnection;
} }
public function testFullFetchMode() : void public function testFullFetchMode() : void
{ {
$rows = $this->getPortableConnection()->fetchAll('SELECT * FROM portability_table'); $rows = $this->portableConnection->fetchAll('SELECT * FROM portability_table');
$this->assertFetchResultRows($rows); $this->assertFetchResultRows($rows);
$stmt = $this->getPortableConnection()->query('SELECT * FROM portability_table'); $stmt = $this->portableConnection->query('SELECT * FROM portability_table');
$stmt->setFetchMode(FetchMode::ASSOCIATIVE); $stmt->setFetchMode(FetchMode::ASSOCIATIVE);
foreach ($stmt as $row) { foreach ($stmt as $row) {
$this->assertFetchResultRow($row); $this->assertFetchResultRow($row);
} }
$stmt = $this->getPortableConnection()->query('SELECT * FROM portability_table'); $stmt = $this->portableConnection->query('SELECT * FROM portability_table');
while (($row = $stmt->fetch(FetchMode::ASSOCIATIVE))) { while (($row = $stmt->fetch(FetchMode::ASSOCIATIVE))) {
$this->assertFetchResultRow($row); $this->assertFetchResultRow($row);
} }
$stmt = $this->getPortableConnection()->prepare('SELECT * FROM portability_table'); $stmt = $this->portableConnection->prepare('SELECT * FROM portability_table');
$stmt->execute(); $stmt->execute();
while (($row = $stmt->fetch(FetchMode::ASSOCIATIVE))) { while (($row = $stmt->fetch(FetchMode::ASSOCIATIVE))) {
...@@ -101,23 +104,22 @@ class PortabilityTest extends DbalFunctionalTestCase ...@@ -101,23 +104,22 @@ class PortabilityTest extends DbalFunctionalTestCase
public function testConnFetchMode() : void public function testConnFetchMode() : void
{ {
$conn = $this->getPortableConnection(); $this->portableConnection->setFetchMode(FetchMode::ASSOCIATIVE);
$conn->setFetchMode(FetchMode::ASSOCIATIVE);
$rows = $conn->fetchAll('SELECT * FROM portability_table'); $rows = $this->portableConnection->fetchAll('SELECT * FROM portability_table');
$this->assertFetchResultRows($rows); $this->assertFetchResultRows($rows);
$stmt = $conn->query('SELECT * FROM portability_table'); $stmt = $this->portableConnection->query('SELECT * FROM portability_table');
foreach ($stmt as $row) { foreach ($stmt as $row) {
$this->assertFetchResultRow($row); $this->assertFetchResultRow($row);
} }
$stmt = $conn->query('SELECT * FROM portability_table'); $stmt = $this->portableConnection->query('SELECT * FROM portability_table');
while (($row = $stmt->fetch())) { while (($row = $stmt->fetch())) {
$this->assertFetchResultRow($row); $this->assertFetchResultRow($row);
} }
$stmt = $conn->prepare('SELECT * FROM portability_table'); $stmt = $this->portableConnection->prepare('SELECT * FROM portability_table');
$stmt->execute(); $stmt->execute();
while (($row = $stmt->fetch())) { while (($row = $stmt->fetch())) {
$this->assertFetchResultRow($row); $this->assertFetchResultRow($row);
...@@ -154,8 +156,7 @@ class PortabilityTest extends DbalFunctionalTestCase ...@@ -154,8 +156,7 @@ class PortabilityTest extends DbalFunctionalTestCase
*/ */
public function testFetchAllColumn(string $field, array $expected) : void public function testFetchAllColumn(string $field, array $expected) : void
{ {
$conn = $this->getPortableConnection(); $stmt = $this->portableConnection->query('SELECT ' . $field . ' FROM portability_table');
$stmt = $conn->query('SELECT ' . $field . ' FROM portability_table');
$column = $stmt->fetchAll(FetchMode::COLUMN); $column = $stmt->fetchAll(FetchMode::COLUMN);
self::assertEquals($expected, $column); self::assertEquals($expected, $column);
...@@ -180,8 +181,7 @@ class PortabilityTest extends DbalFunctionalTestCase ...@@ -180,8 +181,7 @@ class PortabilityTest extends DbalFunctionalTestCase
public function testFetchAllNullColumn() : void public function testFetchAllNullColumn() : void
{ {
$conn = $this->getPortableConnection(); $stmt = $this->portableConnection->query('SELECT Test_Null FROM portability_table');
$stmt = $conn->query('SELECT Test_Null FROM portability_table');
$column = $stmt->fetchAll(FetchMode::COLUMN); $column = $stmt->fetchAll(FetchMode::COLUMN);
self::assertSame([null, null], $column); self::assertSame([null, null], $column);
......
...@@ -23,7 +23,7 @@ use function is_array; ...@@ -23,7 +23,7 @@ use function is_array;
*/ */
class ResultCacheTest extends DbalFunctionalTestCase class ResultCacheTest extends DbalFunctionalTestCase
{ {
/** @var array<int, array<int, int|string>> */ /** @var array<int, array<string, int|string>> */
private $expectedResult = [['test_int' => 100, 'test_string' => 'foo'], ['test_int' => 200, 'test_string' => 'bar'], ['test_int' => 300, 'test_string' => 'baz']]; private $expectedResult = [['test_int' => 100, 'test_string' => 'foo'], ['test_int' => 200, 'test_string' => 'bar'], ['test_int' => 300, 'test_string' => 'baz']];
/** @var DebugStack */ /** @var DebugStack */
...@@ -192,7 +192,7 @@ class ResultCacheTest extends DbalFunctionalTestCase ...@@ -192,7 +192,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
} }
/** /**
* @param array<int, array<int, int|string>> $expectedResult * @param array<int, mixed> $expectedResult
*/ */
private function assertCacheNonCacheSelectSameFetchModeAreEqual(array $expectedResult, int $fetchMode) : void private function assertCacheNonCacheSelectSameFetchModeAreEqual(array $expectedResult, int $fetchMode) : void
{ {
......
...@@ -45,7 +45,12 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -45,7 +45,12 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$tableNew->setPrimaryKey(['bar_id', 'foo_id']); $tableNew->setPrimaryKey(['bar_id', 'foo_id']);
$comparator = new Comparator(); $comparator = new Comparator();
$this->schemaManager->alterTable($comparator->diffTable($tableFetched, $tableNew));
$diff = $comparator->diffTable($tableFetched, $tableNew);
self::assertNotNull($diff);
$this->schemaManager->alterTable($diff);
$table = $this->schemaManager->listTableDetails('switch_primary_key_columns'); $table = $this->schemaManager->listTableDetails('switch_primary_key_columns');
$primaryKey = $table->getPrimaryKeyColumns(); $primaryKey = $table->getPrimaryKeyColumns();
...@@ -120,7 +125,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -120,7 +125,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$diffTable->dropIndex('idx_id'); $diffTable->dropIndex('idx_id');
$diffTable->setPrimaryKey(['id']); $diffTable->setPrimaryKey(['id']);
$this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); $diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
$this->schemaManager->alterTable($diff);
$table = $this->schemaManager->listTableDetails('alter_table_add_pk'); $table = $this->schemaManager->listTableDetails('alter_table_add_pk');
...@@ -146,7 +155,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -146,7 +155,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$comparator = new Comparator(); $comparator = new Comparator();
$this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); $diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
$this->schemaManager->alterTable($diff);
$table = $this->schemaManager->listTableDetails('drop_primary_key'); $table = $this->schemaManager->listTableDetails('drop_primary_key');
...@@ -184,7 +197,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -184,7 +197,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$comparator = new Comparator(); $comparator = new Comparator();
$this->schemaManager->alterTable($comparator->diffTable($table, $onlineTable)); $diff = $comparator->diffTable($table, $onlineTable);
self::assertNotNull($diff);
$this->schemaManager->alterTable($diff);
$onlineTable = $this->schemaManager->listTableDetails('text_blob_default_value'); $onlineTable = $this->schemaManager->listTableDetails('text_blob_default_value');
...@@ -227,7 +244,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -227,7 +244,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$comparator = new Comparator(); $comparator = new Comparator();
$this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); $diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
$this->schemaManager->alterTable($diff);
$table = $this->schemaManager->listTableDetails($tableName); $table = $this->schemaManager->listTableDetails($tableName);
......
...@@ -44,7 +44,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -44,7 +44,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$tables = $this->schemaManager->listTables(); $tables = $this->schemaManager->listTables();
self::assertHasTable($tables, 'list_tables_test_new_name'); self::assertHasTable($tables);
} }
public function testListTableWithBinary() : void public function testListTableWithBinary() : void
...@@ -98,7 +98,11 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -98,7 +98,11 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
$diffTable->changeColumn('foo', ['notnull' => false]); $diffTable->changeColumn('foo', ['notnull' => false]);
$diffTable->changeColumn('bar', ['length' => 1024]); $diffTable->changeColumn('bar', ['length' => 1024]);
$this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); $diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
$this->schemaManager->alterTable($diff);
$columns = $this->schemaManager->listTableColumns($tableName); $columns = $this->schemaManager->listTableColumns($tableName);
......
...@@ -9,6 +9,7 @@ use Doctrine\DBAL\Platforms\PostgreSQL94Platform; ...@@ -9,6 +9,7 @@ use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\PostgreSqlSchemaManager;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\BlobType;
...@@ -23,14 +24,13 @@ use function strtolower; ...@@ -23,14 +24,13 @@ use function strtolower;
class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{ {
/** @var PostgreSqlSchemaManager */
protected $schemaManager;
protected function tearDown() : void protected function tearDown() : void
{ {
parent::tearDown(); parent::tearDown();
if (! $this->connection) {
return;
}
$this->connection->getConfiguration()->setSchemaAssetsFilter(null); $this->connection->getConfiguration()->setSchemaAssetsFilter(null);
} }
...@@ -109,7 +109,10 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -109,7 +109,10 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$c = new Comparator(); $c = new Comparator();
$diff = $c->diffTable($tableFrom, $tableTo); $diff = $c->diffTable($tableFrom, $tableTo);
$sql = $this->connection->getDatabasePlatform()->getAlterTableSQL($diff);
self::assertNotNull($diff);
$sql = $this->connection->getDatabasePlatform()->getAlterTableSQL($diff);
self::assertEquals([ self::assertEquals([
'CREATE SEQUENCE autoinc_table_add_id_seq', 'CREATE SEQUENCE autoinc_table_add_id_seq',
"SELECT setval('autoinc_table_add_id_seq', (SELECT MAX(id) FROM autoinc_table_add))", "SELECT setval('autoinc_table_add_id_seq', (SELECT MAX(id) FROM autoinc_table_add))",
...@@ -138,6 +141,9 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -138,6 +141,9 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$c = new Comparator(); $c = new Comparator();
$diff = $c->diffTable($tableFrom, $tableTo); $diff = $c->diffTable($tableFrom, $tableTo);
self::assertNotNull($diff);
self::assertInstanceOf(TableDiff::class, $diff, 'There should be a difference and not false being returned from the table comparison'); self::assertInstanceOf(TableDiff::class, $diff, 'There should be a difference and not false being returned from the table comparison');
self::assertEquals(['ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT'], $this->connection->getDatabasePlatform()->getAlterTableSQL($diff)); self::assertEquals(['ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT'], $this->connection->getDatabasePlatform()->getAlterTableSQL($diff));
......
...@@ -29,7 +29,7 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -29,7 +29,7 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this->schemaManager->createTable($table); $this->schemaManager->createTable($table);
$diff = new TableDiff('sqlsrv_drop_column', [], [], [new Column('todrop', Type::getType('decimal'))]); $diff = new TableDiff('sqlsrv_drop_column', [], [], ['todrop' => new Column('todrop', Type::getType('decimal'))]);
$this->schemaManager->alterTable($diff); $this->schemaManager->alterTable($diff);
$columns = $this->schemaManager->listTableColumns('sqlsrv_drop_column'); $columns = $this->schemaManager->listTableColumns('sqlsrv_drop_column');
......
...@@ -7,6 +7,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; ...@@ -7,6 +7,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\Common\EventManager; use Doctrine\Common\EventManager;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Events; use Doctrine\DBAL\Events;
use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Schema\AbstractAsset; use Doctrine\DBAL\Schema\AbstractAsset;
...@@ -38,11 +39,13 @@ use function array_keys; ...@@ -38,11 +39,13 @@ use function array_keys;
use function array_map; use function array_map;
use function array_search; use function array_search;
use function array_values; use function array_values;
use function assert;
use function count; use function count;
use function current; use function current;
use function end; use function end;
use function explode; use function explode;
use function in_array; use function in_array;
use function is_string;
use function sprintf; use function sprintf;
use function str_replace; use function str_replace;
use function strcasecmp; use function strcasecmp;
...@@ -60,8 +63,9 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -60,8 +63,9 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$class = static::class; $class = static::class;
$e = explode('\\', $class); $e = explode('\\', $class);
$testClass = end($e); $testClass = end($e);
assert(is_string($testClass));
return strtolower(str_replace('SchemaManagerTest', null, $testClass)); return strtolower(str_replace('SchemaManagerTest', '', $testClass));
} }
protected function setUp() : void protected function setUp() : void
...@@ -379,6 +383,7 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -379,6 +383,7 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
->method('onSchemaColumnDefinition'); ->method('onSchemaColumnDefinition');
$oldEventManager = $this->schemaManager->getDatabasePlatform()->getEventManager(); $oldEventManager = $this->schemaManager->getDatabasePlatform()->getEventManager();
assert($oldEventManager instanceof EventManager);
$eventManager = new EventManager(); $eventManager = new EventManager();
$eventManager->addEventListener([Events::onSchemaColumnDefinition], $listenerMock); $eventManager->addEventListener([Events::onSchemaColumnDefinition], $listenerMock);
...@@ -406,6 +411,7 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -406,6 +411,7 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
->method('onSchemaIndexDefinition'); ->method('onSchemaIndexDefinition');
$oldEventManager = $this->schemaManager->getDatabasePlatform()->getEventManager(); $oldEventManager = $this->schemaManager->getDatabasePlatform()->getEventManager();
assert($oldEventManager instanceof EventManager);
$eventManager = new EventManager(); $eventManager = new EventManager();
$eventManager->addEventListener([Events::onSchemaIndexDefinition], $listenerMock); $eventManager->addEventListener([Events::onSchemaIndexDefinition], $listenerMock);
...@@ -580,9 +586,9 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -580,9 +586,9 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
self::assertFalse($table->hasColumn('test')); self::assertFalse($table->hasColumn('test'));
self::assertTrue($table->hasColumn('foo')); self::assertTrue($table->hasColumn('foo'));
$tableDiff = new TableDiff('alter_table'); $tableDiff = new TableDiff('alter_table');
$tableDiff->fromTable = $table; $tableDiff->fromTable = $table;
$tableDiff->addedIndexes[] = new Index('foo_idx', ['foo']); $tableDiff->addedIndexes['foo_idx'] = new Index('foo_idx', ['foo']);
$this->schemaManager->alterTable($tableDiff); $this->schemaManager->alterTable($tableDiff);
...@@ -593,9 +599,9 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -593,9 +599,9 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
self::assertFalse($table->getIndex('foo_idx')->isPrimary()); self::assertFalse($table->getIndex('foo_idx')->isPrimary());
self::assertFalse($table->getIndex('foo_idx')->isUnique()); self::assertFalse($table->getIndex('foo_idx')->isUnique());
$tableDiff = new TableDiff('alter_table'); $tableDiff = new TableDiff('alter_table');
$tableDiff->fromTable = $table; $tableDiff->fromTable = $table;
$tableDiff->changedIndexes[] = new Index('foo_idx', ['foo', 'foreign_key_test']); $tableDiff->changedIndexes['foo_idx'] = new Index('foo_idx', ['foo', 'foreign_key_test']);
$this->schemaManager->alterTable($tableDiff); $this->schemaManager->alterTable($tableDiff);
...@@ -618,11 +624,11 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -618,11 +624,11 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
self::assertFalse($table->getIndex('bar_idx')->isPrimary()); self::assertFalse($table->getIndex('bar_idx')->isPrimary());
self::assertFalse($table->getIndex('bar_idx')->isUnique()); self::assertFalse($table->getIndex('bar_idx')->isUnique());
$tableDiff = new TableDiff('alter_table'); $tableDiff = new TableDiff('alter_table');
$tableDiff->fromTable = $table; $tableDiff->fromTable = $table;
$tableDiff->removedIndexes[] = new Index('bar_idx', ['foo', 'foreign_key_test']); $tableDiff->removedIndexes['bar_idx'] = new Index('bar_idx', ['foo', 'foreign_key_test']);
$fk = new ForeignKeyConstraint(['foreign_key_test'], 'alter_table_foreign', ['id']); $fk = new ForeignKeyConstraint(['foreign_key_test'], 'alter_table_foreign', ['id']);
$tableDiff->addedForeignKeys[] = $fk; $tableDiff->addedForeignKeys[] = $fk;
$this->schemaManager->alterTable($tableDiff); $this->schemaManager->alterTable($tableDiff);
$table = $this->schemaManager->listTableDetails('alter_table'); $table = $this->schemaManager->listTableDetails('alter_table');
...@@ -649,8 +655,8 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -649,8 +655,8 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
} }
//create schema //create schema
$diff = new SchemaDiff(); $diff = new SchemaDiff();
$diff->newNamespaces[] = 'testschema'; $diff->newNamespaces['testschema'] = 'testschema';
foreach ($diff->toSql($this->schemaManager->getDatabasePlatform()) as $sql) { foreach ($diff->toSql($this->schemaManager->getDatabasePlatform()) as $sql) {
$this->connection->exec($sql); $this->connection->exec($sql);
...@@ -759,6 +765,8 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -759,6 +765,8 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$c = new Comparator(); $c = new Comparator();
$tableDiff = $c->diffTable($tableFK, $tableFKNew); $tableDiff = $c->diffTable($tableFK, $tableFKNew);
self::assertNotNull($tableDiff);
$this->schemaManager->alterTable($tableDiff); $this->schemaManager->alterTable($tableDiff);
$table = $this->schemaManager->listTableDetails('test_fk_rename'); $table = $this->schemaManager->listTableDetails('test_fk_rename');
...@@ -801,7 +809,11 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -801,7 +809,11 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$comparator = new Comparator(); $comparator = new Comparator();
$this->schemaManager->alterTable($comparator->diffTable($foreignTable, $foreignTable2)); $diff = $comparator->diffTable($foreignTable, $foreignTable2);
self::assertNotNull($diff);
$this->schemaManager->alterTable($diff);
$foreignTable = $this->schemaManager->listTableDetails('test_rename_index_foreign'); $foreignTable = $this->schemaManager->listTableDetails('test_rename_index_foreign');
...@@ -1108,7 +1120,11 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -1108,7 +1120,11 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$comparator = new Comparator(); $comparator = new Comparator();
$this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); $diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
$this->schemaManager->alterTable($diff);
$columns = $this->schemaManager->listTableColumns('col_def_lifecycle'); $columns = $this->schemaManager->listTableColumns('col_def_lifecycle');
...@@ -1452,6 +1468,8 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -1452,6 +1468,8 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$this->connection->insert('test_pk_auto_increment', ['text' => '1']); $this->connection->insert('test_pk_auto_increment', ['text' => '1']);
$query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'1\''); $query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'1\'');
assert($query instanceof Statement);
$query->execute(); $query->execute();
$lastUsedIdBeforeDelete = (int) $query->fetchColumn(); $lastUsedIdBeforeDelete = (int) $query->fetchColumn();
...@@ -1460,6 +1478,8 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase ...@@ -1460,6 +1478,8 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$this->connection->insert('test_pk_auto_increment', ['text' => '2']); $this->connection->insert('test_pk_auto_increment', ['text' => '2']);
$query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'2\''); $query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'2\'');
assert($query instanceof Statement);
$query->execute(); $query->execute();
$lastUsedIdAfterDelete = (int) $query->fetchColumn(); $lastUsedIdAfterDelete = (int) $query->fetchColumn();
......
...@@ -6,6 +6,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; ...@@ -6,6 +6,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\BlobType;
...@@ -13,6 +14,7 @@ use Doctrine\DBAL\Types\Type; ...@@ -13,6 +14,7 @@ use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\Types;
use SQLite3; use SQLite3;
use function array_map; use function array_map;
use function assert;
use function dirname; use function dirname;
use function extension_loaded; use function extension_loaded;
use function version_compare; use function version_compare;
...@@ -235,6 +237,8 @@ SQL; ...@@ -235,6 +237,8 @@ SQL;
$diff = $comparator->diffTable($offlineTable, $onlineTable); $diff = $comparator->diffTable($offlineTable, $onlineTable);
if ($expectedComparatorDiff) { if ($expectedComparatorDiff) {
self::assertNotNull($diff);
self::assertEmpty($this->schemaManager->getDatabasePlatform()->getAlterTableSQL($diff)); self::assertEmpty($this->schemaManager->getDatabasePlatform()->getAlterTableSQL($diff));
} else { } else {
self::assertNull($diff); self::assertNull($diff);
...@@ -274,6 +278,8 @@ SQL; ...@@ -274,6 +278,8 @@ SQL;
$this->connection->insert('test_pk_auto_increment', ['text' => '2']); $this->connection->insert('test_pk_auto_increment', ['text' => '2']);
$query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = "2"'); $query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = "2"');
assert($query instanceof Statement);
$query->execute(); $query->execute();
$lastUsedIdAfterDelete = (int) $query->fetchColumn(); $lastUsedIdAfterDelete = (int) $query->fetchColumn();
......
...@@ -22,12 +22,10 @@ class TemporaryTableTest extends DbalFunctionalTestCase ...@@ -22,12 +22,10 @@ class TemporaryTableTest extends DbalFunctionalTestCase
protected function tearDown() : void protected function tearDown() : void
{ {
if ($this->connection) { try {
try { $tempTable = $this->connection->getDatabasePlatform()->getTemporaryTableName('my_temporary');
$tempTable = $this->connection->getDatabasePlatform()->getTemporaryTableName('my_temporary'); $this->connection->exec($this->connection->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable));
$this->connection->exec($this->connection->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable)); } catch (Throwable $e) {
} catch (Throwable $e) {
}
} }
parent::tearDown(); parent::tearDown();
......
...@@ -8,6 +8,7 @@ use Doctrine\DBAL\DBALException; ...@@ -8,6 +8,7 @@ use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\Tests\DbalFunctionalTestCase; use Doctrine\Tests\DbalFunctionalTestCase;
use PDO; use PDO;
use function assert;
use function in_array; use function in_array;
/** /**
...@@ -39,9 +40,10 @@ class DBAL630Test extends DbalFunctionalTestCase ...@@ -39,9 +40,10 @@ class DBAL630Test extends DbalFunctionalTestCase
protected function tearDown() : void protected function tearDown() : void
{ {
if ($this->running) { if ($this->running) {
$this->connection->getWrappedConnection() $wrappedConnection = $this->connection->getWrappedConnection();
->getWrappedConnection() assert($wrappedConnection instanceof PDO);
->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$wrappedConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} }
parent::tearDown(); parent::tearDown();
...@@ -75,9 +77,10 @@ class DBAL630Test extends DbalFunctionalTestCase ...@@ -75,9 +77,10 @@ class DBAL630Test extends DbalFunctionalTestCase
public function testBooleanConversionBoolParamEmulatedPrepares() : void public function testBooleanConversionBoolParamEmulatedPrepares() : void
{ {
$this->connection->getWrappedConnection() $wrappedConnection = $this->connection->getWrappedConnection();
->getWrappedConnection() assert($wrappedConnection instanceof PDO);
->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$wrappedConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$platform = $this->connection->getDatabasePlatform(); $platform = $this->connection->getDatabasePlatform();
...@@ -101,9 +104,10 @@ class DBAL630Test extends DbalFunctionalTestCase ...@@ -101,9 +104,10 @@ class DBAL630Test extends DbalFunctionalTestCase
?bool $statementValue, ?bool $statementValue,
?bool $databaseConvertedValue ?bool $databaseConvertedValue
) : void { ) : void {
$this->connection->getWrappedConnection() $wrappedConnection = $this->connection->getWrappedConnection();
->getWrappedConnection() assert($wrappedConnection instanceof PDO);
->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$wrappedConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$platform = $this->connection->getDatabasePlatform(); $platform = $this->connection->getDatabasePlatform();
...@@ -127,9 +131,10 @@ class DBAL630Test extends DbalFunctionalTestCase ...@@ -127,9 +131,10 @@ class DBAL630Test extends DbalFunctionalTestCase
?bool $statementValue, ?bool $statementValue,
bool $databaseConvertedValue bool $databaseConvertedValue
) : void { ) : void {
$this->connection->getWrappedConnection() $wrappedConnection = $this->connection->getWrappedConnection();
->getWrappedConnection() assert($wrappedConnection instanceof PDO);
->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$wrappedConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$platform = $this->connection->getDatabasePlatform(); $platform = $this->connection->getDatabasePlatform();
......
...@@ -9,7 +9,6 @@ use Doctrine\DBAL\Driver\DriverException; ...@@ -9,7 +9,6 @@ use Doctrine\DBAL\Driver\DriverException;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalFunctionalTestCase; use Doctrine\Tests\DbalFunctionalTestCase;
use Throwable; use Throwable;
use function array_filter; use function array_filter;
...@@ -35,18 +34,6 @@ class WriteTest extends DbalFunctionalTestCase ...@@ -35,18 +34,6 @@ class WriteTest extends DbalFunctionalTestCase
$this->connection->executeUpdate('DELETE FROM write_table'); $this->connection->executeUpdate('DELETE FROM write_table');
} }
/**
* @group DBAL-80
*/
public function testExecuteUpdateFirstTypeIsNull() : void
{
$sql = 'INSERT INTO write_table (test_string, test_int) VALUES (?, ?)';
$this->connection->executeUpdate($sql, ['text', 1111], [null, ParameterType::INTEGER]);
$sql = 'SELECT * FROM write_table WHERE test_string = ? AND test_int = ?';
self::assertTrue((bool) $this->connection->fetchColumn($sql, ['text', 1111]));
}
public function testExecuteUpdate() : void public function testExecuteUpdate() : void
{ {
$sql = 'INSERT INTO write_table (test_int) VALUES (1)'; $sql = 'INSERT INTO write_table (test_int) VALUES (1)';
...@@ -96,8 +83,8 @@ class WriteTest extends DbalFunctionalTestCase ...@@ -96,8 +83,8 @@ class WriteTest extends DbalFunctionalTestCase
$sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)';
$stmt = $this->connection->prepare($sql); $stmt = $this->connection->prepare($sql);
$stmt->bindValue(1, 1, Type::getType('integer')); $stmt->bindValue(1, 1, ParameterType::INTEGER);
$stmt->bindValue(2, 'foo', Type::getType('string')); $stmt->bindValue(2, 'foo', ParameterType::STRING);
$stmt->execute(); $stmt->execute();
self::assertEquals(1, $stmt->rowCount()); self::assertEquals(1, $stmt->rowCount());
...@@ -108,8 +95,8 @@ class WriteTest extends DbalFunctionalTestCase ...@@ -108,8 +95,8 @@ class WriteTest extends DbalFunctionalTestCase
$sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)';
$stmt = $this->connection->prepare($sql); $stmt = $this->connection->prepare($sql);
$stmt->bindValue(1, 1, 'integer'); $stmt->bindValue(1, 1, ParameterType::INTEGER);
$stmt->bindValue(2, 'foo', 'string'); $stmt->bindValue(2, 'foo', ParameterType::STRING);
$stmt->execute(); $stmt->execute();
self::assertEquals(1, $stmt->rowCount()); self::assertEquals(1, $stmt->rowCount());
......
...@@ -6,6 +6,7 @@ namespace Doctrine\Tests\DBAL\Platforms; ...@@ -6,6 +6,7 @@ namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Exception\ColumnLengthRequired; use Doctrine\DBAL\Exception\ColumnLengthRequired;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
...@@ -157,6 +158,8 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -157,6 +158,8 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$c = new Comparator(); $c = new Comparator();
$diff = $c->diffTable($oldTable, $keyTable); $diff = $c->diffTable($oldTable, $keyTable);
self::assertNotNull($diff);
$sql = $this->platform->getAlterTableSQL($diff); $sql = $this->platform->getAlterTableSQL($diff);
self::assertEquals([ self::assertEquals([
...@@ -219,11 +222,11 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -219,11 +222,11 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$index = new Index('idx', ['col'], false); $index = new Index('idx', ['col'], false);
$unique = new Index('uniq', ['col'], true); $unique = new Index('uniq', ['col'], true);
$diff = new TableDiff('test', [], [], [], [$unique], [], [$index]); $diff = new TableDiff('test', [], [], [], ['uniq' => $unique], [], ['idx' => $index]);
$sql = $this->platform->getAlterTableSQL($diff); $sql = $this->platform->getAlterTableSQL($diff);
self::assertEquals(['ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)'], $sql); self::assertEquals(['ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)'], $sql);
$diff = new TableDiff('test', [], [], [], [$index], [], [$unique]); $diff = new TableDiff('test', [], [], [], ['idx' => $index], [], ['unique' => $unique]);
$sql = $this->platform->getAlterTableSQL($diff); $sql = $this->platform->getAlterTableSQL($diff);
self::assertEquals(['ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)'], $sql); self::assertEquals(['ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)'], $sql);
} }
...@@ -333,9 +336,13 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -333,9 +336,13 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$diffTable->dropIndex('idx_id'); $diffTable->dropIndex('idx_id');
$diffTable->setPrimaryKey(['id']); $diffTable->setPrimaryKey(['id']);
$diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
self::assertEquals( self::assertEquals(
['DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'], ['DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'],
$this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) $this->platform->getAlterTableSQL($diff)
); );
} }
...@@ -355,13 +362,17 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -355,13 +362,17 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$diffTable->dropPrimaryKey(); $diffTable->dropPrimaryKey();
$diffTable->setPrimaryKey(['foo']); $diffTable->setPrimaryKey(['foo']);
$diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
self::assertEquals( self::assertEquals(
[ [
'ALTER TABLE alter_primary_key MODIFY id INT NOT NULL', 'ALTER TABLE alter_primary_key MODIFY id INT NOT NULL',
'ALTER TABLE alter_primary_key DROP PRIMARY KEY', 'ALTER TABLE alter_primary_key DROP PRIMARY KEY',
'ALTER TABLE alter_primary_key ADD PRIMARY KEY (foo)', 'ALTER TABLE alter_primary_key ADD PRIMARY KEY (foo)',
], ],
$this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) $this->platform->getAlterTableSQL($diff)
); );
} }
...@@ -381,12 +392,16 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -381,12 +392,16 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$diffTable->dropPrimaryKey(); $diffTable->dropPrimaryKey();
$diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
self::assertEquals( self::assertEquals(
[ [
'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL', 'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL',
'ALTER TABLE drop_primary_key DROP PRIMARY KEY', 'ALTER TABLE drop_primary_key DROP PRIMARY KEY',
], ],
$this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) $this->platform->getAlterTableSQL($diff)
); );
} }
...@@ -407,13 +422,17 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -407,13 +422,17 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$diffTable->dropPrimaryKey(); $diffTable->dropPrimaryKey();
$diffTable->setPrimaryKey(['id']); $diffTable->setPrimaryKey(['id']);
$diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
self::assertSame( self::assertSame(
[ [
'ALTER TABLE tbl MODIFY id INT NOT NULL', 'ALTER TABLE tbl MODIFY id INT NOT NULL',
'ALTER TABLE tbl DROP PRIMARY KEY', 'ALTER TABLE tbl DROP PRIMARY KEY',
'ALTER TABLE tbl ADD PRIMARY KEY (id)', 'ALTER TABLE tbl ADD PRIMARY KEY (id)',
], ],
$this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) $this->platform->getAlterTableSQL($diff)
); );
} }
...@@ -434,13 +453,17 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -434,13 +453,17 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$diffTable->dropPrimaryKey(); $diffTable->dropPrimaryKey();
$diffTable->setPrimaryKey(['id', 'foo']); $diffTable->setPrimaryKey(['id', 'foo']);
$diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
self::assertSame( self::assertSame(
[ [
'ALTER TABLE tbl MODIFY id INT NOT NULL', 'ALTER TABLE tbl MODIFY id INT NOT NULL',
'ALTER TABLE tbl DROP PRIMARY KEY', 'ALTER TABLE tbl DROP PRIMARY KEY',
'ALTER TABLE tbl ADD PRIMARY KEY (id, foo)', 'ALTER TABLE tbl ADD PRIMARY KEY (id, foo)',
], ],
$this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) $this->platform->getAlterTableSQL($diff)
); );
} }
...@@ -460,6 +483,8 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -460,6 +483,8 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$c = new Comparator(); $c = new Comparator();
$diff = $c->diffTable($oldTable, $keyTable); $diff = $c->diffTable($oldTable, $keyTable);
self::assertNotNull($diff);
$sql = $this->platform->getAlterTableSQL($diff); $sql = $this->platform->getAlterTableSQL($diff);
self::assertEquals(['ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)'], $sql); self::assertEquals(['ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)'], $sql);
...@@ -492,13 +517,17 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -492,13 +517,17 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$diffTable->dropPrimaryKey(); $diffTable->dropPrimaryKey();
$diffTable->setPrimaryKey(['pkc1', 'pkc2']); $diffTable->setPrimaryKey(['pkc1', 'pkc2']);
$diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
self::assertSame( self::assertSame(
[ [
'ALTER TABLE yolo DROP PRIMARY KEY', 'ALTER TABLE yolo DROP PRIMARY KEY',
'ALTER TABLE yolo ADD pkc2 INT NOT NULL', 'ALTER TABLE yolo ADD pkc2 INT NOT NULL',
'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)', 'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)',
], ],
$this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) $this->platform->getAlterTableSQL($diff)
); );
} }
...@@ -684,7 +713,11 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -684,7 +713,11 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
$comparator = new Comparator(); $comparator = new Comparator();
self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))); $diff = $comparator->diffTable($table, $diffTable);
self::assertNotNull($diff);
self::assertEmpty($this->platform->getAlterTableSQL($diff));
} }
/** /**
......
...@@ -1070,9 +1070,13 @@ abstract class AbstractPlatformTestCase extends DbalTestCase ...@@ -1070,9 +1070,13 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
$comparator = new Comparator(); $comparator = new Comparator();
$diff = $comparator->diffTable($fromTable, $toTable);
self::assertNotNull($diff);
self::assertEquals( self::assertEquals(
$this->getQuotedAlterTableRenameColumnSQL(), $this->getQuotedAlterTableRenameColumnSQL(),
$this->platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) $this->platform->getAlterTableSQL($diff)
); );
} }
...@@ -1112,9 +1116,13 @@ abstract class AbstractPlatformTestCase extends DbalTestCase ...@@ -1112,9 +1116,13 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
$comparator = new Comparator(); $comparator = new Comparator();
$diff = $comparator->diffTable($fromTable, $toTable);
self::assertNotNull($diff);
self::assertEquals( self::assertEquals(
$this->getQuotedAlterTableChangeColumnLengthSQL(), $this->getQuotedAlterTableChangeColumnLengthSQL(),
$this->platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) $this->platform->getAlterTableSQL($diff)
); );
} }
......
...@@ -4,6 +4,7 @@ declare(strict_types=1); ...@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Doctrine\Tests\DBAL\Platforms; namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Comparator;
...@@ -14,10 +15,14 @@ use Doctrine\DBAL\Schema\TableDiff; ...@@ -14,10 +15,14 @@ use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use UnexpectedValueException; use UnexpectedValueException;
use function assert;
use function sprintf; use function sprintf;
abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCase abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCase
{ {
/** @var PostgreSqlPlatform */
protected $platform;
public function getGenerateTableSql() : string public function getGenerateTableSql() : string
{ {
return 'CREATE TABLE test (id SERIAL NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'; return 'CREATE TABLE test (id SERIAL NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
...@@ -415,9 +420,7 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -415,9 +420,7 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
int $integerValue, int $integerValue,
bool $booleanValue bool $booleanValue
) : void { ) : void {
$platform = $this->createPlatform(); self::assertEquals($preparedStatementValue, $this->platform->convertBooleans($databaseValue));
self::assertEquals($preparedStatementValue, $platform->convertBooleans($databaseValue));
} }
/** /**
...@@ -425,14 +428,13 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -425,14 +428,13 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/ */
public function testConvertBooleanAsLiteralIntegers() : void public function testConvertBooleanAsLiteralIntegers() : void
{ {
$platform = $this->createPlatform(); $this->platform->setUseBooleanTrueFalseStrings(false);
$platform->setUseBooleanTrueFalseStrings(false);
self::assertEquals(1, $platform->convertBooleans(true)); self::assertEquals(1, $this->platform->convertBooleans(true));
self::assertEquals(1, $platform->convertBooleans('1')); self::assertEquals(1, $this->platform->convertBooleans('1'));
self::assertEquals(0, $platform->convertBooleans(false)); self::assertEquals(0, $this->platform->convertBooleans(false));
self::assertEquals(0, $platform->convertBooleans('0')); self::assertEquals(0, $this->platform->convertBooleans('0'));
} }
/** /**
...@@ -445,9 +447,7 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -445,9 +447,7 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
int $integerValue, int $integerValue,
bool $booleanValue bool $booleanValue
) : void { ) : void {
$platform = $this->createPlatform(); self::assertSame($integerValue, $this->platform->convertBooleansToDatabaseValue($booleanValue));
self::assertSame($integerValue, $platform->convertBooleansToDatabaseValue($booleanValue));
} }
/** /**
...@@ -455,11 +455,10 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -455,11 +455,10 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/ */
public function testConvertBooleanAsDatabaseValueIntegers() : void public function testConvertBooleanAsDatabaseValueIntegers() : void
{ {
$platform = $this->createPlatform(); $this->platform->setUseBooleanTrueFalseStrings(false);
$platform->setUseBooleanTrueFalseStrings(false);
self::assertSame(1, $platform->convertBooleansToDatabaseValue(true)); self::assertSame(1, $this->platform->convertBooleansToDatabaseValue(true));
self::assertSame(0, $platform->convertBooleansToDatabaseValue(false)); self::assertSame(0, $this->platform->convertBooleansToDatabaseValue(false));
} }
/** /**
...@@ -467,19 +466,15 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -467,19 +466,15 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/ */
public function testConvertFromBoolean(string $databaseValue, string $prepareStatementValue, int $integerValue, bool $booleanValue) : void public function testConvertFromBoolean(string $databaseValue, string $prepareStatementValue, int $integerValue, bool $booleanValue) : void
{ {
$platform = $this->createPlatform(); self::assertSame($booleanValue, $this->platform->convertFromBoolean($databaseValue));
self::assertSame($booleanValue, $platform->convertFromBoolean($databaseValue));
} }
public function testThrowsExceptionWithInvalidBooleanLiteral() : void public function testThrowsExceptionWithInvalidBooleanLiteral() : void
{ {
$platform = $this->createPlatform();
$this->expectException(UnexpectedValueException::class); $this->expectException(UnexpectedValueException::class);
$this->expectExceptionMessage('Unrecognized boolean literal, my-bool given.'); $this->expectExceptionMessage('Unrecognized boolean literal, my-bool given.');
$platform->convertBooleansToDatabaseValue('my-bool'); $this->platform->convertBooleansToDatabaseValue('my-bool');
} }
public function testGetCreateSchemaSQL() : void public function testGetCreateSchemaSQL() : void
...@@ -564,6 +559,8 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -564,6 +559,8 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
$comparator = new Comparator(); $comparator = new Comparator();
$tableDiff = $comparator->diffTable($oldTable, $newTable); $tableDiff = $comparator->diffTable($oldTable, $newTable);
self::assertNotNull($tableDiff);
$sql = $this->platform->getAlterTableSQL($tableDiff); $sql = $this->platform->getAlterTableSQL($tableDiff);
$expectedSql = [ $expectedSql = [
...@@ -645,30 +642,42 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -645,30 +642,42 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
$comparator = new Comparator(); $comparator = new Comparator();
$diff = $comparator->diffTable($table1, $table2);
self::assertNotNull($diff);
// VARBINARY -> BINARY // VARBINARY -> BINARY
// BINARY -> VARBINARY // BINARY -> VARBINARY
// BLOB -> VARBINARY // BLOB -> VARBINARY
self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); self::assertEmpty($this->platform->getAlterTableSQL($diff));
$table2 = new Table('mytable'); $table2 = new Table('mytable');
$table2->addColumn('column_varbinary', 'binary', ['length' => 42]); $table2->addColumn('column_varbinary', 'binary', ['length' => 42]);
$table2->addColumn('column_binary', 'blob'); $table2->addColumn('column_binary', 'blob');
$table2->addColumn('column_blob', 'binary', ['length' => 11, 'fixed' => true]); $table2->addColumn('column_blob', 'binary', ['length' => 11, 'fixed' => true]);
$diff = $comparator->diffTable($table1, $table2);
self::assertNotNull($diff);
// VARBINARY -> VARBINARY with changed length // VARBINARY -> VARBINARY with changed length
// BINARY -> BLOB // BINARY -> BLOB
// BLOB -> BINARY // BLOB -> BINARY
self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); self::assertEmpty($this->platform->getAlterTableSQL($diff));
$table2 = new Table('mytable'); $table2 = new Table('mytable');
$table2->addColumn('column_varbinary', 'blob'); $table2->addColumn('column_varbinary', 'blob');
$table2->addColumn('column_binary', 'binary', ['length' => 42, 'fixed' => true]); $table2->addColumn('column_binary', 'binary', ['length' => 42, 'fixed' => true]);
$table2->addColumn('column_blob', 'blob'); $table2->addColumn('column_blob', 'blob');
$diff = $comparator->diffTable($table1, $table2);
self::assertNotNull($diff);
// VARBINARY -> BLOB // VARBINARY -> BLOB
// BINARY -> BINARY with changed length // BINARY -> BINARY with changed length
// BLOB -> BLOB // BLOB -> BLOB
self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); self::assertEmpty($this->platform->getAlterTableSQL($diff));
} }
/** /**
...@@ -924,6 +933,8 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -924,6 +933,8 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/ */
public function testReturnsDisallowDatabaseConnectionsSQL() : void public function testReturnsDisallowDatabaseConnectionsSQL() : void
{ {
assert($this->platform instanceof PostgreSqlPlatform);
self::assertSame( self::assertSame(
"UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'foo'", "UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'foo'",
$this->platform->getDisallowDatabaseConnectionsSQL('foo') $this->platform->getDisallowDatabaseConnectionsSQL('foo')
...@@ -935,6 +946,8 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -935,6 +946,8 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/ */
public function testReturnsCloseActiveDatabaseConnectionsSQL() : void public function testReturnsCloseActiveDatabaseConnectionsSQL() : void
{ {
assert($this->platform instanceof PostgreSqlPlatform);
self::assertSame( self::assertSame(
"SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = 'foo'", "SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = 'foo'",
$this->platform->getCloseActiveDatabaseConnectionsSQL('foo') $this->platform->getCloseActiveDatabaseConnectionsSQL('foo')
...@@ -1023,6 +1036,8 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -1023,6 +1036,8 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/ */
public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() : void public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() : void
{ {
assert($this->platform instanceof PostgreSqlPlatform);
self::assertStringContainsStringIgnoringCase( self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'", "'Foo''Bar\\'",
$this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\") $this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\")
......
...@@ -6,6 +6,7 @@ namespace Doctrine\Tests\DBAL\Platforms; ...@@ -6,6 +6,7 @@ namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Exception\ColumnLengthRequired; use Doctrine\DBAL\Exception\ColumnLengthRequired;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
...@@ -13,6 +14,7 @@ use Doctrine\DBAL\Schema\Table; ...@@ -13,6 +14,7 @@ use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use function assert;
use function sprintf; use function sprintf;
abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCase abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCase
...@@ -1122,6 +1124,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1122,6 +1124,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
*/ */
public function testGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL(string $table, array $column, string $expectedSql) : void public function testGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL(string $table, array $column, string $expectedSql) : void
{ {
assert($this->platform instanceof SQLServerPlatform);
self::assertSame($expectedSql, $this->platform->getDefaultConstraintDeclarationSQL($table, $column)); self::assertSame($expectedSql, $this->platform->getDefaultConstraintDeclarationSQL($table, $column));
} }
...@@ -1236,7 +1239,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1236,7 +1239,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
new TableDiff( new TableDiff(
'mytable', 'mytable',
[ [
new Column('addcolumn', Type::getType('string'), [ 'addcolumn' => new Column('addcolumn', Type::getType('string'), [
'length' => 255, 'length' => 255,
'default' => 'foo', 'default' => 'foo',
]), ]),
...@@ -1256,7 +1259,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1256,7 +1259,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
), ),
], ],
[ [
new Column('removecolumn', Type::getType('string'), [ 'removecolumn' => new Column('removecolumn', Type::getType('string'), [
'length' => 255, 'length' => 255,
'default' => 'foo', 'default' => 'foo',
]), ]),
...@@ -1276,7 +1279,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1276,7 +1279,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
new TableDiff( new TableDiff(
'`mytable`', '`mytable`',
[ [
new Column('`addcolumn`', Type::getType('string'), [ 'addcolumn' => new Column('`addcolumn`', Type::getType('string'), [
'length' => 255, 'length' => 255,
'default' => 'foo', 'default' => 'foo',
]), ]),
...@@ -1296,7 +1299,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1296,7 +1299,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
), ),
], ],
[ [
new Column('`removecolumn`', Type::getType('string'), [ 'removecolumn' => new Column('`removecolumn`', Type::getType('string'), [
'length' => 255, 'length' => 255,
'default' => 'foo', 'default' => 'foo',
]), ]),
...@@ -1316,7 +1319,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1316,7 +1319,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
new TableDiff( new TableDiff(
'table', 'table',
[ [
new Column('add', Type::getType('string'), [ 'add' => new Column('add', Type::getType('string'), [
'length' => 255, 'length' => 255,
'default' => 'foo', 'default' => 'foo',
]), ]),
...@@ -1336,7 +1339,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1336,7 +1339,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
), ),
], ],
[ [
new Column('drop', Type::getType('string'), [ 'drop' => new Column('drop', Type::getType('string'), [
'length' => 255, 'length' => 255,
'default' => 'foo', 'default' => 'foo',
]), ]),
...@@ -1356,7 +1359,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1356,7 +1359,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
new TableDiff( new TableDiff(
'`table`', '`table`',
[ [
new Column('`add`', Type::getType('string'), [ 'add' => new Column('`add`', Type::getType('string'), [
'length' => 255, 'length' => 255,
'default' => 'foo', 'default' => 'foo',
]), ]),
...@@ -1376,7 +1379,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1376,7 +1379,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
), ),
], ],
[ [
new Column('`drop`', Type::getType('string'), [ 'drop' => new Column('`drop`', Type::getType('string'), [
'length' => 255, 'length' => 255,
'default' => 'foo', 'default' => 'foo',
]), ]),
......
...@@ -304,13 +304,17 @@ class DB2PlatformTest extends AbstractPlatformTestCase ...@@ -304,13 +304,17 @@ class DB2PlatformTest extends AbstractPlatformTestCase
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getIsCommentedDoctrineType() : array public function getIsCommentedDoctrineType() : iterable
{ {
$data = parent::getIsCommentedDoctrineType(); $types = [];
$data[Types::BOOLEAN] = [Type::getType(Types::BOOLEAN), true]; foreach (parent::getIsCommentedDoctrineType() as $key => $value) {
$types[$key] = $value;
}
$types[Types::BOOLEAN] = [Type::getType(Types::BOOLEAN), true];
return $data; return $types;
} }
public function testGeneratesDDLSnippets() : void public function testGeneratesDDLSnippets() : void
......
...@@ -18,6 +18,7 @@ use Doctrine\DBAL\Schema\TableDiff; ...@@ -18,6 +18,7 @@ use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use function array_walk; use function array_walk;
use function assert;
use function preg_replace; use function preg_replace;
use function sprintf; use function sprintf;
use function strtoupper; use function strtoupper;
...@@ -48,8 +49,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -48,8 +49,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase
*/ */
public function testValidIdentifiers(string $identifier) : void public function testValidIdentifiers(string $identifier) : void
{ {
$platform = $this->createPlatform(); OraclePlatform::assertValidIdentifier($identifier);
$platform->assertValidIdentifier($identifier);
$this->addToAssertionCount(1); $this->addToAssertionCount(1);
} }
...@@ -75,8 +75,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -75,8 +75,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase
{ {
$this->expectException(DBALException::class); $this->expectException(DBALException::class);
$platform = $this->createPlatform(); OraclePlatform::assertValidIdentifier($identifier);
$platform->assertValidIdentifier($identifier);
} }
public function createPlatform() : AbstractPlatform public function createPlatform() : AbstractPlatform
...@@ -547,9 +546,13 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -547,9 +546,13 @@ class OraclePlatformTest extends AbstractPlatformTestCase
$comparator = new Comparator(); $comparator = new Comparator();
$diff = $comparator->diffTable($table1, $table2);
self::assertNotNull($diff);
// VARBINARY -> BINARY // VARBINARY -> BINARY
// BINARY -> VARBINARY // BINARY -> VARBINARY
self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); self::assertEmpty($this->platform->getAlterTableSQL($diff));
} }
/** /**
...@@ -695,6 +698,8 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -695,6 +698,8 @@ class OraclePlatformTest extends AbstractPlatformTestCase
*/ */
public function testReturnsDropAutoincrementSQL(string $table, array $expectedSql) : void public function testReturnsDropAutoincrementSQL(string $table, array $expectedSql) : void
{ {
assert($this->platform instanceof OraclePlatform);
self::assertSame($expectedSql, $this->platform->getDropAutoincrementSql($table)); self::assertSame($expectedSql, $this->platform->getDropAutoincrementSql($table));
} }
......
...@@ -8,6 +8,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; ...@@ -8,6 +8,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use function assert;
class PostgreSqlPlatformTest extends AbstractPostgreSqlPlatformTestCase class PostgreSqlPlatformTest extends AbstractPostgreSqlPlatformTestCase
{ {
...@@ -92,6 +93,8 @@ class PostgreSqlPlatformTest extends AbstractPostgreSqlPlatformTestCase ...@@ -92,6 +93,8 @@ class PostgreSqlPlatformTest extends AbstractPostgreSqlPlatformTestCase
*/ */
public function testReturnsCloseActiveDatabaseConnectionsSQL() : void public function testReturnsCloseActiveDatabaseConnectionsSQL() : void
{ {
assert($this->platform instanceof PostgreSqlPlatform);
self::assertSame( self::assertSame(
"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'foo'", "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'foo'",
$this->platform->getCloseActiveDatabaseConnectionsSQL('foo') $this->platform->getCloseActiveDatabaseConnectionsSQL('foo')
......
...@@ -1155,7 +1155,7 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase ...@@ -1155,7 +1155,7 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
*/ */
public function testQuotesTableNameInListTableConstraintsSQL() : void public function testQuotesTableNameInListTableConstraintsSQL() : void
{ {
self::assertStringContainsStringIgnoringCase("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); self::assertStringContainsStringIgnoringCase("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '');
} }
/** /**
......
...@@ -12,6 +12,7 @@ use Doctrine\DBAL\Schema\Table; ...@@ -12,6 +12,7 @@ use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use function assert;
class SqlitePlatformTest extends AbstractPlatformTestCase class SqlitePlatformTest extends AbstractPlatformTestCase
{ {
...@@ -82,6 +83,8 @@ class SqlitePlatformTest extends AbstractPlatformTestCase ...@@ -82,6 +83,8 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
*/ */
public function testGeneratesTypeDeclarationForTinyIntegers() : void public function testGeneratesTypeDeclarationForTinyIntegers() : void
{ {
assert($this->platform instanceof SqlitePlatform);
self::assertEquals( self::assertEquals(
'TINYINT', 'TINYINT',
$this->platform->getTinyIntTypeDeclarationSQL([]) $this->platform->getTinyIntTypeDeclarationSQL([])
...@@ -112,6 +115,8 @@ class SqlitePlatformTest extends AbstractPlatformTestCase ...@@ -112,6 +115,8 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
*/ */
public function testGeneratesTypeDeclarationForSmallIntegers() : void public function testGeneratesTypeDeclarationForSmallIntegers() : void
{ {
assert($this->platform instanceof SqlitePlatform);
self::assertEquals( self::assertEquals(
'SMALLINT', 'SMALLINT',
$this->platform->getSmallIntTypeDeclarationSQL([]) $this->platform->getSmallIntTypeDeclarationSQL([])
...@@ -146,6 +151,8 @@ class SqlitePlatformTest extends AbstractPlatformTestCase ...@@ -146,6 +151,8 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
*/ */
public function testGeneratesTypeDeclarationForMediumIntegers() : void public function testGeneratesTypeDeclarationForMediumIntegers() : void
{ {
assert($this->platform instanceof SqlitePlatform);
self::assertEquals( self::assertEquals(
'MEDIUMINT', 'MEDIUMINT',
$this->platform->getMediumIntTypeDeclarationSQL([]) $this->platform->getMediumIntTypeDeclarationSQL([])
......
...@@ -37,10 +37,6 @@ class CompositeExpressionTest extends DbalTestCase ...@@ -37,10 +37,6 @@ class CompositeExpressionTest extends DbalTestCase
self::assertCount(2, $expr); self::assertCount(2, $expr);
$expr->add(null);
self::assertCount(2, $expr);
$expr->add('u.user_id = 1'); $expr->add('u.user_id = 1');
self::assertCount(3, $expr); self::assertCount(3, $expr);
......
...@@ -217,7 +217,7 @@ class ExpressionBuilderTest extends DbalTestCase ...@@ -217,7 +217,7 @@ class ExpressionBuilderTest extends DbalTestCase
public function testIn() : void public function testIn() : void
{ {
self::assertEquals('u.groups IN (1, 3, 4, 7)', $this->expr->in('u.groups', [1, 3, 4, 7])); self::assertEquals('u.groups IN (1, 3, 4, 7)', $this->expr->in('u.groups', ['1', '3', '4', '7']));
} }
public function testInWithPlaceholder() : void public function testInWithPlaceholder() : void
...@@ -227,7 +227,7 @@ class ExpressionBuilderTest extends DbalTestCase ...@@ -227,7 +227,7 @@ class ExpressionBuilderTest extends DbalTestCase
public function testNotIn() : void public function testNotIn() : void
{ {
self::assertEquals('u.groups NOT IN (1, 3, 4, 7)', $this->expr->notIn('u.groups', [1, 3, 4, 7])); self::assertEquals('u.groups NOT IN (1, 3, 4, 7)', $this->expr->notIn('u.groups', ['1', '3', '4', '7']));
} }
public function testNotInWithPlaceholder() : void public function testNotInWithPlaceholder() : void
......
...@@ -12,6 +12,7 @@ use Doctrine\DBAL\Platforms\MySqlPlatform; ...@@ -12,6 +12,7 @@ use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\MySqlSchemaManager; use Doctrine\DBAL\Schema\MySqlSchemaManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use function array_map; use function array_map;
...@@ -20,7 +21,7 @@ class MySqlSchemaManagerTest extends TestCase ...@@ -20,7 +21,7 @@ class MySqlSchemaManagerTest extends TestCase
/** @var AbstractSchemaManager */ /** @var AbstractSchemaManager */
private $manager; private $manager;
/** @var Connection */ /** @var Connection|MockObject */
private $conn; private $conn;
protected function setUp() : void protected function setUp() : void
......
...@@ -35,7 +35,10 @@ class MySQLSchemaTest extends TestCase ...@@ -35,7 +35,10 @@ class MySQLSchemaTest extends TestCase
$tableNew->setPrimaryKey(['bar_id', 'foo_id']); $tableNew->setPrimaryKey(['bar_id', 'foo_id']);
$diff = $this->comparator->diffTable($tableOld, $tableNew); $diff = $this->comparator->diffTable($tableOld, $tableNew);
$sql = $this->platform->getAlterTableSQL($diff);
self::assertNotNull($diff);
$sql = $this->platform->getAlterTableSQL($diff);
self::assertEquals( self::assertEquals(
[ [
...@@ -76,7 +79,10 @@ class MySQLSchemaTest extends TestCase ...@@ -76,7 +79,10 @@ class MySQLSchemaTest extends TestCase
$tableNew->setPrimaryKey(['id']); $tableNew->setPrimaryKey(['id']);
$diff = $this->comparator->diffTable($tableOld, $tableNew); $diff = $this->comparator->diffTable($tableOld, $tableNew);
$sql = $this->platform->getAlterTableSQL($diff);
self::assertNotNull($diff);
$sql = $this->platform->getAlterTableSQL($diff);
self::assertEquals( self::assertEquals(
['ALTER TABLE test ADD PRIMARY KEY (id)'], ['ALTER TABLE test ADD PRIMARY KEY (id)'],
......
...@@ -109,9 +109,9 @@ class SchemaDiffTest extends TestCase ...@@ -109,9 +109,9 @@ class SchemaDiffTest extends TestCase
$diff = new SchemaDiff(); $diff = new SchemaDiff();
$diff->newNamespaces['foo_ns'] = 'foo_ns'; $diff->newNamespaces['foo_ns'] = 'foo_ns';
$diff->removedNamespaces['bar_ns'] = 'bar_ns'; $diff->removedNamespaces['bar_ns'] = 'bar_ns';
$diff->changedSequences['foo_seq'] = new Sequence('foo_seq'); $diff->changedSequences[] = new Sequence('foo_seq');
$diff->newSequences['bar_seq'] = new Sequence('bar_seq'); $diff->newSequences[] = new Sequence('bar_seq');
$diff->removedSequences['baz_seq'] = new Sequence('baz_seq'); $diff->removedSequences[] = new Sequence('baz_seq');
$diff->newTables['foo_table'] = new Table('foo_table'); $diff->newTables['foo_table'] = new Table('foo_table');
$diff->removedTables['bar_table'] = new Table('bar_table'); $diff->removedTables['bar_table'] = new Table('bar_table');
$diff->changedTables['baz_table'] = new TableDiff('baz_table'); $diff->changedTables['baz_table'] = new TableDiff('baz_table');
......
...@@ -401,7 +401,7 @@ class SchemaTest extends TestCase ...@@ -401,7 +401,7 @@ class SchemaTest extends TestCase
$visitor->expects($this->exactly(2)) $visitor->expects($this->exactly(2))
->method('acceptSequence'); ->method('acceptSequence');
self::assertNull($schema->visit($visitor)); $schema->visit($visitor);
} }
/** /**
...@@ -462,6 +462,8 @@ class SchemaTest extends TestCase ...@@ -462,6 +462,8 @@ class SchemaTest extends TestCase
$visitor->expects($this->exactly(2)) $visitor->expects($this->exactly(2))
->method('acceptSequence'); ->method('acceptSequence');
self::assertNull($schema->visit($visitor)); $schema->visit($visitor);
self::doesNotPerformAssertions(); // FIXME
} }
} }
...@@ -12,6 +12,7 @@ use InvalidArgumentException; ...@@ -12,6 +12,7 @@ use InvalidArgumentException;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use stdClass; use stdClass;
use function array_merge; use function array_merge;
use function assert;
/** /**
* @requires extension pdo_sqlite * @requires extension pdo_sqlite
...@@ -30,6 +31,8 @@ class PoolingShardConnectionTest extends TestCase ...@@ -30,6 +31,8 @@ class PoolingShardConnectionTest extends TestCase
'shardChoser' => MultiTenantShardChoser::class, 'shardChoser' => MultiTenantShardChoser::class,
]); ]);
assert($conn instanceof PoolingShardConnection);
self::assertFalse($conn->isConnected(0)); self::assertFalse($conn->isConnected(0));
$conn->connect(0); $conn->connect(0);
self::assertEquals(1, $conn->fetchColumn('SELECT 1')); self::assertEquals(1, $conn->fetchColumn('SELECT 1'));
...@@ -166,6 +169,8 @@ class PoolingShardConnectionTest extends TestCase ...@@ -166,6 +169,8 @@ class PoolingShardConnectionTest extends TestCase
'shardChoser' => MultiTenantShardChoser::class, 'shardChoser' => MultiTenantShardChoser::class,
]); ]);
assert($conn instanceof PoolingShardConnection);
$conn->beginTransaction(); $conn->beginTransaction();
$this->expectException(ShardingException::class); $this->expectException(ShardingException::class);
...@@ -184,6 +189,8 @@ class PoolingShardConnectionTest extends TestCase ...@@ -184,6 +189,8 @@ class PoolingShardConnectionTest extends TestCase
'shardChoser' => MultiTenantShardChoser::class, 'shardChoser' => MultiTenantShardChoser::class,
]); ]);
assert($conn instanceof PoolingShardConnection);
self::assertNull($conn->getActiveShardId()); self::assertNull($conn->getActiveShardId());
$conn->connect(0); $conn->connect(0);
...@@ -207,6 +214,8 @@ class PoolingShardConnectionTest extends TestCase ...@@ -207,6 +214,8 @@ class PoolingShardConnectionTest extends TestCase
'shardChoser' => MultiTenantShardChoser::class, 'shardChoser' => MultiTenantShardChoser::class,
]); ]);
assert($conn instanceof PoolingShardConnection);
self::assertEquals([ self::assertEquals([
'wrapperClass' => PoolingShardConnection::class, 'wrapperClass' => PoolingShardConnection::class,
'driver' => 'pdo_sqlite', 'driver' => 'pdo_sqlite',
...@@ -239,9 +248,13 @@ class PoolingShardConnectionTest extends TestCase ...@@ -239,9 +248,13 @@ class PoolingShardConnectionTest extends TestCase
*/ */
private function createConnection(array $parameters) : PoolingShardConnection private function createConnection(array $parameters) : PoolingShardConnection
{ {
return DriverManager::getConnection(array_merge( $connection = DriverManager::getConnection(array_merge(
['wrapperClass' => PoolingShardConnection::class], ['wrapperClass' => PoolingShardConnection::class],
$parameters $parameters
)); ));
self::assertInstanceOf(PoolingShardConnection::class, $connection);
return $connection;
} }
} }
...@@ -7,6 +7,7 @@ namespace Doctrine\Tests\DBAL\Sharding\SQLAzure; ...@@ -7,6 +7,7 @@ namespace Doctrine\Tests\DBAL\Sharding\SQLAzure;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Sharding\ShardingException; use Doctrine\DBAL\Sharding\ShardingException;
use Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager; use Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class SQLAzureShardManagerTest extends TestCase class SQLAzureShardManagerTest extends TestCase
...@@ -83,6 +84,8 @@ class SQLAzureShardManagerTest extends TestCase ...@@ -83,6 +84,8 @@ class SQLAzureShardManagerTest extends TestCase
/** /**
* @param mixed[] $params * @param mixed[] $params
*
* @return Connection|MockObject
*/ */
private function createConnection(array $params) : Connection private function createConnection(array $params) : Connection
{ {
......
...@@ -15,17 +15,17 @@ use Doctrine\DBAL\ParameterType; ...@@ -15,17 +15,17 @@ use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Statement; use Doctrine\DBAL\Statement;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use Exception; use Exception;
use PDOStatement; use PHPUnit\Framework\MockObject\MockObject;
class StatementTest extends DbalTestCase class StatementTest extends DbalTestCase
{ {
/** @var Connection */ /** @var Connection|MockObject */
private $conn; private $conn;
/** @var Configuration */ /** @var Configuration|MockObject */
private $configuration; private $configuration;
/** @var PDOStatement */ /** @var DriverStatement|MockObject */
private $driverStatement; private $driverStatement;
protected function setUp() : void protected function setUp() : void
......
...@@ -8,6 +8,7 @@ use Doctrine\DBAL\Connection; ...@@ -8,6 +8,7 @@ use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand;
use Doctrine\DBAL\Tools\Console\ConsoleRunner; use Doctrine\DBAL\Tools\Console\ConsoleRunner;
use LogicException; use LogicException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use RuntimeException; use RuntimeException;
use Symfony\Component\Console\Application; use Symfony\Component\Console\Application;
...@@ -20,7 +21,7 @@ class RunSqlCommandTest extends TestCase ...@@ -20,7 +21,7 @@ class RunSqlCommandTest extends TestCase
/** @var RunSqlCommand */ /** @var RunSqlCommand */
private $command; private $command;
/** @var Connection */ /** @var Connection|MockObject */
private $connectionMock; private $connectionMock;
protected function setUp() : void protected function setUp() : void
......
...@@ -100,8 +100,8 @@ class DumperTest extends DbalTestCase ...@@ -100,8 +100,8 @@ class DumperTest extends DbalTestCase
$print_r_class = print_r($class, true); $print_r_class = print_r($class, true);
$print_r_expected = print_r($expected, true); $print_r_expected = print_r($expected, true);
$print_r_class = substr($print_r_class, strpos($print_r_class, '(')); $print_r_class = substr($print_r_class, (int) strpos($print_r_class, '('));
$print_r_expected = substr($print_r_expected, strpos($print_r_expected, '(')); $print_r_expected = substr($print_r_expected, (int) strpos($print_r_expected, '('));
self::assertSame($print_r_class, $print_r_expected); self::assertSame($print_r_class, $print_r_expected);
......
...@@ -14,7 +14,6 @@ use Doctrine\Tests\DbalTestCase; ...@@ -14,7 +14,6 @@ use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use function base64_encode; use function base64_encode;
use function fopen; use function fopen;
use function json_encode;
class JsonTest extends DbalTestCase class JsonTest extends DbalTestCase
{ {
...@@ -64,9 +63,11 @@ class JsonTest extends DbalTestCase ...@@ -64,9 +63,11 @@ class JsonTest extends DbalTestCase
public function testJsonStringConvertsToPHPValue() : void public function testJsonStringConvertsToPHPValue() : void
{ {
$value = ['foo' => 'bar', 'bar' => 'foo']; $value = ['foo' => 'bar', 'bar' => 'foo'];
$databaseValue = json_encode($value);
$phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); $databaseValue = '{"foo":"bar","bar":"foo"}';
$phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform);
self::assertEquals($value, $phpValue); self::assertEquals($value, $phpValue);
} }
...@@ -88,8 +89,11 @@ class JsonTest extends DbalTestCase ...@@ -88,8 +89,11 @@ class JsonTest extends DbalTestCase
public function testJsonResourceConvertsToPHPValue() : void public function testJsonResourceConvertsToPHPValue() : void
{ {
$value = ['foo' => 'bar', 'bar' => 'foo']; $value = ['foo' => 'bar', 'bar' => 'foo'];
$databaseValue = fopen('data://text/plain;base64,' . base64_encode(json_encode($value)), 'r');
$json = '{"foo":"bar","bar":"foo"}';
$databaseValue = fopen('data://text/plain;base64,' . base64_encode($json), 'r');
$phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform);
self::assertSame($value, $phpValue); self::assertSame($value, $phpValue);
......
...@@ -25,7 +25,7 @@ abstract class DbalFunctionalTestCase extends DbalTestCase ...@@ -25,7 +25,7 @@ abstract class DbalFunctionalTestCase extends DbalTestCase
/** /**
* Shared connection when a TestCase is run alone (outside of it's functional suite) * Shared connection when a TestCase is run alone (outside of it's functional suite)
* *
* @var Connection * @var Connection|null
*/ */
private static $sharedConnection; private static $sharedConnection;
...@@ -37,7 +37,7 @@ abstract class DbalFunctionalTestCase extends DbalTestCase ...@@ -37,7 +37,7 @@ abstract class DbalFunctionalTestCase extends DbalTestCase
protected function resetSharedConn() : void protected function resetSharedConn() : void
{ {
if (! self::$sharedConnection) { if (self::$sharedConnection === null) {
return; return;
} }
......
...@@ -6,6 +6,7 @@ namespace Doctrine\Tests; ...@@ -6,6 +6,7 @@ namespace Doctrine\Tests;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
use InvalidArgumentException;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use function explode; use function explode;
use function extension_loaded; use function extension_loaded;
...@@ -101,6 +102,12 @@ class TestUtil ...@@ -101,6 +102,12 @@ class TestUtil
$dbname = $realConn->getDatabase(); $dbname = $realConn->getDatabase();
$realConn->close(); $realConn->close();
if ($dbname === null) {
throw new InvalidArgumentException(
'You must have a database configured in your connection.'
);
}
$tmpConn->getSchemaManager()->dropAndCreateDatabase($dbname); $tmpConn->getSchemaManager()->dropAndCreateDatabase($dbname);
$tmpConn->close(); $tmpConn->close();
......
...@@ -20,6 +20,8 @@ use Doctrine\DBAL\DriverManager; ...@@ -20,6 +20,8 @@ use Doctrine\DBAL\DriverManager;
return; return;
} }
assert(is_int($pos));
$file = $_SERVER['argv'][$pos + 1]; $file = $_SERVER['argv'][$pos + 1];
register_shutdown_function(static function () use ($file) : void { register_shutdown_function(static function () use ($file) : void {
......
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