From 73bd82a3d77d6414771744d346002dddc9ce4f9c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 23 Sep 2018 17:47:40 -0700 Subject: [PATCH] PHPCBF --- .../DBAL/Cache/QueryCacheProfileTest.php | 46 +- .../Doctrine/Tests/DBAL/ConfigurationTest.php | 4 +- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 174 ++-- .../Doctrine/Tests/DBAL/DBALExceptionTest.php | 32 +- .../Tests/DBAL/Driver/AbstractDriverTest.php | 88 +- .../DBAL/Driver/AbstractMySQLDriverTest.php | 154 +-- .../EasyConnectStringTest.php | 1 + .../DBAL/Driver/AbstractOracleDriverTest.php | 76 +- .../Driver/AbstractPostgreSQLDriverTest.php | 100 +- .../Driver/AbstractSQLAnywhereDriverTest.php | 150 +-- .../Driver/AbstractSQLServerDriverTest.php | 56 +- .../DBAL/Driver/AbstractSQLiteDriverTest.php | 72 +- .../DBAL/Driver/IBMDB2/DB2ConnectionTest.php | 6 +- .../Driver/Mysqli/MysqliConnectionTest.php | 9 +- .../DBAL/Driver/OCI8/OCI8ConnectionTest.php | 6 +- .../DBAL/Driver/OCI8/OCI8StatementTest.php | 43 +- .../Tests/DBAL/Driver/PDOExceptionTest.php | 15 +- .../Tests/DBAL/Driver/PDOPgSql/DriverTest.php | 31 +- .../SQLAnywhere/SQLAnywhereConnectionTest.php | 6 +- .../Driver/SQLSrv/SQLSrvConnectionTest.php | 6 +- .../DBAL/Driver/StatementIteratorTest.php | 7 +- .../Doctrine/Tests/DBAL/DriverManagerTest.php | 17 +- .../DBAL/Events/MysqlSessionInitTest.php | 5 +- .../DBAL/Events/OracleSessionInitTest.php | 13 +- .../Tests/DBAL/Events/SQLSessionInitTest.php | 2 +- .../InvalidArgumentExceptionTest.php | 5 +- .../Tests/DBAL/Functional/BlobTest.php | 10 +- .../Tests/DBAL/Functional/ConnectionTest.php | 52 +- .../Tests/DBAL/Functional/DataAccessTest.php | 373 +++---- .../Functional/Driver/AbstractDriverTest.php | 7 +- .../Driver/IBMDB2/DB2DriverTest.php | 6 +- .../Driver/IBMDB2/DB2StatementTest.php | 8 +- .../Driver/Mysqli/ConnectionTest.php | 36 +- .../Functional/Driver/Mysqli/DriverTest.php | 6 +- .../Functional/Driver/OCI8/DriverTest.php | 6 +- .../Driver/OCI8/OCI8ConnectionTest.php | 11 +- .../Functional/Driver/OCI8/StatementTest.php | 70 +- .../Functional/Driver/PDOConnectionTest.php | 14 +- .../Functional/Driver/PDOMySql/DriverTest.php | 6 +- .../Driver/PDOOracle/DriverTest.php | 6 +- .../Functional/Driver/PDOPgSql/DriverTest.php | 36 +- .../Driver/PDOPgsqlConnectionTest.php | 23 +- .../Driver/PDOSqlite/DriverTest.php | 6 +- .../Driver/PDOSqlsrv/DriverTest.php | 2 +- .../Driver/SQLAnywhere/ConnectionTest.php | 13 +- .../Driver/SQLAnywhere/DriverTest.php | 6 +- .../Driver/SQLAnywhere/StatementTest.php | 22 +- .../Functional/Driver/SQLSrv/DriverTest.php | 6 +- .../Driver/SQLSrv/StatementTest.php | 8 +- .../Tests/DBAL/Functional/ExceptionTest.php | 197 ++-- .../Functional/LikeWildcardsEscapingTest.php | 1 - .../Tests/DBAL/Functional/LoggingTest.php | 14 +- .../Functional/MasterSlaveConnectionTest.php | 45 +- .../DBAL/Functional/ModifyLimitQueryTest.php | 166 +-- .../DBAL/Functional/NamedParametersTest.php | 97 +- .../Tests/DBAL/Functional/PortabilityTest.php | 66 +- .../Tests/DBAL/Functional/ResultCacheTest.php | 85 +- .../Schema/Db2SchemaManagerTest.php | 2 +- .../Schema/DrizzleSchemaManagerTest.php | 8 +- .../Schema/MySqlSchemaManagerTest.php | 116 ++- .../Schema/OracleSchemaManagerTest.php | 78 +- .../Schema/PostgreSqlSchemaManagerTest.php | 179 ++-- .../Schema/SQLAnywhereSchemaManagerTest.php | 16 +- .../Schema/SQLServerSchemaManagerTest.php | 222 ++-- .../SchemaManagerFunctionalTestCase.php | 584 +++++------ .../Schema/SqliteSchemaManagerTest.php | 81 +- .../Tests/DBAL/Functional/StatementTest.php | 93 +- .../DBAL/Functional/TableGeneratorTest.php | 39 +- .../DBAL/Functional/TemporaryTableTest.php | 71 +- .../DBAL/Functional/Ticket/DBAL168Test.php | 13 +- .../DBAL/Functional/Ticket/DBAL202Test.php | 11 +- .../DBAL/Functional/Ticket/DBAL421Test.php | 20 +- .../DBAL/Functional/Ticket/DBAL461Test.php | 12 +- .../DBAL/Functional/Ticket/DBAL510Test.php | 15 +- .../DBAL/Functional/Ticket/DBAL630Test.php | 41 +- .../DBAL/Functional/Ticket/DBAL752Test.php | 10 +- .../DBAL/Functional/TypeConversionTest.php | 124 +-- .../Tests/DBAL/Functional/WriteTest.php | 124 +-- .../Tests/DBAL/Logging/DebugStackTest.php | 15 +- .../Tests/DBAL/Mocks/MockPlatform.php | 27 +- .../TypeConversionPerformanceTest.php | 12 +- .../AbstractMySQLPlatformTestCase.php | 410 ++++---- .../Platforms/AbstractPlatformTestCase.php | 515 +++++----- .../AbstractPostgreSqlPlatformTestCase.php | 362 +++---- .../AbstractSQLServerPlatformTestCase.php | 854 ++++++++-------- .../Tests/DBAL/Platforms/DB2PlatformTest.php | 286 +++--- .../Platforms/MariaDb1027PlatformTest.php | 1 + .../DBAL/Platforms/MySQL57PlatformTest.php | 22 +- .../DBAL/Platforms/MySqlPlatformTest.php | 2 +- .../DBAL/Platforms/OraclePlatformTest.php | 299 +++--- .../Platforms/PostgreSQL92PlatformTest.php | 8 +- .../Platforms/PostgreSQL94PlatformTest.php | 4 +- .../DBAL/Platforms/PostgreSqlPlatformTest.php | 2 +- .../ReservedKeywordsValidatorTest.php | 20 +- .../Platforms/SQLAnywhere11PlatformTest.php | 6 +- .../Platforms/SQLAnywhere12PlatformTest.php | 30 +- .../Platforms/SQLAnywhere16PlatformTest.php | 18 +- .../Platforms/SQLAnywherePlatformTest.php | 286 +++--- .../DBAL/Platforms/SQLAzurePlatformTest.php | 14 +- .../Platforms/SQLServer2008PlatformTest.php | 2 +- .../Platforms/SQLServer2012PlatformTest.php | 238 ++--- .../DBAL/Platforms/SQLServerPlatformTest.php | 21 +- .../DBAL/Platforms/SqlitePlatformTest.php | 223 +++-- .../Tests/DBAL/Portability/StatementTest.php | 35 +- .../Expression/CompositeExpressionTest.php | 75 +- .../Expression/ExpressionBuilderTest.php | 155 ++- .../Tests/DBAL/Query/QueryBuilderTest.php | 88 +- .../Tests/DBAL/SQLParserUtilsTest.php | 617 ++++++------ .../Tests/DBAL/Schema/ColumnDiffTest.php | 11 +- .../Doctrine/Tests/DBAL/Schema/ColumnTest.php | 61 +- .../Tests/DBAL/Schema/ComparatorTest.php | 946 +++++++++--------- .../DBAL/Schema/DB2SchemaManagerTest.php | 40 +- .../DBAL/Schema/ForeignKeyConstraintTest.php | 38 +- .../Doctrine/Tests/DBAL/Schema/IndexTest.php | 43 +- .../DBAL/Schema/MySqlInheritCharsetTest.php | 2 +- .../DBAL/Schema/MySqlSchemaManagerTest.php | 78 +- .../DBAL/Schema/Platforms/MySQLSchemaTest.php | 45 +- .../Tests/DBAL/Schema/SchemaDiffTest.php | 32 +- .../Doctrine/Tests/DBAL/Schema/SchemaTest.php | 123 +-- .../Tests/DBAL/Schema/SequenceTest.php | 30 +- .../DBAL/Schema/SqliteSchemaManagerTest.php | 46 +- .../SingleDatabaseSynchronizerTest.php | 32 +- .../Tests/DBAL/Schema/TableDiffTest.php | 7 +- .../Doctrine/Tests/DBAL/Schema/TableTest.php | 493 ++++----- .../Visitor/CreateSchemaSqlCollectorTest.php | 52 +- .../Visitor/DropSchemaSqlCollectorTest.php | 11 +- .../Visitor/RemoveNamespacedAssetsTest.php | 45 +- .../Schema/Visitor/SchemaSqlCollectorTest.php | 41 +- .../Sharding/PoolingShardConnectionTest.php | 211 ++-- .../DBAL/Sharding/PoolingShardManagerTest.php | 59 +- .../Sharding/SQLAzure/AbstractTestCase.php | 36 +- .../DBAL/Sharding/SQLAzure/FunctionalTest.php | 39 +- .../SQLAzure/MultiTenantVisitorTest.php | 24 +- .../SQLAzureFederationsSynchronizerTest.php | 19 +- .../SQLAzure/SQLAzureShardManagerTest.php | 27 +- .../MultiTenantShardChoserTest.php | 8 +- tests/Doctrine/Tests/DBAL/StatementTest.php | 61 +- .../DBAL/Tools/Console/RunSqlCommandTest.php | 38 +- .../Doctrine/Tests/DBAL/Tools/DumperTest.php | 3 +- tests/Doctrine/Tests/DBAL/Types/ArrayTest.php | 17 +- .../Tests/DBAL/Types/BaseDateTypeTestCase.php | 33 +- .../Doctrine/Tests/DBAL/Types/BinaryTest.php | 34 +- tests/Doctrine/Tests/DBAL/Types/BlobTest.php | 14 +- .../Doctrine/Tests/DBAL/Types/BooleanTest.php | 13 +- .../DBAL/Types/ConversionExceptionTest.php | 17 +- .../DBAL/Types/DateImmutableTypeTest.php | 24 +- .../Tests/DBAL/Types/DateIntervalTest.php | 27 +- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 3 +- .../DBAL/Types/DateTimeImmutableTypeTest.php | 24 +- .../Tests/DBAL/Types/DateTimeTest.php | 5 +- .../Types/DateTimeTzImmutableTypeTest.php | 24 +- .../Tests/DBAL/Types/DateTimeTzTest.php | 5 +- .../Doctrine/Tests/DBAL/Types/DecimalTest.php | 13 +- tests/Doctrine/Tests/DBAL/Types/FloatTest.php | 13 +- .../Tests/DBAL/Types/GuidTypeTest.php | 14 +- .../Doctrine/Tests/DBAL/Types/IntegerTest.php | 13 +- .../Tests/DBAL/Types/JsonArrayTest.php | 22 +- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 20 +- .../Doctrine/Tests/DBAL/Types/ObjectTest.php | 18 +- .../Tests/DBAL/Types/SmallIntTest.php | 13 +- .../Doctrine/Tests/DBAL/Types/StringTest.php | 21 +- .../DBAL/Types/TimeImmutableTypeTest.php | 24 +- .../Types/VarDateTimeImmutableTypeTest.php | 26 +- .../Tests/DBAL/Types/VarDateTimeTest.php | 20 +- tests/Doctrine/Tests/DBAL/UtilTest.php | 74 +- .../Doctrine/Tests/DbalFunctionalTestCase.php | 70 +- .../Tests/DbalPerformanceTestCase.php | 10 +- .../Tests/DbalPerformanceTestListener.php | 44 +- tests/Doctrine/Tests/DbalTestCase.php | 4 +- tests/Doctrine/Tests/Mocks/ConnectionMock.php | 32 +- .../Tests/Mocks/DatabasePlatformMock.php | 63 +- .../Tests/Mocks/DriverConnectionMock.php | 39 +- tests/Doctrine/Tests/Mocks/DriverMock.php | 47 +- .../Tests/Mocks/DriverResultStatementMock.php | 3 +- .../Tests/Mocks/DriverStatementMock.php | 3 +- .../Tests/Mocks/SchemaManagerMock.php | 13 +- tests/Doctrine/Tests/TestUtil.php | 53 +- tests/Doctrine/Tests/Types/MySqlPointType.php | 2 +- tests/continuousphp/bootstrap.php | 4 +- tests/phpstan-polyfill.php | 2 +- 180 files changed, 6406 insertions(+), 6249 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php index 5bc77c911c3..1d500046260 100644 --- a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php +++ b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php @@ -12,36 +12,26 @@ class QueryCacheProfileTest extends DbalTestCase private const LIFETIME = 3600; private const CACHE_KEY = 'user_specified_cache_key'; - /** - * @var QueryCacheProfile - */ + /** @var QueryCacheProfile */ private $queryCacheProfile; - /** - * @var string - */ + /** @var string */ private $query = 'SELECT * FROM foo WHERE bar = ?'; - /** - * @var int[] - */ + /** @var int[] */ private $params = [666]; - /** - * @var string[] - */ + /** @var string[] */ private $types = [ParameterType::INTEGER]; - /** - * @var string[] - */ + /** @var string[] */ private $connectionParams = [ - 'dbname' => 'database_name', - 'user' => 'database_user', - 'password' => 'database_password', - 'host' => 'database_host', - 'driver' => 'database_driver', - ]; + 'dbname' => 'database_name', + 'user' => 'database_user', + 'password' => 'database_password', + 'host' => 'database_host', + 'driver' => 'database_driver', + ]; protected function setUp() { @@ -50,7 +40,7 @@ protected function setUp() public function testShouldUseTheGivenCacheKeyIfPresent() { - list($cacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$cacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, @@ -64,7 +54,7 @@ public function testShouldGenerateAnAutomaticKeyIfNoKeyHasBeenGiven() { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); - list($cacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$cacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, @@ -84,7 +74,7 @@ public function testShouldGenerateDifferentKeysForSameQueryAndParamsAndDifferent { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); - list($firstCacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$firstCacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, @@ -93,7 +83,7 @@ public function testShouldGenerateDifferentKeysForSameQueryAndParamsAndDifferent $this->connectionParams['host'] = 'a_different_host'; - list($secondCacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$secondCacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, @@ -107,7 +97,7 @@ public function testConnectionParamsShouldBeHashed() { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); - list($cacheKey, $queryString) = $this->queryCacheProfile->generateCacheKeys( + [$cacheKey, $queryString] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, @@ -128,14 +118,14 @@ public function testShouldGenerateSameKeysIfNoneOfTheParamsChanges() { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); - list($firstCacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$firstCacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, $this->connectionParams ); - list($secondCacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$secondCacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, diff --git a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php index 4379b3b35a9..851f973e66e 100644 --- a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php +++ b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php @@ -24,15 +24,13 @@ /** * Unit tests for the configuration container. - * - * @author Steve Müller */ class ConfigurationTest extends DbalTestCase { /** * The configuration container instance under test. * - * @var \Doctrine\DBAL\Configuration + * @var Configuration */ protected $config; diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 819dd71f487..dfb908f40f4 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -15,32 +15,36 @@ use Doctrine\DBAL\Events; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\Logging\DebugStack; +use Doctrine\DBAL\Logging\EchoSQLLogger; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\Mocks\DriverMock; +use Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock; use Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock; +use Exception; +use PHPUnit_Framework_MockObject_MockObject; +use ReflectionObject; +use stdClass; use function call_user_func_array; /** * @requires extension pdo_mysql */ -class ConnectionTest extends \Doctrine\Tests\DbalTestCase +class ConnectionTest extends DbalTestCase { - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ protected $_conn = null; - /** - * @var string[] - */ - protected $params = array( + /** @var string[] */ + protected $params = [ 'driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'password' => 'password', - 'port' => '1234' - ); + 'port' => '1234', + ]; protected function setUp() { @@ -49,7 +53,7 @@ protected function setUp() public function getExecuteUpdateMockConnection() { - $driverMock = $this->createMock(\Doctrine\DBAL\Driver::class); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') @@ -57,12 +61,10 @@ public function getExecuteUpdateMockConnection() $this->createMock(DriverConnection::class) )); - $conn = $this->getMockBuilder(Connection::class) + return $this->getMockBuilder(Connection::class) ->setMethods(['executeUpdate']) ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); - - return $conn; } public function testIsConnected() @@ -139,19 +141,19 @@ public function testGetEventManager() public function testConnectDispatchEvent() { $listenerMock = $this->getMockBuilder('ConnectDispatchEventListener') - ->setMethods(array('postConnect')) + ->setMethods(['postConnect']) ->getMock(); $listenerMock->expects($this->once())->method('postConnect'); $eventManager = new EventManager(); - $eventManager->addEventListener(array(Events::postConnect), $listenerMock); + $eventManager->addEventListener([Events::postConnect], $listenerMock); $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - $driverMock->expects(($this->at(0))) + $driverMock->expects($this->at(0)) ->method('connect'); $platform = new Mocks\MockPlatform(); - $conn = new Connection(array('platform' => $platform), $driverMock, new Configuration(), $eventManager); + $conn = new Connection(['platform' => $platform], $driverMock, new Configuration(), $eventManager); $conn->connect(); } @@ -183,13 +185,13 @@ public function testDriverExceptionIsWrapped($method) public function getQueryMethods() { - return array( - array('exec'), - array('query'), - array('executeQuery'), - array('executeUpdate'), - array('prepare'), - ); + return [ + ['exec'], + ['query'], + ['executeQuery'], + ['executeUpdate'], + ['prepare'], + ]; } /** @@ -199,7 +201,7 @@ public function getQueryMethods() */ public function testEchoSQLLogger() { - $logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); + $logger = new EchoSQLLogger(); $this->_conn->getConfiguration()->setSQLLogger($logger); self::assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger()); } @@ -211,7 +213,7 @@ public function testEchoSQLLogger() */ public function testDebugSQLStack() { - $logger = new \Doctrine\DBAL\Logging\DebugStack(); + $logger = new DebugStack(); $this->_conn->getConfiguration()->setSQLLogger($logger); self::assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger()); } @@ -246,7 +248,7 @@ public function testConnectStartsTransactionInNoAutoCommitMode() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); + $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn->setAutoCommit(false); @@ -268,7 +270,7 @@ public function testCommitStartsTransactionInNoAutoCommitMode() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); + $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn->setAutoCommit(false); $conn->connect(); @@ -288,7 +290,7 @@ public function testRollBackStartsTransactionInNoAutoCommitMode() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); + $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn->setAutoCommit(false); $conn->connect(); @@ -308,7 +310,7 @@ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); + $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn->connect(); $conn->beginTransaction(); @@ -332,7 +334,7 @@ public function testEmptyInsert() ->method('executeUpdate') ->with('INSERT INTO footable () VALUES ()'); - $conn->insert('footable', array()); + $conn->insert('footable', []); } /** @@ -475,12 +477,8 @@ public function testDeleteWithIsNull() ->method('executeUpdate') ->with( 'DELETE FROM TestTable WHERE id IS NULL AND name = ?', - [ - 'foo', - ], - [ - 'string', - ] + ['foo'], + ['string'] ); $conn->delete( @@ -518,10 +516,10 @@ public function testFetchAssoc() ->with(FetchMode::ASSOCIATIVE) ->will($this->returnValue($result)); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Doctrine\DBAL\Connection $conn */ + /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeQuery')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) + ->setMethods(['executeQuery']) + ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -554,10 +552,10 @@ public function testFetchArray() ->with(FetchMode::NUMERIC) ->will($this->returnValue($result)); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Doctrine\DBAL\Connection $conn */ + /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeQuery')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) + ->setMethods(['executeQuery']) + ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -591,10 +589,10 @@ public function testFetchColumn() ->with($column) ->will($this->returnValue($result)); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Doctrine\DBAL\Connection $conn */ + /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeQuery')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) + ->setMethods(['executeQuery']) + ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -610,14 +608,14 @@ public function testConnectionIsClosedButNotUnset() // mock Connection, and make connect() purposefully do nothing $connection = $this->getMockBuilder('Doctrine\DBAL\Connection') ->disableOriginalConstructor() - ->setMethods(array('connect')) + ->setMethods(['connect']) ->getMock(); // artificially set the wrapped connection to non-null - $reflection = new \ReflectionObject($connection); + $reflection = new ReflectionObject($connection); $connProperty = $reflection->getProperty('_conn'); $connProperty->setAccessible(true); - $connProperty->setValue($connection, new \stdClass); + $connProperty->setValue($connection, new stdClass()); // close the connection (should nullify the wrapped connection) $connection->close(); @@ -649,10 +647,10 @@ public function testFetchAll() ->method('fetchAll') ->will($this->returnValue($result)); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Doctrine\DBAL\Connection $conn */ + /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeQuery')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) + ->setMethods(['executeQuery']) + ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -665,29 +663,29 @@ public function testFetchAll() public function testConnectionDoesNotMaintainTwoReferencesToExternalPDO() { - $params['pdo'] = new \stdClass(); + $params['pdo'] = new stdClass(); $driverMock = $this->createMock('Doctrine\DBAL\Driver'); $conn = new Connection($params, $driverMock); - self::assertArrayNotHasKey('pdo', $conn->getParams(), "Connection is maintaining additional reference to the PDO connection"); + self::assertArrayNotHasKey('pdo', $conn->getParams(), 'Connection is maintaining additional reference to the PDO connection'); } public function testPassingExternalPDOMeansConnectionIsConnected() { - $params['pdo'] = new \stdClass(); + $params['pdo'] = new stdClass(); $driverMock = $this->createMock('Doctrine\DBAL\Driver'); $conn = new Connection($params, $driverMock); - self::assertTrue($conn->isConnected(), "Connection is not connected after passing external PDO"); + self::assertTrue($conn->isConnected(), 'Connection is not connected after passing external PDO'); } public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() { - /* @var $driver \Doctrine\DBAL\Driver */ + /** @var Driver $driver */ $driver = $this->createMock('Doctrine\DBAL\Driver'); $pdoMock = $this->createMock('Doctrine\DBAL\Driver\Connection'); @@ -695,21 +693,21 @@ public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentE $pdoMock->expects($this->never())->method('exec'); $pdoMock->expects($this->never())->method('prepare'); - $conn = new Connection(array('pdo' => $pdoMock), $driver); + $conn = new Connection(['pdo' => $pdoMock], $driver); $this->expectException(InvalidArgumentException::class); - $conn->delete('kittens', array()); + $conn->delete('kittens', []); } public function dataCallConnectOnce() { - return array( - array('delete', array('tbl', array('id' => 12345))), - array('insert', array('tbl', array('data' => 'foo'))), - array('update', array('tbl', array('data' => 'bar'), array('id' => 12345))), - array('prepare', array('select * from dual')), - array('executeUpdate', array('insert into tbl (id) values (?)'), array(123)), - ); + return [ + ['delete', ['tbl', ['id' => 12345]]], + ['insert', ['tbl', ['data' => 'foo']]], + ['update', ['tbl', ['data' => 'bar'], ['id' => 12345]]], + ['prepare', ['select * from dual']], + ['executeUpdate', ['insert into tbl (id) values (?)'], [123]], + ]; } /** @@ -727,13 +725,13 @@ public function testCallConnectOnce($method, $params) ->will($this->returnValue($stmtMock)); $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setConstructorArgs(array(array('pdo' => $pdoMock, 'platform' => $platformMock), $driverMock)) - ->setMethods(array('connect')) + ->setConstructorArgs([['pdo' => $pdoMock, 'platform' => $platformMock], $driverMock]) + ->setMethods(['connect']) ->getMock(); $conn->expects($this->once())->method('connect'); - call_user_func_array(array($conn, $method), $params); + call_user_func_array([$conn, $method], $params); } /** @@ -741,16 +739,16 @@ public function testCallConnectOnce($method, $params) */ public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() { - /** @var \Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock|\PHPUnit_Framework_MockObject_MockObject $driverMock */ + /** @var VersionAwarePlatformDriverMock|PHPUnit_Framework_MockObject_MockObject $driverMock */ $driverMock = $this->createMock('Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock'); - /** @var \Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock|\PHPUnit_Framework_MockObject_MockObject $driverConnectionMock */ + /** @var ServerInfoAwareConnectionMock|PHPUnit_Framework_MockObject_MockObject $driverConnectionMock */ $driverConnectionMock = $this->createMock('Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock'); - /** @var \Doctrine\DBAL\Platforms\AbstractPlatform|\PHPUnit_Framework_MockObject_MockObject $platformMock */ + /** @var AbstractPlatform|PHPUnit_Framework_MockObject_MockObject $platformMock */ $platformMock = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform'); - $connection = new Connection(array(), $driverMock); + $connection = new Connection([], $driverMock); $driverMock->expects($this->once()) ->method('connect') @@ -786,7 +784,7 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach $params = [666]; $types = [ParameterType::INTEGER]; - /* @var $queryCacheProfileMock QueryCacheProfile|\PHPUnit_Framework_MockObject_MockObject */ + /** @var QueryCacheProfile|PHPUnit_Framework_MockObject_MockObject $queryCacheProfileMock */ $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); $queryCacheProfileMock @@ -801,7 +799,7 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach ->with($query, $params, $types, $this->params) ->will($this->returnValue(['cacheKey', 'realKey'])); - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); self::assertInstanceOf( @@ -813,7 +811,7 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach /** * @group #2821 */ - public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecuteCacheQuery(): void + public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecuteCacheQuery() : void { $resultCacheDriverMock = $this->createMock(Cache::class); @@ -823,7 +821,7 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute ->with('cacheKey') ->will($this->returnValue(['realKey' => []])); - /* @var $queryCacheProfileMock QueryCacheProfile|\PHPUnit_Framework_MockObject_MockObject */ + /** @var QueryCacheProfile|PHPUnit_Framework_MockObject_MockObject $queryCacheProfileMock */ $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); $queryCacheProfileMock @@ -831,7 +829,7 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute ->method('getResultCacheDriver') ->will($this->returnValue($resultCacheDriverMock)); - $query = 'SELECT 1'; + $query = 'SELECT 1'; $connectionParams = $this->params; @@ -843,7 +841,7 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute $connectionParams['platform'] = $this->createMock(AbstractPlatform::class); - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); (new Connection($connectionParams, $driver))->executeCacheQuery($query, [], [], $queryCacheProfileMock); @@ -852,12 +850,12 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute /** * @group #2821 */ - public function testThrowsExceptionWhenInValidPlatformSpecified(): void + public function testThrowsExceptionWhenInValidPlatformSpecified() : void { - $connectionParams = $this->params; - $connectionParams['platform'] = new \stdClass(); + $connectionParams = $this->params; + $connectionParams['platform'] = new stdClass(); - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); $this->expectException(DBALException::class); @@ -870,12 +868,12 @@ public function testThrowsExceptionWhenInValidPlatformSpecified(): void */ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase() { - /** @var \Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock|\PHPUnit_Framework_MockObject_MockObject $driverMock */ + /** @var VersionAwarePlatformDriverMock|PHPUnit_Framework_MockObject_MockObject $driverMock */ $driverMock = $this->createMock(VersionAwarePlatformDriverMock::class); - $connection = new Connection(array('dbname' => 'foo'), $driverMock); - $originalException = new \Exception('Original exception'); - $fallbackException = new \Exception('Fallback exception'); + $connection = new Connection(['dbname' => 'foo'], $driverMock); + $originalException = new Exception('Original exception'); + $fallbackException = new Exception('Fallback exception'); $driverMock->expects($this->at(0)) ->method('connect') diff --git a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php index e83524f3c84..9c0cc18c0be 100644 --- a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php @@ -3,10 +3,12 @@ namespace Doctrine\Tests\DBAL; use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException as InnerDriverException; +use Doctrine\DBAL\Exception\DriverException; use Doctrine\Tests\DbalTestCase; -use Doctrine\DBAL\Driver; +use Exception; +use stdClass; use function chr; use function fopen; use function sprintf; @@ -15,25 +17,25 @@ class DBALExceptionTest extends DbalTestCase { public function testDriverExceptionDuringQueryAcceptsBinaryData() { - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); - $e = DBALException::driverExceptionDuringQuery($driver, new \Exception, '', array('ABC', chr(128))); + $e = DBALException::driverExceptionDuringQuery($driver, new Exception(), '', ['ABC', chr(128)]); self::assertContains('with params ["ABC", "\x80"]', $e->getMessage()); } - + public function testDriverExceptionDuringQueryAcceptsResource() { - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); - $e = \Doctrine\DBAL\DBALException::driverExceptionDuringQuery($driver, new \Exception, "INSERT INTO file (`content`) VALUES (?)", [1 => fopen(__FILE__, 'r')]); + $e = DBALException::driverExceptionDuringQuery($driver, new Exception(), 'INSERT INTO file (`content`) VALUES (?)', [1 => fopen(__FILE__, 'r')]); self::assertContains('Resource', $e->getMessage()); } public function testAvoidOverWrappingOnDriverException() { - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); - $inner = new class extends \Exception implements InnerDriverException + $inner = new class extends Exception implements InnerDriverException { /** * {@inheritDoc} @@ -49,14 +51,14 @@ public function getSQLState() { } }; - $ex = new DriverException('', $inner); - $e = DBALException::driverExceptionDuringQuery($driver, $ex, ''); + $ex = new DriverException('', $inner); + $e = DBALException::driverExceptionDuringQuery($driver, $ex, ''); self::assertSame($ex, $e); } public function testDriverRequiredWithUrl() { - $url = 'mysql://localhost'; + $url = 'mysql://localhost'; $exception = DBALException::driverRequired($url); self::assertInstanceOf(DBALException::class, $exception); @@ -73,9 +75,9 @@ public function testDriverRequiredWithUrl() /** * @group #2821 */ - public function testInvalidPlatformTypeObject(): void + public function testInvalidPlatformTypeObject() : void { - $exception = DBALException::invalidPlatformType(new \stdClass()); + $exception = DBALException::invalidPlatformType(new stdClass()); self::assertSame( "Option 'platform' must be a subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform', instance of 'stdClass' given", @@ -86,7 +88,7 @@ public function testInvalidPlatformTypeObject(): void /** * @group #2821 */ - public function testInvalidPlatformTypeScalar(): void + public function testInvalidPlatformTypeScalar() : void { $exception = DBALException::invalidPlatformType('some string'); diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 7a49b3f9577..9eda7f8de77 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -3,37 +3,41 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Driver\ExceptionConverterDriver; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\Tests\DbalTestCase; +use Exception; use function get_class; use function sprintf; abstract class AbstractDriverTest extends DbalTestCase { - const EXCEPTION_CONNECTION = 'Doctrine\DBAL\Exception\ConnectionException'; - const EXCEPTION_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\ConstraintViolationException'; - const EXCEPTION_DATABASE_OBJECT_EXISTS = 'Doctrine\DBAL\Exception\DatabaseObjectExistsException'; - const EXCEPTION_DATABASE_OBJECT_NOT_FOUND = 'Doctrine\DBAL\Exception\DatabaseObjectNotFoundException'; - const EXCEPTION_DRIVER = 'Doctrine\DBAL\Exception\DriverException'; - const EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'; - const EXCEPTION_INVALID_FIELD_NAME = 'Doctrine\DBAL\Exception\InvalidFieldNameException'; - const EXCEPTION_NON_UNIQUE_FIELD_NAME = 'Doctrine\DBAL\Exception\NonUniqueFieldNameException'; - const EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\NotNullConstraintViolationException'; - const EXCEPTION_READ_ONLY = 'Doctrine\DBAL\Exception\ReadOnlyException'; - const EXCEPTION_SERVER = 'Doctrine\DBAL\Exception\ServerException'; - const EXCEPTION_SYNTAX_ERROR = 'Doctrine\DBAL\Exception\SyntaxErrorException'; - const EXCEPTION_TABLE_EXISTS = 'Doctrine\DBAL\Exception\TableExistsException'; - const EXCEPTION_TABLE_NOT_FOUND = 'Doctrine\DBAL\Exception\TableNotFoundException'; - const EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\UniqueConstraintViolationException'; - const EXCEPTION_DEADLOCK = 'Doctrine\DBAL\Exception\DeadlockException'; - const EXCEPTION_LOCK_WAIT_TIMEOUT = 'Doctrine\DBAL\Exception\LockWaitTimeoutException'; + public const EXCEPTION_CONNECTION = 'Doctrine\DBAL\Exception\ConnectionException'; + public const EXCEPTION_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\ConstraintViolationException'; + public const EXCEPTION_DATABASE_OBJECT_EXISTS = 'Doctrine\DBAL\Exception\DatabaseObjectExistsException'; + public const EXCEPTION_DATABASE_OBJECT_NOT_FOUND = 'Doctrine\DBAL\Exception\DatabaseObjectNotFoundException'; + public const EXCEPTION_DRIVER = 'Doctrine\DBAL\Exception\DriverException'; + public const EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'; + public const EXCEPTION_INVALID_FIELD_NAME = 'Doctrine\DBAL\Exception\InvalidFieldNameException'; + public const EXCEPTION_NON_UNIQUE_FIELD_NAME = 'Doctrine\DBAL\Exception\NonUniqueFieldNameException'; + public const EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\NotNullConstraintViolationException'; + public const EXCEPTION_READ_ONLY = 'Doctrine\DBAL\Exception\ReadOnlyException'; + public const EXCEPTION_SERVER = 'Doctrine\DBAL\Exception\ServerException'; + public const EXCEPTION_SYNTAX_ERROR = 'Doctrine\DBAL\Exception\SyntaxErrorException'; + public const EXCEPTION_TABLE_EXISTS = 'Doctrine\DBAL\Exception\TableExistsException'; + public const EXCEPTION_TABLE_NOT_FOUND = 'Doctrine\DBAL\Exception\TableNotFoundException'; + public const EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\UniqueConstraintViolationException'; + public const EXCEPTION_DEADLOCK = 'Doctrine\DBAL\Exception\DeadlockException'; + public const EXCEPTION_LOCK_WAIT_TIMEOUT = 'Doctrine\DBAL\Exception\LockWaitTimeoutException'; /** * The driver mock under test. * - * @var \Doctrine\DBAL\Driver + * @var Driver */ protected $driver; @@ -46,7 +50,7 @@ protected function setUp() public function testConvertsException() { - if ( ! $this->driver instanceof ExceptionConverterDriver) { + if (! $this->driver instanceof ExceptionConverterDriver) { $this->markTestSkipped('This test is only intended for exception converter drivers.'); } @@ -56,13 +60,13 @@ public function testConvertsException() $this->fail( sprintf( 'No test data found for test %s. You have to return test data from %s.', - get_class($this) . '::' . __FUNCTION__, - get_class($this) . '::getExceptionConversionData' + static::class . '::' . __FUNCTION__, + static::class . '::getExceptionConversionData' ) ); } - $driverException = new class extends \Exception implements DriverException + $driverException = new class extends Exception implements DriverException { public function __construct() { @@ -86,13 +90,13 @@ public function getSQLState() } }; - $data[] = array($driverException, self::EXCEPTION_DRIVER); + $data[] = [$driverException, self::EXCEPTION_DRIVER]; $message = 'DBAL exception message'; foreach ($data as $item) { /** @var $driverException \Doctrine\DBAL\Driver\DriverException */ - list($driverException, $convertedExceptionClassName) = $item; + [$driverException, $convertedExceptionClassName] = $item; $convertedException = $this->driver->convertException($message, $driverException); @@ -106,7 +110,7 @@ public function getSQLState() public function testCreatesDatabasePlatformForVersion() { - if ( ! $this->driver instanceof VersionAwarePlatformDriver) { + if (! $this->driver instanceof VersionAwarePlatformDriver) { $this->markTestSkipped('This test is only intended for version aware platform drivers.'); } @@ -116,8 +120,8 @@ public function testCreatesDatabasePlatformForVersion() $data, sprintf( 'No test data found for test %s. You have to return test data from %s.', - get_class($this) . '::' . __FUNCTION__, - get_class($this) . '::getDatabasePlatformsForVersions' + static::class . '::' . __FUNCTION__, + static::class . '::getDatabasePlatformsForVersions' ) ); @@ -142,7 +146,7 @@ public function testCreatesDatabasePlatformForVersion() */ public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion() { - if ( ! $this->driver instanceof VersionAwarePlatformDriver) { + if (! $this->driver instanceof VersionAwarePlatformDriver) { $this->markTestSkipped('This test is only intended for version aware platform drivers.'); } @@ -151,11 +155,11 @@ public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion( public function testReturnsDatabaseName() { - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', 'dbname' => 'baz', - ); + ]; $connection = $this->getConnectionMock(); @@ -183,7 +187,7 @@ public function testReturnsSchemaManager() /** * Factory method for creating the driver instance under test. * - * @return \Doctrine\DBAL\Driver + * @return Driver */ abstract protected function createDriver(); @@ -193,7 +197,7 @@ abstract protected function createDriver(); * The platform instance returned by this method must be the same as returned by * the driver's getDatabasePlatform() method. * - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ abstract protected function createPlatform(); @@ -205,7 +209,7 @@ abstract protected function createPlatform(); * * @param Connection $connection The underlying connection to use. * - * @return \Doctrine\DBAL\Schema\AbstractSchemaManager + * @return AbstractSchemaManager */ abstract protected function createSchemaManager(Connection $connection); @@ -218,32 +222,28 @@ protected function getConnectionMock() protected function getDatabasePlatformsForVersions() { - return array(); + return []; } protected function getExceptionConversionData() { - return array(); + return []; } private function getExceptionConversions() { - $data = array(); + $data = []; foreach ($this->getExceptionConversionData() as $convertedExceptionClassName => $errors) { foreach ($errors as $error) { $driverException = new class ($error[0], $error[1], $error[2]) - extends \Exception + extends Exception implements DriverException { - /** - * @var mixed - */ + /** @var mixed */ private $errorCode; - /** - * @var mixed - */ + /** @var mixed */ private $sqlState; public function __construct($errorCode, $sqlState, $message) @@ -271,7 +271,7 @@ public function getSQLState() } }; - $data[] = array($driverException, $convertedExceptionClassName); + $data[] = [$driverException, $convertedExceptionClassName]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php index 337a73c0e29..ebeb81d160f 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php @@ -16,10 +16,10 @@ public function testReturnsDatabaseName() parent::testReturnsDatabaseName(); $database = 'bloo'; - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', - ); + ]; $statement = $this->createMock('Doctrine\Tests\Mocks\DriverResultStatementMock'); @@ -74,85 +74,85 @@ protected function getDatabasePlatformsForVersions() : array ['5.5.40-MariaDB-1~wheezy', MySqlPlatform::class], ['5.5.5-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class], ['10.2.8-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class], - ['10.2.8-MariaDB-1~lenny-log', MariaDb1027Platform::class] + ['10.2.8-MariaDB-1~lenny-log', MariaDb1027Platform::class], ]; } protected function getExceptionConversionData() { - return array( - self::EXCEPTION_CONNECTION => array( - array('1044', null, null), - array('1045', null, null), - array('1046', null, null), - array('1049', null, null), - array('1095', null, null), - array('1142', null, null), - array('1143', null, null), - array('1227', null, null), - array('1370', null, null), - array('2002', null, null), - array('2005', null, null), - ), - self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => array( - array('1216', null, null), - array('1217', null, null), - array('1451', null, null), - array('1452', null, null), - ), - self::EXCEPTION_INVALID_FIELD_NAME => array( - array('1054', null, null), - array('1166', null, null), - array('1611', null, null), - ), - self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array( - array('1052', null, null), - array('1060', null, null), - array('1110', null, null), - ), - self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array( - array('1048', null, null), - array('1121', null, null), - array('1138', null, null), - array('1171', null, null), - array('1252', null, null), - array('1263', null, null), - array('1364', null, null), - array('1566', null, null), - ), - self::EXCEPTION_SYNTAX_ERROR => array( - array('1064', null, null), - array('1149', null, null), - array('1287', null, null), - array('1341', null, null), - array('1342', null, null), - array('1343', null, null), - array('1344', null, null), - array('1382', null, null), - array('1479', null, null), - array('1541', null, null), - array('1554', null, null), - array('1626', null, null), - ), - self::EXCEPTION_TABLE_EXISTS => array( - array('1050', null, null), - ), - self::EXCEPTION_TABLE_NOT_FOUND => array( - array('1051', null, null), - array('1146', null, null), - ), - self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array( - array('1062', null, null), - array('1557', null, null), - array('1569', null, null), - array('1586', null, null), - ), - self::EXCEPTION_DEADLOCK => array( - array('1213', null, null), - ), - self::EXCEPTION_LOCK_WAIT_TIMEOUT => array( - array('1205', null, null), - ), - ); + return [ + self::EXCEPTION_CONNECTION => [ + ['1044', null, null], + ['1045', null, null], + ['1046', null, null], + ['1049', null, null], + ['1095', null, null], + ['1142', null, null], + ['1143', null, null], + ['1227', null, null], + ['1370', null, null], + ['2002', null, null], + ['2005', null, null], + ], + self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => [ + ['1216', null, null], + ['1217', null, null], + ['1451', null, null], + ['1452', null, null], + ], + self::EXCEPTION_INVALID_FIELD_NAME => [ + ['1054', null, null], + ['1166', null, null], + ['1611', null, null], + ], + self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [ + ['1052', null, null], + ['1060', null, null], + ['1110', null, null], + ], + self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [ + ['1048', null, null], + ['1121', null, null], + ['1138', null, null], + ['1171', null, null], + ['1252', null, null], + ['1263', null, null], + ['1364', null, null], + ['1566', null, null], + ], + self::EXCEPTION_SYNTAX_ERROR => [ + ['1064', null, null], + ['1149', null, null], + ['1287', null, null], + ['1341', null, null], + ['1342', null, null], + ['1343', null, null], + ['1344', null, null], + ['1382', null, null], + ['1479', null, null], + ['1541', null, null], + ['1554', null, null], + ['1626', null, null], + ], + self::EXCEPTION_TABLE_EXISTS => [ + ['1050', null, null], + ], + self::EXCEPTION_TABLE_NOT_FOUND => [ + ['1051', null, null], + ['1146', null, null], + ], + self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [ + ['1062', null, null], + ['1557', null, null], + ['1569', null, null], + ['1586', null, null], + ], + self::EXCEPTION_DEADLOCK => [ + ['1213', null, null], + ], + self::EXCEPTION_LOCK_WAIT_TIMEOUT => [ + ['1205', null, null], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php index 812a46b5682..efb250d1ac7 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php @@ -9,6 +9,7 @@ class EasyConnectStringTest extends TestCase { /** * @param mixed[] $params + * * @dataProvider connectionParametersProvider */ public function testFromConnectionParameters(array $params, string $expected) : void diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php index 59d3c20ae0b..a427f12c945 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php @@ -10,11 +10,11 @@ class AbstractOracleDriverTest extends AbstractDriverTest { public function testReturnsDatabaseName() { - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', 'dbname' => 'baz', - ); + ]; $connection = $this->getConnectionMock(); @@ -27,13 +27,13 @@ public function testReturnsDatabaseName() public function testReturnsDatabaseNameWithConnectDescriptor() { - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', 'connectionstring' => '(DESCRIPTION=' . '(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))' . - '(CONNECT_DATA=(SERVICE_NAME=baz)))' - ); + '(CONNECT_DATA=(SERVICE_NAME=baz)))', + ]; $connection = $this->getConnectionMock(); @@ -61,38 +61,38 @@ protected function createSchemaManager(Connection $connection) protected function getExceptionConversionData() { - return array( - self::EXCEPTION_CONNECTION => array( - array('1017', null, null), - array('12545', null, null), - ), - self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => array( - array('2292', null, null), - ), - self::EXCEPTION_INVALID_FIELD_NAME => array( - array('904', null, null), - ), - self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array( - array('918', null, null), - array('960', null, null), - ), - self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array( - array('1400', null, null), - ), - self::EXCEPTION_SYNTAX_ERROR => array( - array('923', null, null), - ), - self::EXCEPTION_TABLE_EXISTS => array( - array('955', null, null), - ), - self::EXCEPTION_TABLE_NOT_FOUND => array( - array('942', null, null), - ), - self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array( - array('1', null, null), - array('2299', null, null), - array('38911', null, null), - ), - ); + return [ + self::EXCEPTION_CONNECTION => [ + ['1017', null, null], + ['12545', null, null], + ], + self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => [ + ['2292', null, null], + ], + self::EXCEPTION_INVALID_FIELD_NAME => [ + ['904', null, null], + ], + self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [ + ['918', null, null], + ['960', null, null], + ], + self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [ + ['1400', null, null], + ], + self::EXCEPTION_SYNTAX_ERROR => [ + ['923', null, null], + ], + self::EXCEPTION_TABLE_EXISTS => [ + ['955', null, null], + ], + self::EXCEPTION_TABLE_NOT_FOUND => [ + ['942', null, null], + ], + self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [ + ['1', null, null], + ['2299', null, null], + ['38911', null, null], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php index b71e10f80ce..9c9bcd5c354 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php @@ -14,10 +14,10 @@ public function testReturnsDatabaseName() parent::testReturnsDatabaseName(); $database = 'bloo'; - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', - ); + ]; $statement = $this->createMock('Doctrine\Tests\Mocks\DriverResultStatementMock'); @@ -55,57 +55,57 @@ protected function createSchemaManager(Connection $connection) protected function getDatabasePlatformsForVersions() { - return array( - array('9.0.9', 'Doctrine\DBAL\Platforms\PostgreSqlPlatform'), - array('9.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'), - array('9.1.0', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'), - array('9.1.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'), - array('9.1.9', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'), - array('9.2', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'), - array('9.2.0', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'), - array('9.2.1', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'), - array('9.3.6', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'), - array('9.4', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'), - array('9.4.0', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'), - array('9.4.1', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'), - array('10', PostgreSQL100Platform::class), - ); + return [ + ['9.0.9', 'Doctrine\DBAL\Platforms\PostgreSqlPlatform'], + ['9.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], + ['9.1.0', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], + ['9.1.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], + ['9.1.9', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], + ['9.2', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], + ['9.2.0', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], + ['9.2.1', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], + ['9.3.6', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], + ['9.4', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'], + ['9.4.0', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'], + ['9.4.1', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'], + ['10', PostgreSQL100Platform::class], + ]; } protected function getExceptionConversionData() { - return array( - self::EXCEPTION_CONNECTION => array( - array(null, '7', 'SQLSTATE[08006]'), - ), - self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => array( - array(null, '23503', null), - ), - self::EXCEPTION_INVALID_FIELD_NAME => array( - array(null, '42703', null), - ), - self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array( - array(null, '42702', null), - ), - self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array( - array(null, '23502', null), - ), - self::EXCEPTION_SYNTAX_ERROR => array( - array(null, '42601', null), - ), - self::EXCEPTION_TABLE_EXISTS => array( - array(null, '42P07', null), - ), - self::EXCEPTION_TABLE_NOT_FOUND => array( - array(null, '42P01', null), - ), - self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array( - array(null, '23505', null), - ), - self::EXCEPTION_DEADLOCK => array( - array(null, '40001', null), - array(null, '40P01', null), - ), - ); + return [ + self::EXCEPTION_CONNECTION => [ + [null, '7', 'SQLSTATE[08006]'], + ], + self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => [ + [null, '23503', null], + ], + self::EXCEPTION_INVALID_FIELD_NAME => [ + [null, '42703', null], + ], + self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [ + [null, '42702', null], + ], + self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [ + [null, '23502', null], + ], + self::EXCEPTION_SYNTAX_ERROR => [ + [null, '42601', null], + ], + self::EXCEPTION_TABLE_EXISTS => [ + [null, '42P07', null], + ], + self::EXCEPTION_TABLE_NOT_FOUND => [ + [null, '42P01', null], + ], + self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [ + [null, '23505', null], + ], + self::EXCEPTION_DEADLOCK => [ + [null, '40001', null], + [null, '40P01', null], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php index f2b13c3c1c9..53480e7d82a 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php @@ -25,84 +25,84 @@ protected function createSchemaManager(Connection $connection) protected function getDatabasePlatformsForVersions() { - return array( - array('10', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('10.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('10.0.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('10.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('10.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('10.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('11', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('11.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('11.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('11.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('11.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('11.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('12', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('12.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('12.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('12.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('12.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('12.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('13', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('14', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('15', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('15.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('16', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('16.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('16.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('16.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('16.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('16.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('17', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - ); + return [ + ['10', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['10.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['10.0.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['10.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['10.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['10.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['11', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['11.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['11.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['11.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['11.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['11.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['12', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['12.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['12.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['12.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['12.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['12.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['13', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['14', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['15', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['15.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['16', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['16.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['16.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['16.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['16.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['16.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['17', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ]; } protected function getExceptionConversionData() { - return array( - self::EXCEPTION_CONNECTION => array( - array('-100', null, null), - array('-103', null, null), - array('-832', null, null), - ), - self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => array( - array('-198', null, null), - ), - self::EXCEPTION_INVALID_FIELD_NAME => array( - array('-143', null, null), - ), - self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array( - array('-144', null, null), - ), - self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array( - array('-184', null, null), - array('-195', null, null), - ), - self::EXCEPTION_SYNTAX_ERROR => array( - array('-131', null, null), - ), - self::EXCEPTION_TABLE_EXISTS => array( - array('-110', null, null), - ), - self::EXCEPTION_TABLE_NOT_FOUND => array( - array('-141', null, null), - array('-1041', null, null), - ), - self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array( - array('-193', null, null), - array('-196', null, null), - ), - self::EXCEPTION_DEADLOCK => array( - array('-306', null, null), - array('-307', null, null), - array('-684', null, null), - ), - self::EXCEPTION_LOCK_WAIT_TIMEOUT => array( - array('-210', null, null), - array('-1175', null, null), - array('-1281', null, null), - ), - ); + return [ + self::EXCEPTION_CONNECTION => [ + ['-100', null, null], + ['-103', null, null], + ['-832', null, null], + ], + self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => [ + ['-198', null, null], + ], + self::EXCEPTION_INVALID_FIELD_NAME => [ + ['-143', null, null], + ], + self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [ + ['-144', null, null], + ], + self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [ + ['-184', null, null], + ['-195', null, null], + ], + self::EXCEPTION_SYNTAX_ERROR => [ + ['-131', null, null], + ], + self::EXCEPTION_TABLE_EXISTS => [ + ['-110', null, null], + ], + self::EXCEPTION_TABLE_NOT_FOUND => [ + ['-141', null, null], + ['-1041', null, null], + ], + self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [ + ['-193', null, null], + ['-196', null, null], + ], + self::EXCEPTION_DEADLOCK => [ + ['-306', null, null], + ['-307', null, null], + ['-684', null, null], + ], + self::EXCEPTION_LOCK_WAIT_TIMEOUT => [ + ['-210', null, null], + ['-1175', null, null], + ['-1281', null, null], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php index 35d2d721a51..31e72a661af 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php @@ -25,33 +25,33 @@ protected function createSchemaManager(Connection $connection) protected function getDatabasePlatformsForVersions() { - return array( - array('9', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), - array('9.00', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), - array('9.00.0', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), - array('9.00.1398', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), - array('9.00.1398.99', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), - array('9.00.1399', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('9.00.1399.0', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('9.00.1399.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('9.00.1400', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('9.10', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('9.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('10.00.1599', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('10.00.1599.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('10.00.1600', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('10.00.1600.0', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('10.00.1600.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('10.00.1601', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('10.10', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('10.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('11.00.2099', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('11.00.2099.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('11.00.2100', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), - array('11.00.2100.0', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), - array('11.00.2100.99', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), - array('11.00.2101', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), - array('12', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), - ); + return [ + ['9', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], + ['9.00', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], + ['9.00.0', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], + ['9.00.1398', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], + ['9.00.1398.99', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], + ['9.00.1399', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['9.00.1399.0', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['9.00.1399.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['9.00.1400', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['9.10', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['9.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['10.00.1599', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['10.00.1599.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['10.00.1600', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['10.00.1600.0', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['10.00.1600.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['10.00.1601', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['10.10', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['10.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['11.00.2099', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['11.00.2099.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['11.00.2100', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], + ['11.00.2100.0', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], + ['11.00.2100.99', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], + ['11.00.2101', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], + ['12', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php index e1ce3f10127..96f3b6b9d64 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php @@ -10,12 +10,12 @@ class AbstractSQLiteDriverTest extends AbstractDriverTest { public function testReturnsDatabaseName() { - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', 'dbname' => 'baz', 'path' => 'bloo', - ); + ]; $connection = $this->getConnectionMock(); @@ -43,39 +43,39 @@ protected function createSchemaManager(Connection $connection) protected function getExceptionConversionData() { - return array( - self::EXCEPTION_CONNECTION => array( - array(null, null, 'unable to open database file'), - ), - self::EXCEPTION_INVALID_FIELD_NAME => array( - array(null, null, 'has no column named'), - ), - self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array( - array(null, null, 'ambiguous column name'), - ), - self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array( - array(null, null, 'may not be NULL'), - ), - self::EXCEPTION_READ_ONLY => array( - array(null, null, 'attempt to write a readonly database'), - ), - self::EXCEPTION_SYNTAX_ERROR => array( - array(null, null, 'syntax error'), - ), - self::EXCEPTION_TABLE_EXISTS => array( - array(null, null, 'already exists'), - ), - self::EXCEPTION_TABLE_NOT_FOUND => array( - array(null, null, 'no such table:'), - ), - self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array( - array(null, null, 'must be unique'), - array(null, null, 'is not unique'), - array(null, null, 'are not unique'), - ), - self::EXCEPTION_LOCK_WAIT_TIMEOUT => array( - array(null, null, 'database is locked'), - ), - ); + return [ + self::EXCEPTION_CONNECTION => [ + [null, null, 'unable to open database file'], + ], + self::EXCEPTION_INVALID_FIELD_NAME => [ + [null, null, 'has no column named'], + ], + self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [ + [null, null, 'ambiguous column name'], + ], + self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [ + [null, null, 'may not be NULL'], + ], + self::EXCEPTION_READ_ONLY => [ + [null, null, 'attempt to write a readonly database'], + ], + self::EXCEPTION_SYNTAX_ERROR => [ + [null, null, 'syntax error'], + ], + self::EXCEPTION_TABLE_EXISTS => [ + [null, null, 'already exists'], + ], + self::EXCEPTION_TABLE_NOT_FOUND => [ + [null, null, 'no such table:'], + ], + self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [ + [null, null, 'must be unique'], + [null, null, 'is not unique'], + [null, null, 'are not unique'], + ], + self::EXCEPTION_LOCK_WAIT_TIMEOUT => [ + [null, null, 'database is locked'], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php index 114a5a108a1..eaebefb728c 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\DBAL\Driver\IBMDB2; +use Doctrine\DBAL\Driver\IBMDB2\DB2Connection; use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; class DB2ConnectionTest extends DbalTestCase @@ -10,13 +12,13 @@ class DB2ConnectionTest extends DbalTestCase /** * The ibm_db2 driver connection mock under test. * - * @var \Doctrine\DBAL\Driver\IBMDB2\DB2Connection|\PHPUnit_Framework_MockObject_MockObject + * @var DB2Connection|PHPUnit_Framework_MockObject_MockObject */ private $connectionMock; protected function setUp() { - if ( ! extension_loaded('ibm_db2')) { + if (! extension_loaded('ibm_db2')) { $this->markTestSkipped('ibm_db2 is not installed.'); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php index 1dec0608eba..b0b34309f28 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\Mysqli\MysqliException; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\Tests\DbalFunctionalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; use function restore_error_handler; use function set_error_handler; @@ -15,13 +16,13 @@ class MysqliConnectionTest extends DbalFunctionalTestCase /** * The mysqli driver connection mock under test. * - * @var \Doctrine\DBAL\Driver\Mysqli\MysqliConnection|\PHPUnit_Framework_MockObject_MockObject + * @var MysqliConnection|PHPUnit_Framework_MockObject_MockObject */ private $connectionMock; protected function setUp() { - if ( ! extension_loaded('mysqli')) { + if (! extension_loaded('mysqli')) { $this->markTestSkipped('mysqli is not installed.'); } @@ -43,7 +44,9 @@ public function testDoesNotRequireQueryForServerVersion() public function testRestoresErrorHandlerOnException() { - $handler = function () { self::fail('Never expected this to be called'); }; + $handler = static function () { + self::fail('Never expected this to be called'); + }; $default_handler = set_error_handler($handler); try { diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php index 864b1a643d5..b8141a84f2a 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\DBAL\Driver\OCI8; +use Doctrine\DBAL\Driver\OCI8\OCI8Connection; use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; class OCI8ConnectionTest extends DbalTestCase @@ -10,13 +12,13 @@ class OCI8ConnectionTest extends DbalTestCase /** * The oci8 driver connection mock under test. * - * @var \Doctrine\DBAL\Driver\OCI8\OCI8Connection|\PHPUnit_Framework_MockObject_MockObject + * @var OCI8Connection|PHPUnit_Framework_MockObject_MockObject */ private $connectionMock; protected function setUp() { - if ( ! extension_loaded('oci8')) { + if (! extension_loaded('oci8')) { $this->markTestSkipped('oci8 is not installed.'); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php index 65a3c95ce36..103b7ab57d7 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php @@ -5,13 +5,14 @@ use Doctrine\DBAL\Driver\OCI8\OCI8Exception; use Doctrine\DBAL\Driver\OCI8\OCI8Statement; use Doctrine\Tests\DbalTestCase; +use ReflectionProperty; use function extension_loaded; class OCI8StatementTest extends DbalTestCase { protected function setUp() { - if (!extension_loaded('oci8')) { + if (! extension_loaded('oci8')) { $this->markTestSkipped('oci8 is not installed.'); } @@ -33,7 +34,7 @@ protected function setUp() public function testExecute(array $params) { $statement = $this->getMockBuilder('\Doctrine\DBAL\Driver\OCI8\OCI8Statement') - ->setMethods(array('bindValue', 'errorInfo')) + ->setMethods(['bindValue', 'errorInfo']) ->disableOriginalConstructor() ->getMock(); @@ -54,18 +55,18 @@ public function testExecute(array $params) ->with( $this->equalTo(3), $this->equalTo($params[2]) - ); + ); // can't pass to constructor since we don't have a real database handle, // but execute must check the connection for the executeMode $conn = $this->getMockBuilder('\Doctrine\DBAL\Driver\OCI8\OCI8Connection') - ->setMethods(array('getExecuteMode')) + ->setMethods(['getExecuteMode']) ->disableOriginalConstructor() ->getMock(); $conn->expects($this->once()) ->method('getExecuteMode'); - $reflProperty = new \ReflectionProperty($statement, '_conn'); + $reflProperty = new ReflectionProperty($statement, '_conn'); $reflProperty->setAccessible(true); $reflProperty->setValue($statement, $conn); @@ -74,16 +75,16 @@ public function testExecute(array $params) public static function executeDataProvider() { - return array( + return [ // $hasZeroIndex = isset($params[0]); == true - array( - array(0 => 'test', 1 => null, 2 => 'value') - ), + [ + [0 => 'test', 1 => null, 2 => 'value'], + ], // $hasZeroIndex = isset($params[0]); == false - array( - array(0 => null, 1 => 'test', 2 => 'value') - ) - ); + [ + [0 => null, 1 => 'test', 2 => 'value'], + ], + ]; } /** @@ -98,19 +99,19 @@ public function testConvertNonTerminatedLiteral($sql, $message) public static function nonTerminatedLiteralProvider() { - return array( - 'no-matching-quote' => array( + return [ + 'no-matching-quote' => [ "SELECT 'literal FROM DUAL", '/offset 7/', - ), - 'no-matching-double-quote' => array( + ], + 'no-matching-double-quote' => [ 'SELECT 1 "COL1 FROM DUAL', '/offset 9/', - ), - 'incorrect-escaping-syntax' => array( + ], + 'incorrect-escaping-syntax' => [ "SELECT 'quoted \\'string' FROM DUAL", '/offset 23/', - ), - ); + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php index 96691bacd9c..593f04d203c 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php @@ -4,33 +4,34 @@ use Doctrine\DBAL\Driver\PDOException; use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; class PDOExceptionTest extends DbalTestCase { - const ERROR_CODE = 666; + public const ERROR_CODE = 666; - const MESSAGE = 'PDO Exception'; + public const MESSAGE = 'PDO Exception'; - const SQLSTATE = 28000; + public const SQLSTATE = 28000; /** * The PDO exception wrapper under test. * - * @var \Doctrine\DBAL\Driver\PDOException + * @var PDOException */ private $exception; /** * The wrapped PDO exception mock. * - * @var \PDOException|\PHPUnit_Framework_MockObject_MockObject + * @var \PDOException|PHPUnit_Framework_MockObject_MockObject */ private $wrappedException; protected function setUp() { - if ( ! extension_loaded('PDO')) { + if (! extension_loaded('PDO')) { $this->markTestSkipped('PDO is not installed.'); } @@ -38,7 +39,7 @@ protected function setUp() $this->wrappedException = new \PDOException(self::MESSAGE, self::SQLSTATE); - $this->wrappedException->errorInfo = array(self::SQLSTATE, self::ERROR_CODE); + $this->wrappedException->errorInfo = [self::SQLSTATE, self::ERROR_CODE]; $this->exception = new PDOException($this->wrappedException); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php index 6fd187e3d28..3f1c3efa1f8 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php @@ -6,6 +6,7 @@ use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest; use PDO; use PDOException; +use PHPUnit_Framework_SkippedTestError; use function defined; class DriverTest extends AbstractPostgreSQLDriverTest @@ -23,10 +24,10 @@ public function testConnectionDisablesPreparesOnPhp56() $this->skipWhenNotUsingPhp56AndPdoPgsql(); $connection = $this->createDriver()->connect( - array( + [ 'host' => $GLOBALS['db_host'], - 'port' => $GLOBALS['db_port'] - ), + 'port' => $GLOBALS['db_port'], + ], $GLOBALS['db_username'], $GLOBALS['db_password'] ); @@ -49,13 +50,13 @@ public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined( $this->skipWhenNotUsingPhp56AndPdoPgsql(); $connection = $this->createDriver()->connect( - array( + [ 'host' => $GLOBALS['db_host'], - 'port' => $GLOBALS['db_port'] - ), + 'port' => $GLOBALS['db_port'], + ], $GLOBALS['db_username'], $GLOBALS['db_password'], - array(PDO::PGSQL_ATTR_DISABLE_PREPARES => false) + [PDO::PGSQL_ATTR_DISABLE_PREPARES => false] ); self::assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection); @@ -76,13 +77,13 @@ public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplici $this->skipWhenNotUsingPhp56AndPdoPgsql(); $connection = $this->createDriver()->connect( - array( + [ 'host' => $GLOBALS['db_host'], - 'port' => $GLOBALS['db_port'] - ), + 'port' => $GLOBALS['db_port'], + ], $GLOBALS['db_username'], $GLOBALS['db_password'], - array(PDO::PGSQL_ATTR_DISABLE_PREPARES => true) + [PDO::PGSQL_ATTR_DISABLE_PREPARES => true] ); self::assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection); @@ -104,7 +105,7 @@ protected function createDriver() } /** - * @throws \PHPUnit_Framework_SkippedTestError + * @throws PHPUnit_Framework_SkippedTestError */ private function skipWhenNotUsingPhp56AndPdoPgsql() { @@ -112,8 +113,10 @@ private function skipWhenNotUsingPhp56AndPdoPgsql() $this->markTestSkipped('Test requires PHP 5.6+'); } - if (! (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql')) { - $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml'); + if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql') { + return; } + + $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml'); } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php index 273c2de1b85..49bc5d05a16 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\DBAL\Driver\SQLAnywhere; +use Doctrine\DBAL\Driver\SQLAnywhere\SQLAnywhereConnection; use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; class SQLAnywhereConnectionTest extends DbalTestCase @@ -10,13 +12,13 @@ class SQLAnywhereConnectionTest extends DbalTestCase /** * The sqlanywhere driver connection mock under test. * - * @var \Doctrine\DBAL\Driver\SQLAnywhere\SQLAnywhereConnection|\PHPUnit_Framework_MockObject_MockObject + * @var SQLAnywhereConnection|PHPUnit_Framework_MockObject_MockObject */ private $connectionMock; protected function setUp() { - if ( ! extension_loaded('sqlanywhere')) { + if (! extension_loaded('sqlanywhere')) { $this->markTestSkipped('sqlanywhere is not installed.'); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php index 089d2b11085..9e467cca01f 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\DBAL\Driver\SQLSrv; +use Doctrine\DBAL\Driver\SQLSrv\SQLSrvConnection; use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; class SQLSrvConnectionTest extends DbalTestCase @@ -10,13 +12,13 @@ class SQLSrvConnectionTest extends DbalTestCase /** * The sqlsrv driver connection mock under test. * - * @var \Doctrine\DBAL\Driver\SQLSrv\SQLSrvConnection|\PHPUnit_Framework_MockObject_MockObject + * @var SQLSrvConnection|PHPUnit_Framework_MockObject_MockObject */ private $connectionMock; protected function setUp() { - if ( ! extension_loaded('sqlsrv')) { + if (! extension_loaded('sqlsrv')) { $this->markTestSkipped('sqlsrv is not installed.'); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php b/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php index 95f107cf921..90244cd2ac8 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php @@ -10,12 +10,13 @@ use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\Portability\Statement as PortabilityStatement; +use Doctrine\Tests\DbalTestCase; use IteratorAggregate; use PHPUnit\Framework\MockObject\MockObject; use Traversable; use function extension_loaded; -class StatementIteratorTest extends \Doctrine\Tests\DbalTestCase +class StatementIteratorTest extends DbalTestCase { /** * @dataProvider statementProvider() @@ -58,11 +59,11 @@ public function testStatementIterationCallsFetchOncePerStep(string $class) : voi private function configureStatement(MockObject $stmt, int &$calls) : void { $values = ['foo', '', 'bar', '0', 'baz', 0, 'qux', null, 'quz', false, 'impossible']; - $calls = 0; + $calls = 0; $stmt->expects($this->exactly(10)) ->method('fetch') - ->willReturnCallback(function() use ($values, &$calls) { + ->willReturnCallback(static function () use ($values, &$calls) { $value = $values[$calls]; $calls++; diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index 7e7c5b0153a..e5520afcf1e 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -15,6 +15,7 @@ use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; +use PDO; use stdClass; use function extension_loaded; use function in_array; @@ -37,7 +38,7 @@ public function testInvalidPdoInstance() public function testValidPdoInstance() { $conn = DriverManager::getConnection([ - 'pdo' => new \PDO('sqlite::memory:'), + 'pdo' => new PDO('sqlite::memory:'), ]); self::assertEquals('sqlite', $conn->getDatabasePlatform()->getName()); @@ -49,12 +50,12 @@ public function testValidPdoInstance() */ public function testPdoInstanceSetErrorMode() { - $pdo = new \PDO('sqlite::memory:'); - $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT); + $pdo = new PDO('sqlite::memory:'); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); $options = ['pdo' => $pdo]; DriverManager::getConnection($options); - self::assertEquals(\PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(\PDO::ATTR_ERRMODE)); + self::assertEquals(PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(PDO::ATTR_ERRMODE)); } /** @@ -80,7 +81,7 @@ public function testCustomPlatform() { $mockPlatform = new MockPlatform(); $options = [ - 'pdo' => new \PDO('sqlite::memory:'), + 'pdo' => new PDO('sqlite::memory:'), 'platform' => $mockPlatform, ]; @@ -96,7 +97,7 @@ public function testCustomWrapper() $wrapperClass = ConnectionMock::class; $options = [ - 'pdo' => new \PDO('sqlite::memory:'), + 'pdo' => new PDO('sqlite::memory:'), 'wrapperClass' => $wrapperClass, ]; @@ -112,7 +113,7 @@ public function testInvalidWrapperClass() $this->expectException(DBALException::class); $options = [ - 'pdo' => new \PDO('sqlite::memory:'), + 'pdo' => new PDO('sqlite::memory:'), 'wrapperClass' => stdClass::class, ]; @@ -216,7 +217,7 @@ public function testDatabaseUrl($url, $expected) $this->markTestSkipped('PDO is not installed'); } - $options['pdo'] = $this->createMock(\PDO::class); + $options['pdo'] = $this->createMock(PDO::class); } $options = is_array($url) ? $url : ['url' => $url]; diff --git a/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php b/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php index 2a19d2c5fee..981851a6b9e 100644 --- a/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php @@ -14,11 +14,10 @@ public function testPostConnect() $connectionMock = $this->createMock('Doctrine\DBAL\Connection'); $connectionMock->expects($this->once()) ->method('executeUpdate') - ->with($this->equalTo("SET NAMES foo COLLATE bar")); + ->with($this->equalTo('SET NAMES foo COLLATE bar')); $eventArgs = new ConnectionEventArgs($connectionMock); - $listener = new MysqlSessionInit('foo', 'bar'); $listener->postConnect($eventArgs); } @@ -26,6 +25,6 @@ public function testPostConnect() public function testGetSubscribedEvents() { $listener = new MysqlSessionInit(); - self::assertEquals(array(Events::postConnect), $listener->getSubscribedEvents()); + self::assertEquals([Events::postConnect], $listener->getSubscribedEvents()); } } diff --git a/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php b/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php index 4ec3545c002..b86af27fc3f 100644 --- a/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php @@ -19,14 +19,12 @@ public function testPostConnect() $eventArgs = new ConnectionEventArgs($connectionMock); - $listener = new OracleSessionInit(); $listener->postConnect($eventArgs); } /** * @group DBAL-1824 - * * @dataProvider getPostConnectWithSessionParameterValuesData */ public function testPostConnectQuotesSessionParameterValues($name, $value) @@ -40,21 +38,20 @@ public function testPostConnectQuotesSessionParameterValues($name, $value) $eventArgs = new ConnectionEventArgs($connectionMock); - - $listener = new OracleSessionInit(array($name => $value)); + $listener = new OracleSessionInit([$name => $value]); $listener->postConnect($eventArgs); } public function getPostConnectWithSessionParameterValuesData() { - return array( - array('CURRENT_SCHEMA', 'foo'), - ); + return [ + ['CURRENT_SCHEMA', 'foo'], + ]; } public function testGetSubscribedEvents() { $listener = new OracleSessionInit(); - self::assertEquals(array(Events::postConnect), $listener->getSubscribedEvents()); + self::assertEquals([Events::postConnect], $listener->getSubscribedEvents()); } } diff --git a/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php b/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php index 2b25301da98..bf74e5180ae 100644 --- a/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php @@ -28,6 +28,6 @@ public function testPostConnect() public function testGetSubscribedEvents() { $listener = new SQLSessionInit("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'"); - self::assertEquals(array(Events::postConnect), $listener->getSubscribedEvents()); + self::assertEquals([Events::postConnect], $listener->getSubscribedEvents()); } } diff --git a/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php b/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php index 9984e3d0223..c2e7c7ec29a 100644 --- a/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php @@ -20,15 +20,14 @@ namespace Doctrine\Tests\DBAL\Exception; use Doctrine\DBAL\Exception\InvalidArgumentException; +use PHPUnit\Framework\TestCase; /** * Tests for {@see \Doctrine\DBAL\Exception\InvalidArgumentException} * * @covers \Doctrine\DBAL\Exception\InvalidArgumentException - * - * @author Marco Pivetta */ -class InvalidArgumentExceptionTest extends \PHPUnit\Framework\TestCase +class InvalidArgumentExceptionTest extends TestCase { public function testFromEmptyCriteria() { diff --git a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php index e409f5f5f5e..66332ed20ba 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php @@ -5,8 +5,10 @@ use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; use function fopen; use function in_array; use function str_repeat; @@ -15,7 +17,7 @@ /** * @group DBAL-6 */ -class BlobTest extends \Doctrine\Tests\DbalFunctionalTestCase +class BlobTest extends DbalFunctionalTestCase { protected function setUp() { @@ -25,7 +27,7 @@ protected function setUp() $this->markTestSkipped('This test does not work on pdo_sqlsrv driver due to a bug. See: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/5a755bdd-41e9-45cb-9166-c9da4475bb94/how-to-set-null-for-varbinarymax-using-bindvalue-using-pdosqlsrv?forum=sqldriverforphp'); } - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ + /** @var AbstractSchemaManager $sm */ $table = new Table('blob_table'); $table->addColumn('id', 'integer'); $table->addColumn('clobfield', 'text'); @@ -100,9 +102,7 @@ public function testUpdate() ParameterType::LARGE_OBJECT, ]); - $this->_conn->update('blob_table', [ - 'blobfield' => 'test2', - ], ['id' => 1], [ + $this->_conn->update('blob_table', ['blobfield' => 'test2'], ['id' => 1], [ ParameterType::LARGE_OBJECT, ParameterType::INTEGER, ]); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index 0c9d57895aa..c6cca6d8e68 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -2,14 +2,20 @@ namespace Doctrine\Tests\DBAL\Functional; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\ConnectionException; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; +use Error; +use Exception; +use RuntimeException; +use Throwable; use function in_array; -class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase +class ConnectionTest extends DbalFunctionalTestCase { protected function setUp() { @@ -46,9 +52,9 @@ public function testTransactionNestingBehavior() try { $this->_conn->beginTransaction(); self::assertEquals(2, $this->_conn->getTransactionNestingLevel()); - throw new \Exception; + throw new Exception(); $this->_conn->commit(); // never reached - } catch (\Exception $e) { + } catch (Throwable $e) { $this->_conn->rollBack(); self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); //no rethrow @@ -82,9 +88,9 @@ public function testTransactionNestingBehaviorWithSavepoints() self::assertEquals(3, $this->_conn->getTransactionNestingLevel()); $this->_conn->commit(); self::assertEquals(2, $this->_conn->getTransactionNestingLevel()); - throw new \Exception; + throw new Exception(); $this->_conn->commit(); // never reached - } catch (\Exception $e) { + } catch (Throwable $e) { $this->_conn->rollBack(); self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); //no rethrow @@ -121,7 +127,7 @@ public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsExce } $this->expectException(ConnectionException::class); - $this->expectExceptionMessage("Savepoints are not supported by this driver."); + $this->expectExceptionMessage('Savepoints are not supported by this driver.'); $this->_conn->setNestTransactionsWithSavepoints(true); } @@ -133,7 +139,7 @@ public function testCreateSavepointsNotSupportedThrowsException() } $this->expectException(ConnectionException::class); - $this->expectExceptionMessage("Savepoints are not supported by this driver."); + $this->expectExceptionMessage('Savepoints are not supported by this driver.'); $this->_conn->createSavepoint('foo'); } @@ -145,7 +151,7 @@ public function testReleaseSavepointsNotSupportedThrowsException() } $this->expectException(ConnectionException::class); - $this->expectExceptionMessage("Savepoints are not supported by this driver."); + $this->expectExceptionMessage('Savepoints are not supported by this driver.'); $this->_conn->releaseSavepoint('foo'); } @@ -157,7 +163,7 @@ public function testRollbackSavepointsNotSupportedThrowsException() } $this->expectException(ConnectionException::class); - $this->expectExceptionMessage("Savepoints are not supported by this driver."); + $this->expectExceptionMessage('Savepoints are not supported by this driver.'); $this->_conn->rollbackSavepoint('foo'); } @@ -168,10 +174,10 @@ public function testTransactionBehaviorWithRollback() $this->_conn->beginTransaction(); self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); - throw new \Exception; + throw new Exception(); $this->_conn->commit(); // never reached - } catch (\Exception $e) { + } catch (Throwable $e) { self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); $this->_conn->rollBack(); self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); @@ -184,7 +190,7 @@ public function testTransactionBehaviour() $this->_conn->beginTransaction(); self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); $this->_conn->commit(); - } catch (\Exception $e) { + } catch (Throwable $e) { $this->_conn->rollBack(); self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); } @@ -195,13 +201,13 @@ public function testTransactionBehaviour() public function testTransactionalWithException() { try { - $this->_conn->transactional(function($conn) { - /* @var $conn \Doctrine\DBAL\Connection */ + $this->_conn->transactional(static function($conn) { + /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); - throw new \RuntimeException("Ooops!"); + throw new RuntimeException('Ooops!'); }); $this->fail('Expected exception'); - } catch (\RuntimeException $expected) { + } catch (RuntimeException $expected) { self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); } } @@ -209,21 +215,21 @@ public function testTransactionalWithException() public function testTransactionalWithThrowable() { try { - $this->_conn->transactional(function($conn) { - /* @var $conn \Doctrine\DBAL\Connection */ + $this->_conn->transactional(static function($conn) { + /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); - throw new \Error("Ooops!"); + throw new Error('Ooops!'); }); $this->fail('Expected exception'); - } catch (\Error $expected) { + } catch (Error $expected) { self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); } } public function testTransactional() { - $res = $this->_conn->transactional(function($conn) { - /* @var $conn \Doctrine\DBAL\Connection */ + $res = $this->_conn->transactional(static function($conn) { + /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); }); @@ -232,7 +238,7 @@ public function testTransactional() public function testTransactionalReturnValue() { - $res = $this->_conn->transactional(function() { + $res = $this->_conn->transactional(static function() { return 42; }); diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index f63e397c65b..e688a5f0604 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -2,13 +2,16 @@ namespace Doctrine\Tests\DBAL\Functional; +use DateTime; use Doctrine\DBAL\Connection; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Platforms\TrimMode; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; use const CASE_LOWER; use const PHP_EOL; use function array_change_key_case; @@ -22,36 +25,36 @@ use function property_exists; use function strtotime; -class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase +class DataAccessTest extends DbalFunctionalTestCase { - /** - * @var bool - */ + /** @var bool */ static private $generated = false; protected function setUp() { parent::setUp(); - if (self::$generated === false) { - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ - $table = new \Doctrine\DBAL\Schema\Table("fetch_table"); - $table->addColumn('test_int', 'integer'); - $table->addColumn('test_string', 'string'); - $table->addColumn('test_datetime', 'datetime', array('notnull' => false)); - $table->setPrimaryKey(array('test_int')); + if (self::$generated !== false) { + return; + } - $sm = $this->_conn->getSchemaManager(); - $sm->createTable($table); + /** @var AbstractSchemaManager $sm */ + $table = new Table('fetch_table'); + $table->addColumn('test_int', 'integer'); + $table->addColumn('test_string', 'string'); + $table->addColumn('test_datetime', 'datetime', ['notnull' => false]); + $table->setPrimaryKey(['test_int']); - $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo', 'test_datetime' => '2010-01-01 10:10:10')); - self::$generated = true; - } + $sm = $this->_conn->getSchemaManager(); + $sm->createTable($table); + + $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo', 'test_datetime' => '2010-01-01 10:10:10')); + self::$generated = true; } public function testPrepareWithBindValue() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -60,8 +63,8 @@ public function testPrepareWithBindValue() $stmt->execute(); $row = $stmt->fetch(FetchMode::ASSOCIATIVE); - $row = array_change_key_case($row, \CASE_LOWER); - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); + $row = array_change_key_case($row, CASE_LOWER); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $row); } public function testPrepareWithBindParam() @@ -69,7 +72,7 @@ public function testPrepareWithBindParam() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -78,8 +81,8 @@ public function testPrepareWithBindParam() $stmt->execute(); $row = $stmt->fetch(FetchMode::ASSOCIATIVE); - $row = array_change_key_case($row, \CASE_LOWER); - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); + $row = array_change_key_case($row, CASE_LOWER); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $row); } public function testPrepareWithFetchAll() @@ -87,7 +90,7 @@ public function testPrepareWithFetchAll() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -96,8 +99,8 @@ public function testPrepareWithFetchAll() $stmt->execute(); $rows = $stmt->fetchAll(FetchMode::ASSOCIATIVE); - $rows[0] = array_change_key_case($rows[0], \CASE_LOWER); - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $rows[0]); + $rows[0] = array_change_key_case($rows[0], CASE_LOWER); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $rows[0]); } /** @@ -108,7 +111,7 @@ public function testPrepareWithFetchAllBoth() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -117,8 +120,8 @@ public function testPrepareWithFetchAllBoth() $stmt->execute(); $rows = $stmt->fetchAll(FetchMode::MIXED); - $rows[0] = array_change_key_case($rows[0], \CASE_LOWER); - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo', 0 => 1, 1 => 'foo'), $rows[0]); + $rows[0] = array_change_key_case($rows[0], CASE_LOWER); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo', 0 => 1, 1 => 'foo'], $rows[0]); } public function testPrepareWithFetchColumn() @@ -126,7 +129,7 @@ public function testPrepareWithFetchColumn() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -143,7 +146,7 @@ public function testPrepareWithIterator() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -151,18 +154,18 @@ public function testPrepareWithIterator() $stmt->bindParam(2, $paramStr); $stmt->execute(); - $rows = array(); + $rows = []; $stmt->setFetchMode(FetchMode::ASSOCIATIVE); foreach ($stmt as $row) { - $rows[] = array_change_key_case($row, \CASE_LOWER); + $rows[] = array_change_key_case($row, CASE_LOWER); } - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $rows[0]); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $rows[0]); } public function testPrepareWithQuoted() { - $table = 'fetch_table'; + $table = 'fetch_table'; $paramInt = 1; $paramStr = 'foo'; @@ -177,20 +180,20 @@ public function testPrepareWithExecuteParams() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); - $stmt->execute(array($paramInt, $paramStr)); + $stmt->execute([$paramInt, $paramStr]); $row = $stmt->fetch(FetchMode::ASSOCIATIVE); self::assertNotFalse($row); - $row = array_change_key_case($row, \CASE_LOWER); - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); + $row = array_change_key_case($row, CASE_LOWER); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $row); } public function testFetchAll() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $data = $this->_conn->fetchAll($sql, array(1, 'foo')); self::assertCount(1, $data); @@ -198,7 +201,7 @@ public function testFetchAll() $row = $data[0]; self::assertCount(2, $row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row['test_int']); self::assertEquals('foo', $row['test_string']); } @@ -209,7 +212,7 @@ public function testFetchAll() public function testFetchAllWithTypes() { $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); + $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; $data = $this->_conn->fetchAll($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); @@ -219,7 +222,7 @@ public function testFetchAllWithTypes() $row = $data[0]; self::assertCount(2, $row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row['test_int']); self::assertStringStartsWith($datetimeString, $row['test_datetime']); } @@ -236,9 +239,9 @@ public function testFetchAllWithMissingTypes() } $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); - $sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?"; - $data = $this->_conn->fetchAll($sql, array(1, $datetime)); + $datetime = new DateTime($datetimeString); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + $data = $this->_conn->fetchAll($sql, [1, $datetime]); } public function testFetchBoth() @@ -248,7 +251,7 @@ public function testFetchBoth() self::assertNotFalse($row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row['test_int']); self::assertEquals('foo', $row['test_string']); @@ -265,12 +268,12 @@ public function testFetchNoResult() public function testFetchAssoc() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $row = $this->_conn->fetchAssoc($sql, array(1, 'foo')); self::assertNotFalse($row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row['test_int']); self::assertEquals('foo', $row['test_string']); @@ -279,14 +282,14 @@ public function testFetchAssoc() public function testFetchAssocWithTypes() { $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); + $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; $row = $this->_conn->fetchAssoc($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); self::assertNotFalse($row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row['test_int']); self::assertStringStartsWith($datetimeString, $row['test_datetime']); @@ -303,14 +306,14 @@ public function testFetchAssocWithMissingTypes() } $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); - $sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?"; + $datetime = new DateTime($datetimeString); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; $row = $this->_conn->fetchAssoc($sql, array(1, $datetime)); } public function testFetchArray() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $row = $this->_conn->fetchArray($sql, array(1, 'foo')); self::assertEquals(1, $row[0]); @@ -320,14 +323,14 @@ public function testFetchArray() public function testFetchArrayWithTypes() { $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); + $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; $row = $this->_conn->fetchArray($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); self::assertNotFalse($row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row[0]); self::assertStringStartsWith($datetimeString, $row[1]); @@ -344,20 +347,20 @@ public function testFetchArrayWithMissingTypes() } $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); - $sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?"; - $row = $this->_conn->fetchArray($sql, array(1, $datetime)); + $datetime = new DateTime($datetimeString); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + $row = $this->_conn->fetchArray($sql, [1, $datetime]); } public function testFetchColumn() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; - $testInt = $this->_conn->fetchColumn($sql, array(1, 'foo'), 0); + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; + $testInt = $this->_conn->fetchColumn($sql, [1, 'foo'], 0); self::assertEquals(1, $testInt); - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; - $testString = $this->_conn->fetchColumn($sql, array(1, 'foo'), 1); + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; + $testString = $this->_conn->fetchColumn($sql, [1, 'foo'], 1); self::assertEquals('foo', $testString); } @@ -365,7 +368,7 @@ public function testFetchColumn() public function testFetchColumnWithTypes() { $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); + $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; $column = $this->_conn->fetchColumn($sql, [1, $datetime], 1, [ParameterType::STRING, Type::DATETIME]); @@ -386,9 +389,9 @@ public function testFetchColumnWithMissingTypes() } $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); - $sql = "SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?"; - $column = $this->_conn->fetchColumn($sql, array(1, $datetime), 1); + $datetime = new DateTime($datetimeString); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + $column = $this->_conn->fetchColumn($sql, [1, $datetime], 1); } /** @@ -396,10 +399,11 @@ public function testFetchColumnWithMissingTypes() */ public function testExecuteQueryBindDateTimeType() { - $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; - $stmt = $this->_conn->executeQuery($sql, - array(1 => new \DateTime('2010-01-01 10:10:10')), - array(1 => Type::DATETIME) + $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; + $stmt = $this->_conn->executeQuery( + $sql, + [1 => new DateTime('2010-01-01 10:10:10')], + [1 => Type::DATETIME] ); self::assertEquals(1, $stmt->fetchColumn()); @@ -410,9 +414,9 @@ public function testExecuteQueryBindDateTimeType() */ public function testExecuteUpdateBindDateTimeType() { - $datetime = new \DateTime('2010-02-02 20:20:20'); + $datetime = new DateTime('2010-02-02 20:20:20'); - $sql = 'INSERT INTO fetch_table (test_int, test_string, test_datetime) VALUES (?, ?, ?)'; + $sql = 'INSERT INTO fetch_table (test_int, test_string, test_datetime) VALUES (?, ?, ?)'; $affectedRows = $this->_conn->executeUpdate($sql, [ 1 => 50, 2 => 'foo', @@ -426,8 +430,8 @@ public function testExecuteUpdateBindDateTimeType() self::assertEquals(1, $affectedRows); self::assertEquals(1, $this->_conn->executeQuery( 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?', - array(1 => $datetime), - array(1 => Type::DATETIME) + [1 => $datetime], + [1 => Type::DATETIME] )->fetchColumn()); } @@ -436,9 +440,9 @@ public function testExecuteUpdateBindDateTimeType() */ public function testPrepareQueryBindValueDateTimeType() { - $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; + $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; $stmt = $this->_conn->prepare($sql); - $stmt->bindValue(1, new \DateTime('2010-01-01 10:10:10'), Type::DATETIME); + $stmt->bindValue(1, new DateTime('2010-01-01 10:10:10'), Type::DATETIME); $stmt->execute(); self::assertEquals(1, $stmt->fetchColumn()); @@ -450,22 +454,28 @@ public function testPrepareQueryBindValueDateTimeType() public function testNativeArrayListSupport() { for ($i = 100; $i < 110; $i++) { - $this->_conn->insert('fetch_table', array('test_int' => $i, 'test_string' => 'foo' . $i, 'test_datetime' => '2010-01-01 10:10:10')); + $this->_conn->insert('fetch_table', ['test_int' => $i, 'test_string' => 'foo' . $i, 'test_datetime' => '2010-01-01 10:10:10']); } - $stmt = $this->_conn->executeQuery('SELECT test_int FROM fetch_table WHERE test_int IN (?)', - array(array(100, 101, 102, 103, 104)), array(Connection::PARAM_INT_ARRAY)); + $stmt = $this->_conn->executeQuery( + 'SELECT test_int FROM fetch_table WHERE test_int IN (?)', + [[100, 101, 102, 103, 104]], + [Connection::PARAM_INT_ARRAY] + ); $data = $stmt->fetchAll(FetchMode::NUMERIC); self::assertCount(5, $data); - self::assertEquals(array(array(100), array(101), array(102), array(103), array(104)), $data); + self::assertEquals([[100], [101], [102], [103], [104]], $data); - $stmt = $this->_conn->executeQuery('SELECT test_int FROM fetch_table WHERE test_string IN (?)', - array(array('foo100', 'foo101', 'foo102', 'foo103', 'foo104')), array(Connection::PARAM_STR_ARRAY)); + $stmt = $this->_conn->executeQuery( + 'SELECT test_int FROM fetch_table WHERE test_string IN (?)', + [['foo100', 'foo101', 'foo102', 'foo103', 'foo104']], + [Connection::PARAM_STR_ARRAY] + ); $data = $stmt->fetchAll(FetchMode::NUMERIC); self::assertCount(5, $data); - self::assertEquals(array(array(100), array(101), array(102), array(103), array(104)), $data); + self::assertEquals([[100], [101], [102], [103], [104]], $data); } /** @@ -485,7 +495,7 @@ public function testTrimExpression($value, $position, $char, $expectedResult) public function getTrimExpressionData() { - return array( + return [ ['test_string', TrimMode::UNSPECIFIED, false, 'foo'], ['test_string', TrimMode::LEADING, false, 'foo'], ['test_string', TrimMode::TRAILING, false, 'foo'], @@ -522,7 +532,7 @@ public function getTrimExpressionData() ["' foo '", TrimMode::BOTH, "'o'", ' foo '], ["' foo '", TrimMode::BOTH, "'.'", ' foo '], ["' foo '", TrimMode::BOTH, "' '", 'foo'], - ); + ]; } /** @@ -530,45 +540,45 @@ public function getTrimExpressionData() */ public function testDateArithmetics() { - $p = $this->_conn->getDatabasePlatform(); - $sql = 'SELECT '; - $sql .= $p->getDateAddSecondsExpression('test_datetime', 1) .' AS add_seconds, '; - $sql .= $p->getDateSubSecondsExpression('test_datetime', 1) .' AS sub_seconds, '; - $sql .= $p->getDateAddMinutesExpression('test_datetime', 5) .' AS add_minutes, '; - $sql .= $p->getDateSubMinutesExpression('test_datetime', 5) .' AS sub_minutes, '; - $sql .= $p->getDateAddHourExpression('test_datetime', 3) .' AS add_hour, '; - $sql .= $p->getDateSubHourExpression('test_datetime', 3) .' AS sub_hour, '; - $sql .= $p->getDateAddDaysExpression('test_datetime', 10) .' AS add_days, '; - $sql .= $p->getDateSubDaysExpression('test_datetime', 10) .' AS sub_days, '; - $sql .= $p->getDateAddWeeksExpression('test_datetime', 1) .' AS add_weeks, '; - $sql .= $p->getDateSubWeeksExpression('test_datetime', 1) .' AS sub_weeks, '; - $sql .= $p->getDateAddMonthExpression('test_datetime', 2) .' AS add_month, '; - $sql .= $p->getDateSubMonthExpression('test_datetime', 2) .' AS sub_month, '; - $sql .= $p->getDateAddQuartersExpression('test_datetime', 3) .' AS add_quarters, '; - $sql .= $p->getDateSubQuartersExpression('test_datetime', 3) .' AS sub_quarters, '; - $sql .= $p->getDateAddYearsExpression('test_datetime', 6) .' AS add_years, '; - $sql .= $p->getDateSubYearsExpression('test_datetime', 6) .' AS sub_years '; + $p = $this->_conn->getDatabasePlatform(); + $sql = 'SELECT '; + $sql .= $p->getDateAddSecondsExpression('test_datetime', 1) . ' AS add_seconds, '; + $sql .= $p->getDateSubSecondsExpression('test_datetime', 1) . ' AS sub_seconds, '; + $sql .= $p->getDateAddMinutesExpression('test_datetime', 5) . ' AS add_minutes, '; + $sql .= $p->getDateSubMinutesExpression('test_datetime', 5) . ' AS sub_minutes, '; + $sql .= $p->getDateAddHourExpression('test_datetime', 3) . ' AS add_hour, '; + $sql .= $p->getDateSubHourExpression('test_datetime', 3) . ' AS sub_hour, '; + $sql .= $p->getDateAddDaysExpression('test_datetime', 10) . ' AS add_days, '; + $sql .= $p->getDateSubDaysExpression('test_datetime', 10) . ' AS sub_days, '; + $sql .= $p->getDateAddWeeksExpression('test_datetime', 1) . ' AS add_weeks, '; + $sql .= $p->getDateSubWeeksExpression('test_datetime', 1) . ' AS sub_weeks, '; + $sql .= $p->getDateAddMonthExpression('test_datetime', 2) . ' AS add_month, '; + $sql .= $p->getDateSubMonthExpression('test_datetime', 2) . ' AS sub_month, '; + $sql .= $p->getDateAddQuartersExpression('test_datetime', 3) . ' AS add_quarters, '; + $sql .= $p->getDateSubQuartersExpression('test_datetime', 3) . ' AS sub_quarters, '; + $sql .= $p->getDateAddYearsExpression('test_datetime', 6) . ' AS add_years, '; + $sql .= $p->getDateSubYearsExpression('test_datetime', 6) . ' AS sub_years '; $sql .= 'FROM fetch_table'; $row = $this->_conn->fetchAssoc($sql); $row = array_change_key_case($row, CASE_LOWER); - self::assertEquals('2010-01-01 10:10:11', date('Y-m-d H:i:s', strtotime($row['add_seconds'])), "Adding second should end up on 2010-01-01 10:10:11"); - self::assertEquals('2010-01-01 10:10:09', date('Y-m-d H:i:s', strtotime($row['sub_seconds'])), "Subtracting second should end up on 2010-01-01 10:10:09"); - self::assertEquals('2010-01-01 10:15:10', date('Y-m-d H:i:s', strtotime($row['add_minutes'])), "Adding minutes should end up on 2010-01-01 10:15:10"); - self::assertEquals('2010-01-01 10:05:10', date('Y-m-d H:i:s', strtotime($row['sub_minutes'])), "Subtracting minutes should end up on 2010-01-01 10:05:10"); - self::assertEquals('2010-01-01 13:10', date('Y-m-d H:i', strtotime($row['add_hour'])), "Adding date should end up on 2010-01-01 13:10"); - self::assertEquals('2010-01-01 07:10', date('Y-m-d H:i', strtotime($row['sub_hour'])), "Subtracting date should end up on 2010-01-01 07:10"); - self::assertEquals('2010-01-11', date('Y-m-d', strtotime($row['add_days'])), "Adding date should end up on 2010-01-11"); - self::assertEquals('2009-12-22', date('Y-m-d', strtotime($row['sub_days'])), "Subtracting date should end up on 2009-12-22"); - self::assertEquals('2010-01-08', date('Y-m-d', strtotime($row['add_weeks'])), "Adding week should end up on 2010-01-08"); - self::assertEquals('2009-12-25', date('Y-m-d', strtotime($row['sub_weeks'])), "Subtracting week should end up on 2009-12-25"); - self::assertEquals('2010-03-01', date('Y-m-d', strtotime($row['add_month'])), "Adding month should end up on 2010-03-01"); - self::assertEquals('2009-11-01', date('Y-m-d', strtotime($row['sub_month'])), "Subtracting month should end up on 2009-11-01"); - self::assertEquals('2010-10-01', date('Y-m-d', strtotime($row['add_quarters'])), "Adding quarters should end up on 2010-04-01"); - self::assertEquals('2009-04-01', date('Y-m-d', strtotime($row['sub_quarters'])), "Subtracting quarters should end up on 2009-10-01"); - self::assertEquals('2016-01-01', date('Y-m-d', strtotime($row['add_years'])), "Adding years should end up on 2016-01-01"); - self::assertEquals('2004-01-01', date('Y-m-d', strtotime($row['sub_years'])), "Subtracting years should end up on 2004-01-01"); + self::assertEquals('2010-01-01 10:10:11', date('Y-m-d H:i:s', strtotime($row['add_seconds'])), 'Adding second should end up on 2010-01-01 10:10:11'); + self::assertEquals('2010-01-01 10:10:09', date('Y-m-d H:i:s', strtotime($row['sub_seconds'])), 'Subtracting second should end up on 2010-01-01 10:10:09'); + self::assertEquals('2010-01-01 10:15:10', date('Y-m-d H:i:s', strtotime($row['add_minutes'])), 'Adding minutes should end up on 2010-01-01 10:15:10'); + self::assertEquals('2010-01-01 10:05:10', date('Y-m-d H:i:s', strtotime($row['sub_minutes'])), 'Subtracting minutes should end up on 2010-01-01 10:05:10'); + self::assertEquals('2010-01-01 13:10', date('Y-m-d H:i', strtotime($row['add_hour'])), 'Adding date should end up on 2010-01-01 13:10'); + self::assertEquals('2010-01-01 07:10', date('Y-m-d H:i', strtotime($row['sub_hour'])), 'Subtracting date should end up on 2010-01-01 07:10'); + self::assertEquals('2010-01-11', date('Y-m-d', strtotime($row['add_days'])), 'Adding date should end up on 2010-01-11'); + self::assertEquals('2009-12-22', date('Y-m-d', strtotime($row['sub_days'])), 'Subtracting date should end up on 2009-12-22'); + self::assertEquals('2010-01-08', date('Y-m-d', strtotime($row['add_weeks'])), 'Adding week should end up on 2010-01-08'); + self::assertEquals('2009-12-25', date('Y-m-d', strtotime($row['sub_weeks'])), 'Subtracting week should end up on 2009-12-25'); + self::assertEquals('2010-03-01', date('Y-m-d', strtotime($row['add_month'])), 'Adding month should end up on 2010-03-01'); + self::assertEquals('2009-11-01', date('Y-m-d', strtotime($row['sub_month'])), 'Subtracting month should end up on 2009-11-01'); + self::assertEquals('2010-10-01', date('Y-m-d', strtotime($row['add_quarters'])), 'Adding quarters should end up on 2010-04-01'); + self::assertEquals('2009-04-01', date('Y-m-d', strtotime($row['sub_quarters'])), 'Subtracting quarters should end up on 2009-10-01'); + self::assertEquals('2016-01-01', date('Y-m-d', strtotime($row['add_years'])), 'Adding years should end up on 2016-01-01'); + self::assertEquals('2004-01-01', date('Y-m-d', strtotime($row['sub_years'])), 'Subtracting years should end up on 2004-01-01'); } public function testSqliteDateArithmeticWithDynamicInterval() @@ -584,7 +594,7 @@ public function testSqliteDateArithmeticWithDynamicInterval() $table->addColumn('test_days', 'integer'); $table->setPrimaryKey(['test_date']); - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ + /** @var AbstractSchemaManager $sm */ $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); @@ -603,16 +613,16 @@ public function testLocateExpression() { $platform = $this->_conn->getDatabasePlatform(); - $sql = 'SELECT '; - $sql .= $platform->getLocateExpression('test_string', "'oo'") .' AS locate1, '; - $sql .= $platform->getLocateExpression('test_string', "'foo'") .' AS locate2, '; - $sql .= $platform->getLocateExpression('test_string', "'bar'") .' AS locate3, '; - $sql .= $platform->getLocateExpression('test_string', 'test_string') .' AS locate4, '; - $sql .= $platform->getLocateExpression("'foo'", 'test_string') .' AS locate5, '; - $sql .= $platform->getLocateExpression("'barfoobaz'", 'test_string') .' AS locate6, '; - $sql .= $platform->getLocateExpression("'bar'", 'test_string') .' AS locate7, '; - $sql .= $platform->getLocateExpression('test_string', "'oo'", 2) .' AS locate8, '; - $sql .= $platform->getLocateExpression('test_string', "'oo'", 3) .' AS locate9 '; + $sql = 'SELECT '; + $sql .= $platform->getLocateExpression('test_string', "'oo'") . ' AS locate1, '; + $sql .= $platform->getLocateExpression('test_string', "'foo'") . ' AS locate2, '; + $sql .= $platform->getLocateExpression('test_string', "'bar'") . ' AS locate3, '; + $sql .= $platform->getLocateExpression('test_string', 'test_string') . ' AS locate4, '; + $sql .= $platform->getLocateExpression("'foo'", 'test_string') . ' AS locate5, '; + $sql .= $platform->getLocateExpression("'barfoobaz'", 'test_string') . ' AS locate6, '; + $sql .= $platform->getLocateExpression("'bar'", 'test_string') . ' AS locate7, '; + $sql .= $platform->getLocateExpression('test_string', "'oo'", 2) . ' AS locate8, '; + $sql .= $platform->getLocateExpression('test_string', "'oo'", 3) . ' AS locate9 '; $sql .= 'FROM fetch_table'; $row = $this->_conn->fetchAssoc($sql); @@ -631,10 +641,10 @@ public function testLocateExpression() public function testQuoteSQLInjection() { - $sql = "SELECT * FROM fetch_table WHERE test_string = " . $this->_conn->quote("bar' OR '1'='1"); + $sql = 'SELECT * FROM fetch_table WHERE test_string = ' . $this->_conn->quote("bar' OR '1'='1"); $rows = $this->_conn->fetchAll($sql); - self::assertCount(0, $rows, "no result should be returned, otherwise SQL injection is possible"); + self::assertCount(0, $rows, 'no result should be returned, otherwise SQL injection is possible'); } /** @@ -644,31 +654,30 @@ public function testBitComparisonExpressionSupport() { $this->_conn->exec('DELETE FROM fetch_table'); $platform = $this->_conn->getDatabasePlatform(); - $bitmap = array(); + $bitmap = []; - for ($i = 2; $i < 9; $i = $i + 2) { - $bitmap[$i] = array( + for ($i = 2; $i < 9; $i += 2) { + $bitmap[$i] = [ 'bit_or' => ($i | 2), - 'bit_and' => ($i & 2) - ); - $this->_conn->insert('fetch_table', array( + 'bit_and' => ($i & 2), + ]; + $this->_conn->insert('fetch_table', [ 'test_int' => $i, 'test_string' => json_encode($bitmap[$i]), - 'test_datetime' => '2010-01-01 10:10:10' - )); + 'test_datetime' => '2010-01-01 10:10:10', + ]); } - $sql[] = 'SELECT '; - $sql[] = 'test_int, '; - $sql[] = 'test_string, '; - $sql[] = $platform->getBitOrComparisonExpression('test_int', 2) . ' AS bit_or, '; - $sql[] = $platform->getBitAndComparisonExpression('test_int', 2) . ' AS bit_and '; - $sql[] = 'FROM fetch_table'; + $sql[] = 'SELECT '; + $sql[] = 'test_int, '; + $sql[] = 'test_string, '; + $sql[] = $platform->getBitOrComparisonExpression('test_int', 2) . ' AS bit_or, '; + $sql[] = $platform->getBitAndComparisonExpression('test_int', 2) . ' AS bit_and '; + $sql[] = 'FROM fetch_table'; $stmt = $this->_conn->executeQuery(implode(PHP_EOL, $sql)); $data = $stmt->fetchAll(FetchMode::ASSOCIATIVE); - self::assertCount(4, $data); self::assertEquals(count($bitmap), count($data)); foreach ($data as $row) { @@ -691,11 +700,13 @@ public function testBitComparisonExpressionSupport() public function testSetDefaultFetchMode() { - $stmt = $this->_conn->query("SELECT * FROM fetch_table"); + $stmt = $this->_conn->query('SELECT * FROM fetch_table'); $stmt->setFetchMode(FetchMode::NUMERIC); $row = array_keys($stmt->fetch()); - self::assertCount(0, array_filter($row, function($v) { return ! is_numeric($v); }), "should be no non-numerical elements in the result."); + self::assertCount(0, array_filter($row, static function ($v) { + return ! is_numeric($v); + }), 'should be no non-numerical elements in the result.'); } /** @@ -705,7 +716,7 @@ public function testFetchAllStyleObject() { $this->setupFixture(); - $sql = 'SELECT test_int, test_string, test_datetime FROM fetch_table'; + $sql = 'SELECT test_int, test_string, test_datetime FROM fetch_table'; $stmt = $this->_conn->prepare($sql); $stmt->execute(); @@ -737,17 +748,17 @@ public function testFetchAllSupportFetchClass() $this->skipOci8AndMysqli(); $this->setupFixture(); - $sql = "SELECT test_int, test_string, test_datetime FROM fetch_table"; - $stmt = $this->_conn->prepare($sql); + $sql = 'SELECT test_int, test_string, test_datetime FROM fetch_table'; + $stmt = $this->_conn->prepare($sql); $stmt->execute(); $results = $stmt->fetchAll( FetchMode::CUSTOM_OBJECT, - __NAMESPACE__.'\\MyFetchClass' + __NAMESPACE__ . '\\MyFetchClass' ); self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); + self::assertInstanceOf(__NAMESPACE__ . '\\MyFetchClass', $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); @@ -759,16 +770,16 @@ public function testFetchAllSupportFetchClass() */ public function testFetchAllStyleColumn() { - $sql = "DELETE FROM fetch_table"; + $sql = 'DELETE FROM fetch_table'; $this->_conn->executeUpdate($sql); - $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo')); - $this->_conn->insert('fetch_table', array('test_int' => 10, 'test_string' => 'foo')); + $this->_conn->insert('fetch_table', ['test_int' => 1, 'test_string' => 'foo']); + $this->_conn->insert('fetch_table', ['test_int' => 10, 'test_string' => 'foo']); - $sql = "SELECT test_int FROM fetch_table"; + $sql = 'SELECT test_int FROM fetch_table'; $rows = $this->_conn->query($sql)->fetchAll(FetchMode::COLUMN); - self::assertEquals(array(1, 10), $rows); + self::assertEquals([1, 10], $rows); } /** @@ -779,14 +790,14 @@ public function testSetFetchModeClassFetchAll() $this->skipOci8AndMysqli(); $this->setupFixture(); - $sql = "SELECT * FROM fetch_table"; + $sql = 'SELECT * FROM fetch_table'; $stmt = $this->_conn->query($sql); $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass'); $results = $stmt->fetchAll(); self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); + self::assertInstanceOf(__NAMESPACE__ . '\\MyFetchClass', $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); @@ -801,17 +812,17 @@ public function testSetFetchModeClassFetch() $this->skipOci8AndMysqli(); $this->setupFixture(); - $sql = "SELECT * FROM fetch_table"; + $sql = 'SELECT * FROM fetch_table'; $stmt = $this->_conn->query($sql); $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass'); - $results = array(); + $results = []; while ($row = $stmt->fetch()) { $results[] = $row; } self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); + self::assertInstanceOf(__NAMESPACE__ . '\\MyFetchClass', $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); @@ -835,8 +846,8 @@ public function testEmptyFetchColumnReturnsFalse() */ public function testSetFetchModeOnDbalStatement() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; - $stmt = $this->_conn->executeQuery($sql, array(1, "foo")); + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; + $stmt = $this->_conn->executeQuery($sql, [1, 'foo']); $stmt->setFetchMode(FetchMode::NUMERIC); $row = $stmt->fetch(); @@ -851,11 +862,11 @@ public function testSetFetchModeOnDbalStatement() */ public function testEmptyParameters() { - $sql = "SELECT * FROM fetch_table WHERE test_int IN (?)"; - $stmt = $this->_conn->executeQuery($sql, array(array()), array(\Doctrine\DBAL\Connection::PARAM_INT_ARRAY)); + $sql = 'SELECT * FROM fetch_table WHERE test_int IN (?)'; + $stmt = $this->_conn->executeQuery($sql, [[]], [Connection::PARAM_INT_ARRAY]); $rows = $stmt->fetchAll(); - self::assertEquals(array(), $rows); + self::assertEquals([], $rows); } /** @@ -865,11 +876,11 @@ public function testFetchColumnNullValue() { $this->_conn->executeUpdate( 'INSERT INTO fetch_table (test_int, test_string) VALUES (?, ?)', - array(2, 'foo') + [2, 'foo'] ); self::assertNull( - $this->_conn->fetchColumn('SELECT test_datetime FROM fetch_table WHERE test_int = ?', array(2)) + $this->_conn->fetchColumn('SELECT test_datetime FROM fetch_table WHERE test_int = ?', [2]) ); } @@ -885,7 +896,7 @@ public function testFetchColumnNonExistingIndex() } self::assertNull( - $this->_conn->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', array(1), 1) + $this->_conn->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', [1], 1) ); } @@ -895,28 +906,30 @@ public function testFetchColumnNonExistingIndex() public function testFetchColumnNoResult() { self::assertFalse( - $this->_conn->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', array(-1)) + $this->_conn->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', [-1]) ); } private function setupFixture() { $this->_conn->exec('DELETE FROM fetch_table'); - $this->_conn->insert('fetch_table', array( + $this->_conn->insert('fetch_table', [ 'test_int' => 1, 'test_string' => 'foo', - 'test_datetime' => '2010-01-01 10:10:10' - )); + 'test_datetime' => '2010-01-01 10:10:10', + ]); } private function skipOci8AndMysqli() { - if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] == "oci8") { - $this->markTestSkipped("Not supported by OCI8"); + if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'oci8') { + $this->markTestSkipped('Not supported by OCI8'); } - if ('mysqli' == $this->_conn->getDriver()->getName()) { - $this->markTestSkipped('Mysqli driver dont support this feature.'); + if ($this->_conn->getDriver()->getName() !== 'mysqli') { + return; } + + $this->markTestSkipped('Mysqli driver dont support this feature.'); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php index 4857e81a5e1..a013a7706a8 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\Tests\DbalFunctionalTestCase; abstract class AbstractDriverTest extends DbalFunctionalTestCase @@ -10,7 +11,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase /** * The driver instance under test. * - * @var \Doctrine\DBAL\Driver + * @var Driver */ protected $driver; @@ -29,7 +30,7 @@ public function testConnectsWithoutDatabaseNameParameter() $params = $this->_conn->getParams(); unset($params['dbname']); - $user = $params['user'] ?? null; + $user = $params['user'] ?? null; $password = $params['password'] ?? null; $connection = $this->driver->connect($params, $user, $password); @@ -59,7 +60,7 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() } /** - * @return \Doctrine\DBAL\Driver + * @return Driver */ abstract protected function createDriver(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php index 4bcc5b6cf76..cb39d81135c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof DB2Driver) { - $this->markTestSkipped('ibm_db2 only test.'); + if ($this->_conn->getDriver() instanceof DB2Driver) { + return; } + + $this->markTestSkipped('ibm_db2 only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php index 59b42a75635..13226c32613 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php @@ -13,15 +13,17 @@ class DB2StatementTest extends DbalFunctionalTestCase { protected function setUp() { - if ( ! extension_loaded('ibm_db2')) { + if (! extension_loaded('ibm_db2')) { $this->markTestSkipped('ibm_db2 is not installed.'); } parent::setUp(); - if ( ! $this->_conn->getDriver() instanceof DB2Driver) { - $this->markTestSkipped('ibm_db2 only test.'); + if ($this->_conn->getDriver() instanceof DB2Driver) { + return; } + + $this->markTestSkipped('ibm_db2 only test.'); } public function testExecutionErrorsAreNotSuppressed() diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php index c20533a4700..591fff5a13e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php @@ -1,20 +1,28 @@ markTestSkipped('mysqli is not installed.'); } parent::setUp(); - if ( !($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\Mysqli\Driver)) { - $this->markTestSkipped('MySQLi only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('MySQLi only test.'); } protected function tearDown() @@ -24,12 +32,10 @@ protected function tearDown() public function testDriverOptions() { - $driverOptions = array( - \MYSQLI_OPT_CONNECT_TIMEOUT => 1, - ); + $driverOptions = [MYSQLI_OPT_CONNECT_TIMEOUT => 1]; $connection = $this->getConnection($driverOptions); - self::assertInstanceOf("\Doctrine\DBAL\Driver\Mysqli\MysqliConnection", $connection); + self::assertInstanceOf('\Doctrine\DBAL\Driver\Mysqli\MysqliConnection', $connection); } /** @@ -37,22 +43,22 @@ public function testDriverOptions() */ public function testUnsupportedDriverOption() { - $this->getConnection(array('hello' => 'world')); // use local infile + $this->getConnection(['hello' => 'world']); // use local infile } public function testPing() { - $conn = $this->getConnection(array()); + $conn = $this->getConnection([]); self::assertTrue($conn->ping()); } private function getConnection(array $driverOptions) { - return new \Doctrine\DBAL\Driver\Mysqli\MysqliConnection( - array( - 'host' => $GLOBALS['db_host'], - 'dbname' => $GLOBALS['db_name'], - ), + return new MysqliConnection( + [ + 'host' => $GLOBALS['db_host'], + 'dbname' => $GLOBALS['db_name'], + ], $GLOBALS['db_username'], $GLOBALS['db_password'], $driverOptions diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php index d88265d4aa3..da9ee0b5e5b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('MySQLi only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('MySQLi only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php index 8a08d24f051..a5776b75c68 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('oci8 only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('oci8 only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php index 90430e92a02..cba1041129e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php @@ -3,15 +3,14 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\OCI8; use Doctrine\DBAL\Driver\OCI8\Driver; +use Doctrine\DBAL\Driver\OCI8\OCI8Connection; use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalFunctionalTestCase; use function extension_loaded; class OCI8ConnectionTest extends DbalFunctionalTestCase { - /** - * @var \Doctrine\DBAL\Driver\OCI8\OCI8Connection - */ + /** @var OCI8Connection */ protected $driverConnection; protected function setUp() @@ -34,18 +33,18 @@ protected function setUp() */ public function testLastInsertIdAcceptsFqn() { - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->_conn->getDatabasePlatform(); $schemaManager = $this->_conn->getSchemaManager(); $table = new Table('DBAL2595'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $schemaManager->dropAndCreateTable($table); $this->_conn->executeUpdate('INSERT INTO DBAL2595 (foo) VALUES (1)'); - $schema = $this->_conn->getDatabase(); + $schema = $this->_conn->getDatabase(); $sequence = $platform->getIdentitySequenceName($schema . '.DBAL2595', 'id'); self::assertSame(1, $this->driverConnection->lastInsertId($sequence)); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php index 5cbaa9c137c..f9ddce6f11c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('oci8 only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('oci8 only test.'); } /** @@ -34,53 +36,47 @@ public function testQueryConversion($query, array $params, array $expected) public static function queryConversionProvider() { - return array( - 'simple' => array( + return [ + 'simple' => [ 'SELECT ? COL1 FROM DUAL', - array(1), - array( - 'COL1' => 1, - ), - ), - 'literal-with-placeholder' => array( + [1], + ['COL1' => 1], + ], + 'literal-with-placeholder' => [ "SELECT '?' COL1, ? COL2 FROM DUAL", - array(2), - array( + [2], + [ 'COL1' => '?', 'COL2' => 2, - ), - ), - 'literal-with-quotes' => array( + ], + ], + 'literal-with-quotes' => [ "SELECT ? COL1, '?\"?''?' \"COL?\" FROM DUAL", - array(3), - array( + [3], + [ 'COL1' => 3, 'COL?' => '?"?\'?', - ), - ), - 'placeholder-at-the-end' => array( + ], + ], + 'placeholder-at-the-end' => [ 'SELECT ? COL1 FROM DUAL WHERE 1 = ?', - array(4, 1), - array( - 'COL1' => 4, - ), - ), - 'multi-line-literal' => array( + [4, 1], + ['COL1' => 4], + ], + 'multi-line-literal' => [ "SELECT 'Hello, World?!' COL1 FROM DUAL WHERE 1 = ?", - array(1), - array( + [1], + [ 'COL1' => 'Hello, World?!', - ), - ), - 'empty-literal' => array( + ], + ], + 'empty-literal' => [ "SELECT '' COL1 FROM DUAL", - array(), - array( - 'COL1' => '', - ), - ), - ); + [], + ['COL1' => ''], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php index 29f18f8c78f..b5eebb92da3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\Tests\DbalFunctionalTestCase; +use PDO; use function extension_loaded; use function sprintf; @@ -12,13 +13,13 @@ class PDOConnectionTest extends DbalFunctionalTestCase /** * The PDO driver connection under test. * - * @var \Doctrine\DBAL\Driver\PDOConnection + * @var PDOConnection */ protected $driverConnection; protected function setUp() { - if ( ! extension_loaded('PDO')) { + if (! extension_loaded('PDO')) { $this->markTestSkipped('PDO is not installed.'); } @@ -26,9 +27,11 @@ protected function setUp() $this->driverConnection = $this->_conn->getWrappedConnection(); - if ( ! $this->driverConnection instanceof PDOConnection) { - $this->markTestSkipped('PDO connection only test.'); + if ($this->driverConnection instanceof PDOConnection) { + return; } + + $this->markTestSkipped('PDO connection only test.'); } protected function tearDown() @@ -53,7 +56,6 @@ public function testThrowsWrappedExceptionOnConstruct() /** * @group DBAL-1022 - * * @expectedException \Doctrine\DBAL\Driver\PDOException */ public function testThrowsWrappedExceptionOnExec() @@ -72,7 +74,7 @@ public function testThrowsWrappedExceptionOnPrepare() // Emulated prepared statements have to be disabled for this test // so that PDO actually communicates with the database server to check the query. - $this->driverConnection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); + $this->driverConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $this->driverConnection->prepare('foo'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php index 299fd4798e4..462f5941fa2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('pdo_mysql only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('pdo_mysql only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php index afbdc08c7e8..0fcba6d6431 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('PDO_OCI only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('PDO_OCI only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php index 04be88079ec..7c595c9c7df 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php @@ -21,9 +21,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('pdo_pgsql only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('pdo_pgsql only test.'); } /** @@ -31,8 +33,8 @@ protected function setUp() */ public function testDatabaseParameters($databaseName, $defaultDatabaseName, $expectedDatabaseName) { - $params = $this->_conn->getParams(); - $params['dbname'] = $databaseName; + $params = $this->_conn->getParams(); + $params['dbname'] = $databaseName; $params['default_dbname'] = $defaultDatabaseName; $connection = new Connection( @@ -50,17 +52,17 @@ public function testDatabaseParameters($databaseName, $defaultDatabaseName, $exp public function getDatabaseParameter() { - $params = TestUtil::getConnection()->getParams(); - $realDatabaseName = $params['dbname'] ?? ''; + $params = TestUtil::getConnection()->getParams(); + $realDatabaseName = $params['dbname'] ?? ''; $dummyDatabaseName = $realDatabaseName . 'a'; - return array( + return [ // dbname, default_dbname, expected - array($realDatabaseName, null, $realDatabaseName), - array($realDatabaseName, $dummyDatabaseName, $realDatabaseName), - array(null, $realDatabaseName, $realDatabaseName), - array(null, null, $this->getDatabaseNameForConnectionWithoutDatabaseNameParameter()), - ); + [$realDatabaseName, null, $realDatabaseName], + [$realDatabaseName, $dummyDatabaseName, $realDatabaseName], + [null, $realDatabaseName, $realDatabaseName], + [null, null, $this->getDatabaseNameForConnectionWithoutDatabaseNameParameter()], + ]; } /** @@ -68,18 +70,18 @@ public function getDatabaseParameter() */ public function testConnectsWithApplicationNameParameter() { - $parameters = $this->_conn->getParams(); + $parameters = $this->_conn->getParams(); $parameters['application_name'] = 'doctrine'; - $user = $parameters['user'] ?? null; + $user = $parameters['user'] ?? null; $password = $parameters['password'] ?? null; $connection = $this->driver->connect($parameters, $user, $password); - $hash = microtime(true); // required to identify the record in the results uniquely - $sql = sprintf('SELECT * FROM pg_stat_activity WHERE %d = %d', $hash, $hash); + $hash = microtime(true); // required to identify the record in the results uniquely + $sql = sprintf('SELECT * FROM pg_stat_activity WHERE %d = %d', $hash, $hash); $statement = $connection->query($sql); - $records = $statement->fetchAll(); + $records = $statement->fetchAll(); foreach ($records as $record) { // The query column is named "current_query" on PostgreSQL < 9.2 diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php index 52c7cda4efa..16021c3ea24 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php @@ -12,28 +12,29 @@ class PDOPgsqlConnectionTest extends DbalFunctionalTestCase { protected function setUp() { - if ( ! extension_loaded('pdo_pgsql')) { + if (! extension_loaded('pdo_pgsql')) { $this->markTestSkipped('pdo_pgsql is not loaded.'); } parent::setUp(); - if ( ! $this->_conn->getDatabasePlatform() instanceof PostgreSqlPlatform) { - $this->markTestSkipped('PDOPgsql only test.'); + if ($this->_conn->getDatabasePlatform() instanceof PostgreSqlPlatform) { + return; } + + $this->markTestSkipped('PDOPgsql only test.'); } /** + * @param string $charset + * * @group DBAL-1183 * @group DBAL-1189 - * * @dataProvider getValidCharsets - * - * @param string $charset */ public function testConnectsWithValidCharsetOption($charset) { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['charset'] = $charset; $connection = DriverManager::getConnection( @@ -54,9 +55,9 @@ public function testConnectsWithValidCharsetOption($charset) */ public function getValidCharsets() { - return array( - array("UTF8"), - array("LATIN1") - ); + return [ + ['UTF8'], + ['LATIN1'], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php index d292db1583c..e6ad8639552 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('pdo_sqlite only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('pdo_sqlite only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php index 88c87d7e08b..e9d224f8e0f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\PDOSqlsrv; -use Doctrine\DBAL\Driver\Connection as Connection; +use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\PDOSqlsrv\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use PDO; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php index 9f62612ca3b..d94fb91df7d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php @@ -4,9 +4,10 @@ use Doctrine\DBAL\Driver\SQLAnywhere\Driver; use Doctrine\DBAL\DriverManager; +use Doctrine\Tests\DbalFunctionalTestCase; use function extension_loaded; -class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase +class ConnectionTest extends DbalFunctionalTestCase { protected function setUp() { @@ -16,14 +17,16 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('sqlanywhere only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('sqlanywhere only test.'); } public function testNonPersistentConnection() { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['persistent'] = false; $conn = DriverManager::getConnection($params); @@ -35,7 +38,7 @@ public function testNonPersistentConnection() public function testPersistentConnection() { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['persistent'] = true; $conn = DriverManager::getConnection($params); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php index 172b6479e94..1dbe8eebee7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php @@ -17,9 +17,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('sqlanywhere only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('sqlanywhere only test.'); } public function testReturnsDatabaseNameWithoutDatabaseNameParameter() diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php index 4fbc16acf27..1e2debe949f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php @@ -4,9 +4,10 @@ use Doctrine\DBAL\Driver\SQLAnywhere\Driver; use Doctrine\DBAL\DriverManager; +use Doctrine\Tests\DbalFunctionalTestCase; use function extension_loaded; -class StatementTest extends \Doctrine\Tests\DbalFunctionalTestCase +class StatementTest extends DbalFunctionalTestCase { protected function setUp() { @@ -16,39 +17,40 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('sqlanywhere only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('sqlanywhere only test.'); } public function testNonPersistentStatement() { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['persistent'] = false; $conn = DriverManager::getConnection($params); $conn->connect(); - self::assertTrue($conn->isConnected(),'No SQLAnywhere-Connection established'); + self::assertTrue($conn->isConnected(), 'No SQLAnywhere-Connection established'); $prepStmt = $conn->prepare('SELECT 1'); - self::assertTrue($prepStmt->execute(),' Statement non-persistent failed'); + self::assertTrue($prepStmt->execute(), ' Statement non-persistent failed'); } public function testPersistentStatement() { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['persistent'] = true; $conn = DriverManager::getConnection($params); $conn->connect(); - self::assertTrue($conn->isConnected(),'No SQLAnywhere-Connection established'); + self::assertTrue($conn->isConnected(), 'No SQLAnywhere-Connection established'); $prepStmt = $conn->prepare('SELECT 1'); - self::assertTrue($prepStmt->execute(),' Statement persistent failed'); + self::assertTrue($prepStmt->execute(), ' Statement persistent failed'); } - } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php index aa7ed63a3e1..4ea3c9bc143 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('sqlsrv only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('sqlsrv only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php index 6c9ea327a62..b6b325f23b4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php @@ -11,15 +11,17 @@ class StatementTest extends DbalFunctionalTestCase { protected function setUp() { - if (!extension_loaded('sqlsrv')) { + if (! extension_loaded('sqlsrv')) { self::markTestSkipped('sqlsrv is not installed.'); } parent::setUp(); - if (!$this->_conn->getDriver() instanceof Driver) { - self::markTestSkipped('sqlsrv only test'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + self::markTestSkipped('sqlsrv only test'); } public function testFailureToPrepareResultsInException() diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index a8c73ce33c5..a2e1ca901e3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -1,9 +1,14 @@ _conn->getDriver() instanceof ExceptionConverterDriver)) { - $this->markTestSkipped('Driver does not support special exception handling.'); + if ($this->_conn->getDriver() instanceof ExceptionConverterDriver) { + return; } + + $this->markTestSkipped('Driver does not support special exception handling.'); } public function testPrimaryConstraintViolationException() { - $table = new \Doctrine\DBAL\Schema\Table("duplicatekey_table"); - $table->addColumn('id', 'integer', array()); - $table->setPrimaryKey(array('id')); + $table = new Table('duplicatekey_table'); + $table->addColumn('id', 'integer', []); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); - $this->_conn->insert("duplicatekey_table", array('id' => 1)); + $this->_conn->insert('duplicatekey_table', ['id' => 1]); $this->expectException(Exception\UniqueConstraintViolationException::class); - $this->_conn->insert("duplicatekey_table", array('id' => 1)); + $this->_conn->insert('duplicatekey_table', ['id' => 1]); } public function testTableNotFoundException() { - $sql = "SELECT * FROM unknown_table"; + $sql = 'SELECT * FROM unknown_table'; $this->expectException(Exception\TableNotFoundException::class); $this->_conn->executeQuery($sql); @@ -49,9 +56,9 @@ public function testTableNotFoundException() public function testTableExistsException() { $schemaManager = $this->_conn->getSchemaManager(); - $table = new \Doctrine\DBAL\Schema\Table("alreadyexist_table"); - $table->addColumn('id', 'integer', array()); - $table->setPrimaryKey(array('id')); + $table = new Table('alreadyexist_table'); + $table->addColumn('id', 'integer', []); + $table->setPrimaryKey(['id']); $this->expectException(Exception\TableExistsException::class); $schemaManager->createTable($table); @@ -60,16 +67,16 @@ public function testTableExistsException() public function testForeignKeyConstraintViolationExceptionOnInsert() { - if ( ! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped("Only fails on platforms with foreign key constraints."); + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); - } catch (\Exception $exception) { + $this->_conn->insert('constraint_error_table', ['id' => 1]); + $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -78,12 +85,12 @@ public function testForeignKeyConstraintViolationExceptionOnInsert() $this->expectException(Exception\ForeignKeyConstraintViolationException::class); try { - $this->_conn->insert('owning_table', array('id' => 2, 'constraint_id' => 2)); + $this->_conn->insert('owning_table', ['id' => 2, 'constraint_id' => 2]); } catch (Exception\ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; - } catch (\Exception $exception) { + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -94,16 +101,16 @@ public function testForeignKeyConstraintViolationExceptionOnInsert() public function testForeignKeyConstraintViolationExceptionOnUpdate() { - if ( ! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped("Only fails on platforms with foreign key constraints."); + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); - } catch (\Exception $exception) { + $this->_conn->insert('constraint_error_table', ['id' => 1]); + $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -112,12 +119,12 @@ public function testForeignKeyConstraintViolationExceptionOnUpdate() $this->expectException(Exception\ForeignKeyConstraintViolationException::class); try { - $this->_conn->update('constraint_error_table', array('id' => 2), array('id' => 1)); + $this->_conn->update('constraint_error_table', ['id' => 2], ['id' => 1]); } catch (Exception\ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; - } catch (\Exception $exception) { + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -128,16 +135,16 @@ public function testForeignKeyConstraintViolationExceptionOnUpdate() public function testForeignKeyConstraintViolationExceptionOnDelete() { - if ( ! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped("Only fails on platforms with foreign key constraints."); + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); - } catch (\Exception $exception) { + $this->_conn->insert('constraint_error_table', ['id' => 1]); + $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -146,12 +153,12 @@ public function testForeignKeyConstraintViolationExceptionOnDelete() $this->expectException(Exception\ForeignKeyConstraintViolationException::class); try { - $this->_conn->delete('constraint_error_table', array('id' => 1)); + $this->_conn->delete('constraint_error_table', ['id' => 1]); } catch (Exception\ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; - } catch (\Exception $exception) { + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -164,16 +171,16 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate() { $platform = $this->_conn->getDatabasePlatform(); - if (!$platform->supportsForeignKeyConstraints()) { - $this->markTestSkipped("Only fails on platforms with foreign key constraints."); + if (! $platform->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); - } catch (\Exception $exception) { + $this->_conn->insert('constraint_error_table', ['id' => 1]); + $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -187,7 +194,7 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate() $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; - } catch (\Exception $exception) { + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -198,44 +205,44 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate() public function testNotNullConstraintViolationException() { - $schema = new \Doctrine\DBAL\Schema\Schema(); + $schema = new Schema(); - $table = $schema->createTable("notnull_table"); - $table->addColumn('id', 'integer', array()); - $table->addColumn('value', 'integer', array('notnull' => true)); - $table->setPrimaryKey(array('id')); + $table = $schema->createTable('notnull_table'); + $table->addColumn('id', 'integer', []); + $table->addColumn('value', 'integer', ['notnull' => true]); + $table->setPrimaryKey(['id']); foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { $this->_conn->exec($sql); } $this->expectException(Exception\NotNullConstraintViolationException::class); - $this->_conn->insert("notnull_table", array('id' => 1, 'value' => null)); + $this->_conn->insert('notnull_table', ['id' => 1, 'value' => null]); } public function testInvalidFieldNameException() { - $schema = new \Doctrine\DBAL\Schema\Schema(); + $schema = new Schema(); - $table = $schema->createTable("bad_fieldname_table"); - $table->addColumn('id', 'integer', array()); + $table = $schema->createTable('bad_fieldname_table'); + $table->addColumn('id', 'integer', []); foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { $this->_conn->exec($sql); } $this->expectException(Exception\InvalidFieldNameException::class); - $this->_conn->insert("bad_fieldname_table", array('name' => 5)); + $this->_conn->insert('bad_fieldname_table', ['name' => 5]); } public function testNonUniqueFieldNameException() { - $schema = new \Doctrine\DBAL\Schema\Schema(); + $schema = new Schema(); - $table = $schema->createTable("ambiguous_list_table"); + $table = $schema->createTable('ambiguous_list_table'); $table->addColumn('id', 'integer'); - $table2 = $schema->createTable("ambiguous_list_table_2"); + $table2 = $schema->createTable('ambiguous_list_table_2'); $table2->addColumn('id', 'integer'); foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { @@ -249,26 +256,26 @@ public function testNonUniqueFieldNameException() public function testUniqueConstraintViolationException() { - $schema = new \Doctrine\DBAL\Schema\Schema(); + $schema = new Schema(); - $table = $schema->createTable("unique_field_table"); + $table = $schema->createTable('unique_field_table'); $table->addColumn('id', 'integer'); - $table->addUniqueIndex(array('id')); + $table->addUniqueIndex(['id']); foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { $this->_conn->exec($sql); } - $this->_conn->insert("unique_field_table", array('id' => 5)); + $this->_conn->insert('unique_field_table', ['id' => 5]); $this->expectException(Exception\UniqueConstraintViolationException::class); - $this->_conn->insert("unique_field_table", array('id' => 5)); + $this->_conn->insert('unique_field_table', ['id' => 5]); } public function testSyntaxErrorException() { - $table = new \Doctrine\DBAL\Schema\Table("syntax_error_table"); - $table->addColumn('id', 'integer', array()); - $table->setPrimaryKey(array('id')); + $table = new Table('syntax_error_table'); + $table->addColumn('id', 'integer', []); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); @@ -282,11 +289,11 @@ public function testSyntaxErrorException() */ public function testConnectionExceptionSqLite($mode, $exceptionClass) { - if ($this->_conn->getDatabasePlatform()->getName() != 'sqlite') { - $this->markTestSkipped("Only fails this way on sqlite"); + if ($this->_conn->getDatabasePlatform()->getName() !== 'sqlite') { + $this->markTestSkipped('Only fails this way on sqlite'); } - $filename = sprintf('%s/%s', sys_get_temp_dir(), 'doctrine_failed_connection_'.$mode.'.db'); + $filename = sprintf('%s/%s', sys_get_temp_dir(), 'doctrine_failed_connection_' . $mode . '.db'); if (file_exists($filename)) { chmod($filename, 0200); // make the file writable again, so it can be removed on Windows @@ -296,14 +303,14 @@ public function testConnectionExceptionSqLite($mode, $exceptionClass) touch($filename); chmod($filename, $mode); - $params = array( + $params = [ 'driver' => 'pdo_sqlite', 'path' => $filename, - ); - $conn = \Doctrine\DBAL\DriverManager::getConnection($params); + ]; + $conn = DriverManager::getConnection($params); - $schema = new \Doctrine\DBAL\Schema\Schema(); - $table = $schema->createTable("no_connection"); + $schema = new Schema(); + $table = $schema->createTable('no_connection'); $table->addColumn('id', 'integer'); $this->expectException($exceptionClass); @@ -314,11 +321,11 @@ public function testConnectionExceptionSqLite($mode, $exceptionClass) public function getSqLiteOpenConnection() { - return array( + return [ // mode 0 is considered read-only on Windows - array(0000, defined('PHP_WINDOWS_VERSION_BUILD') ? Exception\ReadOnlyException::class : Exception\ConnectionException::class), - array(0444, Exception\ReadOnlyException::class), - ); + [0000, defined('PHP_WINDOWS_VERSION_BUILD') ? Exception\ReadOnlyException::class : Exception\ConnectionException::class], + [0444, Exception\ReadOnlyException::class], + ]; } /** @@ -326,25 +333,25 @@ public function getSqLiteOpenConnection() */ public function testConnectionException($params) { - if ($this->_conn->getDatabasePlatform()->getName() == 'sqlite') { - $this->markTestSkipped("Only skipped if platform is not sqlite"); + if ($this->_conn->getDatabasePlatform()->getName() === 'sqlite') { + $this->markTestSkipped('Only skipped if platform is not sqlite'); } - if ($this->_conn->getDatabasePlatform()->getName() == 'drizzle') { - $this->markTestSkipped("Drizzle does not always support authentication"); + if ($this->_conn->getDatabasePlatform()->getName() === 'drizzle') { + $this->markTestSkipped('Drizzle does not always support authentication'); } - if ($this->_conn->getDatabasePlatform()->getName() == 'postgresql' && isset($params['password'])) { - $this->markTestSkipped("Does not work on Travis"); + if ($this->_conn->getDatabasePlatform()->getName() === 'postgresql' && isset($params['password'])) { + $this->markTestSkipped('Does not work on Travis'); } $defaultParams = $this->_conn->getParams(); - $params = array_merge($defaultParams, $params); + $params = array_merge($defaultParams, $params); - $conn = \Doctrine\DBAL\DriverManager::getConnection($params); + $conn = DriverManager::getConnection($params); - $schema = new \Doctrine\DBAL\Schema\Schema(); - $table = $schema->createTable("no_connection"); + $schema = new Schema(); + $table = $schema->createTable('no_connection'); $table->addColumn('id', 'integer'); $this->expectException(Exception\ConnectionException::class); @@ -356,26 +363,26 @@ public function testConnectionException($params) public function getConnectionParams() { - return array( - array(array('user' => 'not_existing')), - array(array('password' => 'really_not')), - array(array('host' => 'localnope')), - ); + return [ + [['user' => 'not_existing']], + [['password' => 'really_not']], + [['host' => 'localnope']], + ]; } private function setUpForeignKeyConstraintViolationExceptionTest() { $schemaManager = $this->_conn->getSchemaManager(); - $table = new Table("constraint_error_table"); - $table->addColumn('id', 'integer', array()); - $table->setPrimaryKey(array('id')); + $table = new Table('constraint_error_table'); + $table->addColumn('id', 'integer', []); + $table->setPrimaryKey(['id']); - $owningTable = new Table("owning_table"); - $owningTable->addColumn('id', 'integer', array()); - $owningTable->addColumn('constraint_id', 'integer', array()); - $owningTable->setPrimaryKey(array('id')); - $owningTable->addForeignKeyConstraint($table, array('constraint_id'), array('id')); + $owningTable = new Table('owning_table'); + $owningTable->addColumn('id', 'integer', []); + $owningTable->addColumn('constraint_id', 'integer', []); + $owningTable->setPrimaryKey(['id']); + $owningTable->addForeignKeyConstraint($table, ['constraint_id'], ['id']); $schemaManager->createTable($table); $schemaManager->createTable($owningTable); diff --git a/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php b/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php index 9f2a098d7f5..59306f153fd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php @@ -4,7 +4,6 @@ use Doctrine\Tests\DbalFunctionalTestCase; use function sprintf; -use function str_replace; final class LikeWildcardsEscapingTest extends DbalFunctionalTestCase { diff --git a/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php b/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php index f32520485ef..8ba5daa0669 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\DBAL\Functional; -class LoggingTest extends \Doctrine\Tests\DbalFunctionalTestCase +use Doctrine\Tests\DbalFunctionalTestCase; + +class LoggingTest extends DbalFunctionalTestCase { public function testLogExecuteQuery() { @@ -11,11 +13,11 @@ public function testLogExecuteQuery() $logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger'); $logMock->expects($this->at(0)) ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo(array()), $this->equalTo(array())); + ->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([])); $logMock->expects($this->at(1)) ->method('stopQuery'); $this->_conn->getConfiguration()->setSQLLogger($logMock); - $this->_conn->executeQuery($sql, array()); + $this->_conn->executeQuery($sql, []); } public function testLogExecuteUpdate() @@ -27,11 +29,11 @@ public function testLogExecuteUpdate() $logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger'); $logMock->expects($this->at(0)) ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo(array()), $this->equalTo(array())); + ->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([])); $logMock->expects($this->at(1)) ->method('stopQuery'); $this->_conn->getConfiguration()->setSQLLogger($logMock); - $this->_conn->executeUpdate($sql, array()); + $this->_conn->executeUpdate($sql, []); } public function testLogPrepareExecute() @@ -41,7 +43,7 @@ public function testLogPrepareExecute() $logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger'); $logMock->expects($this->once()) ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo(array())); + ->with($this->equalTo($sql), $this->equalTo([])); $logMock->expects($this->at(1)) ->method('stopQuery'); $this->_conn->getConfiguration()->setSQLLogger($logMock); diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index 8b4c01e31d2..af894cf147c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -4,7 +4,10 @@ use Doctrine\DBAL\Connections\MasterSlaveConnection; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; use const CASE_LOWER; use function array_change_key_case; use function sprintf; @@ -24,25 +27,23 @@ protected function setUp() $platformName = $this->_conn->getDatabasePlatform()->getName(); // This is a MySQL specific test, skip other vendors. - if ($platformName != 'mysql') { + if ($platformName !== 'mysql') { $this->markTestSkipped(sprintf('Test does not work on %s.', $platformName)); } try { - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ - $table = new \Doctrine\DBAL\Schema\Table("master_slave_table"); + /** @var AbstractSchemaManager $sm */ + $table = new Table('master_slave_table'); $table->addColumn('test_int', 'integer'); - $table->setPrimaryKey(array('test_int')); + $table->setPrimaryKey(['test_int']); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); - - - } catch(\Exception $e) { + } catch (Throwable $e) { } $this->_conn->executeUpdate('DELETE FROM master_slave_table'); - $this->_conn->insert('master_slave_table', array('test_int' => 1)); + $this->_conn->insert('master_slave_table', ['test_int' => 1]); } private function createMasterSlaveConnection(bool $keepSlave = false) : MasterSlaveConnection @@ -52,9 +53,9 @@ private function createMasterSlaveConnection(bool $keepSlave = false) : MasterSl private function createMasterSlaveConnectionParams(bool $keepSlave = false) : array { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['master'] = $params; - $params['slaves'] = array($params, $params); + $params['slaves'] = [$params, $params]; $params['keepSlave'] = $keepSlave; $params['wrapperClass'] = MasterSlaveConnection::class; @@ -65,17 +66,19 @@ public function testInheritCharsetFromMaster() : void { $charsets = [ 'utf8', - 'latin1' + 'latin1', ]; foreach ($charsets as $charset) { - $params = $this->createMasterSlaveConnectionParams(); + $params = $this->createMasterSlaveConnectionParams(); $params['master']['charset'] = $charset; foreach ($params['slaves'] as $index => $slaveParams) { - if (isset($slaveParams['charset'])) { - unset($params['slaves'][$index]['charset']); + if (! isset($slaveParams['charset'])) { + continue; } + + unset($params['slaves'][$index]['charset']); } /** @var MasterSlaveConnection $conn */ @@ -108,8 +111,8 @@ public function testNoMasterOnExecuteQuery() { $conn = $this->createMasterSlaveConnection(); - $sql = "SELECT count(*) as num FROM master_slave_table"; - $data = $conn->fetchAll($sql); + $sql = 'SELECT count(*) as num FROM master_slave_table'; + $data = $conn->fetchAll($sql); $data[0] = array_change_key_case($data[0], CASE_LOWER); self::assertEquals(1, $data[0]['num']); @@ -119,12 +122,12 @@ public function testNoMasterOnExecuteQuery() public function testMasterOnWriteOperation() { $conn = $this->createMasterSlaveConnection(); - $conn->insert('master_slave_table', array('test_int' => 30)); + $conn->insert('master_slave_table', ['test_int' => 30]); self::assertTrue($conn->isConnectedToMaster()); - $sql = "SELECT count(*) as num FROM master_slave_table"; - $data = $conn->fetchAll($sql); + $sql = 'SELECT count(*) as num FROM master_slave_table'; + $data = $conn->fetchAll($sql); $data[0] = array_change_key_case($data[0], CASE_LOWER); self::assertEquals(2, $data[0]['num']); @@ -140,7 +143,7 @@ public function testKeepSlaveBeginTransactionStaysOnMaster() $conn->connect('slave'); $conn->beginTransaction(); - $conn->insert('master_slave_table', array('test_int' => 30)); + $conn->insert('master_slave_table', ['test_int' => 30]); $conn->commit(); self::assertTrue($conn->isConnectedToMaster()); @@ -160,7 +163,7 @@ public function testKeepSlaveInsertStaysOnMaster() $conn = $this->createMasterSlaveConnection($keepSlave = true); $conn->connect('slave'); - $conn->insert('master_slave_table', array('test_int' => 30)); + $conn->insert('master_slave_table', ['test_int' => 30]); self::assertTrue($conn->isConnectedToMaster()); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php index 6cd36b74e7e..b68aeaef8b3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php @@ -1,31 +1,33 @@ addColumn('test_int', 'integer'); - $table->setPrimaryKey(array('test_int')); + $table->setPrimaryKey(['test_int']); - $table2 = new \Doctrine\DBAL\Schema\Table("modify_limit_table2"); - $table2->addColumn('id', 'integer', array('autoincrement' => true)); + $table2 = new Table('modify_limit_table2'); + $table2->addColumn('id', 'integer', ['autoincrement' => true]); $table2->addColumn('test_int', 'integer'); - $table2->setPrimaryKey(array('id')); + $table2->setPrimaryKey(['id']); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); @@ -38,104 +40,104 @@ protected function setUp() public function testModifyLimitQuerySimpleQuery() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table', array('test_int' => 3)); - $this->_conn->insert('modify_limit_table', array('test_int' => 4)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table', ['test_int' => 3]); + $this->_conn->insert('modify_limit_table', ['test_int' => 4]); - $sql = "SELECT * FROM modify_limit_table ORDER BY test_int ASC"; + $sql = 'SELECT * FROM modify_limit_table ORDER BY test_int ASC'; - $this->assertLimitResult(array(1, 2, 3, 4), $sql, 10, 0); - $this->assertLimitResult(array(1, 2), $sql, 2, 0); - $this->assertLimitResult(array(3, 4), $sql, 2, 2); - $this->assertLimitResult(array(2, 3, 4), $sql, null, 1); + $this->assertLimitResult([1, 2, 3, 4], $sql, 10, 0); + $this->assertLimitResult([1, 2], $sql, 2, 0); + $this->assertLimitResult([3, 4], $sql, 2, 2); + $this->assertLimitResult([2, 3, 4], $sql, null, 1); } public function testModifyLimitQueryJoinQuery() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 2)); + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); - $sql = "SELECT modify_limit_table.test_int FROM modify_limit_table INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ORDER BY modify_limit_table.test_int DESC"; + $sql = 'SELECT modify_limit_table.test_int FROM modify_limit_table INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ORDER BY modify_limit_table.test_int DESC'; - $this->assertLimitResult(array(2, 2, 1, 1, 1), $sql, 10, 0); - $this->assertLimitResult(array(1, 1, 1), $sql, 3, 2); - $this->assertLimitResult(array(2, 2), $sql, 2, 0); + $this->assertLimitResult([2, 2, 1, 1, 1], $sql, 10, 0); + $this->assertLimitResult([1, 1, 1], $sql, 3, 2); + $this->assertLimitResult([2, 2], $sql, 2, 0); } public function testModifyLimitQueryNonDeterministic() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table', array('test_int' => 3)); - $this->_conn->insert('modify_limit_table', array('test_int' => 4)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table', ['test_int' => 3]); + $this->_conn->insert('modify_limit_table', ['test_int' => 4]); - $sql = "SELECT * FROM modify_limit_table"; + $sql = 'SELECT * FROM modify_limit_table'; - $this->assertLimitResult(array(4, 3, 2, 1), $sql, 10, 0, false); - $this->assertLimitResult(array(4, 3), $sql, 2, 0, false); - $this->assertLimitResult(array(2, 1), $sql, 2, 2, false); + $this->assertLimitResult([4, 3, 2, 1], $sql, 10, 0, false); + $this->assertLimitResult([4, 3], $sql, 2, 0, false); + $this->assertLimitResult([2, 1], $sql, 2, 2, false); } public function testModifyLimitQueryGroupBy() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 2)); - - $sql = "SELECT modify_limit_table.test_int FROM modify_limit_table " . - "INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ". - "GROUP BY modify_limit_table.test_int " . - "ORDER BY modify_limit_table.test_int ASC"; - $this->assertLimitResult(array(1, 2), $sql, 10, 0); - $this->assertLimitResult(array(1), $sql, 1, 0); - $this->assertLimitResult(array(2), $sql, 1, 1); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); + + $sql = 'SELECT modify_limit_table.test_int FROM modify_limit_table ' . + 'INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ' . + 'GROUP BY modify_limit_table.test_int ' . + 'ORDER BY modify_limit_table.test_int ASC'; + $this->assertLimitResult([1, 2], $sql, 10, 0); + $this->assertLimitResult([1], $sql, 1, 0); + $this->assertLimitResult([2], $sql, 1, 1); } public function testModifyLimitQuerySubSelect() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table', array('test_int' => 3)); - $this->_conn->insert('modify_limit_table', array('test_int' => 4)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table', ['test_int' => 3]); + $this->_conn->insert('modify_limit_table', ['test_int' => 4]); - $sql = "SELECT modify_limit_table.*, (SELECT COUNT(*) FROM modify_limit_table) AS cnt FROM modify_limit_table ORDER BY test_int DESC"; + $sql = 'SELECT modify_limit_table.*, (SELECT COUNT(*) FROM modify_limit_table) AS cnt FROM modify_limit_table ORDER BY test_int DESC'; - $this->assertLimitResult(array(4, 3, 2, 1), $sql, 10, 0); - $this->assertLimitResult(array(4, 3), $sql, 2, 0); - $this->assertLimitResult(array(2, 1), $sql, 2, 2); + $this->assertLimitResult([4, 3, 2, 1], $sql, 10, 0); + $this->assertLimitResult([4, 3], $sql, 2, 0); + $this->assertLimitResult([2, 1], $sql, 2, 2); } public function testModifyLimitQueryFromSubSelect() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table', array('test_int' => 3)); - $this->_conn->insert('modify_limit_table', array('test_int' => 4)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table', ['test_int' => 3]); + $this->_conn->insert('modify_limit_table', ['test_int' => 4]); - $sql = "SELECT * FROM (SELECT * FROM modify_limit_table) sub ORDER BY test_int DESC"; + $sql = 'SELECT * FROM (SELECT * FROM modify_limit_table) sub ORDER BY test_int DESC'; - $this->assertLimitResult(array(4, 3, 2, 1), $sql, 10, 0); - $this->assertLimitResult(array(4, 3), $sql, 2, 0); - $this->assertLimitResult(array(2, 1), $sql, 2, 2); + $this->assertLimitResult([4, 3, 2, 1], $sql, 10, 0); + $this->assertLimitResult([4, 3], $sql, 2, 0); + $this->assertLimitResult([2, 1], $sql, 2, 2); } public function testModifyLimitQueryLineBreaks() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table', array('test_int' => 3)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table', ['test_int' => 3]); $sql = <<assertLimitResult(array(2), $sql, 1, 1); + $this->assertLimitResult([2], $sql, 1, 1); } public function testModifyLimitQueryZeroOffsetNoLimit() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); - $sql = "SELECT test_int FROM modify_limit_table ORDER BY test_int ASC"; + $sql = 'SELECT test_int FROM modify_limit_table ORDER BY test_int ASC'; - $this->assertLimitResult(array(1, 2), $sql, null, 0); + $this->assertLimitResult([1, 2], $sql, null, 0); } public function assertLimitResult($expectedResults, $sql, $limit, $offset, $deterministic = true) { - $p = $this->_conn->getDatabasePlatform(); - $data = array(); + $p = $this->_conn->getDatabasePlatform(); + $data = []; foreach ($this->_conn->fetchAll($p->modifyLimitQuery($sql, $limit, $offset)) as $row) { - $row = array_change_key_case($row, CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); $data[] = $row['test_int']; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php index fd001d496e5..cbe56ef9bfc 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php @@ -6,13 +6,15 @@ use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; use const CASE_LOWER; use function array_change_key_case; /** * @group DDC-1372 */ -class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase +class NamedParametersTest extends DbalFunctionalTestCase { public function ticketProvider() { @@ -149,61 +151,64 @@ protected function setUp() { parent::setUp(); - if (! $this->_conn->getSchemaManager()->tablesExist('ddc1372_foobar')) { - try { - $table = new Table('ddc1372_foobar'); - $table->addColumn('id', 'integer'); - $table->addColumn('foo', 'string'); - $table->addColumn('bar', 'string'); - $table->setPrimaryKey(['id']); - - $sm = $this->_conn->getSchemaManager(); - $sm->createTable($table); + if ($this->_conn->getSchemaManager()->tablesExist('ddc1372_foobar')) { + return; + } - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 1, - 'foo' => 1, - 'bar' => 1, - ]); - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 2, - 'foo' => 1, - 'bar' => 2, - ]); - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 3, - 'foo' => 1, - 'bar' => 3, - ]); - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 4, - 'foo' => 1, - 'bar' => 4, - ]); - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 5, - 'foo' => 2, - 'bar' => 1, - ]); - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 6, - 'foo' => 2, - 'bar' => 2, - ]); - } catch(\Exception $e) { - $this->fail($e->getMessage()); - } + try { + $table = new Table('ddc1372_foobar'); + $table->addColumn('id', 'integer'); + $table->addColumn('foo', 'string'); + $table->addColumn('bar', 'string'); + $table->setPrimaryKey(['id']); + + $sm = $this->_conn->getSchemaManager(); + $sm->createTable($table); + + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 1, + 'foo' => 1, + 'bar' => 1, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 2, + 'foo' => 1, + 'bar' => 2, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 3, + 'foo' => 1, + 'bar' => 3, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 4, + 'foo' => 1, + 'bar' => 4, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 5, + 'foo' => 2, + 'bar' => 1, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 6, + 'foo' => 2, + 'bar' => 2, + ]); + } catch (Throwable $e) { + $this->fail($e->getMessage()); } } /** - * @dataProvider ticketProvider * @param string $query * @param array $params * @param array $types * @param array $expected + * + * @dataProvider ticketProvider */ - public function testTicket($query,$params,$types,$expected) + public function testTicket($query, $params, $types, $expected) { $stmt = $this->_conn->executeQuery($query, $params, $types); $result = $stmt->fetchAll(FetchMode::ASSOCIATIVE); diff --git a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php index f95f5bed47a..32a43664d6e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -7,16 +7,18 @@ use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Portability\Connection as ConnectionPortability; +use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; use function strlen; /** * @group DBAL-56 */ -class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase +class PortabilityTest extends DbalFunctionalTestCase { - /** - * @var Connection - */ + /** @var Connection */ private $portableConnection; protected function tearDown() @@ -31,13 +33,14 @@ protected function tearDown() /** * @param int $portabilityMode * @param int $case + * * @return Connection */ private function getPortableConnection( $portabilityMode = ConnectionPortability::PORTABILITY_ALL, $case = ColumnCase::LOWER ) { - if (!$this->portableConnection) { + if (! $this->portableConnection) { $params = $this->_conn->getParams(); $params['wrapperClass'] = ConnectionPortability::class; @@ -47,20 +50,19 @@ private function getPortableConnection( $this->portableConnection = DriverManager::getConnection($params, $this->_conn->getConfiguration(), $this->_conn->getEventManager()); try { - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ - $table = new \Doctrine\DBAL\Schema\Table("portability_table"); + /** @var AbstractSchemaManager $sm */ + $table = new Table('portability_table'); $table->addColumn('Test_Int', 'integer'); - $table->addColumn('Test_String', 'string', array('fixed' => true, 'length' => 32)); - $table->addColumn('Test_Null', 'string', array('notnull' => false)); - $table->setPrimaryKey(array('Test_Int')); + $table->addColumn('Test_String', 'string', ['fixed' => true, 'length' => 32]); + $table->addColumn('Test_Null', 'string', ['notnull' => false]); + $table->setPrimaryKey(['Test_Int']); $sm = $this->portableConnection->getSchemaManager(); $sm->createTable($table); - $this->portableConnection->insert('portability_table', array('Test_Int' => 1, 'Test_String' => 'foo', 'Test_Null' => '')); - $this->portableConnection->insert('portability_table', array('Test_Int' => 2, 'Test_String' => 'foo ', 'Test_Null' => null)); - } catch(\Exception $e) { - + $this->portableConnection->insert('portability_table', ['Test_Int' => 1, 'Test_String' => 'foo', 'Test_Null' => '']); + $this->portableConnection->insert('portability_table', ['Test_Int' => 2, 'Test_String' => 'foo ', 'Test_Null' => null]); + } catch (Throwable $e) { } } @@ -103,18 +105,18 @@ public function testConnFetchMode() $stmt = $conn->query('SELECT * FROM portability_table'); foreach ($stmt as $row) { - $this->assertFetchResultRow($row); + $this->assertFetchResultRow($row); } $stmt = $conn->query('SELECT * FROM portability_table'); while (($row = $stmt->fetch())) { - $this->assertFetchResultRow($row); + $this->assertFetchResultRow($row); } $stmt = $conn->prepare('SELECT * FROM portability_table'); $stmt->execute(); while (($row = $stmt->fetch())) { - $this->assertFetchResultRow($row); + $this->assertFetchResultRow($row); } } @@ -128,9 +130,9 @@ public function assertFetchResultRows($rows) public function assertFetchResultRow($row) { - self::assertContains($row['test_int'], array(1, 2), "Primary key test_int should either be 1 or 2."); - self::assertArrayHasKey('test_string', $row, "Case should be lowered."); - self::assertEquals(3, strlen($row['test_string']), "test_string should be rtrimed to length of three for CHAR(32) column."); + self::assertContains($row['test_int'], [1, 2], 'Primary key test_int should either be 1 or 2.'); + self::assertArrayHasKey('test_string', $row, 'Case should be lowered.'); + self::assertEquals(3, strlen($row['test_string']), 'test_string should be rtrimed to length of three for CHAR(32) column.'); self::assertNull($row['test_null']); self::assertArrayNotHasKey(0, $row, 'The row should not contain numerical keys.'); } @@ -141,12 +143,10 @@ public function assertFetchResultRow($row) public function testPortabilityPdoSqlServer() { $portability = ConnectionPortability::PORTABILITY_SQLSRV; - $params = array( - 'portability' => $portability - ); + $params = ['portability' => $portability]; $driverMock = $this->getMockBuilder('Doctrine\\DBAL\\Driver\\PDOSqlsrv\\Driver') - ->setMethods(array('connect')) + ->setMethods(['connect']) ->getMock(); $driverMock->expects($this->once()) @@ -174,16 +174,16 @@ public function testFetchAllColumn($field, array $expected) public static function fetchAllColumnProvider() { - return array( - 'int' => array( + return [ + 'int' => [ 'Test_Int', - array(1, 2), - ), - 'string' => array( + [1, 2], + ], + 'string' => [ 'Test_String', - array('foo', 'foo'), - ), - ); + ['foo', 'foo'], + ], + ]; } public function testFetchAllNullColumn() @@ -192,6 +192,6 @@ public function testFetchAllNullColumn() $stmt = $conn->query('SELECT Test_Null FROM portability_table'); $column = $stmt->fetchAll(FetchMode::COLUMN); - self::assertSame(array(null, null), $column); + self::assertSame([null, null], $column); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index 63d82ad42c8..cb32a94252c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -2,9 +2,12 @@ namespace Doctrine\Tests\DBAL\Functional; +use Doctrine\Common\Cache\ArrayCache; use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Logging\DebugStack; +use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; use const CASE_LOWER; use function array_change_key_case; use function array_merge; @@ -15,26 +18,22 @@ /** * @group DDC-217 */ -class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase +class ResultCacheTest extends DbalFunctionalTestCase { - /** - * @var int[][]|string[][] - */ - private $expectedResult = array(array('test_int' => 100, 'test_string' => 'foo'), array('test_int' => 200, 'test_string' => 'bar'), array('test_int' => 300, 'test_string' => 'baz')); - - /** - * @var DebugStack - */ + /** @var int[][]|string[][] */ + private $expectedResult = [['test_int' => 100, 'test_string' => 'foo'], ['test_int' => 200, 'test_string' => 'bar'], ['test_int' => 300, 'test_string' => 'baz']]; + + /** @var DebugStack */ private $sqlLogger; protected function setUp() { parent::setUp(); - $table = new \Doctrine\DBAL\Schema\Table("caching"); + $table = new Table('caching'); $table->addColumn('test_int', 'integer'); - $table->addColumn('test_string', 'string', array('notnull' => false)); - $table->setPrimaryKey(array('test_int')); + $table->addColumn('test_string', 'string', ['notnull' => false]); + $table->setPrimaryKey(['test_int']); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); @@ -43,10 +42,10 @@ protected function setUp() $this->_conn->insert('caching', $row); } - $config = $this->_conn->getConfiguration(); - $config->setSQLLogger($this->sqlLogger = new DebugStack); + $config = $this->_conn->getConfiguration(); + $config->setSQLLogger($this->sqlLogger = new DebugStack()); - $cache = new \Doctrine\Common\Cache\ArrayCache; + $cache = new ArrayCache(); $config->setResultCacheImpl($cache); } @@ -67,7 +66,7 @@ public function testCacheFetchAssoc() public function testFetchNum() { - $expectedResult = array(); + $expectedResult = []; foreach ($this->expectedResult as $v) { $expectedResult[] = array_values($v); } @@ -77,7 +76,7 @@ public function testFetchNum() public function testFetchBoth() { - $expectedResult = array(); + $expectedResult = []; foreach ($this->expectedResult as $v) { $expectedResult[] = array_merge($v, array_values($v)); } @@ -87,7 +86,7 @@ public function testFetchBoth() public function testFetchColumn() { - $expectedResult = array(); + $expectedResult = []; foreach ($this->expectedResult as $v) { $expectedResult[] = array_shift($v); } @@ -97,17 +96,17 @@ public function testFetchColumn() public function testMixingFetch() { - $numExpectedResult = array(); + $numExpectedResult = []; foreach ($this->expectedResult as $v) { $numExpectedResult[] = array_values($v); } - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = $this->hydrateStmt($stmt, FetchMode::ASSOCIATIVE); self::assertEquals($this->expectedResult, $data); - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = $this->hydrateStmt($stmt, FetchMode::NUMERIC); @@ -123,10 +122,10 @@ public function testIteratorFetch() public function assertStandardAndIteratorFetchAreEqual($fetchMode) { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = $this->hydrateStmt($stmt, $fetchMode); - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data_iterator = $this->hydrateStmtIterator($stmt, $fetchMode); self::assertEquals($data, $data_iterator); @@ -134,17 +133,17 @@ public function assertStandardAndIteratorFetchAreEqual($fetchMode) public function testDontCloseNoCache() { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); - $data = array(); + $data = []; while ($row = $stmt->fetch(FetchMode::ASSOCIATIVE)) { $data[] = $row; } - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); - $data = array(); + $data = []; while ($row = $stmt->fetch(FetchMode::NUMERIC)) { $data[] = $row; @@ -155,12 +154,12 @@ public function testDontCloseNoCache() public function testDontFinishNoCache() { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt->fetch(FetchMode::ASSOCIATIVE); $stmt->closeCursor(); - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $this->hydrateStmt($stmt, FetchMode::NUMERIC); @@ -169,47 +168,47 @@ public function testDontFinishNoCache() public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, $fetchMode) { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); self::assertEquals(2, $stmt->columnCount()); $data = $this->hydrateStmt($stmt, $fetchMode); self::assertEquals($expectedResult, $data); - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); self::assertEquals(2, $stmt->columnCount()); $data = $this->hydrateStmt($stmt, $fetchMode); self::assertEquals($expectedResult, $data); - self::assertCount(1, $this->sqlLogger->queries, "just one dbal hit"); + self::assertCount(1, $this->sqlLogger->queries, 'just one dbal hit'); } public function testEmptyResultCache() { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $data = $this->hydrateStmt($stmt); - $stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $data = $this->hydrateStmt($stmt); - self::assertCount(1, $this->sqlLogger->queries, "just one dbal hit"); + self::assertCount(1, $this->sqlLogger->queries, 'just one dbal hit'); } public function testChangeCacheImpl() { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $data = $this->hydrateStmt($stmt); - $secondCache = new \Doctrine\Common\Cache\ArrayCache; - $stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey", $secondCache)); - $data = $this->hydrateStmt($stmt); + $secondCache = new ArrayCache(); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey', $secondCache)); + $data = $this->hydrateStmt($stmt); - self::assertCount(2, $this->sqlLogger->queries, "two hits"); - self::assertCount(1, $secondCache->fetch("emptycachekey")); + self::assertCount(2, $this->sqlLogger->queries, 'two hits'); + self::assertCount(1, $secondCache->fetch('emptycachekey')); } private function hydrateStmt($stmt, $fetchMode = FetchMode::ASSOCIATIVE) { - $data = array(); + $data = []; while ($row = $stmt->fetch($fetchMode)) { $data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row; } @@ -219,7 +218,7 @@ private function hydrateStmt($stmt, $fetchMode = FetchMode::ASSOCIATIVE) private function hydrateStmtIterator($stmt, $fetchMode = FetchMode::ASSOCIATIVE) { - $data = array(); + $data = []; $stmt->setFetchMode($fetchMode); foreach ($stmt as $row) { $data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php index e81cc4a3978..bb1f46d2787 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php @@ -13,7 +13,7 @@ public function testGetBooleanColumn() { $table = new Table('boolean_column_test'); $table->addColumn('bool', 'boolean'); - $table->addColumn('bool_commented', 'boolean', array('comment' => "That's a comment")); + $table->addColumn('bool_commented', 'boolean', ['comment' => "That's a comment"]); $this->_sm->createTable($table); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php index 5b63b363a51..bbc1b5a5fdd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php @@ -12,9 +12,9 @@ public function testListTableWithBinary() $table = new Table($tableName); $table->addColumn('id', 'integer'); - $table->addColumn('column_varbinary', 'binary', array()); - $table->addColumn('column_binary', 'binary', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('column_varbinary', 'binary', []); + $table->addColumn('column_binary', 'binary', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -29,7 +29,7 @@ public function testListTableWithBinary() public function testColumnCollation() { - $table = new Table('test_collation'); + $table = new Table('test_collation'); $table->addOption('collate', $collation = 'utf8_unicode_ci'); $table->addColumn('id', 'integer'); $table->addColumn('text', 'text'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 9f246ad4119..80a89e29541 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use DateTime; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Comparator; @@ -17,23 +18,25 @@ protected function setUp() { parent::setUp(); - if ( ! Type::hasType('point')) { - Type::addType('point', MySqlPointType::class); + if (Type::hasType('point')) { + return; } + + Type::addType('point', MySqlPointType::class); } public function testSwitchPrimaryKeyColumns() { - $tableOld = new Table("switch_primary_key_columns"); + $tableOld = new Table('switch_primary_key_columns'); $tableOld->addColumn('foo_id', 'integer'); $tableOld->addColumn('bar_id', 'integer'); $this->_sm->createTable($tableOld); - $tableFetched = $this->_sm->listTableDetails("switch_primary_key_columns"); - $tableNew = clone $tableFetched; - $tableNew->setPrimaryKey(array('bar_id', 'foo_id')); + $tableFetched = $this->_sm->listTableDetails('switch_primary_key_columns'); + $tableNew = clone $tableFetched; + $tableNew->setPrimaryKey(['bar_id', 'foo_id']); - $comparator = new Comparator; + $comparator = new Comparator(); $this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew)); $table = $this->_sm->listTableDetails('switch_primary_key_columns'); @@ -47,31 +50,31 @@ public function testSwitchPrimaryKeyColumns() public function testDiffTableBug() { $schema = new Schema(); - $table = $schema->createTable('diffbug_routing_translations'); + $table = $schema->createTable('diffbug_routing_translations'); $table->addColumn('id', 'integer'); $table->addColumn('route', 'string'); $table->addColumn('locale', 'string'); $table->addColumn('attribute', 'string'); $table->addColumn('localized_value', 'string'); $table->addColumn('original_value', 'string'); - $table->setPrimaryKey(array('id')); - $table->addUniqueIndex(array('route', 'locale', 'attribute')); - $table->addIndex(array('localized_value')); // this is much more selective than the unique index + $table->setPrimaryKey(['id']); + $table->addUniqueIndex(['route', 'locale', 'attribute']); + $table->addIndex(['localized_value']); // this is much more selective than the unique index $this->_sm->createTable($table); - $tableFetched = $this->_sm->listTableDetails("diffbug_routing_translations"); + $tableFetched = $this->_sm->listTableDetails('diffbug_routing_translations'); - $comparator = new Comparator; - $diff = $comparator->diffTable($tableFetched, $table); + $comparator = new Comparator(); + $diff = $comparator->diffTable($tableFetched, $table); - self::assertFalse($diff, "no changes expected."); + self::assertFalse($diff, 'no changes expected.'); } public function testFulltextIndex() { $table = new Table('fulltext_index'); $table->addColumn('text', 'text'); - $table->addIndex(array('text'), 'f_index'); + $table->addIndex(['text'], 'f_index'); $table->addOption('engine', 'MyISAM'); $index = $table->getIndex('f_index'); @@ -88,7 +91,7 @@ public function testSpatialIndex() { $table = new Table('spatial_index'); $table->addColumn('point', 'point'); - $table->addIndex(array('point'), 's_index'); + $table->addIndex(['point'], 's_index'); $table->addOption('engine', 'MyISAM'); $index = $table->getIndex('s_index'); @@ -109,7 +112,7 @@ public function testAlterTableAddPrimaryKey() $table = new Table('alter_table_add_pk'); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); - $table->addIndex(array('id'), 'idx_id'); + $table->addIndex(['id'], 'idx_id'); $this->_sm->createTable($table); @@ -117,11 +120,11 @@ public function testAlterTableAddPrimaryKey() $diffTable = clone $table; $diffTable->dropIndex('idx_id'); - $diffTable->setPrimaryKey(array('id')); + $diffTable->setPrimaryKey(['id']); $this->_sm->alterTable($comparator->diffTable($table, $diffTable)); - $table = $this->_sm->listTableDetails("alter_table_add_pk"); + $table = $this->_sm->listTableDetails('alter_table_add_pk'); self::assertFalse($table->hasIndex('idx_id')); self::assertTrue($table->hasPrimaryKey()); @@ -132,10 +135,10 @@ public function testAlterTableAddPrimaryKey() */ public function testDropPrimaryKeyWithAutoincrementColumn() { - $table = new Table("drop_primary_key"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('drop_primary_key'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); - $table->setPrimaryKey(array('id', 'foo')); + $table->setPrimaryKey(['id', 'foo']); $this->_sm->dropAndCreateTable($table); @@ -147,7 +150,7 @@ public function testDropPrimaryKeyWithAutoincrementColumn() $this->_sm->alterTable($comparator->diffTable($table, $diffTable)); - $table = $this->_sm->listTableDetails("drop_primary_key"); + $table = $this->_sm->listTableDetails('drop_primary_key'); self::assertFalse($table->hasPrimaryKey()); self::assertFalse($table->getColumn('id')->getAutoincrement()); @@ -164,7 +167,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() ); } - $table = new Table("text_blob_default_value"); + $table = new Table('text_blob_default_value'); $table->addColumn('def_text', 'text', ['default' => 'def']); $table->addColumn('def_text_null', 'text', ['notnull' => false, 'default' => 'def']); $table->addColumn('def_blob', 'blob', ['default' => 'def']); @@ -172,7 +175,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() $this->_sm->dropAndCreateTable($table); - $onlineTable = $this->_sm->listTableDetails("text_blob_default_value"); + $onlineTable = $this->_sm->listTableDetails('text_blob_default_value'); self::assertNull($onlineTable->getColumn('def_text')->getDefault()); self::assertNull($onlineTable->getColumn('def_text_null')->getDefault()); @@ -185,7 +188,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() $this->_sm->alterTable($comparator->diffTable($table, $onlineTable)); - $onlineTable = $this->_sm->listTableDetails("text_blob_default_value"); + $onlineTable = $this->_sm->listTableDetails('text_blob_default_value'); self::assertNull($onlineTable->getColumn('def_text')->getDefault()); self::assertNull($onlineTable->getColumn('def_text_null')->getDefault()); @@ -197,7 +200,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() public function testColumnCollation() { - $table = new Table('test_collation'); + $table = new Table('test_collation'); $table->addOption('collate', $collation = 'latin1_swedish_ci'); $table->addOption('charset', 'latin1'); $table->addColumn('id', 'integer'); @@ -220,23 +223,23 @@ public function testColumnCollation() public function testListLobTypeColumns() { $tableName = 'lob_type_columns'; - $table = new Table($tableName); + $table = new Table($tableName); - $table->addColumn('col_tinytext', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TINYTEXT)); - $table->addColumn('col_text', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TEXT)); - $table->addColumn('col_mediumtext', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMTEXT)); + $table->addColumn('col_tinytext', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_TINYTEXT]); + $table->addColumn('col_text', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_TEXT]); + $table->addColumn('col_mediumtext', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMTEXT]); $table->addColumn('col_longtext', 'text'); - $table->addColumn('col_tinyblob', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TINYBLOB)); - $table->addColumn('col_blob', 'blob', array('length' => MySqlPlatform::LENGTH_LIMIT_BLOB)); - $table->addColumn('col_mediumblob', 'blob', array('length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMBLOB)); + $table->addColumn('col_tinyblob', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_TINYBLOB]); + $table->addColumn('col_blob', 'blob', ['length' => MySqlPlatform::LENGTH_LIMIT_BLOB]); + $table->addColumn('col_mediumblob', 'blob', ['length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMBLOB]); $table->addColumn('col_longblob', 'blob'); $this->_sm->dropAndCreateTable($table); - $platform = $this->_sm->getDatabasePlatform(); + $platform = $this->_sm->getDatabasePlatform(); $offlineColumns = $table->getColumns(); - $onlineColumns = $this->_sm->listTableColumns($tableName); + $onlineColumns = $this->_sm->listTableColumns($tableName); self::assertSame( $platform->getClobTypeDeclarationSQL($offlineColumns['col_tinytext']->toArray()), @@ -289,7 +292,7 @@ public function testDiffListGuidTableColumn() self::assertFalse( $comparator->diffTable($offlineTable, $onlineTable), - "No differences should be detected with the offline vs online schema." + 'No differences should be detected with the offline vs online schema.' ); } @@ -299,10 +302,10 @@ public function testDiffListGuidTableColumn() public function testListDecimalTypeColumns() { $tableName = 'test_list_decimal_columns'; - $table = new Table($tableName); + $table = new Table($tableName); $table->addColumn('col', 'decimal'); - $table->addColumn('col_unsigned', 'decimal', array('unsigned' => true)); + $table->addColumn('col_unsigned', 'decimal', ['unsigned' => true]); $this->_sm->dropAndCreateTable($table); @@ -320,10 +323,10 @@ public function testListDecimalTypeColumns() public function testListFloatTypeColumns() { $tableName = 'test_list_float_columns'; - $table = new Table($tableName); + $table = new Table($tableName); $table->addColumn('col', 'float'); - $table->addColumn('col_unsigned', 'float', array('unsigned' => true)); + $table->addColumn('col_unsigned', 'float', ['unsigned' => true]); $this->_sm->dropAndCreateTable($table); @@ -350,7 +353,7 @@ public function testColumnDefaultCurrentTimestamp() : void { $platform = $this->_sm->getDatabasePlatform(); - $table = new Table("test_column_defaults_current_timestamp"); + $table = new Table('test_column_defaults_current_timestamp'); $currentTimeStampSql = $platform->getCurrentTimestampSQL(); @@ -359,19 +362,19 @@ public function testColumnDefaultCurrentTimestamp() : void $this->_sm->dropAndCreateTable($table); - $onlineTable = $this->_sm->listTableDetails("test_column_defaults_current_timestamp"); + $onlineTable = $this->_sm->listTableDetails('test_column_defaults_current_timestamp'); self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime')->getDefault()); self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime_nullable')->getDefault()); $comparator = new Comparator(); $diff = $comparator->diffTable($table, $onlineTable); - self::assertFalse($diff, "Tables should be identical with column defaults."); + self::assertFalse($diff, 'Tables should be identical with column defaults.'); } public function testColumnDefaultsAreValid() { - $table = new Table("test_column_defaults_are_valid"); + $table = new Table('test_column_defaults_are_valid'); $currentTimeStampSql = $this->_sm->getDatabasePlatform()->getCurrentTimestampSQL(); $table->addColumn('col_datetime', 'datetime', ['default' => $currentTimeStampSql]); @@ -385,14 +388,14 @@ public function testColumnDefaultsAreValid() $this->_sm->dropAndCreateTable($table); $this->_conn->executeUpdate( - "INSERT INTO test_column_defaults_are_valid () VALUES()" + 'INSERT INTO test_column_defaults_are_valid () VALUES()' ); $row = $this->_conn->fetchAssoc( 'SELECT *, DATEDIFF(CURRENT_TIMESTAMP(), col_datetime) as diff_seconds FROM test_column_defaults_are_valid' ); - self::assertInstanceOf(\DateTime::class, \DateTime::createFromFormat('Y-m-d H:i:s', $row['col_datetime'])); + self::assertInstanceOf(DateTime::class, DateTime::createFromFormat('Y-m-d H:i:s', $row['col_datetime'])); self::assertNull($row['col_datetime_null']); self::assertSame('2012-12-12', $row['col_date']); self::assertSame('A', $row['col_string']); @@ -414,13 +417,13 @@ public function testColumnDefaultsAreValid() */ public function testColumnDefaultValuesCurrentTimeAndDate() : void { - if ( ! $this->_sm->getDatabasePlatform() instanceof MariaDb1027Platform) { + if (! $this->_sm->getDatabasePlatform() instanceof MariaDb1027Platform) { $this->markTestSkipped('Only relevant for MariaDb102Platform.'); } $platform = $this->_sm->getDatabasePlatform(); - $table = new Table("test_column_defaults_current_time_and_date"); + $table = new Table('test_column_defaults_current_time_and_date'); $currentTimestampSql = $platform->getCurrentTimestampSQL(); $currentTimeSql = $platform->getCurrentTimeSQL(); @@ -432,7 +435,7 @@ public function testColumnDefaultValuesCurrentTimeAndDate() : void $this->_sm->dropAndCreateTable($table); - $onlineTable = $this->_sm->listTableDetails("test_column_defaults_current_time_and_date"); + $onlineTable = $this->_sm->listTableDetails('test_column_defaults_current_time_and_date'); self::assertSame($currentTimestampSql, $onlineTable->getColumn('col_datetime')->getDefault()); self::assertSame($currentDateSql, $onlineTable->getColumn('col_date')->getDefault()); @@ -441,13 +444,14 @@ public function testColumnDefaultValuesCurrentTimeAndDate() : void $comparator = new Comparator(); $diff = $comparator->diffTable($table, $onlineTable); - self::assertFalse($diff, "Tables should be identical with column defauts time and date."); + self::assertFalse($diff, 'Tables should be identical with column defauts time and date.'); } /** * Ensure default values (un-)escaping is properly done by mysql platforms. * The test is voluntarily relying on schema introspection due to current * doctrine limitations. Once #2850 is landed, this test can be removed. + * * @see https://dev.mysql.com/doc/refman/5.7/en/string-literals.html */ public function testEnsureDefaultsAreUnescapedFromSchemaIntrospection() : void @@ -457,8 +461,10 @@ public function testEnsureDefaultsAreUnescapedFromSchemaIntrospection() : void $escapeSequences = [ "\\0", // An ASCII NUL (X'00') character - "\\'", "''", // Single quote - '\\"', '""', // Double quote + "\\'", + "''", // Single quote + '\\"', + '""', // Double quote '\\b', // A backspace character '\\n', // A new-line character '\\r', // A carriage return character @@ -475,7 +481,7 @@ public function testEnsureDefaultsAreUnescapedFromSchemaIntrospection() : void col1 VARCHAR(255) NULL DEFAULT {$platform->quoteStringLiteral($default)} )"; $this->_conn->query($sql); - $onlineTable = $this->_sm->listTableDetails("test_column_defaults_with_create"); + $onlineTable = $this->_sm->listTableDetails('test_column_defaults_with_create'); self::assertSame($default, $onlineTable->getColumn('col1')->getDefault()); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index d1f0245b015..bc9327677f2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -14,15 +14,15 @@ protected function setUp() { parent::setUp(); - if(!isset($GLOBALS['db_username'])) { + if (! isset($GLOBALS['db_username'])) { $this->markTestSkipped('Foo'); } $username = $GLOBALS['db_username']; - $query = "GRANT ALL PRIVILEGES TO ".$username; + $query = 'GRANT ALL PRIVILEGES TO ' . $username; - $conn = \Doctrine\Tests\TestUtil::getTempConnection(); + $conn = TestUtil::getTempConnection(); $conn->executeUpdate($query); } @@ -43,11 +43,11 @@ public function testListTableWithBinary() { $tableName = 'test_binary_table'; - $table = new \Doctrine\DBAL\Schema\Table($tableName); + $table = new Table($tableName); $table->addColumn('id', 'integer'); - $table->addColumn('column_varbinary', 'binary', array()); - $table->addColumn('column_binary', 'binary', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('column_varbinary', 'binary', []); + $table->addColumn('column_binary', 'binary', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -73,7 +73,7 @@ public function testAlterTableColumnNotNull() $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'string'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($table); @@ -84,8 +84,8 @@ public function testAlterTableColumnNotNull() self::assertTrue($columns['bar']->getNotnull()); $diffTable = clone $table; - $diffTable->changeColumn('foo', array('notnull' => false)); - $diffTable->changeColumn('bar', array('length' => 1024)); + $diffTable->changeColumn('foo', ['notnull' => false]); + $diffTable->changeColumn('bar', ['length' => 1024]); $this->_sm->alterTable($comparator->diffTable($table, $diffTable)); @@ -114,36 +114,36 @@ public function testListDatabases() */ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() { - $primaryTableName = '"Primary_Table"'; + $primaryTableName = '"Primary_Table"'; $offlinePrimaryTable = new Schema\Table($primaryTableName); $offlinePrimaryTable->addColumn( '"Id"', 'integer', - array('autoincrement' => true, 'comment' => 'Explicit casing.') + ['autoincrement' => true, 'comment' => 'Explicit casing.'] ); - $offlinePrimaryTable->addColumn('select', 'integer', array('comment' => 'Reserved keyword.')); - $offlinePrimaryTable->addColumn('foo', 'integer', array('comment' => 'Implicit uppercasing.')); + $offlinePrimaryTable->addColumn('select', 'integer', ['comment' => 'Reserved keyword.']); + $offlinePrimaryTable->addColumn('foo', 'integer', ['comment' => 'Implicit uppercasing.']); $offlinePrimaryTable->addColumn('BAR', 'integer'); $offlinePrimaryTable->addColumn('"BAZ"', 'integer'); - $offlinePrimaryTable->addIndex(array('select'), 'from'); - $offlinePrimaryTable->addIndex(array('foo'), 'foo_index'); - $offlinePrimaryTable->addIndex(array('BAR'), 'BAR_INDEX'); - $offlinePrimaryTable->addIndex(array('"BAZ"'), 'BAZ_INDEX'); - $offlinePrimaryTable->setPrimaryKey(array('"Id"')); + $offlinePrimaryTable->addIndex(['select'], 'from'); + $offlinePrimaryTable->addIndex(['foo'], 'foo_index'); + $offlinePrimaryTable->addIndex(['BAR'], 'BAR_INDEX'); + $offlinePrimaryTable->addIndex(['"BAZ"'], 'BAZ_INDEX'); + $offlinePrimaryTable->setPrimaryKey(['"Id"']); - $foreignTableName = 'foreign'; + $foreignTableName = 'foreign'; $offlineForeignTable = new Schema\Table($foreignTableName); - $offlineForeignTable->addColumn('id', 'integer', array('autoincrement' => true)); + $offlineForeignTable->addColumn('id', 'integer', ['autoincrement' => true]); $offlineForeignTable->addColumn('"Fk"', 'integer'); - $offlineForeignTable->addIndex(array('"Fk"'), '"Fk_index"'); + $offlineForeignTable->addIndex(['"Fk"'], '"Fk_index"'); $offlineForeignTable->addForeignKeyConstraint( $primaryTableName, - array('"Fk"'), - array('"Id"'), - array(), + ['"Fk"'], + ['"Id"'], + [], '"Primary_Table_Fk"' ); - $offlineForeignTable->setPrimaryKey(array('id')); + $offlineForeignTable->setPrimaryKey(['id']); $this->_sm->tryMethod('dropTable', $foreignTableName); $this->_sm->tryMethod('dropTable', $primaryTableName); @@ -162,7 +162,7 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() self::assertTrue($onlinePrimaryTable->hasColumn('"Id"')); self::assertSame('"Id"', $onlinePrimaryTable->getColumn('"Id"')->getQuotedName($platform)); self::assertTrue($onlinePrimaryTable->hasPrimaryKey()); - self::assertSame(array('"Id"'), $onlinePrimaryTable->getPrimaryKey()->getQuotedColumns($platform)); + self::assertSame(['"Id"'], $onlinePrimaryTable->getPrimaryKey()->getQuotedColumns($platform)); self::assertTrue($onlinePrimaryTable->hasColumn('select')); self::assertSame('"select"', $onlinePrimaryTable->getColumn('select')->getQuotedName($platform)); @@ -178,32 +178,32 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() self::assertTrue($onlinePrimaryTable->hasIndex('from')); self::assertTrue($onlinePrimaryTable->getIndex('from')->hasColumnAtPosition('"select"')); - self::assertSame(array('"select"'), $onlinePrimaryTable->getIndex('from')->getQuotedColumns($platform)); + self::assertSame(['"select"'], $onlinePrimaryTable->getIndex('from')->getQuotedColumns($platform)); self::assertTrue($onlinePrimaryTable->hasIndex('foo_index')); self::assertTrue($onlinePrimaryTable->getIndex('foo_index')->hasColumnAtPosition('foo')); - self::assertSame(array('FOO'), $onlinePrimaryTable->getIndex('foo_index')->getQuotedColumns($platform)); + self::assertSame(['FOO'], $onlinePrimaryTable->getIndex('foo_index')->getQuotedColumns($platform)); self::assertTrue($onlinePrimaryTable->hasIndex('BAR_INDEX')); self::assertTrue($onlinePrimaryTable->getIndex('BAR_INDEX')->hasColumnAtPosition('BAR')); - self::assertSame(array('BAR'), $onlinePrimaryTable->getIndex('BAR_INDEX')->getQuotedColumns($platform)); + self::assertSame(['BAR'], $onlinePrimaryTable->getIndex('BAR_INDEX')->getQuotedColumns($platform)); self::assertTrue($onlinePrimaryTable->hasIndex('BAZ_INDEX')); self::assertTrue($onlinePrimaryTable->getIndex('BAZ_INDEX')->hasColumnAtPosition('"BAZ"')); - self::assertSame(array('BAZ'), $onlinePrimaryTable->getIndex('BAZ_INDEX')->getQuotedColumns($platform)); + self::assertSame(['BAZ'], $onlinePrimaryTable->getIndex('BAZ_INDEX')->getQuotedColumns($platform)); // Foreign table assertions self::assertTrue($onlineForeignTable->hasColumn('id')); self::assertSame('ID', $onlineForeignTable->getColumn('id')->getQuotedName($platform)); self::assertTrue($onlineForeignTable->hasPrimaryKey()); - self::assertSame(array('ID'), $onlineForeignTable->getPrimaryKey()->getQuotedColumns($platform)); + self::assertSame(['ID'], $onlineForeignTable->getPrimaryKey()->getQuotedColumns($platform)); self::assertTrue($onlineForeignTable->hasColumn('"Fk"')); self::assertSame('"Fk"', $onlineForeignTable->getColumn('"Fk"')->getQuotedName($platform)); self::assertTrue($onlineForeignTable->hasIndex('"Fk_index"')); self::assertTrue($onlineForeignTable->getIndex('"Fk_index"')->hasColumnAtPosition('"Fk"')); - self::assertSame(array('"Fk"'), $onlineForeignTable->getIndex('"Fk_index"')->getQuotedColumns($platform)); + self::assertSame(['"Fk"'], $onlineForeignTable->getIndex('"Fk_index"')->getQuotedColumns($platform)); self::assertTrue($onlineForeignTable->hasForeignKey('"Primary_Table_Fk"')); self::assertSame( @@ -211,11 +211,11 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedForeignTableName($platform) ); self::assertSame( - array('"Fk"'), + ['"Fk"'], $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedLocalColumns($platform) ); self::assertSame( - array('"Id"'), + ['"Id"'], $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedForeignColumns($platform) ); } @@ -240,18 +240,18 @@ public function testListTableIndexesPrimaryKeyConstraintNameDiffersFromIndexName { $table = new Table('list_table_indexes_pk_id_test'); $table->setSchemaConfig($this->_sm->createSchemaConfig()); - $table->addColumn('id', 'integer', array('notnull' => true)); - $table->addUniqueIndex(array('id'), 'id_unique_index'); + $table->addColumn('id', 'integer', ['notnull' => true]); + $table->addUniqueIndex(['id'], 'id_unique_index'); $this->_sm->dropAndCreateTable($table); // Adding a primary key on already indexed columns // Oracle will reuse the unique index, which cause a constraint name differing from the index name - $this->_sm->createConstraint(new Schema\Index('id_pk_id_index', array('id'), true, true), 'list_table_indexes_pk_id_test'); + $this->_sm->createConstraint(new Schema\Index('id_pk_id_index', ['id'], true, true), 'list_table_indexes_pk_id_test'); $tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_pk_id_test'); self::assertArrayHasKey('primary', $tableIndexes, 'listTableIndexes() has to return a "primary" array key.'); - self::assertEquals(array('id'), array_map('strtolower', $tableIndexes['primary']->getColumns())); + self::assertEquals(['id'], array_map('strtolower', $tableIndexes['primary']->getColumns())); self::assertTrue($tableIndexes['primary']->isUnique()); self::assertTrue($tableIndexes['primary']->isPrimary()); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index 40d0f03f108..4dc76ba1da0 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Comparator; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Type; @@ -20,7 +21,7 @@ protected function tearDown() { parent::tearDown(); - if (!$this->_conn) { + if (! $this->_conn) { return; } @@ -55,10 +56,10 @@ public function testGetSchemaNames() */ public function testSupportDomainTypeFallback() { - $createDomainTypeSQL = "CREATE DOMAIN MyMoney AS DECIMAL(18,2)"; + $createDomainTypeSQL = 'CREATE DOMAIN MyMoney AS DECIMAL(18,2)'; $this->_conn->exec($createDomainTypeSQL); - $createTableSQL = "CREATE TABLE domain_type_test (id INT PRIMARY KEY, value MyMoney)"; + $createTableSQL = 'CREATE TABLE domain_type_test (id INT PRIMARY KEY, value MyMoney)'; $this->_conn->exec($createTableSQL); $table = $this->_conn->getSchemaManager()->listTableDetails('domain_type_test'); @@ -76,8 +77,8 @@ public function testSupportDomainTypeFallback() */ public function testDetectsAutoIncrement() { - $autoincTable = new \Doctrine\DBAL\Schema\Table('autoinc_table'); - $column = $autoincTable->addColumn('id', 'integer'); + $autoincTable = new Table('autoinc_table'); + $column = $autoincTable->addColumn('id', 'integer'); $column->setAutoincrement(true); $this->_sm->createTable($autoincTable); $autoincTable = $this->_sm->listTableDetails('autoinc_table'); @@ -90,24 +91,24 @@ public function testDetectsAutoIncrement() */ public function testAlterTableAutoIncrementAdd() { - $tableFrom = new \Doctrine\DBAL\Schema\Table('autoinc_table_add'); - $column = $tableFrom->addColumn('id', 'integer'); + $tableFrom = new Table('autoinc_table_add'); + $column = $tableFrom->addColumn('id', 'integer'); $this->_sm->createTable($tableFrom); $tableFrom = $this->_sm->listTableDetails('autoinc_table_add'); self::assertFalse($tableFrom->getColumn('id')->getAutoincrement()); - $tableTo = new \Doctrine\DBAL\Schema\Table('autoinc_table_add'); - $column = $tableTo->addColumn('id', 'integer'); + $tableTo = new Table('autoinc_table_add'); + $column = $tableTo->addColumn('id', 'integer'); $column->setAutoincrement(true); - $c = new \Doctrine\DBAL\Schema\Comparator(); + $c = new Comparator(); $diff = $c->diffTable($tableFrom, $tableTo); - $sql = $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff); - self::assertEquals(array( - "CREATE SEQUENCE autoinc_table_add_id_seq", + $sql = $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff); + self::assertEquals([ + 'CREATE SEQUENCE autoinc_table_add_id_seq', "SELECT setval('autoinc_table_add_id_seq', (SELECT MAX(id) FROM autoinc_table_add))", "ALTER TABLE autoinc_table_add ALTER id SET DEFAULT nextval('autoinc_table_add_id_seq')", - ), $sql); + ], $sql); $this->_sm->alterTable($diff); $tableFinal = $this->_sm->listTableDetails('autoinc_table_add'); @@ -119,20 +120,20 @@ public function testAlterTableAutoIncrementAdd() */ public function testAlterTableAutoIncrementDrop() { - $tableFrom = new \Doctrine\DBAL\Schema\Table('autoinc_table_drop'); - $column = $tableFrom->addColumn('id', 'integer'); + $tableFrom = new Table('autoinc_table_drop'); + $column = $tableFrom->addColumn('id', 'integer'); $column->setAutoincrement(true); $this->_sm->createTable($tableFrom); $tableFrom = $this->_sm->listTableDetails('autoinc_table_drop'); self::assertTrue($tableFrom->getColumn('id')->getAutoincrement()); - $tableTo = new \Doctrine\DBAL\Schema\Table('autoinc_table_drop'); - $column = $tableTo->addColumn('id', 'integer'); + $tableTo = new Table('autoinc_table_drop'); + $column = $tableTo->addColumn('id', 'integer'); - $c = new \Doctrine\DBAL\Schema\Comparator(); + $c = new Comparator(); $diff = $c->diffTable($tableFrom, $tableTo); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $diff, "There should be a difference and not false being returned from the table comparison"); - self::assertEquals(array("ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT"), $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff)); + self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $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->_conn->getDatabasePlatform()->getAlterTableSQL($diff)); $this->_sm->alterTable($diff); $tableFinal = $this->_sm->listTableDetails('autoinc_table_drop'); @@ -146,31 +147,31 @@ public function testTableWithSchema() { $this->_conn->exec('CREATE SCHEMA nested'); - $nestedRelatedTable = new \Doctrine\DBAL\Schema\Table('nested.schemarelated'); - $column = $nestedRelatedTable->addColumn('id', 'integer'); + $nestedRelatedTable = new Table('nested.schemarelated'); + $column = $nestedRelatedTable->addColumn('id', 'integer'); $column->setAutoincrement(true); - $nestedRelatedTable->setPrimaryKey(array('id')); + $nestedRelatedTable->setPrimaryKey(['id']); - $nestedSchemaTable = new \Doctrine\DBAL\Schema\Table('nested.schematable'); - $column = $nestedSchemaTable->addColumn('id', 'integer'); + $nestedSchemaTable = new Table('nested.schematable'); + $column = $nestedSchemaTable->addColumn('id', 'integer'); $column->setAutoincrement(true); - $nestedSchemaTable->setPrimaryKey(array('id')); - $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, array('id'), array('id')); + $nestedSchemaTable->setPrimaryKey(['id']); + $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, ['id'], ['id']); $this->_sm->createTable($nestedRelatedTable); $this->_sm->createTable($nestedSchemaTable); $tables = $this->_sm->listTableNames(); - self::assertContains('nested.schematable', $tables, "The table should be detected with its non-public schema."); + self::assertContains('nested.schematable', $tables, 'The table should be detected with its non-public schema.'); $nestedSchemaTable = $this->_sm->listTableDetails('nested.schematable'); self::assertTrue($nestedSchemaTable->hasColumn('id')); - self::assertEquals(array('id'), $nestedSchemaTable->getPrimaryKey()->getColumns()); + self::assertEquals(['id'], $nestedSchemaTable->getPrimaryKey()->getColumns()); $relatedFks = $nestedSchemaTable->getForeignKeys(); self::assertCount(1, $relatedFks); $relatedFk = array_pop($relatedFks); - self::assertEquals("nested.schemarelated", $relatedFk->getForeignTableName()); + self::assertEquals('nested.schemarelated', $relatedFk->getForeignTableName()); } /** @@ -188,10 +189,10 @@ public function testReturnQuotedAssets() $table = $this->_sm->listTableDetails('dbal91_something'); self::assertEquals( - array( - "CREATE TABLE dbal91_something (id INT NOT NULL, \"table\" INT DEFAULT NULL, PRIMARY KEY(id))", - "CREATE INDEX IDX_A9401304ECA7352B ON dbal91_something (\"table\")", - ), + [ + 'CREATE TABLE dbal91_something (id INT NOT NULL, "table" INT DEFAULT NULL, PRIMARY KEY(id))', + 'CREATE INDEX IDX_A9401304ECA7352B ON dbal91_something ("table")', + ], $this->_conn->getDatabasePlatform()->getCreateTableSQL($table) ); } @@ -201,11 +202,11 @@ public function testReturnQuotedAssets() */ public function testFilterSchemaExpression() { - $testTable = new \Doctrine\DBAL\Schema\Table('dbal204_test_prefix'); - $column = $testTable->addColumn('id', 'integer'); + $testTable = new Table('dbal204_test_prefix'); + $column = $testTable->addColumn('id', 'integer'); $this->_sm->createTable($testTable); - $testTable = new \Doctrine\DBAL\Schema\Table('dbal204_without_prefix'); - $column = $testTable->addColumn('id', 'integer'); + $testTable = new Table('dbal204_without_prefix'); + $column = $testTable->addColumn('id', 'integer'); $this->_sm->createTable($testTable); $this->_conn->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_#'); @@ -219,32 +220,37 @@ public function testFilterSchemaExpression() public function testListForeignKeys() { - if(!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); } - $fkOptions = array('SET NULL', 'SET DEFAULT', 'NO ACTION','CASCADE', 'RESTRICT'); - $foreignKeys = array(); - $fkTable = $this->getTestTable('test_create_fk1'); - for($i = 0; $i < count($fkOptions); $i++) { + $fkOptions = ['SET NULL', 'SET DEFAULT', 'NO ACTION','CASCADE', 'RESTRICT']; + $foreignKeys = []; + $fkTable = $this->getTestTable('test_create_fk1'); + for ($i = 0; $i < count($fkOptions); $i++) { $fkTable->addColumn("foreign_key_test$i", 'integer'); - $foreignKeys[] = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array("foreign_key_test$i"), 'test_create_fk2', array('id'), "foreign_key_test_$i"."_fk", array('onDelete' => $fkOptions[$i])); + $foreignKeys[] = new ForeignKeyConstraint( + ["foreign_key_test$i"], + 'test_create_fk2', + ['id'], + "foreign_key_test_$i" . '_fk', + ['onDelete' => $fkOptions[$i]] + ); } $this->_sm->dropAndCreateTable($fkTable); $this->createTestTable('test_create_fk2'); - foreach($foreignKeys as $foreignKey) { + foreach ($foreignKeys as $foreignKey) { $this->_sm->createForeignKey($foreignKey, 'test_create_fk1'); } $fkeys = $this->_sm->listTableForeignKeys('test_create_fk1'); - self::assertEquals(count($foreignKeys), count($fkeys), "Table 'test_create_fk1' has to have " . count($foreignKeys) . " foreign keys."); + self::assertEquals(count($foreignKeys), count($fkeys), "Table 'test_create_fk1' has to have " . count($foreignKeys) . ' foreign keys.'); for ($i = 0; $i < count($fkeys); $i++) { - self::assertEquals(array("foreign_key_test$i"), array_map('strtolower', $fkeys[$i]->getLocalColumns())); - self::assertEquals(array('id'), array_map('strtolower', $fkeys[$i]->getForeignColumns())); + self::assertEquals(["foreign_key_test$i"], array_map('strtolower', $fkeys[$i]->getLocalColumns())); + self::assertEquals(['id'], array_map('strtolower', $fkeys[$i]->getForeignColumns())); self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName())); - if ($foreignKeys[$i]->getOption('onDelete') == 'NO ACTION') { - self::assertFalse($fkeys[$i]->hasOption('onDelete'), 'Unexpected option: '. $fkeys[$i]->getOption('onDelete')); + if ($foreignKeys[$i]->getOption('onDelete') === 'NO ACTION') { + self::assertFalse($fkeys[$i]->hasOption('onDelete'), 'Unexpected option: ' . $fkeys[$i]->getOption('onDelete')); } else { self::assertEquals($foreignKeys[$i]->getOption('onDelete'), $fkeys[$i]->getOption('onDelete')); } @@ -256,10 +262,10 @@ public function testListForeignKeys() */ public function testDefaultValueCharacterVarying() { - $testTable = new \Doctrine\DBAL\Schema\Table('dbal511_default'); + $testTable = new Table('dbal511_default'); $testTable->addColumn('id', 'integer'); - $testTable->addColumn('def', 'string', array('default' => 'foo')); - $testTable->setPrimaryKey(array('id')); + $testTable->addColumn('def', 'string', ['default' => 'foo']); + $testTable->setPrimaryKey(['id']); $this->_sm->createTable($testTable); @@ -273,15 +279,15 @@ public function testDefaultValueCharacterVarying() */ public function testBooleanDefault() { - $table = new \Doctrine\DBAL\Schema\Table('ddc2843_bools'); + $table = new Table('ddc2843_bools'); $table->addColumn('id', 'integer'); - $table->addColumn('checked', 'boolean', array('default' => false)); + $table->addColumn('checked', 'boolean', ['default' => false]); $this->_sm->createTable($table); $databaseTable = $this->_sm->listTableDetails($table->getName()); - $c = new \Doctrine\DBAL\Schema\Comparator(); + $c = new Comparator(); $diff = $c->diffTable($table, $databaseTable); self::assertFalse($diff); @@ -291,11 +297,11 @@ public function testListTableWithBinary() { $tableName = 'test_binary_table'; - $table = new \Doctrine\DBAL\Schema\Table($tableName); + $table = new Table($tableName); $table->addColumn('id', 'integer'); - $table->addColumn('column_varbinary', 'binary', array()); - $table->addColumn('column_binary', 'binary', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('column_varbinary', 'binary', []); + $table->addColumn('column_binary', 'binary', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -314,8 +320,8 @@ public function testListQuotedTable() $offlineTable->addColumn('id', 'integer'); $offlineTable->addColumn('username', 'string'); $offlineTable->addColumn('fk', 'integer'); - $offlineTable->setPrimaryKey(array('id')); - $offlineTable->addForeignKeyConstraint($offlineTable, array('fk'), array('id')); + $offlineTable->setPrimaryKey(['id']); + $offlineTable->addForeignKeyConstraint($offlineTable, ['fk'], ['id']); $this->_sm->dropAndCreateTable($offlineTable); @@ -330,8 +336,8 @@ public function testListTablesExcludesViews() { $this->createTestTable('list_tables_excludes_views'); - $name = "list_tables_excludes_views_test_view"; - $sql = "SELECT * from list_tables_excludes_views"; + $name = 'list_tables_excludes_views_test_view'; + $sql = 'SELECT * from list_tables_excludes_views'; $view = new Schema\View($name, $sql); @@ -342,9 +348,11 @@ public function testListTablesExcludesViews() $foundTable = false; foreach ($tables as $table) { self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table, 'No Table instance was found in tables array.'); - if (strtolower($table->getName()) == 'list_tables_excludes_views_test_view') { - $foundTable = true; + if (strtolower($table->getName()) !== 'list_tables_excludes_views_test_view') { + continue; } + + $foundTable = true; } self::assertFalse($foundTable, 'View "list_tables_excludes_views_test_view" must not be found in table list'); @@ -359,7 +367,7 @@ public function testPartialIndexes() $offlineTable->addColumn('id', 'integer'); $offlineTable->addColumn('name', 'string'); $offlineTable->addColumn('email', 'string'); - $offlineTable->addUniqueIndex(array('id', 'name'), 'simple_partial_index', array('where' => '(id IS NULL)')); + $offlineTable->addUniqueIndex(['id', 'name'], 'simple_partial_index', ['where' => '(id IS NULL)']); $this->_sm->dropAndCreateTable($offlineTable); @@ -376,10 +384,10 @@ public function testPartialIndexes() /** * @dataProvider jsonbColumnTypeProvider */ - public function testJsonbColumn(string $type): void + public function testJsonbColumn(string $type) : void { - if (!$this->_sm->getDatabasePlatform() instanceof PostgreSQL94Platform) { - $this->markTestSkipped("Requires PostgresSQL 9.4+"); + if (! $this->_sm->getDatabasePlatform() instanceof PostgreSQL94Platform) { + $this->markTestSkipped('Requires PostgresSQL 9.4+'); return; } @@ -394,7 +402,7 @@ public function testJsonbColumn(string $type): void self::assertTrue(true, $columns['foo']->getPlatformOption('jsonb')); } - public function jsonbColumnTypeProvider(): array + public function jsonbColumnTypeProvider() : array { return [ [Type::JSON], @@ -408,12 +416,12 @@ public function jsonbColumnTypeProvider(): array public function testListNegativeColumnDefaultValue() { $table = new Schema\Table('test_default_negative'); - $table->addColumn('col_smallint', 'smallint', array('default' => -1)); - $table->addColumn('col_integer', 'integer', array('default' => -1)); - $table->addColumn('col_bigint', 'bigint', array('default' => -1)); - $table->addColumn('col_float', 'float', array('default' => -1.1)); - $table->addColumn('col_decimal', 'decimal', array('default' => -1.1)); - $table->addColumn('col_string', 'string', array('default' => '(-1)')); + $table->addColumn('col_smallint', 'smallint', ['default' => -1]); + $table->addColumn('col_integer', 'integer', ['default' => -1]); + $table->addColumn('col_bigint', 'bigint', ['default' => -1]); + $table->addColumn('col_float', 'float', ['default' => -1.1]); + $table->addColumn('col_decimal', 'decimal', ['default' => -1.1]); + $table->addColumn('col_string', 'string', ['default' => '(-1)']); $this->_sm->dropAndCreateTable($table); @@ -473,25 +481,24 @@ public function testAutoIncrementCreatesSerialDataTypesWithoutADefaultValueEvenW /** * @group 2916 - * * @dataProvider autoIncrementTypeMigrations */ public function testAlterTableAutoIncrementIntToBigInt(string $from, string $to, string $expected) : void { $tableFrom = new Table('autoinc_type_modification'); - $column = $tableFrom->addColumn('id', $from); + $column = $tableFrom->addColumn('id', $from); $column->setAutoincrement(true); $this->_sm->dropAndCreateTable($tableFrom); $tableFrom = $this->_sm->listTableDetails('autoinc_type_modification'); self::assertTrue($tableFrom->getColumn('id')->getAutoincrement()); $tableTo = new Table('autoinc_type_modification'); - $column = $tableTo->addColumn('id', $to); + $column = $tableTo->addColumn('id', $to); $column->setAutoincrement(true); - $c = new Comparator(); + $c = new Comparator(); $diff = $c->diffTable($tableFrom, $tableTo); - 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::assertSame(['ALTER TABLE autoinc_type_modification ALTER id TYPE ' . $expected], $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff)); $this->_sm->alterTable($diff); @@ -510,15 +517,13 @@ public function autoIncrementTypeMigrations() : array class MoneyType extends Type { - public function getName() { - return "MyMoney"; + return 'MyMoney'; } public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return 'MyMoney'; } - } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php index 996e91699bb..5c68a19bcfd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php @@ -12,8 +12,8 @@ public function testCreateAndListViews() { $this->createTestTable('view_test_table'); - $name = "doctrine_test_view"; - $sql = "SELECT * from DBA.view_test_table"; + $name = 'doctrine_test_view'; + $sql = 'SELECT * from DBA.view_test_table'; $view = new View($name, $sql); @@ -21,7 +21,7 @@ public function testCreateAndListViews() $views = $this->_sm->listViews(); - self::assertCount(1, $views, "Database has to have one view."); + self::assertCount(1, $views, 'Database has to have one view.'); self::assertInstanceOf('Doctrine\DBAL\Schema\View', $views[$name]); self::assertEquals($name, $views[$name]->getName()); self::assertEquals($sql, $views[$name]->getSql()); @@ -32,14 +32,14 @@ public function testDropAndCreateAdvancedIndex() $table = $this->getTestTable('test_create_advanced_index'); $this->_sm->dropAndCreateTable($table); $this->_sm->dropAndCreateIndex( - new Index('test', array('test'), true, false, array('clustered', 'with_nulls_not_distinct', 'for_olap_workload')), + new Index('test', ['test'], true, false, ['clustered', 'with_nulls_not_distinct', 'for_olap_workload']), $table->getName() ); $tableIndexes = $this->_sm->listTableIndexes('test_create_advanced_index'); self::assertInternalType('array', $tableIndexes); self::assertEquals('test', $tableIndexes['test']->getName()); - self::assertEquals(array('test'), $tableIndexes['test']->getColumns()); + self::assertEquals(['test'], $tableIndexes['test']->getColumns()); self::assertTrue($tableIndexes['test']->isUnique()); self::assertFalse($tableIndexes['test']->isPrimary()); self::assertTrue($tableIndexes['test']->hasFlag('clustered')); @@ -50,9 +50,9 @@ public function testDropAndCreateAdvancedIndex() public function testListTableColumnsWithFixedStringTypeColumn() { $table = new Table('list_table_columns_char'); - $table->addColumn('id', 'integer', array('notnull' => true)); - $table->addColumn('test', 'string', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['notnull' => true]); + $table->addColumn('test', 'string', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($table); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php index feee67710c2..218c11292be 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php @@ -13,7 +13,7 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase { protected function getPlatformName() { - return "mssql"; + return 'mssql'; } /** @@ -23,13 +23,11 @@ public function testDropColumnConstraints() { $table = new Table('sqlsrv_drop_column'); $table->addColumn('id', 'integer'); - $table->addColumn('todrop', 'decimal', array('default' => 10.2)); + $table->addColumn('todrop', 'decimal', ['default' => 10.2]); $this->_sm->createTable($table); - $diff = new TableDiff('sqlsrv_drop_column', array(), array(), array( - new Column('todrop', Type::getType('decimal')) - )); + $diff = new TableDiff('sqlsrv_drop_column', [], [], [new Column('todrop', Type::getType('decimal'))]); $this->_sm->alterTable($diff); $columns = $this->_sm->listTableColumns('sqlsrv_drop_column'); @@ -38,7 +36,7 @@ public function testDropColumnConstraints() public function testColumnCollation() { - $table = new \Doctrine\DBAL\Schema\Table($tableName = 'test_collation'); + $table = new Table($tableName = 'test_collation'); $column = $table->addColumn($columnName = 'test', 'string'); $this->_sm->dropAndCreateTable($table); @@ -57,16 +55,16 @@ public function testColumnCollation() public function testDefaultConstraints() { $platform = $this->_sm->getDatabasePlatform(); - $table = new Table('sqlsrv_default_constraints'); + $table = new Table('sqlsrv_default_constraints'); $table->addColumn('no_default', 'string'); - $table->addColumn('df_integer', 'integer', array('default' => 666)); - $table->addColumn('df_string_1', 'string', array('default' => 'foobar')); - $table->addColumn('df_string_2', 'string', array('default' => 'Doctrine rocks!!!')); - $table->addColumn('df_string_3', 'string', array('default' => 'another default value')); - $table->addColumn('df_string_4', 'string', array('default' => 'column to rename')); - $table->addColumn('df_boolean', 'boolean', array('default' => true)); - $table->addColumn('df_current_date', 'date', array('default' => $platform->getCurrentDateSQL())); - $table->addColumn('df_current_time', 'time', array('default' => $platform->getCurrentTimeSQL())); + $table->addColumn('df_integer', 'integer', ['default' => 666]); + $table->addColumn('df_string_1', 'string', ['default' => 'foobar']); + $table->addColumn('df_string_2', 'string', ['default' => 'Doctrine rocks!!!']); + $table->addColumn('df_string_3', 'string', ['default' => 'another default value']); + $table->addColumn('df_string_4', 'string', ['default' => 'column to rename']); + $table->addColumn('df_boolean', 'boolean', ['default' => true]); + $table->addColumn('df_current_date', 'date', ['default' => $platform->getCurrentDateSQL()]); + $table->addColumn('df_current_time', 'time', ['default' => $platform->getCurrentTimeSQL()]); $this->_sm->createTable($table); $columns = $this->_sm->listTableColumns('sqlsrv_default_constraints'); @@ -80,50 +78,48 @@ public function testDefaultConstraints() self::assertSame($platform->getCurrentDateSQL(), $columns['df_current_date']->getDefault()); self::assertSame($platform->getCurrentTimeSQL(), $columns['df_current_time']->getDefault()); - $diff = new TableDiff( + $diff = new TableDiff( 'sqlsrv_default_constraints', - array( - new Column('df_current_timestamp', Type::getType('datetime'), array('default' => 'CURRENT_TIMESTAMP')) - ), - array( + [new Column('df_current_timestamp', Type::getType('datetime'), ['default' => 'CURRENT_TIMESTAMP'])], + [ 'df_integer' => new ColumnDiff( 'df_integer', - new Column('df_integer', Type::getType('integer'), array('default' => 0)), - array('default'), - new Column('df_integer', Type::getType('integer'), array('default' => 666)) + new Column('df_integer', Type::getType('integer'), ['default' => 0]), + ['default'], + new Column('df_integer', Type::getType('integer'), ['default' => 666]) ), 'df_string_2' => new ColumnDiff( 'df_string_2', new Column('df_string_2', Type::getType('string')), - array('default'), - new Column('df_string_2', Type::getType('string'), array('default' => 'Doctrine rocks!!!')) + ['default'], + new Column('df_string_2', Type::getType('string'), ['default' => 'Doctrine rocks!!!']) ), 'df_string_3' => new ColumnDiff( 'df_string_3', - new Column('df_string_3', Type::getType('string'), array('length' => 50, 'default' => 'another default value')), - array('length'), - new Column('df_string_3', Type::getType('string'), array('length' => 50, 'default' => 'another default value')) + new Column('df_string_3', Type::getType('string'), ['length' => 50, 'default' => 'another default value']), + ['length'], + new Column('df_string_3', Type::getType('string'), ['length' => 50, 'default' => 'another default value']) ), 'df_boolean' => new ColumnDiff( 'df_boolean', - new Column('df_boolean', Type::getType('boolean'), array('default' => false)), - array('default'), - new Column('df_boolean', Type::getType('boolean'), array('default' => true)) - ) - ), - array( - 'df_string_1' => new Column('df_string_1', Type::getType('string')) - ), - array(), - array(), - array(), + new Column('df_boolean', Type::getType('boolean'), ['default' => false]), + ['default'], + new Column('df_boolean', Type::getType('boolean'), ['default' => true]) + ), + ], + [ + 'df_string_1' => new Column('df_string_1', Type::getType('string')), + ], + [], + [], + [], $table ); - $diff->newName = 'sqlsrv_default_constraints'; + $diff->newName = 'sqlsrv_default_constraints'; $diff->renamedColumns['df_string_4'] = new Column( 'df_string_renamed', Type::getType('string'), - array('default' => 'column to rename') + ['default' => 'column to rename'] ); $this->_sm->alterTable($diff); @@ -142,25 +138,25 @@ public function testDefaultConstraints() */ $diff = new TableDiff( 'sqlsrv_default_constraints', - array(), - array( + [], + [ 'df_current_timestamp' => new ColumnDiff( 'df_current_timestamp', new Column('df_current_timestamp', Type::getType('datetime')), - array('default'), - new Column('df_current_timestamp', Type::getType('datetime'), array('default' => 'CURRENT_TIMESTAMP')) + ['default'], + new Column('df_current_timestamp', Type::getType('datetime'), ['default' => 'CURRENT_TIMESTAMP']) ), 'df_integer' => new ColumnDiff( 'df_integer', - new Column('df_integer', Type::getType('integer'), array('default' => 666)), - array('default'), - new Column('df_integer', Type::getType('integer'), array('default' => 0)) - ) - ), - array(), - array(), - array(), - array(), + new Column('df_integer', Type::getType('integer'), ['default' => 666]), + ['default'], + new Column('df_integer', Type::getType('integer'), ['default' => 0]) + ), + ], + [], + [], + [], + [], $table ); @@ -177,23 +173,23 @@ public function testDefaultConstraints() public function testColumnComments() { $table = new Table('sqlsrv_column_comment'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->addColumn('comment_null', 'integer', array('comment' => null)); - $table->addColumn('comment_false', 'integer', array('comment' => false)); - $table->addColumn('comment_empty_string', 'integer', array('comment' => '')); - $table->addColumn('comment_integer_0', 'integer', array('comment' => 0)); - $table->addColumn('comment_float_0', 'integer', array('comment' => 0.0)); - $table->addColumn('comment_string_0', 'integer', array('comment' => '0')); - $table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!')); - $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitly quoted columns!')); - $table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->addColumn('comment_null', 'integer', ['comment' => null]); + $table->addColumn('comment_false', 'integer', ['comment' => false]); + $table->addColumn('comment_empty_string', 'integer', ['comment' => '']); + $table->addColumn('comment_integer_0', 'integer', ['comment' => 0]); + $table->addColumn('comment_float_0', 'integer', ['comment' => 0.0]); + $table->addColumn('comment_string_0', 'integer', ['comment' => '0']); + $table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']); + $table->addColumn('`comment_quoted`', 'integer', ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!']); + $table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']); $table->addColumn('commented_type', 'object'); - $table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.')); - $table->setPrimaryKey(array('id')); + $table->addColumn('commented_type_with_comment', 'array', ['comment' => 'Doctrine array type.']); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); - $columns = $this->_sm->listTableColumns("sqlsrv_column_comment"); + $columns = $this->_sm->listTableColumns('sqlsrv_column_comment'); self::assertCount(12, $columns); self::assertNull($columns['id']->getComment()); self::assertNull($columns['comment_null']->getComment()); @@ -208,92 +204,92 @@ public function testColumnComments() self::assertNull($columns['commented_type']->getComment()); self::assertEquals('Doctrine array type.', $columns['commented_type_with_comment']->getComment()); - $tableDiff = new TableDiff('sqlsrv_column_comment'); - $tableDiff->fromTable = $table; - $tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer')); - $tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), array('comment' => null)); - $tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), array('comment' => false)); - $tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), array('comment' => '')); - $tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), array('comment' => 0)); - $tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), array('comment' => 0.0)); - $tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), array('comment' => '0')); - $tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), array('comment' => 'Doctrine')); - $tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), array('comment' => 'rulez')); - $tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), array('comment' => '666')); - $tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object')); - $tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), array('comment' => '666')); - - $tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), array('comment' => 'Double for real!')); + $tableDiff = new TableDiff('sqlsrv_column_comment'); + $tableDiff->fromTable = $table; + $tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer')); + $tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), ['comment' => null]); + $tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), ['comment' => false]); + $tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), ['comment' => '']); + $tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), ['comment' => 0]); + $tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), ['comment' => 0.0]); + $tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), ['comment' => '0']); + $tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), ['comment' => 'Doctrine']); + $tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), ['comment' => 'rulez']); + $tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), ['comment' => '666']); + $tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object')); + $tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), ['comment' => '666']); + + $tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), ['comment' => 'Double for real!']); // Add comment to non-commented column. $tableDiff->changedColumns['id'] = new ColumnDiff( 'id', - new Column('id', Type::getType('integer'), array('autoincrement' => true, 'comment' => 'primary')), - array('comment'), - new Column('id', Type::getType('integer'), array('autoincrement' => true)) + new Column('id', Type::getType('integer'), ['autoincrement' => true, 'comment' => 'primary']), + ['comment'], + new Column('id', Type::getType('integer'), ['autoincrement' => true]) ); // Remove comment from null-commented column. $tableDiff->changedColumns['comment_null'] = new ColumnDiff( 'comment_null', new Column('comment_null', Type::getType('string')), - array('type'), - new Column('comment_null', Type::getType('integer'), array('comment' => null)) + ['type'], + new Column('comment_null', Type::getType('integer'), ['comment' => null]) ); // Add comment to false-commented column. $tableDiff->changedColumns['comment_false'] = new ColumnDiff( 'comment_false', - new Column('comment_false', Type::getType('integer'), array('comment' => 'false')), - array('comment'), - new Column('comment_false', Type::getType('integer'), array('comment' => false)) + new Column('comment_false', Type::getType('integer'), ['comment' => 'false']), + ['comment'], + new Column('comment_false', Type::getType('integer'), ['comment' => false]) ); // Change type to custom type from empty string commented column. $tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff( 'comment_empty_string', new Column('comment_empty_string', Type::getType('object')), - array('type'), - new Column('comment_empty_string', Type::getType('integer'), array('comment' => '')) + ['type'], + new Column('comment_empty_string', Type::getType('integer'), ['comment' => '']) ); // Change comment to false-comment from zero-string commented column. $tableDiff->changedColumns['comment_string_0'] = new ColumnDiff( 'comment_string_0', - new Column('comment_string_0', Type::getType('integer'), array('comment' => false)), - array('comment'), - new Column('comment_string_0', Type::getType('integer'), array('comment' => '0')) + new Column('comment_string_0', Type::getType('integer'), ['comment' => false]), + ['comment'], + new Column('comment_string_0', Type::getType('integer'), ['comment' => '0']) ); // Remove comment from regular commented column. $tableDiff->changedColumns['comment'] = new ColumnDiff( 'comment', new Column('comment', Type::getType('integer')), - array('comment'), - new Column('comment', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!')) + ['comment'], + new Column('comment', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']) ); // Change comment and change type to custom type from regular commented column. $tableDiff->changedColumns['`comment_quoted`'] = new ColumnDiff( '`comment_quoted`', - new Column('`comment_quoted`', Type::getType('array'), array('comment' => 'Doctrine array.')), - array('comment', 'type'), - new Column('`comment_quoted`', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!')) + new Column('`comment_quoted`', Type::getType('array'), ['comment' => 'Doctrine array.']), + ['comment', 'type'], + new Column('`comment_quoted`', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']) ); // Remove comment and change type to custom type from regular commented column. $tableDiff->changedColumns['create'] = new ColumnDiff( 'create', new Column('create', Type::getType('object')), - array('comment', 'type'), - new Column('create', Type::getType('integer'), array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')) + ['comment', 'type'], + new Column('create', Type::getType('integer'), ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']) ); // Add comment and change custom type to regular type from non-commented column. $tableDiff->changedColumns['commented_type'] = new ColumnDiff( 'commented_type', - new Column('commented_type', Type::getType('integer'), array('comment' => 'foo')), - array('comment', 'type'), + new Column('commented_type', Type::getType('integer'), ['comment' => 'foo']), + ['comment', 'type'], new Column('commented_type', Type::getType('object')) ); @@ -301,15 +297,15 @@ public function testColumnComments() $tableDiff->changedColumns['commented_type_with_comment'] = new ColumnDiff( 'commented_type_with_comment', new Column('commented_type_with_comment', Type::getType('array')), - array('comment'), - new Column('commented_type_with_comment', Type::getType('array'), array('comment' => 'Doctrine array type.')) + ['comment'], + new Column('commented_type_with_comment', Type::getType('array'), ['comment' => 'Doctrine array type.']) ); - $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), array('comment' => 0)); + $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), ['comment' => 0]); $this->_sm->alterTable($tableDiff); - $columns = $this->_sm->listTableColumns("sqlsrv_column_comment"); + $columns = $this->_sm->listTableColumns('sqlsrv_column_comment'); self::assertCount(23, $columns); self::assertEquals('primary', $columns['id']->getComment()); self::assertNull($columns['comment_null']->getComment()); @@ -346,9 +342,9 @@ public function testPkOrdering() // key_ordinal holds the index ordering. index_column_id is just a unique identifier // for index columns within the given index. $table = new Table('sqlsrv_pk_ordering'); - $table->addColumn('colA', 'integer', array('notnull' => true)); - $table->addColumn('colB', 'integer', array('notnull' => true)); - $table->setPrimaryKey(array('colB', 'colA')); + $table->addColumn('colA', 'integer', ['notnull' => true]); + $table->addColumn('colB', 'integer', ['notnull' => true]); + $table->setPrimaryKey(['colB', 'colA']); $this->_sm->createTable($table); $indexes = $this->_sm->listTableIndexes('sqlsrv_pk_ordering'); @@ -356,7 +352,7 @@ public function testPkOrdering() self::assertCount(1, $indexes); $firstIndex = current($indexes); - $columns = $firstIndex->getColumns(); + $columns = $firstIndex->getColumns(); self::assertCount(2, $columns); self::assertEquals('colB', $columns[0]); self::assertEquals('colA', $columns[1]); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 6c5329a0bab..0a20f5ca4d9 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -6,14 +6,20 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Events; use Doctrine\DBAL\Platforms\OraclePlatform; +use Doctrine\DBAL\Schema\AbstractAsset; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Comparator; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\SchemaDiff; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; +use Doctrine\DBAL\Schema\View; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; use function array_filter; use function array_keys; use function array_map; @@ -23,7 +29,6 @@ use function current; use function end; use function explode; -use function get_class; use function in_array; use function str_replace; use function strcasecmp; @@ -31,20 +36,17 @@ use function strtolower; use function substr; -class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTestCase +class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase { - /** - * @var \Doctrine\DBAL\Schema\AbstractSchemaManager - */ + /** @var AbstractSchemaManager */ protected $_sm; protected function getPlatformName() { - $class = get_class($this); - $e = explode('\\', $class); + $class = static::class; + $e = explode('\\', $class); $testClass = end($e); - $dbms = strtolower(str_replace('SchemaManagerTest', null, $testClass)); - return $dbms; + return strtolower(str_replace('SchemaManagerTest', null, $testClass)); } protected function setUp() @@ -54,7 +56,7 @@ protected function setUp() $dbms = $this->getPlatformName(); if ($this->_conn->getDatabasePlatform()->getName() !== $dbms) { - $this->markTestSkipped(get_class($this) . ' requires the use of ' . $dbms); + $this->markTestSkipped(static::class . ' requires the use of ' . $dbms); } $this->_sm = $this->_conn->getSchemaManager(); @@ -102,7 +104,7 @@ public function testDropsDatabaseWithActiveConnections() $params['dbname'] = 'test_drop_database'; } - $user = $params['user'] ?? null; + $user = $params['user'] ?? null; $password = $params['password'] ?? null; $connection = $this->_conn->getDriver()->connect($params, $user, $password); @@ -119,8 +121,8 @@ public function testDropsDatabaseWithActiveConnections() */ public function testDropAndCreateSequence() { - if ( ! $this->_conn->getDatabasePlatform()->supportsSequences()) { - $this->markTestSkipped($this->_conn->getDriver()->getName().' does not support sequences.'); + if (! $this->_conn->getDatabasePlatform()->supportsSequences()) { + $this->markTestSkipped($this->_conn->getDriver()->getName() . ' does not support sequences.'); } $name = 'dropcreate_sequences_test_seq'; @@ -134,7 +136,7 @@ private function hasElementWithName(array $items, string $name) : bool { $filteredList = array_filter( $items, - function (\Doctrine\DBAL\Schema\AbstractAsset $item) use ($name) : bool { + static function (AbstractAsset $item) use ($name) : bool { return $item->getShortestName($item->getNamespaceName()) === $name; } ); @@ -172,7 +174,7 @@ public function testListSequences() public function testListDatabases() { - if (!$this->_sm->getDatabasePlatform()->supportsCreateDropDatabase()) { + if (! $this->_sm->getDatabasePlatform()->supportsCreateDropDatabase()) { $this->markTestSkipped('Cannot drop Database client side with this Driver.'); } @@ -189,7 +191,7 @@ public function testListDatabases() */ public function testListNamespaceNames() { - if (!$this->_sm->getDatabasePlatform()->supportsSchemas()) { + if (! $this->_sm->getDatabasePlatform()->supportsSchemas()) { $this->markTestSkipped('Platform does not support schemas.'); } @@ -197,7 +199,7 @@ public function testListNamespaceNames() $namespaces = $this->_sm->listNamespaceNames(); $namespaces = array_map('strtolower', $namespaces); - if (!in_array('test_create_schema', $namespaces)) { + if (! in_array('test_create_schema', $namespaces)) { $this->_conn->executeUpdate($this->_sm->getDatabasePlatform()->getCreateSchemaSQL('test_create_schema')); $namespaces = $this->_sm->listNamespaceNames(); @@ -218,29 +220,31 @@ public function testListTables() $foundTable = false; foreach ($tables as $table) { self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table); - if (strtolower($table->getName()) == 'list_tables_test') { - $foundTable = true; - - self::assertTrue($table->hasColumn('id')); - self::assertTrue($table->hasColumn('test')); - self::assertTrue($table->hasColumn('foreign_key_test')); + if (strtolower($table->getName()) !== 'list_tables_test') { + continue; } + + $foundTable = true; + + self::assertTrue($table->hasColumn('id')); + self::assertTrue($table->hasColumn('test')); + self::assertTrue($table->hasColumn('foreign_key_test')); } - self::assertTrue( $foundTable , "The 'list_tables_test' table has to be found."); + self::assertTrue($foundTable, "The 'list_tables_test' table has to be found."); } public function createListTableColumns() { $table = new Table('list_table_columns'); - $table->addColumn('id', 'integer', array('notnull' => true)); - $table->addColumn('test', 'string', array('length' => 255, 'notnull' => false, 'default' => 'expected default')); - $table->addColumn('foo', 'text', array('notnull' => true)); - $table->addColumn('bar', 'decimal', array('precision' => 10, 'scale' => 4, 'notnull' => false)); + $table->addColumn('id', 'integer', ['notnull' => true]); + $table->addColumn('test', 'string', ['length' => 255, 'notnull' => false, 'default' => 'expected default']); + $table->addColumn('foo', 'text', ['notnull' => true]); + $table->addColumn('bar', 'decimal', ['precision' => 10, 'scale' => 4, 'notnull' => false]); $table->addColumn('baz1', 'datetime'); $table->addColumn('baz2', 'time'); $table->addColumn('baz3', 'date'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); return $table; } @@ -251,69 +255,69 @@ public function testListTableColumns() $this->_sm->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns('list_table_columns'); + $columns = $this->_sm->listTableColumns('list_table_columns'); $columnsKeys = array_keys($columns); self::assertArrayHasKey('id', $columns); self::assertEquals(0, array_search('id', $columnsKeys)); - self::assertEquals('id', strtolower($columns['id']->getname())); + self::assertEquals('id', strtolower($columns['id']->getname())); self::assertInstanceOf('Doctrine\DBAL\Types\IntegerType', $columns['id']->gettype()); - self::assertEquals(false, $columns['id']->getunsigned()); - self::assertEquals(true, $columns['id']->getnotnull()); - self::assertEquals(null, $columns['id']->getdefault()); - self::assertInternalType('array', $columns['id']->getPlatformOptions()); + self::assertEquals(false, $columns['id']->getunsigned()); + self::assertEquals(true, $columns['id']->getnotnull()); + self::assertEquals(null, $columns['id']->getdefault()); + self::assertInternalType('array', $columns['id']->getPlatformOptions()); self::assertArrayHasKey('test', $columns); self::assertEquals(1, array_search('test', $columnsKeys)); self::assertEquals('test', strtolower($columns['test']->getname())); self::assertInstanceOf('Doctrine\DBAL\Types\StringType', $columns['test']->gettype()); - self::assertEquals(255, $columns['test']->getlength()); - self::assertEquals(false, $columns['test']->getfixed()); - self::assertEquals(false, $columns['test']->getnotnull()); - self::assertEquals('expected default', $columns['test']->getdefault()); - self::assertInternalType('array', $columns['test']->getPlatformOptions()); + self::assertEquals(255, $columns['test']->getlength()); + self::assertEquals(false, $columns['test']->getfixed()); + self::assertEquals(false, $columns['test']->getnotnull()); + self::assertEquals('expected default', $columns['test']->getdefault()); + self::assertInternalType('array', $columns['test']->getPlatformOptions()); - self::assertEquals('foo', strtolower($columns['foo']->getname())); + self::assertEquals('foo', strtolower($columns['foo']->getname())); self::assertEquals(2, array_search('foo', $columnsKeys)); self::assertInstanceOf('Doctrine\DBAL\Types\TextType', $columns['foo']->gettype()); - self::assertEquals(false, $columns['foo']->getunsigned()); - self::assertEquals(false, $columns['foo']->getfixed()); - self::assertEquals(true, $columns['foo']->getnotnull()); - self::assertEquals(null, $columns['foo']->getdefault()); - self::assertInternalType('array', $columns['foo']->getPlatformOptions()); + self::assertEquals(false, $columns['foo']->getunsigned()); + self::assertEquals(false, $columns['foo']->getfixed()); + self::assertEquals(true, $columns['foo']->getnotnull()); + self::assertEquals(null, $columns['foo']->getdefault()); + self::assertInternalType('array', $columns['foo']->getPlatformOptions()); - self::assertEquals('bar', strtolower($columns['bar']->getname())); + self::assertEquals('bar', strtolower($columns['bar']->getname())); self::assertEquals(3, array_search('bar', $columnsKeys)); self::assertInstanceOf('Doctrine\DBAL\Types\DecimalType', $columns['bar']->gettype()); - self::assertEquals(null, $columns['bar']->getlength()); - self::assertEquals(10, $columns['bar']->getprecision()); - self::assertEquals(4, $columns['bar']->getscale()); - self::assertEquals(false, $columns['bar']->getunsigned()); - self::assertEquals(false, $columns['bar']->getfixed()); - self::assertEquals(false, $columns['bar']->getnotnull()); - self::assertEquals(null, $columns['bar']->getdefault()); - self::assertInternalType('array', $columns['bar']->getPlatformOptions()); + self::assertEquals(null, $columns['bar']->getlength()); + self::assertEquals(10, $columns['bar']->getprecision()); + self::assertEquals(4, $columns['bar']->getscale()); + self::assertEquals(false, $columns['bar']->getunsigned()); + self::assertEquals(false, $columns['bar']->getfixed()); + self::assertEquals(false, $columns['bar']->getnotnull()); + self::assertEquals(null, $columns['bar']->getdefault()); + self::assertInternalType('array', $columns['bar']->getPlatformOptions()); self::assertEquals('baz1', strtolower($columns['baz1']->getname())); self::assertEquals(4, array_search('baz1', $columnsKeys)); self::assertInstanceOf('Doctrine\DBAL\Types\DateTimeType', $columns['baz1']->gettype()); - self::assertEquals(true, $columns['baz1']->getnotnull()); - self::assertEquals(null, $columns['baz1']->getdefault()); - self::assertInternalType('array', $columns['baz1']->getPlatformOptions()); + self::assertEquals(true, $columns['baz1']->getnotnull()); + self::assertEquals(null, $columns['baz1']->getdefault()); + self::assertInternalType('array', $columns['baz1']->getPlatformOptions()); self::assertEquals('baz2', strtolower($columns['baz2']->getname())); self::assertEquals(5, array_search('baz2', $columnsKeys)); - self::assertContains($columns['baz2']->gettype()->getName(), array('time', 'date', 'datetime')); - self::assertEquals(true, $columns['baz2']->getnotnull()); - self::assertEquals(null, $columns['baz2']->getdefault()); - self::assertInternalType('array', $columns['baz2']->getPlatformOptions()); + self::assertContains($columns['baz2']->gettype()->getName(), ['time', 'date', 'datetime']); + self::assertEquals(true, $columns['baz2']->getnotnull()); + self::assertEquals(null, $columns['baz2']->getdefault()); + self::assertInternalType('array', $columns['baz2']->getPlatformOptions()); self::assertEquals('baz3', strtolower($columns['baz3']->getname())); self::assertEquals(6, array_search('baz3', $columnsKeys)); - self::assertContains($columns['baz3']->gettype()->getName(), array('time', 'date', 'datetime')); - self::assertEquals(true, $columns['baz3']->getnotnull()); - self::assertEquals(null, $columns['baz3']->getdefault()); - self::assertInternalType('array', $columns['baz3']->getPlatformOptions()); + self::assertContains($columns['baz3']->gettype()->getName(), ['time', 'date', 'datetime']); + self::assertEquals(true, $columns['baz3']->getnotnull()); + self::assertEquals(null, $columns['baz3']->getdefault()); + self::assertInternalType('array', $columns['baz3']->getPlatformOptions()); } /** @@ -324,7 +328,7 @@ public function testListTableColumnsWithFixedStringColumn() $tableName = 'test_list_table_fixed_string'; $table = new Table($tableName); - $table->addColumn('column_char', 'string', array('fixed' => true, 'length' => 2)); + $table->addColumn('column_char', 'string', ['fixed' => true, 'length' => 2]); $this->_sm->createTable($table); @@ -353,7 +357,7 @@ public function testListTableColumnsDispatchEvent() $oldEventManager = $this->_sm->getDatabasePlatform()->getEventManager(); $eventManager = new EventManager(); - $eventManager->addEventListener(array(Events::onSchemaColumnDefinition), $listenerMock); + $eventManager->addEventListener([Events::onSchemaColumnDefinition], $listenerMock); $this->_sm->getDatabasePlatform()->setEventManager($eventManager); @@ -365,8 +369,8 @@ public function testListTableColumnsDispatchEvent() public function testListTableIndexesDispatchEvent() { $table = $this->getTestTable('list_table_indexes_test'); - $table->addUniqueIndex(array('test'), 'test_index_name'); - $table->addIndex(array('id', 'test'), 'test_composite_idx'); + $table->addUniqueIndex(['test'], 'test_index_name'); + $table->addIndex(['id', 'test'], 'test_composite_idx'); $this->_sm->dropAndCreateTable($table); @@ -381,7 +385,7 @@ public function testListTableIndexesDispatchEvent() $oldEventManager = $this->_sm->getDatabasePlatform()->getEventManager(); $eventManager = new EventManager(); - $eventManager->addEventListener(array(Events::onSchemaIndexDefinition), $listenerMock); + $eventManager->addEventListener([Events::onSchemaIndexDefinition], $listenerMock); $this->_sm->getDatabasePlatform()->setEventManager($eventManager); @@ -392,7 +396,7 @@ public function testListTableIndexesDispatchEvent() public function testDiffListTableColumns() { - if ($this->_sm->getDatabasePlatform()->getName() == 'oracle') { + if ($this->_sm->getDatabasePlatform()->getName() === 'oracle') { $this->markTestSkipped('Does not work with Oracle, since it cannot detect DateTime, Date and Time differenecs (at the moment).'); } @@ -400,17 +404,17 @@ public function testDiffListTableColumns() $this->_sm->dropAndCreateTable($offlineTable); $onlineTable = $this->_sm->listTableDetails('list_table_columns'); - $comparator = new \Doctrine\DBAL\Schema\Comparator(); - $diff = $comparator->diffTable($offlineTable, $onlineTable); + $comparator = new Comparator(); + $diff = $comparator->diffTable($offlineTable, $onlineTable); - self::assertFalse($diff, "No differences should be detected with the offline vs online schema."); + self::assertFalse($diff, 'No differences should be detected with the offline vs online schema.'); } public function testListTableIndexes() { $table = $this->getTestCompositeTable('list_table_indexes_test'); - $table->addUniqueIndex(array('test'), 'test_index_name'); - $table->addIndex(array('id', 'test'), 'test_composite_idx'); + $table->addUniqueIndex(['test'], 'test_index_name'); + $table->addIndex(['id', 'test'], 'test_composite_idx'); $this->_sm->dropAndCreateTable($table); @@ -419,17 +423,17 @@ public function testListTableIndexes() self::assertEquals(3, count($tableIndexes)); self::assertArrayHasKey('primary', $tableIndexes, 'listTableIndexes() has to return a "primary" array key.'); - self::assertEquals(array('id', 'other_id'), array_map('strtolower', $tableIndexes['primary']->getColumns())); + self::assertEquals(['id', 'other_id'], array_map('strtolower', $tableIndexes['primary']->getColumns())); self::assertTrue($tableIndexes['primary']->isUnique()); self::assertTrue($tableIndexes['primary']->isPrimary()); self::assertEquals('test_index_name', strtolower($tableIndexes['test_index_name']->getName())); - self::assertEquals(array('test'), array_map('strtolower', $tableIndexes['test_index_name']->getColumns())); + self::assertEquals(['test'], array_map('strtolower', $tableIndexes['test_index_name']->getColumns())); self::assertTrue($tableIndexes['test_index_name']->isUnique()); self::assertFalse($tableIndexes['test_index_name']->isPrimary()); self::assertEquals('test_composite_idx', strtolower($tableIndexes['test_composite_idx']->getName())); - self::assertEquals(array('id', 'test'), array_map('strtolower', $tableIndexes['test_composite_idx']->getColumns())); + self::assertEquals(['id', 'test'], array_map('strtolower', $tableIndexes['test_composite_idx']->getColumns())); self::assertFalse($tableIndexes['test_composite_idx']->isUnique()); self::assertFalse($tableIndexes['test_composite_idx']->isPrimary()); } @@ -437,22 +441,22 @@ public function testListTableIndexes() public function testDropAndCreateIndex() { $table = $this->getTestTable('test_create_index'); - $table->addUniqueIndex(array('test'), 'test'); + $table->addUniqueIndex(['test'], 'test'); $this->_sm->dropAndCreateTable($table); $this->_sm->dropAndCreateIndex($table->getIndex('test'), $table); $tableIndexes = $this->_sm->listTableIndexes('test_create_index'); self::assertInternalType('array', $tableIndexes); - self::assertEquals('test', strtolower($tableIndexes['test']->getName())); - self::assertEquals(array('test'), array_map('strtolower', $tableIndexes['test']->getColumns())); + self::assertEquals('test', strtolower($tableIndexes['test']->getName())); + self::assertEquals(['test'], array_map('strtolower', $tableIndexes['test']->getColumns())); self::assertTrue($tableIndexes['test']->isUnique()); self::assertFalse($tableIndexes['test']->isPrimary()); } public function testCreateTableWithForeignKeys() { - if(!$this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Platform does not support foreign keys.'); } @@ -461,34 +465,38 @@ public function testCreateTableWithForeignKeys() $this->_sm->dropAndCreateTable($tableB); $tableA = $this->getTestTable('test_create_fk'); - $tableA->addForeignKeyConstraint('test_foreign', array('foreign_key_test'), array('id')); + $tableA->addForeignKeyConstraint('test_foreign', ['foreign_key_test'], ['id']); $this->_sm->dropAndCreateTable($tableA); - $fkTable = $this->_sm->listTableDetails('test_create_fk'); + $fkTable = $this->_sm->listTableDetails('test_create_fk'); $fkConstraints = $fkTable->getForeignKeys(); self::assertEquals(1, count($fkConstraints), "Table 'test_create_fk1' has to have one foreign key."); $fkConstraint = current($fkConstraints); self::assertInstanceOf('\Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkConstraint); - self::assertEquals('test_foreign', strtolower($fkConstraint->getForeignTableName())); - self::assertEquals(array('foreign_key_test'), array_map('strtolower', $fkConstraint->getColumns())); - self::assertEquals(array('id'), array_map('strtolower', $fkConstraint->getForeignColumns())); + self::assertEquals('test_foreign', strtolower($fkConstraint->getForeignTableName())); + self::assertEquals(['foreign_key_test'], array_map('strtolower', $fkConstraint->getColumns())); + self::assertEquals(['id'], array_map('strtolower', $fkConstraint->getForeignColumns())); - self::assertTrue($fkTable->columnsAreIndexed($fkConstraint->getColumns()), "The columns of a foreign key constraint should always be indexed."); + self::assertTrue($fkTable->columnsAreIndexed($fkConstraint->getColumns()), 'The columns of a foreign key constraint should always be indexed.'); } public function testListForeignKeys() { - if(!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); } $this->createTestTable('test_create_fk1'); $this->createTestTable('test_create_fk2'); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_key_test'), 'test_create_fk2', array('id'), 'foreign_key_test_fk', array('onDelete' => 'CASCADE') + $foreignKey = new ForeignKeyConstraint( + ['foreign_key_test'], + 'test_create_fk2', + ['id'], + 'foreign_key_test_fk', + ['onDelete' => 'CASCADE'] ); $this->_sm->createForeignKey($foreignKey, 'test_create_fk1'); @@ -498,13 +506,15 @@ public function testListForeignKeys() self::assertEquals(1, count($fkeys), "Table 'test_create_fk1' has to have one foreign key."); self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]); - self::assertEquals(array('foreign_key_test'), array_map('strtolower', $fkeys[0]->getLocalColumns())); - self::assertEquals(array('id'), array_map('strtolower', $fkeys[0]->getForeignColumns())); - self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName())); + self::assertEquals(['foreign_key_test'], array_map('strtolower', $fkeys[0]->getLocalColumns())); + self::assertEquals(['id'], array_map('strtolower', $fkeys[0]->getForeignColumns())); + self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName())); - if($fkeys[0]->hasOption('onDelete')) { - self::assertEquals('CASCADE', $fkeys[0]->getOption('onDelete')); + if (! $fkeys[0]->hasOption('onDelete')) { + return; } + + self::assertEquals('CASCADE', $fkeys[0]->getOption('onDelete')); } protected function getCreateExampleViewSql() @@ -522,7 +532,7 @@ public function testCreateSchema() public function testAlterTableScenario() { - if(!$this->_sm->getDatabasePlatform()->supportsAlterTable()) { + if (! $this->_sm->getDatabasePlatform()->supportsAlterTable()) { $this->markTestSkipped('Alter Table is not supported by this platform.'); } @@ -536,9 +546,9 @@ public function testAlterTableScenario() self::assertEquals(0, count($table->getForeignKeys())); self::assertEquals(1, count($table->getIndexes())); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table"); - $tableDiff->fromTable = $alterTable; - $tableDiff->addedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', Type::getType('integer')); + $tableDiff = new TableDiff('alter_table'); + $tableDiff->fromTable = $alterTable; + $tableDiff->addedColumns['foo'] = new Column('foo', Type::getType('integer')); $tableDiff->removedColumns['test'] = $table->getColumn('test'); $this->_sm->alterTable($tableDiff); @@ -547,33 +557,33 @@ public function testAlterTableScenario() self::assertFalse($table->hasColumn('test')); self::assertTrue($table->hasColumn('foo')); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table"); - $tableDiff->fromTable = $table; - $tableDiff->addedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo')); + $tableDiff = new TableDiff('alter_table'); + $tableDiff->fromTable = $table; + $tableDiff->addedIndexes[] = new Index('foo_idx', ['foo']); $this->_sm->alterTable($tableDiff); $table = $this->_sm->listTableDetails('alter_table'); self::assertEquals(2, count($table->getIndexes())); self::assertTrue($table->hasIndex('foo_idx')); - self::assertEquals(array('foo'), array_map('strtolower', $table->getIndex('foo_idx')->getColumns())); + self::assertEquals(['foo'], array_map('strtolower', $table->getIndex('foo_idx')->getColumns())); self::assertFalse($table->getIndex('foo_idx')->isPrimary()); self::assertFalse($table->getIndex('foo_idx')->isUnique()); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table"); - $tableDiff->fromTable = $table; - $tableDiff->changedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo', 'foreign_key_test')); + $tableDiff = new TableDiff('alter_table'); + $tableDiff->fromTable = $table; + $tableDiff->changedIndexes[] = new Index('foo_idx', ['foo', 'foreign_key_test']); $this->_sm->alterTable($tableDiff); $table = $this->_sm->listTableDetails('alter_table'); self::assertEquals(2, count($table->getIndexes())); self::assertTrue($table->hasIndex('foo_idx')); - self::assertEquals(array('foo', 'foreign_key_test'), array_map('strtolower', $table->getIndex('foo_idx')->getColumns())); + self::assertEquals(['foo', 'foreign_key_test'], array_map('strtolower', $table->getIndex('foo_idx')->getColumns())); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table"); - $tableDiff->fromTable = $table; - $tableDiff->renamedIndexes['foo_idx'] = new \Doctrine\DBAL\Schema\Index('bar_idx', array('foo', 'foreign_key_test')); + $tableDiff = new TableDiff('alter_table'); + $tableDiff->fromTable = $table; + $tableDiff->renamedIndexes['foo_idx'] = new Index('bar_idx', ['foo', 'foreign_key_test']); $this->_sm->alterTable($tableDiff); @@ -581,14 +591,14 @@ public function testAlterTableScenario() self::assertEquals(2, count($table->getIndexes())); self::assertTrue($table->hasIndex('bar_idx')); self::assertFalse($table->hasIndex('foo_idx')); - self::assertEquals(array('foo', 'foreign_key_test'), array_map('strtolower', $table->getIndex('bar_idx')->getColumns())); + self::assertEquals(['foo', 'foreign_key_test'], array_map('strtolower', $table->getIndex('bar_idx')->getColumns())); self::assertFalse($table->getIndex('bar_idx')->isPrimary()); self::assertFalse($table->getIndex('bar_idx')->isUnique()); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table"); - $tableDiff->fromTable = $table; - $tableDiff->removedIndexes[] = new \Doctrine\DBAL\Schema\Index('bar_idx', array('foo', 'foreign_key_test')); - $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('foreign_key_test'), 'alter_table_foreign', array('id')); + $tableDiff = new TableDiff('alter_table'); + $tableDiff->fromTable = $table; + $tableDiff->removedIndexes[] = new Index('bar_idx', ['foo', 'foreign_key_test']); + $fk = new ForeignKeyConstraint(['foreign_key_test'], 'alter_table_foreign', ['id']); $tableDiff->addedForeignKeys[] = $fk; $this->_sm->alterTable($tableDiff); @@ -597,14 +607,16 @@ public function testAlterTableScenario() // dont check for index size here, some platforms automatically add indexes for foreign keys. self::assertFalse($table->hasIndex('bar_idx')); - if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $fks = $table->getForeignKeys(); - self::assertCount(1, $fks); - $foreignKey = current($fks); - self::assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName())); - self::assertEquals(array('foreign_key_test'), array_map('strtolower', $foreignKey->getColumns())); - self::assertEquals(array('id'), array_map('strtolower', $foreignKey->getForeignColumns())); + if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + return; } + + $fks = $table->getForeignKeys(); + self::assertCount(1, $fks); + $foreignKey = current($fks); + self::assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName())); + self::assertEquals(['foreign_key_test'], array_map('strtolower', $foreignKey->getColumns())); + self::assertEquals(['id'], array_map('strtolower', $foreignKey->getForeignColumns())); } @@ -634,16 +646,16 @@ public function testTableInNamespace() public function testCreateAndListViews() { - if (!$this->_sm->getDatabasePlatform()->supportsViews()) { + if (! $this->_sm->getDatabasePlatform()->supportsViews()) { $this->markTestSkipped('Views is not supported by this platform.'); } $this->createTestTable('view_test_table'); - $name = "doctrine_test_view"; - $sql = "SELECT * FROM view_test_table"; + $name = 'doctrine_test_view'; + $sql = 'SELECT * FROM view_test_table'; - $view = new \Doctrine\DBAL\Schema\View($name, $sql); + $view = new View($name, $sql); $this->_sm->dropAndCreateView($view); @@ -652,14 +664,14 @@ public function testCreateAndListViews() public function testAutoincrementDetection() { - if (!$this->_sm->getDatabasePlatform()->supportsIdentityColumns()) { + if (! $this->_sm->getDatabasePlatform()->supportsIdentityColumns()) { $this->markTestSkipped('This test is only supported on platforms that have autoincrement'); } $table = new Table('test_autoincrement'); $table->setSchemaConfig($this->_sm->createSchemaConfig()); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -673,7 +685,7 @@ public function testAutoincrementDetection() */ public function testAutoincrementDetectionMulticolumns() { - if (!$this->_sm->getDatabasePlatform()->supportsIdentityColumns()) { + if (! $this->_sm->getDatabasePlatform()->supportsIdentityColumns()) { $this->markTestSkipped('This test is only supported on platforms that have autoincrement'); } @@ -681,7 +693,7 @@ public function testAutoincrementDetectionMulticolumns() $table->setSchemaConfig($this->_sm->createSchemaConfig()); $table->addColumn('id', 'integer'); $table->addColumn('other_id', 'integer'); - $table->setPrimaryKey(array('id', 'other_id')); + $table->setPrimaryKey(['id', 'other_id']); $this->_sm->createTable($table); @@ -695,21 +707,21 @@ public function testAutoincrementDetectionMulticolumns() */ public function testUpdateSchemaWithForeignKeyRenaming() { - if (!$this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('This test is only supported on platforms that have foreign keys.'); } $table = new Table('test_fk_base'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $tableFK = new Table('test_fk_rename'); $tableFK->setSchemaConfig($this->_sm->createSchemaConfig()); $tableFK->addColumn('id', 'integer'); $tableFK->addColumn('fk_id', 'integer'); - $tableFK->setPrimaryKey(array('id')); - $tableFK->addIndex(array('fk_id'), 'fk_idx'); - $tableFK->addForeignKeyConstraint('test_fk_base', array('fk_id'), array('id')); + $tableFK->setPrimaryKey(['id']); + $tableFK->addIndex(['fk_id'], 'fk_idx'); + $tableFK->addForeignKeyConstraint('test_fk_base', ['fk_id'], ['id']); $this->_sm->createTable($table); $this->_sm->createTable($tableFK); @@ -718,11 +730,11 @@ public function testUpdateSchemaWithForeignKeyRenaming() $tableFKNew->setSchemaConfig($this->_sm->createSchemaConfig()); $tableFKNew->addColumn('id', 'integer'); $tableFKNew->addColumn('rename_fk_id', 'integer'); - $tableFKNew->setPrimaryKey(array('id')); - $tableFKNew->addIndex(array('rename_fk_id'), 'fk_idx'); - $tableFKNew->addForeignKeyConstraint('test_fk_base', array('rename_fk_id'), array('id')); + $tableFKNew->setPrimaryKey(['id']); + $tableFKNew->addIndex(['rename_fk_id'], 'fk_idx'); + $tableFKNew->addForeignKeyConstraint('test_fk_base', ['rename_fk_id'], ['id']); - $c = new \Doctrine\DBAL\Schema\Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableFK, $tableFKNew); $this->_sm->alterTable($tableDiff); @@ -746,16 +758,16 @@ public function testRenameIndexUsedInForeignKeyConstraint() $primaryTable = new Table('test_rename_index_primary'); $primaryTable->addColumn('id', 'integer'); - $primaryTable->setPrimaryKey(array('id')); + $primaryTable->setPrimaryKey(['id']); $foreignTable = new Table('test_rename_index_foreign'); $foreignTable->addColumn('fk', 'integer'); - $foreignTable->addIndex(array('fk'), 'rename_index_fk_idx'); + $foreignTable->addIndex(['fk'], 'rename_index_fk_idx'); $foreignTable->addForeignKeyConstraint( 'test_rename_index_primary', - array('fk'), - array('id'), - array(), + ['fk'], + ['id'], + [], 'fk_constraint' ); @@ -781,37 +793,41 @@ public function testRenameIndexUsedInForeignKeyConstraint() */ public function testGetColumnComment() { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() != 'mssql') { + $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } $table = new Table('column_comment_test'); - $table->addColumn('id', 'integer', array('comment' => 'This is a comment')); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); - $columns = $this->_sm->listTableColumns("column_comment_test"); + $columns = $this->_sm->listTableColumns('column_comment_test'); self::assertEquals(1, count($columns)); self::assertEquals('This is a comment', $columns['id']->getComment()); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff('column_comment_test'); - $tableDiff->fromTable = $table; - $tableDiff->changedColumns['id'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'id', new \Doctrine\DBAL\Schema\Column( - 'id', \Doctrine\DBAL\Types\Type::getType('integer') + $tableDiff = new TableDiff('column_comment_test'); + $tableDiff->fromTable = $table; + $tableDiff->changedColumns['id'] = new ColumnDiff( + 'id', + new Column( + 'id', + Type::getType('integer') ), - array('comment'), - new \Doctrine\DBAL\Schema\Column( - 'id', \Doctrine\DBAL\Types\Type::getType('integer'), array('comment' => 'This is a comment') + ['comment'], + new Column( + 'id', + Type::getType('integer'), + ['comment' => 'This is a comment'] ) ); $this->_sm->alterTable($tableDiff); - $columns = $this->_sm->listTableColumns("column_comment_test"); + $columns = $this->_sm->listTableColumns('column_comment_test'); self::assertEquals(1, count($columns)); self::assertEmpty($columns['id']->getComment()); } @@ -821,27 +837,27 @@ public function testGetColumnComment() */ public function testAutomaticallyAppendCommentOnMarkedColumns() { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() != 'mssql') { + $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } $table = new Table('column_comment_test2'); - $table->addColumn('id', 'integer', array('comment' => 'This is a comment')); - $table->addColumn('obj', 'object', array('comment' => 'This is a comment')); - $table->addColumn('arr', 'array', array('comment' => 'This is a comment')); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); + $table->addColumn('obj', 'object', ['comment' => 'This is a comment']); + $table->addColumn('arr', 'array', ['comment' => 'This is a comment']); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); - $columns = $this->_sm->listTableColumns("column_comment_test2"); + $columns = $this->_sm->listTableColumns('column_comment_test2'); self::assertEquals(3, count($columns)); self::assertEquals('This is a comment', $columns['id']->getComment()); - self::assertEquals('This is a comment', $columns['obj']->getComment(), "The Doctrine2 Typehint should be stripped from comment."); - self::assertInstanceOf('Doctrine\DBAL\Types\ObjectType', $columns['obj']->getType(), "The Doctrine2 should be detected from comment hint."); - self::assertEquals('This is a comment', $columns['arr']->getComment(), "The Doctrine2 Typehint should be stripped from comment."); - self::assertInstanceOf('Doctrine\DBAL\Types\ArrayType', $columns['arr']->getType(), "The Doctrine2 should be detected from comment hint."); + self::assertEquals('This is a comment', $columns['obj']->getComment(), 'The Doctrine2 Typehint should be stripped from comment.'); + self::assertInstanceOf('Doctrine\DBAL\Types\ObjectType', $columns['obj']->getType(), 'The Doctrine2 should be detected from comment hint.'); + self::assertEquals('This is a comment', $columns['arr']->getComment(), 'The Doctrine2 Typehint should be stripped from comment.'); + self::assertInstanceOf('Doctrine\DBAL\Types\ArrayType', $columns['arr']->getType(), 'The Doctrine2 should be detected from comment hint.'); } /** @@ -849,24 +865,24 @@ public function testAutomaticallyAppendCommentOnMarkedColumns() */ public function testCommentHintOnDateIntervalTypeColumn() { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() != 'mssql') { + $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } $table = new Table('column_dateinterval_comment'); - $table->addColumn('id', 'integer', array('comment' => 'This is a comment')); - $table->addColumn('date_interval', 'dateinterval', array('comment' => 'This is a comment')); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); + $table->addColumn('date_interval', 'dateinterval', ['comment' => 'This is a comment']); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); - $columns = $this->_sm->listTableColumns("column_dateinterval_comment"); + $columns = $this->_sm->listTableColumns('column_dateinterval_comment'); self::assertEquals(2, count($columns)); self::assertEquals('This is a comment', $columns['id']->getComment()); - self::assertEquals('This is a comment', $columns['date_interval']->getComment(), "The Doctrine2 Typehint should be stripped from comment."); - self::assertInstanceOf('Doctrine\DBAL\Types\DateIntervalType', $columns['date_interval']->getType(), "The Doctrine2 should be detected from comment hint."); + self::assertEquals('This is a comment', $columns['date_interval']->getComment(), 'The Doctrine2 Typehint should be stripped from comment.'); + self::assertInstanceOf('Doctrine\DBAL\Types\DateIntervalType', $columns['date_interval']->getType(), 'The Doctrine2 should be detected from comment hint.'); } /** @@ -877,25 +893,25 @@ public function testChangeColumnsTypeWithDefaultValue() $tableName = 'column_def_change_type'; $table = new Table($tableName); - $table->addColumn('col_int', 'smallint', array('default' => 666)); - $table->addColumn('col_string', 'string', array('default' => 'foo')); + $table->addColumn('col_int', 'smallint', ['default' => 666]); + $table->addColumn('col_string', 'string', ['default' => 'foo']); $this->_sm->dropAndCreateTable($table); - $tableDiff = new TableDiff($tableName); - $tableDiff->fromTable = $table; + $tableDiff = new TableDiff($tableName); + $tableDiff->fromTable = $table; $tableDiff->changedColumns['col_int'] = new ColumnDiff( 'col_int', - new Column('col_int', Type::getType('integer'), array('default' => 666)), - array('type'), - new Column('col_int', Type::getType('smallint'), array('default' => 666)) + new Column('col_int', Type::getType('integer'), ['default' => 666]), + ['type'], + new Column('col_int', Type::getType('smallint'), ['default' => 666]) ); $tableDiff->changedColumns['col_string'] = new ColumnDiff( 'col_string', - new Column('col_string', Type::getType('string'), array('default' => 'foo', 'fixed' => true)), - array('fixed'), - new Column('col_string', Type::getType('string'), array('default' => 'foo')) + new Column('col_string', Type::getType('string'), ['default' => 'foo', 'fixed' => true]), + ['fixed'], + new Column('col_string', Type::getType('string'), ['default' => 'foo']) ); $this->_sm->alterTable($tableDiff); @@ -931,9 +947,10 @@ public function testListTableWithBlob() /** * @param string $name * @param array $data + * * @return Table */ - protected function createTestTable($name = 'test_table', $data = array()) + protected function createTestTable($name = 'test_table', $data = []) { $options = $data['options'] ?? []; @@ -944,25 +961,25 @@ protected function createTestTable($name = 'test_table', $data = array()) return $table; } - protected function getTestTable($name, $options=array()) + protected function getTestTable($name, $options = []) { - $table = new Table($name, array(), array(), array(), false, $options); + $table = new Table($name, [], [], [], false, $options); $table->setSchemaConfig($this->_sm->createSchemaConfig()); - $table->addColumn('id', 'integer', array('notnull' => true)); - $table->setPrimaryKey(array('id')); - $table->addColumn('test', 'string', array('length' => 255)); + $table->addColumn('id', 'integer', ['notnull' => true]); + $table->setPrimaryKey(['id']); + $table->addColumn('test', 'string', ['length' => 255]); $table->addColumn('foreign_key_test', 'integer'); return $table; } protected function getTestCompositeTable($name) { - $table = new Table($name, array(), array(), array(), false, array()); + $table = new Table($name, [], [], [], false, []); $table->setSchemaConfig($this->_sm->createSchemaConfig()); - $table->addColumn('id', 'integer', array('notnull' => true)); - $table->addColumn('other_id', 'integer', array('notnull' => true)); - $table->setPrimaryKey(array('id', 'other_id')); - $table->addColumn('test', 'string', array('length' => 255)); + $table->addColumn('id', 'integer', ['notnull' => true]); + $table->addColumn('other_id', 'integer', ['notnull' => true]); + $table->setPrimaryKey(['id', 'other_id']); + $table->addColumn('test', 'string', ['length' => 255]); return $table; } @@ -971,24 +988,29 @@ protected function assertHasTable($tables, $tableName) $foundTable = false; foreach ($tables as $table) { self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table, 'No Table instance was found in tables array.'); - if (strtolower($table->getName()) == 'list_tables_test_new_name') { - $foundTable = true; + if (strtolower($table->getName()) !== 'list_tables_test_new_name') { + continue; } + + $foundTable = true; } - self::assertTrue($foundTable, "Could not find new table"); + self::assertTrue($foundTable, 'Could not find new table'); } public function testListForeignKeysComposite() { - if(!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); } $this->_sm->createTable($this->getTestTable('test_create_fk3')); $this->_sm->createTable($this->getTestCompositeTable('test_create_fk4')); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('id', 'foreign_key_test'), 'test_create_fk4', array('id', 'other_id'), 'foreign_key_test_fk2' + $foreignKey = new ForeignKeyConstraint( + ['id', 'foreign_key_test'], + 'test_create_fk4', + ['id', 'other_id'], + 'foreign_key_test_fk2' ); $this->_sm->createForeignKey($foreignKey, 'test_create_fk3'); @@ -998,8 +1020,8 @@ public function testListForeignKeysComposite() self::assertEquals(1, count($fkeys), "Table 'test_create_fk3' has to have one foreign key."); self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]); - self::assertEquals(array('id', 'foreign_key_test'), array_map('strtolower', $fkeys[0]->getLocalColumns())); - self::assertEquals(array('id', 'other_id'), array_map('strtolower', $fkeys[0]->getForeignColumns())); + self::assertEquals(['id', 'foreign_key_test'], array_map('strtolower', $fkeys[0]->getLocalColumns())); + self::assertEquals(['id', 'other_id'], array_map('strtolower', $fkeys[0]->getForeignColumns())); } /** @@ -1007,16 +1029,16 @@ public function testListForeignKeysComposite() */ public function testColumnDefaultLifecycle() { - $table = new Table("col_def_lifecycle"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->addColumn('column1', 'string', array('default' => null)); - $table->addColumn('column2', 'string', array('default' => false)); - $table->addColumn('column3', 'string', array('default' => true)); - $table->addColumn('column4', 'string', array('default' => 0)); - $table->addColumn('column5', 'string', array('default' => '')); - $table->addColumn('column6', 'string', array('default' => 'def')); - $table->addColumn('column7', 'integer', array('default' => 0)); - $table->setPrimaryKey(array('id')); + $table = new Table('col_def_lifecycle'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->addColumn('column1', 'string', ['default' => null]); + $table->addColumn('column2', 'string', ['default' => false]); + $table->addColumn('column3', 'string', ['default' => true]); + $table->addColumn('column4', 'string', ['default' => 0]); + $table->addColumn('column5', 'string', ['default' => '']); + $table->addColumn('column6', 'string', ['default' => 'def']); + $table->addColumn('column7', 'integer', ['default' => 0]); + $table->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($table); @@ -1033,13 +1055,13 @@ public function testColumnDefaultLifecycle() $diffTable = clone $table; - $diffTable->changeColumn('column1', array('default' => false)); - $diffTable->changeColumn('column2', array('default' => null)); - $diffTable->changeColumn('column3', array('default' => false)); - $diffTable->changeColumn('column4', array('default' => null)); - $diffTable->changeColumn('column5', array('default' => false)); - $diffTable->changeColumn('column6', array('default' => 666)); - $diffTable->changeColumn('column7', array('default' => null)); + $diffTable->changeColumn('column1', ['default' => false]); + $diffTable->changeColumn('column2', ['default' => null]); + $diffTable->changeColumn('column3', ['default' => false]); + $diffTable->changeColumn('column4', ['default' => null]); + $diffTable->changeColumn('column5', ['default' => false]); + $diffTable->changeColumn('column6', ['default' => 666]); + $diffTable->changeColumn('column7', ['default' => null]); $comparator = new Comparator(); @@ -1062,9 +1084,9 @@ public function testListTableWithBinary() $table = new Table($tableName); $table->addColumn('id', 'integer'); - $table->addColumn('column_varbinary', 'binary', array()); - $table->addColumn('column_binary', 'binary', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('column_varbinary', 'binary', []); + $table->addColumn('column_binary', 'binary', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -1079,7 +1101,7 @@ public function testListTableWithBinary() public function testListTableDetailsWithFullQualifiedTableName() { - if ( ! $this->_sm->getDatabasePlatform()->supportsSchemas()) { + if (! $this->_sm->getDatabasePlatform()->supportsSchemas()) { $this->markTestSkipped('Test only works on platforms that support schemas.'); } @@ -1088,18 +1110,18 @@ public function testListTableDetailsWithFullQualifiedTableName() $foreignTableName = 'foreign_table'; $table = new Table($foreignTableName); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($table); $table = new Table($primaryTableName); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'string'); - $table->addForeignKeyConstraint($foreignTableName, array('foo'), array('id')); - $table->addIndex(array('bar')); - $table->setPrimaryKey(array('id')); + $table->addForeignKeyConstraint($foreignTableName, ['foo'], ['id']); + $table->addIndex(['bar']); + $table->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($table); @@ -1119,38 +1141,38 @@ public function testListTableDetailsWithFullQualifiedTableName() public function testCommentStringsAreQuoted() { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() != 'mssql') { + $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } $table = new Table('my_table'); - $table->addColumn('id', 'integer', array('comment' => "It's a comment with a quote")); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['comment' => "It's a comment with a quote"]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); - $columns = $this->_sm->listTableColumns("my_table"); + $columns = $this->_sm->listTableColumns('my_table'); self::assertEquals("It's a comment with a quote", $columns['id']->getComment()); } public function testCommentNotDuplicated() { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments()) { + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments()) { $this->markTestSkipped('Database does not support column comments.'); } - $options = array( + $options = [ 'type' => Type::getType('integer'), 'default' => 0, 'notnull' => true, 'comment' => 'expected+column+comment', - ); + ]; $columnDefinition = substr($this->_conn->getDatabasePlatform()->getColumnDeclarationSQL('id', $options), strlen('id') + 1); $table = new Table('my_table'); - $table->addColumn('id', 'integer', array('columnDefinition' => $columnDefinition, 'comment' => 'unexpected_column_comment')); + $table->addColumn('id', 'integer', ['columnDefinition' => $columnDefinition, 'comment' => 'unexpected_column_comment']); $sql = $this->_conn->getDatabasePlatform()->getCreateTableSQL($table); self::assertContains('expected+column+comment', $sql[0]); @@ -1159,35 +1181,34 @@ public function testCommentNotDuplicated() /** * @group DBAL-1009 - * * @dataProvider getAlterColumnComment */ public function testAlterColumnComment($comment1, $expectedComment1, $comment2, $expectedComment2) { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() != 'mssql') { + $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } $offlineTable = new Table('alter_column_comment_test'); - $offlineTable->addColumn('comment1', 'integer', array('comment' => $comment1)); - $offlineTable->addColumn('comment2', 'integer', array('comment' => $comment2)); + $offlineTable->addColumn('comment1', 'integer', ['comment' => $comment1]); + $offlineTable->addColumn('comment2', 'integer', ['comment' => $comment2]); $offlineTable->addColumn('no_comment1', 'integer'); $offlineTable->addColumn('no_comment2', 'integer'); $this->_sm->dropAndCreateTable($offlineTable); - $onlineTable = $this->_sm->listTableDetails("alter_column_comment_test"); + $onlineTable = $this->_sm->listTableDetails('alter_column_comment_test'); self::assertSame($expectedComment1, $onlineTable->getColumn('comment1')->getComment()); self::assertSame($expectedComment2, $onlineTable->getColumn('comment2')->getComment()); self::assertNull($onlineTable->getColumn('no_comment1')->getComment()); self::assertNull($onlineTable->getColumn('no_comment2')->getComment()); - $onlineTable->changeColumn('comment1', array('comment' => $comment2)); - $onlineTable->changeColumn('comment2', array('comment' => $comment1)); - $onlineTable->changeColumn('no_comment1', array('comment' => $comment1)); - $onlineTable->changeColumn('no_comment2', array('comment' => $comment2)); + $onlineTable->changeColumn('comment1', ['comment' => $comment2]); + $onlineTable->changeColumn('comment2', ['comment' => $comment1]); + $onlineTable->changeColumn('no_comment1', ['comment' => $comment1]); + $onlineTable->changeColumn('no_comment2', ['comment' => $comment2]); $comparator = new Comparator(); @@ -1197,7 +1218,7 @@ public function testAlterColumnComment($comment1, $expectedComment1, $comment2, $this->_sm->alterTable($tableDiff); - $onlineTable = $this->_sm->listTableDetails("alter_column_comment_test"); + $onlineTable = $this->_sm->listTableDetails('alter_column_comment_test'); self::assertSame($expectedComment2, $onlineTable->getColumn('comment1')->getComment()); self::assertSame($expectedComment1, $onlineTable->getColumn('comment2')->getComment()); @@ -1207,20 +1228,20 @@ public function testAlterColumnComment($comment1, $expectedComment1, $comment2, public function getAlterColumnComment() { - return array( - array(null, null, ' ', ' '), - array(null, null, '0', '0'), - array(null, null, 'foo', 'foo'), + return [ + [null, null, ' ', ' '], + [null, null, '0', '0'], + [null, null, 'foo', 'foo'], - array('', null, ' ', ' '), - array('', null, '0', '0'), - array('', null, 'foo', 'foo'), + ['', null, ' ', ' '], + ['', null, '0', '0'], + ['', null, 'foo', 'foo'], - array(' ', ' ', '0', '0'), - array(' ', ' ', 'foo', 'foo'), + [' ', ' ', '0', '0'], + [' ', ' ', 'foo', 'foo'], - array('0', '0', 'foo', 'foo'), - ); + ['0', '0', 'foo', 'foo'], + ]; } /** @@ -1234,14 +1255,14 @@ public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys() $primaryTable = new Table('test_list_index_impl_primary'); $primaryTable->addColumn('id', 'integer'); - $primaryTable->setPrimaryKey(array('id')); + $primaryTable->setPrimaryKey(['id']); $foreignTable = new Table('test_list_index_impl_foreign'); $foreignTable->addColumn('fk1', 'integer'); $foreignTable->addColumn('fk2', 'integer'); - $foreignTable->addIndex(array('fk1'), 'explicit_fk1_idx'); - $foreignTable->addForeignKeyConstraint('test_list_index_impl_primary', array('fk1'), array('id')); - $foreignTable->addForeignKeyConstraint('test_list_index_impl_primary', array('fk2'), array('id')); + $foreignTable->addIndex(['fk1'], 'explicit_fk1_idx'); + $foreignTable->addForeignKeyConstraint('test_list_index_impl_primary', ['fk1'], ['id']); + $foreignTable->addForeignKeyConstraint('test_list_index_impl_primary', ['fk2'], ['id']); $this->_sm->dropAndCreateTable($primaryTable); $this->_sm->dropAndCreateTable($foreignTable); @@ -1258,9 +1279,11 @@ public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys() */ public function removeJsonArrayTable() : void { - if ($this->_sm->tablesExist(['json_array_test'])) { - $this->_sm->dropTable('json_array_test'); + if (! $this->_sm->tablesExist(['json_array_test'])) { + return; } + + $this->_sm->dropTable('json_array_test'); } /** @@ -1314,7 +1337,7 @@ public function testComparatorShouldModifyOnlyTheCommentWhenUpdatingFromJsonArra */ public function testComparatorShouldAddCommentToLegacyJsonArrayTypeThatDoesNotHaveIt() : void { - if ( ! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } @@ -1336,7 +1359,7 @@ public function testComparatorShouldAddCommentToLegacyJsonArrayTypeThatDoesNotHa */ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType() : void { - if ( ! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } @@ -1358,7 +1381,7 @@ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType */ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayTypeEvenWhenPlatformHasJsonSupport() : void { - if ( ! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } @@ -1380,7 +1403,7 @@ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType */ public function testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNow() : void { - if ( ! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } @@ -1397,7 +1420,6 @@ public function testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNo /** * @dataProvider commentsProvider - * * @group 2596 */ public function testExtractDoctrineTypeFromComment(string $comment, string $expected, string $currentType) : void @@ -1423,7 +1445,7 @@ public function commentsProvider() : array public function testCreateAndListSequences() : void { - if ( ! $this->_sm->getDatabasePlatform()->supportsSequences()) { + if (! $this->_sm->getDatabasePlatform()->supportsSequences()) { self::markTestSkipped('This test is only supported on platforms that support sequences.'); } @@ -1476,7 +1498,7 @@ public function testComparisonWithAutoDetectedSequenceDefinition() : void $createdSequence = array_values( array_filter( $this->_sm->listSequences(), - function (Sequence $sequence) use ($sequenceName) : bool { + static function (Sequence $sequence) use ($sequenceName) : bool { return strcasecmp($sequence->getName(), $sequenceName) === 0; } ) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index 14efbff3cce..ca42061b695 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -3,7 +3,9 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; use Doctrine\DBAL\Schema; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use SQLite3; use function array_map; use function dirname; use function extension_loaded; @@ -23,7 +25,7 @@ public function testListDatabases() public function testCreateAndDropDatabase() { - $path = dirname(__FILE__).'/test_create_and_drop_sqlite_database.sqlite'; + $path = dirname(__FILE__) . '/test_create_and_drop_sqlite_database.sqlite'; $this->_sm->createDatabase($path); self::assertFileExists($path); @@ -40,10 +42,10 @@ public function testDropsDatabaseWithActiveConnections() self::assertFileExists('test_drop_database'); - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['dbname'] = 'test_drop_database'; - $user = $params['user'] ?? null; + $user = $params['user'] ?? null; $password = $params['password'] ?? null; $connection = $this->_conn->getDriver()->connect($params, $user, $password); @@ -88,14 +90,29 @@ public function testListForeignKeysFromExistingDatabase() EOS ); - $expected = array( - new Schema\ForeignKeyConstraint(array('log'), 'log', array(null), 'FK_3', - array('onUpdate' => 'SET NULL', 'onDelete' => 'NO ACTION', 'deferrable' => false, 'deferred' => false)), - new Schema\ForeignKeyConstraint(array('parent'), 'user', array('id'), '1', - array('onUpdate' => 'NO ACTION', 'onDelete' => 'CASCADE', 'deferrable' => false, 'deferred' => false)), - new Schema\ForeignKeyConstraint(array('page'), 'page', array('key'), 'FK_1', - array('onUpdate' => 'NO ACTION', 'onDelete' => 'NO ACTION', 'deferrable' => true, 'deferred' => true)), - ); + $expected = [ + new Schema\ForeignKeyConstraint( + ['log'], + 'log', + [null], + 'FK_3', + ['onUpdate' => 'SET NULL', 'onDelete' => 'NO ACTION', 'deferrable' => false, 'deferred' => false] + ), + new Schema\ForeignKeyConstraint( + ['parent'], + 'user', + ['id'], + '1', + ['onUpdate' => 'NO ACTION', 'onDelete' => 'CASCADE', 'deferrable' => false, 'deferred' => false] + ), + new Schema\ForeignKeyConstraint( + ['page'], + 'page', + ['key'], + 'FK_1', + ['onUpdate' => 'NO ACTION', 'onDelete' => 'NO ACTION', 'deferrable' => true, 'deferred' => true] + ), + ]; self::assertEquals($expected, $this->_sm->listTableForeignKeys('user')); } @@ -121,11 +138,11 @@ public function testListTableWithBinary() { $tableName = 'test_binary_table'; - $table = new \Doctrine\DBAL\Schema\Table($tableName); + $table = new Table($tableName); $table->addColumn('id', 'integer'); - $table->addColumn('column_varbinary', 'binary', array()); - $table->addColumn('column_binary', 'binary', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('column_varbinary', 'binary', []); + $table->addColumn('column_binary', 'binary', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -140,12 +157,12 @@ public function testListTableWithBinary() public function testNonDefaultPKOrder() { - if ( ! extension_loaded('sqlite3')) { + if (! extension_loaded('sqlite3')) { $this->markTestSkipped('This test requires the SQLite3 extension.'); } - $version = \SQLite3::version(); - if(version_compare($version['versionString'], '3.7.16', '<')) { + $version = SQLite3::version(); + if (version_compare($version['versionString'], '3.7.16', '<')) { $this->markTestSkipped('This version of sqlite doesn\'t return the order of the Primary Key.'); } $this->_conn->exec(<<getColumns())); + self::assertEquals(['other_id', 'id'], array_map('strtolower', $tableIndexes['primary']->getColumns())); } /** @@ -201,15 +218,15 @@ public function testDiffListIntegerAutoincrementTableColumns($integerType, $unsi { $tableName = 'test_int_autoincrement_table'; - $offlineTable = new \Doctrine\DBAL\Schema\Table($tableName); - $offlineTable->addColumn('id', $integerType, array('autoincrement' => true, 'unsigned' => $unsigned)); - $offlineTable->setPrimaryKey(array('id')); + $offlineTable = new Table($tableName); + $offlineTable->addColumn('id', $integerType, ['autoincrement' => true, 'unsigned' => $unsigned]); + $offlineTable->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($offlineTable); $onlineTable = $this->_sm->listTableDetails($tableName); - $comparator = new Schema\Comparator(); - $diff = $comparator->diffTable($offlineTable, $onlineTable); + $comparator = new Schema\Comparator(); + $diff = $comparator->diffTable($offlineTable, $onlineTable); if ($expectedComparatorDiff) { self::assertEmpty($this->_sm->getDatabasePlatform()->getAlterTableSQL($diff)); @@ -223,14 +240,14 @@ public function testDiffListIntegerAutoincrementTableColumns($integerType, $unsi */ public function getDiffListIntegerAutoincrementTableColumnsData() { - return array( - array('smallint', false, true), - array('smallint', true, true), - array('integer', false, false), - array('integer', true, true), - array('bigint', false, true), - array('bigint', true, true), - ); + return [ + ['smallint', false, true], + ['smallint', true, true], + ['integer', false, false], + ['integer', true, true], + ['bigint', false, true], + ['bigint', true, true], + ]; } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php index 480cec4c53c..7c8585c3f77 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php @@ -7,10 +7,11 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; use function base64_decode; use function stream_get_contents; -class StatementTest extends \Doctrine\Tests\DbalFunctionalTestCase +class StatementTest extends DbalFunctionalTestCase { protected function setUp() { @@ -18,14 +19,14 @@ protected function setUp() $table = new Table('stmt_test'); $table->addColumn('id', 'integer'); - $table->addColumn('name', 'text', array('notnull' => false)); + $table->addColumn('name', 'text', ['notnull' => false]); $this->_conn->getSchemaManager()->dropAndCreateTable($table); } public function testStatementIsReusableAfterClosingCursor() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test ORDER BY id'); @@ -45,35 +46,35 @@ public function testStatementIsReusableAfterClosingCursor() public function testReuseStatementWithLongerResults() { - $sm = $this->_conn->getSchemaManager(); + $sm = $this->_conn->getSchemaManager(); $table = new Table('stmt_longer_results'); $table->addColumn('param', 'string'); $table->addColumn('val', 'text'); $sm->createTable($table); - $row1 = array( + $row1 = [ 'param' => 'param1', 'val' => 'X', - ); + ]; $this->_conn->insert('stmt_longer_results', $row1); $stmt = $this->_conn->prepare('SELECT param, val FROM stmt_longer_results ORDER BY param'); $stmt->execute(); - self::assertArraySubset(array( - array('param1', 'X'), - ), $stmt->fetchAll(FetchMode::NUMERIC)); + self::assertArraySubset([ + ['param1', 'X'], + ], $stmt->fetchAll(FetchMode::NUMERIC)); - $row2 = array( + $row2 = [ 'param' => 'param2', 'val' => 'A bit longer value', - ); + ]; $this->_conn->insert('stmt_longer_results', $row2); $stmt->execute(); - self::assertArraySubset(array( - array('param1', 'X'), - array('param2', 'A bit longer value'), - ), $stmt->fetchAll(FetchMode::NUMERIC)); + self::assertArraySubset([ + ['param1', 'X'], + ['param2', 'A bit longer value'], + ], $stmt->fetchAll(FetchMode::NUMERIC)); } public function testFetchLongBlob() @@ -82,11 +83,9 @@ public function testFetchLongBlob() // but is still not enough to store a LONGBLOB of the max possible size $this->iniSet('memory_limit', '4G'); - $sm = $this->_conn->getSchemaManager(); + $sm = $this->_conn->getSchemaManager(); $table = new Table('stmt_long_blob'); - $table->addColumn('contents', 'blob', array( - 'length' => 0xFFFFFFFF, - )); + $table->addColumn('contents', 'blob', ['length' => 0xFFFFFFFF]); $sm->createTable($table); $contents = base64_decode(<<_conn->insert('stmt_long_blob', ['contents' => $contents], [ParameterType::LARGE_OBJECT]); @@ -122,8 +121,8 @@ public function testFetchLongBlob() public function testIncompletelyFetchedStatementDoesNotBlockConnection() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt1 = $this->_conn->prepare('SELECT id FROM stmt_test'); $stmt1->execute(); @@ -133,32 +132,32 @@ public function testIncompletelyFetchedStatementDoesNotBlockConnection() $stmt1->fetch(); $stmt2 = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); - $stmt2->execute(array(1)); + $stmt2->execute([1]); self::assertEquals(1, $stmt2->fetchColumn()); } public function testReuseStatementAfterClosingCursor() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); - $stmt->execute(array(1)); + $stmt->execute([1]); $id = $stmt->fetchColumn(); self::assertEquals(1, $id); $stmt->closeCursor(); - $stmt->execute(array(2)); + $stmt->execute([2]); $id = $stmt->fetchColumn(); self::assertEquals(2, $id); } public function testReuseStatementWithParameterBoundByReference() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); $stmt->bindParam(1, $id); @@ -174,8 +173,8 @@ public function testReuseStatementWithParameterBoundByReference() public function testReuseStatementWithReboundValue() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); @@ -190,8 +189,8 @@ public function testReuseStatementWithReboundValue() public function testReuseStatementWithReboundParam() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); @@ -252,7 +251,7 @@ public function testFetchFromNonExecutedStatementWithClosedCursor(callable $fetc */ public function testFetchFromExecutedStatementWithClosedCursor(callable $fetch, $expected) { - $this->_conn->insert('stmt_test', array('id' => 1)); + $this->_conn->insert('stmt_test', ['id' => 1]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test'); $stmt->execute(); @@ -263,26 +262,26 @@ public function testFetchFromExecutedStatementWithClosedCursor(callable $fetch, public static function emptyFetchProvider() { - return array( - 'fetch' => array( - function (Statement $stmt) { + return [ + 'fetch' => [ + static function (Statement $stmt) { return $stmt->fetch(); }, false, - ), - 'fetch-column' => array( - function (Statement $stmt) { + ], + 'fetch-column' => [ + static function (Statement $stmt) { return $stmt->fetchColumn(); }, false, - ), - 'fetch-all' => array( - function (Statement $stmt) { + ], + 'fetch-all' => [ + static function (Statement $stmt) { return $stmt->fetchAll(); }, - array(), - ), - ); + [], + ], + ]; } public function testFetchInColumnMode() : void diff --git a/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php b/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php index b8c63644a85..182a337f295 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php @@ -3,15 +3,17 @@ namespace Doctrine\Tests\DBAL\Functional; use Doctrine\DBAL\Id\TableGenerator; +use Doctrine\DBAL\Id\TableGeneratorSchemaVisitor; +use Doctrine\DBAL\Schema\Schema; +use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; /** * @group DDC-450 */ -class TableGeneratorTest extends \Doctrine\Tests\DbalFunctionalTestCase +class TableGeneratorTest extends DbalFunctionalTestCase { - /** - * @var TableGenerator - */ + /** @var TableGenerator */ private $generator; protected function setUp() @@ -19,43 +21,42 @@ protected function setUp() parent::setUp(); $platform = $this->_conn->getDatabasePlatform(); - if ($platform->getName() == "sqlite") { + if ($platform->getName() === 'sqlite') { $this->markTestSkipped('TableGenerator does not work with SQLite'); } try { - $schema = new \Doctrine\DBAL\Schema\Schema(); - $visitor = new \Doctrine\DBAL\Id\TableGeneratorSchemaVisitor(); + $schema = new Schema(); + $visitor = new TableGeneratorSchemaVisitor(); $schema->visit($visitor); foreach ($schema->toSql($platform) as $sql) { $this->_conn->exec($sql); } - - } catch(\Exception $e) { + } catch (Throwable $e) { } $this->generator = new TableGenerator($this->_conn); } public function testNextVal() { - $id1 = $this->generator->nextValue("tbl1"); - $id2 = $this->generator->nextValue("tbl1"); - $id3 = $this->generator->nextValue("tbl2"); + $id1 = $this->generator->nextValue('tbl1'); + $id2 = $this->generator->nextValue('tbl1'); + $id3 = $this->generator->nextValue('tbl2'); - self::assertGreaterThan(0, $id1, "First id has to be larger than 0"); - self::assertEquals($id1 + 1, $id2, "Second id is one larger than first one."); - self::assertEquals($id1, $id3, "First ids from different tables are equal."); + self::assertGreaterThan(0, $id1, 'First id has to be larger than 0'); + self::assertEquals($id1 + 1, $id2, 'Second id is one larger than first one.'); + self::assertEquals($id1, $id3, 'First ids from different tables are equal.'); } public function testNextValNotAffectedByOuterTransactions() { $this->_conn->beginTransaction(); - $id1 = $this->generator->nextValue("tbl1"); + $id1 = $this->generator->nextValue('tbl1'); $this->_conn->rollBack(); - $id2 = $this->generator->nextValue("tbl1"); + $id2 = $this->generator->nextValue('tbl1'); - self::assertGreaterThan(0, $id1, "First id has to be larger than 0"); - self::assertEquals($id1 + 1, $id2, "Second id is one larger than first one."); + self::assertGreaterThan(0, $id1, 'First id has to be larger than 0'); + self::assertEquals($id1 + 1, $id2, 'Second id is one larger than first one.'); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php b/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php index 3a1277267a9..5ef755ee4da 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php @@ -4,16 +4,17 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; -class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase +class TemporaryTableTest extends DbalFunctionalTestCase { protected function setUp() { parent::setUp(); try { - $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTableSQL("nontemporary")); - } catch(\Exception $e) { - + $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTableSQL('nontemporary')); + } catch (Throwable $e) { } } @@ -21,89 +22,91 @@ protected function tearDown() { if ($this->_conn) { try { - $tempTable = $this->_conn->getDatabasePlatform()->getTemporaryTableName("my_temporary"); + $tempTable = $this->_conn->getDatabasePlatform()->getTemporaryTableName('my_temporary'); $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable)); - } catch(\Exception $e) { } + } catch (Throwable $e) { + } } parent::tearDown(); } /** - * @group DDC-1337 * @return void + * + * @group DDC-1337 */ public function testDropTemporaryTableNotAutoCommitTransaction() { - if ($this->_conn->getDatabasePlatform()->getName() == 'sqlanywhere' || - $this->_conn->getDatabasePlatform()->getName() == 'oracle') { - $this->markTestSkipped("Test does not work on Oracle and SQL Anywhere."); + if ($this->_conn->getDatabasePlatform()->getName() === 'sqlanywhere' || + $this->_conn->getDatabasePlatform()->getName() === 'oracle') { + $this->markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); } - $platform = $this->_conn->getDatabasePlatform(); - $columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true)); - $tempTable = $platform->getTemporaryTableName("my_temporary"); + $platform = $this->_conn->getDatabasePlatform(); + $columnDefinitions = ['id' => ['type' => Type::getType('integer'), 'notnull' => true]]; + $tempTable = $platform->getTemporaryTableName('my_temporary'); $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')'; $this->_conn->executeUpdate($createTempTableSQL); - $table = new Table("nontemporary"); - $table->addColumn("id", "integer"); - $table->setPrimaryKey(array('id')); + $table = new Table('nontemporary'); + $table->addColumn('id', 'integer'); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); $this->_conn->beginTransaction(); - $this->_conn->insert("nontemporary", array("id" => 1)); + $this->_conn->insert('nontemporary', ['id' => 1]); $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable)); - $this->_conn->insert("nontemporary", array("id" => 2)); + $this->_conn->insert('nontemporary', ['id' => 2]); $this->_conn->rollBack(); $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary'); - self::assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit."); + self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.'); } /** - * @group DDC-1337 * @return void + * + * @group DDC-1337 */ public function testCreateTemporaryTableNotAutoCommitTransaction() { - if ($this->_conn->getDatabasePlatform()->getName() == 'sqlanywhere' || - $this->_conn->getDatabasePlatform()->getName() == 'oracle') { - $this->markTestSkipped("Test does not work on Oracle and SQL Anywhere."); + if ($this->_conn->getDatabasePlatform()->getName() === 'sqlanywhere' || + $this->_conn->getDatabasePlatform()->getName() === 'oracle') { + $this->markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); } - $platform = $this->_conn->getDatabasePlatform(); - $columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true)); - $tempTable = $platform->getTemporaryTableName("my_temporary"); + $platform = $this->_conn->getDatabasePlatform(); + $columnDefinitions = ['id' => ['type' => Type::getType('integer'), 'notnull' => true]]; + $tempTable = $platform->getTemporaryTableName('my_temporary'); $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')'; - $table = new Table("nontemporary"); - $table->addColumn("id", "integer"); - $table->setPrimaryKey(array('id')); + $table = new Table('nontemporary'); + $table->addColumn('id', 'integer'); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); $this->_conn->beginTransaction(); - $this->_conn->insert("nontemporary", array("id" => 1)); + $this->_conn->insert('nontemporary', ['id' => 1]); $this->_conn->exec($createTempTableSQL); - $this->_conn->insert("nontemporary", array("id" => 2)); + $this->_conn->insert('nontemporary', ['id' => 2]); $this->_conn->rollBack(); try { $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable)); - } catch(\Exception $e) { - + } catch (Throwable $e) { } $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary'); - self::assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit."); + self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.'); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php index 47b1e5eab4a..b43da19b52d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php @@ -2,22 +2,25 @@ namespace Doctrine\Tests\DBAL\Functional\Ticket; +use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; + /** * @group DBAL-168 */ -class DBAL168Test extends \Doctrine\Tests\DbalFunctionalTestCase +class DBAL168Test extends DbalFunctionalTestCase { public function testDomainsTable() { - if ($this->_conn->getDatabasePlatform()->getName() != "postgresql") { + if ($this->_conn->getDatabasePlatform()->getName() !== 'postgresql') { $this->markTestSkipped('PostgreSQL only test'); } - $table = new \Doctrine\DBAL\Schema\Table("domains"); + $table = new Table('domains'); $table->addColumn('id', 'integer'); $table->addColumn('parent_id', 'integer'); - $table->setPrimaryKey(array('id')); - $table->addForeignKeyConstraint('domains', array('parent_id'), array('id')); + $table->setPrimaryKey(['id']); + $table->addForeignKeyConstraint('domains', ['parent_id'], ['id']); $this->_conn->getSchemaManager()->createTable($table); $table = $this->_conn->getSchemaManager()->listTableDetails('domains'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php index cbb7674f893..63d93ffafa7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php @@ -2,25 +2,28 @@ namespace Doctrine\Tests\DBAL\Functional\Ticket; +use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; + /** * @group DBAL-202 */ -class DBAL202Test extends \Doctrine\Tests\DbalFunctionalTestCase +class DBAL202Test extends DbalFunctionalTestCase { protected function setUp() { parent::setUp(); - if ($this->_conn->getDatabasePlatform()->getName() != 'oracle') { + if ($this->_conn->getDatabasePlatform()->getName() !== 'oracle') { $this->markTestSkipped('OCI8 only test'); } if ($this->_conn->getSchemaManager()->tablesExist('DBAL202')) { $this->_conn->exec('DELETE FROM DBAL202'); } else { - $table = new \Doctrine\DBAL\Schema\Table('DBAL202'); + $table = new Table('DBAL202'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php index 4db10e1173f..b44e7542489 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php @@ -1,29 +1,33 @@ _conn->getDatabasePlatform()->getName(); - if (!in_array($platform, array('mysql', 'sqlite'))) { - $this->markTestSkipped('Currently restricted to MySQL and SQLite.'); + if (in_array($platform, ['mysql', 'sqlite'])) { + return; } + + $this->markTestSkipped('Currently restricted to MySQL and SQLite.'); } public function testGuidShouldMatchPattern() { - $guid = $this->_conn->query($this->getSelectGuidSql())->fetchColumn(); + $guid = $this->_conn->query($this->getSelectGuidSql())->fetchColumn(); $pattern = '/[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[8-9A-B][0-9A-F]{3}\-[0-9A-F]{12}/i'; - self::assertEquals(1, preg_match($pattern, $guid), "GUID does not match pattern"); + self::assertEquals(1, preg_match($pattern, $guid), 'GUID does not match pattern'); } /** @@ -33,12 +37,12 @@ public function testGuidShouldMatchPattern() public function testGuidShouldBeRandom() { $statement = $this->_conn->prepare($this->getSelectGuidSql()); - $guids = array(); + $guids = []; for ($i = 0; $i < 99; $i++) { $statement->execute(); $guid = $statement->fetchColumn(); - self::assertNotContains($guid, $guids, "Duplicate GUID detected"); + self::assertNotContains($guid, $guids, 'Duplicate GUID detected'); $guids[] = $guid; } @@ -47,6 +51,6 @@ public function testGuidShouldBeRandom() private function getSelectGuidSql() { - return "SELECT " . $this->_conn->getDatabasePlatform()->getGuidExpression(); + return 'SELECT ' . $this->_conn->getDatabasePlatform()->getGuidExpression(); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php index 1f40837daa7..2298898d74d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php @@ -4,23 +4,25 @@ use Doctrine\DBAL\Schema\SQLServerSchemaManager; use Doctrine\DBAL\Types\DecimalType; +use PHPUnit\Framework\TestCase; +use ReflectionMethod; /** * @group DBAL-461 */ -class DBAL461Test extends \PHPUnit\Framework\TestCase +class DBAL461Test extends TestCase { public function testIssue() { - $conn = $this->createMock('Doctrine\DBAL\Connection'); + $conn = $this->createMock('Doctrine\DBAL\Connection'); $platform = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform'); $platform->registerDoctrineTypeMapping('numeric', 'decimal'); $schemaManager = new SQLServerSchemaManager($conn, $platform); - $reflectionMethod = new \ReflectionMethod($schemaManager, '_getPortableTableColumnDefinition'); + $reflectionMethod = new ReflectionMethod($schemaManager, '_getPortableTableColumnDefinition'); $reflectionMethod->setAccessible(true); - $column = $reflectionMethod->invoke($schemaManager, array( + $column = $reflectionMethod->invoke($schemaManager, [ 'type' => 'numeric(18,0)', 'length' => null, 'default' => null, @@ -30,7 +32,7 @@ public function testIssue() 'autoincrement' => false, 'collation' => 'foo', 'comment' => null, - )); + ]); $this->assertInstanceOf(DecimalType::class, $column->getType()); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php index 4780e6f5c7d..208db06d19b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php @@ -4,33 +4,36 @@ use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; /** * @group DBAL-510 */ -class DBAL510Test extends \Doctrine\Tests\DbalFunctionalTestCase +class DBAL510Test extends DbalFunctionalTestCase { protected function setUp() { parent::setUp(); - if ($this->_conn->getDatabasePlatform()->getName() !== "postgresql") { - $this->markTestSkipped('PostgreSQL Only test'); + if ($this->_conn->getDatabasePlatform()->getName() === 'postgresql') { + return; } + + $this->markTestSkipped('PostgreSQL Only test'); } public function testSearchPathSchemaChanges() { - $table = new Table("dbal510tbl"); + $table = new Table('dbal510tbl'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); $onlineTable = $this->_conn->getSchemaManager()->listTableDetails('dbal510tbl'); $comparator = new Comparator(); - $diff = $comparator->diffTable($onlineTable, $table); + $diff = $comparator->diffTable($onlineTable, $table); self::assertFalse($diff); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php index 70210133b1f..0709ffd5632 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -4,17 +4,16 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\ParameterType; +use Doctrine\Tests\DbalFunctionalTestCase; use PDO; use function in_array; /** * @group DBAL-630 */ -class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase +class DBAL630Test extends DbalFunctionalTestCase { - /** - * @var bool - */ + /** @var bool */ private $running = false; protected function setUp() @@ -23,7 +22,7 @@ protected function setUp() $platform = $this->_conn->getDatabasePlatform()->getName(); - if (!in_array($platform, array('postgresql'))) { + if (! in_array($platform, ['postgresql'])) { $this->markTestSkipped('Currently restricted to PostgreSQL'); } @@ -50,7 +49,7 @@ public function testBooleanConversionSqlLiteral() $id = $this->_conn->lastInsertId('dbal630_id_seq'); self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', array($id)); + $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); self::assertFalse($row['bool_col']); } @@ -65,7 +64,7 @@ public function testBooleanConversionBoolParamRealPrepares() $id = $this->_conn->lastInsertId('dbal630_id_seq'); self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', array($id)); + $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); self::assertFalse($row['bool_col']); } @@ -84,7 +83,7 @@ public function testBooleanConversionBoolParamEmulatedPrepares() self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', array($id)); + $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); self::assertFalse($row['bool_col']); } @@ -108,7 +107,7 @@ public function testBooleanConversionNullParamEmulatedPrepares( self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', array($id)); + $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); self::assertSame($databaseConvertedValue, $row['bool_col']); } @@ -136,36 +135,38 @@ public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInB self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', array($id)); + $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); self::assertSame($databaseConvertedValue, $row['bool_col']); } /** * Boolean conversion mapping provider + * * @return array */ public function booleanTypeConversionUsingBooleanTypeProvider() { - return array( + return [ // statement value, database converted value result - array(true, true), - array(false, false), - array(null, false) - ); + [true, true], + [false, false], + [null, false], + ]; } /** * Boolean conversion mapping provider + * * @return array */ public function booleanTypeConversionWithoutPdoTypeProvider() { - return array( + return [ // statement value, database converted value result - array(true, true), - array(false, false), - array(null, null) - ); + [true, true], + [false, false], + [null, null], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php index 5368cdc9192..393e3457eed 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php @@ -1,12 +1,14 @@ _conn->getDatabasePlatform()->getName(); - if (!in_array($platform, array('sqlite'))) { - $this->markTestSkipped('Related to SQLite only'); + if (in_array($platform, ['sqlite'])) { + return; } + + $this->markTestSkipped('Related to SQLite only'); } public function testUnsignedIntegerDetection() diff --git a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php index 83c6e4dec55..289d5c7fd9a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php @@ -2,102 +2,110 @@ namespace Doctrine\Tests\DBAL\Functional; +use DateTime; +use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; +use stdClass; +use Throwable; use function str_repeat; -class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase +class TypeConversionTest extends DbalFunctionalTestCase { - /** - * @var int - */ + /** @var int */ static private $typeCounter = 0; protected function setUp() { parent::setUp(); - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ + /** @var AbstractSchemaManager $sm */ $sm = $this->_conn->getSchemaManager(); - $table = new \Doctrine\DBAL\Schema\Table("type_conversion"); - $table->addColumn('id', 'integer', array('notnull' => false)); - $table->addColumn('test_string', 'string', array('notnull' => false)); - $table->addColumn('test_boolean', 'boolean', array('notnull' => false)); - $table->addColumn('test_bigint', 'bigint', array('notnull' => false)); - $table->addColumn('test_smallint', 'bigint', array('notnull' => false)); - $table->addColumn('test_datetime', 'datetime', array('notnull' => false)); - $table->addColumn('test_datetimetz', 'datetimetz', array('notnull' => false)); - $table->addColumn('test_date', 'date', array('notnull' => false)); - $table->addColumn('test_time', 'time', array('notnull' => false)); - $table->addColumn('test_text', 'text', array('notnull' => false)); - $table->addColumn('test_array', 'array', array('notnull' => false)); - $table->addColumn('test_json_array', 'json_array', array('notnull' => false)); - $table->addColumn('test_object', 'object', array('notnull' => false)); - $table->addColumn('test_float', 'float', array('notnull' => false)); - $table->addColumn('test_decimal', 'decimal', array('notnull' => false, 'scale' => 2, 'precision' => 10)); - $table->setPrimaryKey(array('id')); + $table = new Table('type_conversion'); + $table->addColumn('id', 'integer', ['notnull' => false]); + $table->addColumn('test_string', 'string', ['notnull' => false]); + $table->addColumn('test_boolean', 'boolean', ['notnull' => false]); + $table->addColumn('test_bigint', 'bigint', ['notnull' => false]); + $table->addColumn('test_smallint', 'bigint', ['notnull' => false]); + $table->addColumn('test_datetime', 'datetime', ['notnull' => false]); + $table->addColumn('test_datetimetz', 'datetimetz', ['notnull' => false]); + $table->addColumn('test_date', 'date', ['notnull' => false]); + $table->addColumn('test_time', 'time', ['notnull' => false]); + $table->addColumn('test_text', 'text', ['notnull' => false]); + $table->addColumn('test_array', 'array', ['notnull' => false]); + $table->addColumn('test_json_array', 'json_array', ['notnull' => false]); + $table->addColumn('test_object', 'object', ['notnull' => false]); + $table->addColumn('test_float', 'float', ['notnull' => false]); + $table->addColumn('test_decimal', 'decimal', ['notnull' => false, 'scale' => 2, 'precision' => 10]); + $table->setPrimaryKey(['id']); try { $this->_conn->getSchemaManager()->createTable($table); - } catch(\Exception $e) { - + } catch (Throwable $e) { } } public static function dataIdempotentDataConversion() { - $obj = new \stdClass(); - $obj->foo = "bar"; - $obj->bar = "baz"; - - return array( - array('string', 'ABCDEFGaaaBBB', 'string'), - array('boolean', true, 'bool'), - array('boolean', false, 'bool'), - array('bigint', 12345678, 'string'), - array('smallint', 123, 'int'), - array('datetime', new \DateTime('2010-04-05 10:10:10'), 'DateTime'), - array('datetimetz', new \DateTime('2010-04-05 10:10:10'), 'DateTime'), - array('date', new \DateTime('2010-04-05'), 'DateTime'), - array('time', new \DateTime('1970-01-01 10:10:10'), 'DateTime'), - array('text', str_repeat('foo ', 1000), 'string'), - array('array', array('foo' => 'bar'), 'array'), - array('json_array', array('foo' => 'bar'), 'array'), - array('object', $obj, 'object'), - array('float', 1.5, 'float'), - array('decimal', 1.55, 'string'), - ); + $obj = new stdClass(); + $obj->foo = 'bar'; + $obj->bar = 'baz'; + + return [ + ['string', 'ABCDEFGaaaBBB', 'string'], + ['boolean', true, 'bool'], + ['boolean', false, 'bool'], + ['bigint', 12345678, 'string'], + ['smallint', 123, 'int'], + ['datetime', new DateTime('2010-04-05 10:10:10'), 'DateTime'], + ['datetimetz', new DateTime('2010-04-05 10:10:10'), 'DateTime'], + ['date', new DateTime('2010-04-05'), 'DateTime'], + ['time', new DateTime('1970-01-01 10:10:10'), 'DateTime'], + ['text', str_repeat('foo ', 1000), 'string'], + ['array', ['foo' => 'bar'], 'array'], + ['json_array', ['foo' => 'bar'], 'array'], + ['object', $obj, 'object'], + ['float', 1.5, 'float'], + ['decimal', 1.55, 'string'], + ]; } /** - * @dataProvider dataIdempotentDataConversion * @param string $type * @param mixed $originalValue * @param string $expectedPhpType + * + * @dataProvider dataIdempotentDataConversion */ public function testIdempotentDataConversion($type, $originalValue, $expectedPhpType) { - $columnName = "test_" . $type; - $typeInstance = Type::getType($type); + $columnName = 'test_' . $type; + $typeInstance = Type::getType($type); $insertionValue = $typeInstance->convertToDatabaseValue($originalValue, $this->_conn->getDatabasePlatform()); - $this->_conn->insert('type_conversion', array('id' => ++self::$typeCounter, $columnName => $insertionValue)); + $this->_conn->insert('type_conversion', ['id' => ++self::$typeCounter, $columnName => $insertionValue]); - $sql = "SELECT " . $columnName . " FROM type_conversion WHERE id = " . self::$typeCounter; + $sql = 'SELECT ' . $columnName . ' FROM type_conversion WHERE id = ' . self::$typeCounter; $actualDbValue = $typeInstance->convertToPHPValue($this->_conn->fetchColumn($sql), $this->_conn->getDatabasePlatform()); - if ($originalValue instanceof \DateTime) { - self::assertInstanceOf($expectedPhpType, $actualDbValue, "The expected type from the conversion to and back from the database should be " . $expectedPhpType); + if ($originalValue instanceof DateTime) { + self::assertInstanceOf($expectedPhpType, $actualDbValue, 'The expected type from the conversion to and back from the database should be ' . $expectedPhpType); } else { - self::assertInternalType($expectedPhpType, $actualDbValue, "The expected type from the conversion to and back from the database should be " . $expectedPhpType); + self::assertInternalType($expectedPhpType, $actualDbValue, 'The expected type from the conversion to and back from the database should be ' . $expectedPhpType); + } + + if ($type === 'datetimetz') { + return; } - if ($type !== "datetimetz") { - self::assertEquals($originalValue, $actualDbValue, "Conversion between values should produce the same out as in value, but doesnt!"); + self::assertEquals($originalValue, $actualDbValue, 'Conversion between values should produce the same out as in value, but doesnt!'); - if ($originalValue instanceof \DateTime) { - self::assertEquals($originalValue->getTimezone()->getName(), $actualDbValue->getTimezone()->getName(), "Timezones should be the same."); - } + if (! ($originalValue instanceof DateTime)) { + return; } + + self::assertEquals($originalValue->getTimezone()->getName(), $actualDbValue->getTimezone()->getName(), 'Timezones should be the same.'); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php index 8ce8e373e83..60c32fe9615 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php @@ -2,28 +2,33 @@ namespace Doctrine\Tests\DBAL\Functional; +use DateTime; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; use function array_filter; use function strtolower; -class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase +class WriteTest extends DbalFunctionalTestCase { protected function setUp() { parent::setUp(); try { - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ - $table = new \Doctrine\DBAL\Schema\Table("write_table"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + /** @var AbstractSchemaManager $sm */ + $table = new Table('write_table'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('test_int', 'integer'); - $table->addColumn('test_string', 'string', array('notnull' => false)); - $table->setPrimaryKey(array('id')); + $table->addColumn('test_string', 'string', ['notnull' => false]); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); - } catch(\Exception $e) { - + } catch (Throwable $e) { } $this->_conn->executeUpdate('DELETE FROM write_table'); } @@ -33,40 +38,40 @@ protected function setUp() */ public function testExecuteUpdateFirstTypeIsNull() { - $sql = "INSERT INTO write_table (test_string, test_int) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_string, test_int) VALUES (?, ?)'; $this->_conn->executeUpdate($sql, ['text', 1111], [null, ParameterType::INTEGER]); - $sql = "SELECT * FROM write_table WHERE test_string = ? AND test_int = ?"; + $sql = 'SELECT * FROM write_table WHERE test_string = ? AND test_int = ?'; self::assertTrue((bool) $this->_conn->fetchColumn($sql, ['text', 1111])); } public function testExecuteUpdate() { - $sql = "INSERT INTO write_table (test_int) VALUES ( " . $this->_conn->quote(1) . ")"; + $sql = 'INSERT INTO write_table (test_int) VALUES ( ' . $this->_conn->quote(1) . ')'; $affected = $this->_conn->executeUpdate($sql); - self::assertEquals(1, $affected, "executeUpdate() should return the number of affected rows!"); + self::assertEquals(1, $affected, 'executeUpdate() should return the number of affected rows!'); } public function testExecuteUpdateWithTypes() { - $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $affected = $this->_conn->executeUpdate( $sql, [1, 'foo'], [ParameterType::INTEGER, ParameterType::STRING] ); - self::assertEquals(1, $affected, "executeUpdate() should return the number of affected rows!"); + self::assertEquals(1, $affected, 'executeUpdate() should return the number of affected rows!'); } public function testPrepareRowCountReturnsAffectedRows() { - $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->_conn->prepare($sql); $stmt->bindValue(1, 1); - $stmt->bindValue(2, "foo"); + $stmt->bindValue(2, 'foo'); $stmt->execute(); self::assertEquals(1, $stmt->rowCount()); @@ -74,7 +79,7 @@ public function testPrepareRowCountReturnsAffectedRows() public function testPrepareWithPdoTypes() { - $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->_conn->prepare($sql); $stmt->bindValue(1, 1, ParameterType::INTEGER); @@ -86,11 +91,11 @@ public function testPrepareWithPdoTypes() public function testPrepareWithDbalTypes() { - $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->_conn->prepare($sql); $stmt->bindValue(1, 1, Type::getType('integer')); - $stmt->bindValue(2, "foo", Type::getType('string')); + $stmt->bindValue(2, 'foo', Type::getType('string')); $stmt->execute(); self::assertEquals(1, $stmt->rowCount()); @@ -98,11 +103,11 @@ public function testPrepareWithDbalTypes() public function testPrepareWithDbalTypeNames() { - $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->_conn->prepare($sql); $stmt->bindValue(1, 1, 'integer'); - $stmt->bindValue(2, "foo", 'string'); + $stmt->bindValue(2, 'foo', 'string'); $stmt->execute(); self::assertEquals(1, $stmt->rowCount()); @@ -110,8 +115,8 @@ public function testPrepareWithDbalTypeNames() public function insertRows() { - self::assertEquals(1, $this->_conn->insert('write_table', array('test_int' => 1, 'test_string' => 'foo'))); - self::assertEquals(1, $this->_conn->insert('write_table', array('test_int' => 2, 'test_string' => 'bar'))); + self::assertEquals(1, $this->_conn->insert('write_table', ['test_int' => 1, 'test_string' => 'foo'])); + self::assertEquals(1, $this->_conn->insert('write_table', ['test_int' => 2, 'test_string' => 'bar'])); } public function testInsert() @@ -123,10 +128,10 @@ public function testDelete() { $this->insertRows(); - self::assertEquals(1, $this->_conn->delete('write_table', array('test_int' => 2))); + self::assertEquals(1, $this->_conn->delete('write_table', ['test_int' => 2])); self::assertCount(1, $this->_conn->fetchAll('SELECT * FROM write_table')); - self::assertEquals(1, $this->_conn->delete('write_table', array('test_int' => 1))); + self::assertEquals(1, $this->_conn->delete('write_table', ['test_int' => 1])); self::assertCount(0, $this->_conn->fetchAll('SELECT * FROM write_table')); } @@ -134,42 +139,42 @@ public function testUpdate() { $this->insertRows(); - self::assertEquals(1, $this->_conn->update('write_table', array('test_string' => 'bar'), array('test_string' => 'foo'))); - self::assertEquals(2, $this->_conn->update('write_table', array('test_string' => 'baz'), array('test_string' => 'bar'))); - self::assertEquals(0, $this->_conn->update('write_table', array('test_string' => 'baz'), array('test_string' => 'bar'))); + self::assertEquals(1, $this->_conn->update('write_table', ['test_string' => 'bar'], ['test_string' => 'foo'])); + self::assertEquals(2, $this->_conn->update('write_table', ['test_string' => 'baz'], ['test_string' => 'bar'])); + self::assertEquals(0, $this->_conn->update('write_table', ['test_string' => 'baz'], ['test_string' => 'bar'])); } public function testLastInsertId() { - if ( ! $this->_conn->getDatabasePlatform()->prefersIdentityColumns()) { + if (! $this->_conn->getDatabasePlatform()->prefersIdentityColumns()) { $this->markTestSkipped('Test only works on platforms with identity columns.'); } - self::assertEquals(1, $this->_conn->insert('write_table', array('test_int' => 2, 'test_string' => 'bar'))); + self::assertEquals(1, $this->_conn->insert('write_table', ['test_int' => 2, 'test_string' => 'bar'])); $num = $this->_conn->lastInsertId(); - self::assertNotNull($num, "LastInsertId() should not be null."); - self::assertGreaterThan(0, $num, "LastInsertId() should be non-negative number."); + self::assertNotNull($num, 'LastInsertId() should not be null.'); + self::assertGreaterThan(0, $num, 'LastInsertId() should be non-negative number.'); } public function testLastInsertIdSequence() { - if ( ! $this->_conn->getDatabasePlatform()->supportsSequences()) { + if (! $this->_conn->getDatabasePlatform()->supportsSequences()) { $this->markTestSkipped('Test only works on platforms with sequences.'); } - $sequence = new \Doctrine\DBAL\Schema\Sequence('write_table_id_seq'); + $sequence = new Sequence('write_table_id_seq'); try { $this->_conn->getSchemaManager()->createSequence($sequence); - } catch(\Exception $e) { + } catch (Throwable $e) { } $sequences = $this->_conn->getSchemaManager()->listSequences(); - self::assertCount(1, array_filter($sequences, function($sequence) { + self::assertCount(1, array_filter($sequences, static function ($sequence) { return strtolower($sequence->getName()) === 'write_table_id_seq'; })); - $stmt = $this->_conn->query($this->_conn->getDatabasePlatform()->getSequenceNextValSQL('write_table_id_seq')); + $stmt = $this->_conn->query($this->_conn->getDatabasePlatform()->getSequenceNextValSQL('write_table_id_seq')); $nextSequenceVal = $stmt->fetchColumn(); $lastInsertId = $this->_conn->lastInsertId('write_table_id_seq'); @@ -180,12 +185,11 @@ public function testLastInsertIdSequence() public function testLastInsertIdNoSequenceGiven() { - if ( ! $this->_conn->getDatabasePlatform()->supportsSequences() || $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { + if (! $this->_conn->getDatabasePlatform()->supportsSequences() || $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { $this->markTestSkipped("Test only works consistently on platforms that support sequences and don't support identity columns."); } - self::assertFalse($this->_conn->lastInsertId( null )); - + self::assertFalse($this->_conn->lastInsertId(null)); } /** @@ -193,12 +197,12 @@ public function testLastInsertIdNoSequenceGiven() */ public function testInsertWithKeyValueTypes() { - $testString = new \DateTime('2013-04-14 10:10:10'); + $testString = new DateTime('2013-04-14 10:10:10'); $this->_conn->insert( 'write_table', - array('test_int' => '30', 'test_string' => $testString), - array('test_string' => 'datetime', 'test_int' => 'integer') + ['test_int' => '30', 'test_string' => $testString], + ['test_string' => 'datetime', 'test_int' => 'integer'] ); $data = $this->_conn->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); @@ -211,21 +215,21 @@ public function testInsertWithKeyValueTypes() */ public function testUpdateWithKeyValueTypes() { - $testString = new \DateTime('2013-04-14 10:10:10'); + $testString = new DateTime('2013-04-14 10:10:10'); $this->_conn->insert( 'write_table', - array('test_int' => '30', 'test_string' => $testString), - array('test_string' => 'datetime', 'test_int' => 'integer') + ['test_int' => '30', 'test_string' => $testString], + ['test_string' => 'datetime', 'test_int' => 'integer'] ); - $testString = new \DateTime('2013-04-15 10:10:10'); + $testString = new DateTime('2013-04-15 10:10:10'); $this->_conn->update( 'write_table', - array('test_string' => $testString), - array('test_int' => '30'), - array('test_string' => 'datetime', 'test_int' => 'integer') + ['test_string' => $testString], + ['test_int' => '30'], + ['test_string' => 'datetime', 'test_int' => 'integer'] ); $data = $this->_conn->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); @@ -238,14 +242,14 @@ public function testUpdateWithKeyValueTypes() */ public function testDeleteWithKeyValueTypes() { - $val = new \DateTime('2013-04-14 10:10:10'); + $val = new DateTime('2013-04-14 10:10:10'); $this->_conn->insert( 'write_table', - array('test_int' => '30', 'test_string' => $val), - array('test_string' => 'datetime', 'test_int' => 'integer') + ['test_int' => '30', 'test_string' => $val], + ['test_string' => 'datetime', 'test_int' => 'integer'] ); - $this->_conn->delete('write_table', array('test_int' => 30, 'test_string' => $val), array('test_string' => 'datetime', 'test_int' => 'integer')); + $this->_conn->delete('write_table', ['test_int' => 30, 'test_string' => $val], ['test_string' => 'datetime', 'test_int' => 'integer']); $data = $this->_conn->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); @@ -256,19 +260,20 @@ public function testEmptyIdentityInsert() { $platform = $this->_conn->getDatabasePlatform(); - if ( ! ($platform->supportsIdentityColumns() || $platform->usesSequenceEmulatedIdentityColumns()) ) { + if (! ($platform->supportsIdentityColumns() || $platform->usesSequenceEmulatedIdentityColumns())) { $this->markTestSkipped( 'Test only works on platforms with identity columns or sequence emulated identity columns.' ); } - $table = new \Doctrine\DBAL\Schema\Table('test_empty_identity'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->setPrimaryKey(array('id')); + $table = new Table('test_empty_identity'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); try { $this->_conn->getSchemaManager()->dropTable($table->getQuotedName($platform)); - } catch(\Exception $e) { } + } catch (Throwable $e) { + } foreach ($platform->getCreateTableSQL($table) as $sql) { $this->_conn->exec($sql); @@ -289,7 +294,6 @@ public function testEmptyIdentityInsert() $secondId = $this->_conn->lastInsertId($seqName); self::assertGreaterThan($firstId, $secondId); - } /** diff --git a/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php b/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php index 8d9595f1ec5..914351c75dc 100644 --- a/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php +++ b/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php @@ -3,8 +3,9 @@ namespace Doctrine\Tests\DBAL\Logging; use Doctrine\DBAL\Logging\DebugStack; +use Doctrine\Tests\DbalTestCase; -class DebugStackTest extends \Doctrine\Tests\DbalTestCase +class DebugStackTest extends DbalTestCase { /** @var DebugStack */ private $logger; @@ -23,14 +24,14 @@ public function testLoggedQuery() { $this->logger->startQuery('SELECT column FROM table'); self::assertEquals( - array( - 1 => array( + [ + 1 => [ 'sql' => 'SELECT column FROM table', 'params' => null, 'types' => null, 'executionMS' => 0, - ), - ), + ], + ], $this->logger->queries ); @@ -42,9 +43,9 @@ public function testLoggedQueryDisabled() { $this->logger->enabled = false; $this->logger->startQuery('SELECT column FROM table'); - self::assertEquals(array(), $this->logger->queries); + self::assertEquals([], $this->logger->queries); $this->logger->stopQuery(); - self::assertEquals(array(), $this->logger->queries); + self::assertEquals([], $this->logger->queries); } } diff --git a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php b/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php index 3f8f0477cc2..cb6ec18df32 100644 --- a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php +++ b/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php @@ -15,18 +15,27 @@ public function getBlobTypeDeclarationSQL(array $field) throw DBALException::notSupported(__METHOD__); } - public function getBooleanTypeDeclarationSQL(array $columnDef) {} - public function getIntegerTypeDeclarationSQL(array $columnDef) {} - public function getBigIntTypeDeclarationSQL(array $columnDef) {} - public function getSmallIntTypeDeclarationSQL(array $columnDef) {} - public function _getCommonIntegerTypeDeclarationSQL(array $columnDef) {} + public function getBooleanTypeDeclarationSQL(array $columnDef) + { + } + public function getIntegerTypeDeclarationSQL(array $columnDef) + { + } + public function getBigIntTypeDeclarationSQL(array $columnDef) + { + } + public function getSmallIntTypeDeclarationSQL(array $columnDef) + { + } + public function _getCommonIntegerTypeDeclarationSQL(array $columnDef) + { + } public function getVarcharTypeDeclarationSQL(array $field) { - return "DUMMYVARCHAR()"; + return 'DUMMYVARCHAR()'; } - /** @override */ public function getClobTypeDeclarationSQL(array $field) { return 'DUMMYCLOB'; @@ -57,10 +66,10 @@ public function getName() { return 'mock'; } - protected function initializeDoctrineTypeMappings() { + protected function initializeDoctrineTypeMappings() + { } protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { - } } diff --git a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php index 42c549aa399..e60bace5dca 100644 --- a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php +++ b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php @@ -2,25 +2,27 @@ namespace Doctrine\Tests\DBAL\Performance; +use DateTime; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalPerformanceTestCase; /** * Class TypeConversionPerformanceTest - * @package Doctrine\Tests\DBAL\Performance - * @author Bill Schaller + * * @group performance */ class TypeConversionPerformanceTest extends DbalPerformanceTestCase { /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException + * * @dataProvider itemCountProvider */ public function testDateTimeTypeConversionPerformance($count) { - $value = new \DateTime; - $type = Type::getType("datetime"); + $value = new DateTime(); + $type = Type::getType('datetime'); $platform = $this->_conn->getDatabasePlatform(); $this->startTiming(); for ($i = 0; $i < $count; $i++) { diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index b8fcfb35ede..3b81ef680c6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -15,14 +15,14 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase { public function testModifyLimitQueryWitoutLimit() { - $sql = $this->_platform->modifyLimitQuery('SELECT n FROM Foo', null , 10); - self::assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10',$sql); + $sql = $this->_platform->modifyLimitQuery('SELECT n FROM Foo', null, 10); + self::assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10', $sql); } public function testGenerateMixedCaseTableCreate() { - $table = new Table("Foo"); - $table->addColumn("Bar", "integer"); + $table = new Table('Foo'); + $table->addColumn('Bar', 'integer'); $sql = $this->_platform->getCreateTableSQL($table); self::assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql)); @@ -35,16 +35,12 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( - 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA (foo, bar)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB' - ); + return ['CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA (foo, bar)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; } public function getGenerateAlterTableSql() { - return array( - "ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, CHANGE bloo bloo TINYINT(1) DEFAULT '0' NOT NULL" - ); + return ["ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, CHANGE bloo bloo TINYINT(1) DEFAULT '0' NOT NULL"]; } public function testGeneratesSqlSnippets() @@ -88,17 +84,18 @@ public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'INT', - $this->_platform->getIntegerTypeDeclarationSQL(array()) + $this->_platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'INT AUTO_INCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true) - )); + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + ); self::assertEquals( 'INT AUTO_INCREMENT', $this->_platform->getIntegerTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true) - )); + ['autoincrement' => true, 'primary' => true] + ) + ); } public function testGeneratesTypeDeclarationForStrings() @@ -106,16 +103,17 @@ public function testGeneratesTypeDeclarationForStrings() self::assertEquals( 'CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL( - array('length' => 10, 'fixed' => true) - )); + ['length' => 10, 'fixed' => true] + ) + ); self::assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)), + $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL(array()), + $this->_platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } @@ -155,25 +153,25 @@ public function getGenerateForeignKeySql() */ public function testUniquePrimaryKey() { - $keyTable = new Table("foo"); - $keyTable->addColumn("bar", "integer"); - $keyTable->addColumn("baz", "string"); - $keyTable->setPrimaryKey(array("bar")); - $keyTable->addUniqueIndex(array("baz")); + $keyTable = new Table('foo'); + $keyTable->addColumn('bar', 'integer'); + $keyTable->addColumn('baz', 'string'); + $keyTable->setPrimaryKey(['bar']); + $keyTable->addUniqueIndex(['baz']); - $oldTable = new Table("foo"); - $oldTable->addColumn("bar", "integer"); - $oldTable->addColumn("baz", "string"); + $oldTable = new Table('foo'); + $oldTable->addColumn('bar', 'integer'); + $oldTable->addColumn('baz', 'string'); - $c = new \Doctrine\DBAL\Schema\Comparator; + $c = new Comparator(); $diff = $c->diffTable($oldTable, $keyTable); $sql = $this->_platform->getAlterTableSQL($diff); - self::assertEquals(array( - "ALTER TABLE foo ADD PRIMARY KEY (bar)", - "CREATE UNIQUE INDEX UNIQ_8C73652178240498 ON foo (baz)", - ), $sql); + self::assertEquals([ + 'ALTER TABLE foo ADD PRIMARY KEY (bar)', + 'CREATE UNIQUE INDEX UNIQ_8C73652178240498 ON foo (baz)', + ], $sql); } public function testModifyLimitQuery() @@ -193,24 +191,24 @@ public function testModifyLimitQueryWithEmptyOffset() */ public function testGetDateTimeTypeDeclarationSql() { - self::assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => false))); - self::assertEquals("TIMESTAMP", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true))); - self::assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array())); + self::assertEquals('DATETIME', $this->_platform->getDateTimeTypeDeclarationSQL(['version' => false])); + self::assertEquals('TIMESTAMP', $this->_platform->getDateTimeTypeDeclarationSQL(['version' => true])); + self::assertEquals('DATETIME', $this->_platform->getDateTimeTypeDeclarationSQL([])); } public function getCreateTableColumnCommentsSQL() { - return array("CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); + return ["CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"]; } public function getAlterTableColumnCommentsSQL() { - return array("ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE foo foo VARCHAR(255) NOT NULL, CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'"); + return ["ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE foo foo VARCHAR(255) NOT NULL, CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'"]; } public function getCreateTableColumnTypeCommentsSQL() { - return array("CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"); + return ["CREATE TABLE test (id INT NOT NULL, data LONGTEXT NOT NULL COMMENT '(DC2Type:array)', PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB"]; } /** @@ -218,47 +216,41 @@ public function getCreateTableColumnTypeCommentsSQL() */ public function testChangeIndexWithForeignKeys() { - $index = new Index("idx", array("col"), false); - $unique = new Index("uniq", array("col"), true); + $index = new Index('idx', ['col'], false); + $unique = new Index('uniq', ['col'], true); - $diff = new TableDiff("test", array(), array(), array(), array($unique), array(), array($index)); - $sql = $this->_platform->getAlterTableSQL($diff); - self::assertEquals(array("ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)"), $sql); + $diff = new TableDiff('test', [], [], [], [$unique], [], [$index]); + $sql = $this->_platform->getAlterTableSQL($diff); + self::assertEquals(['ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)'], $sql); - $diff = new TableDiff("test", array(), array(), array(), array($index), array(), array($unique)); - $sql = $this->_platform->getAlterTableSQL($diff); - self::assertEquals(array("ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)"), $sql); + $diff = new TableDiff('test', [], [], [], [$index], [], [$unique]); + $sql = $this->_platform->getAlterTableSQL($diff); + self::assertEquals(['ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)'], $sql); } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - 'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, PRIMARY KEY(`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB' - ); + return ['CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, PRIMARY KEY(`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; } protected function getQuotedColumnInIndexSQL() { - return array( - 'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, INDEX IDX_22660D028FD6E0FB (`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB' - ); + return ['CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, INDEX IDX_22660D028FD6E0FB (`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; } protected function getQuotedNameInIndexSQL() { - return array( - 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL, INDEX `key` (column1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB' - ); + return ['CREATE TABLE test (column1 VARCHAR(255) NOT NULL, INDEX `key` (column1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; } protected function getQuotedColumnInForeignKeySQL() { - return array( + return [ 'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, `bar` VARCHAR(255) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', 'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foreign` (`create`, bar, `foo-bar`)', 'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES foo (`create`, bar, `foo-bar`)', 'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foo-bar` (`create`, bar, `foo-bar`)', - ); + ]; } public function testCreateTableWithFulltextIndex() @@ -266,13 +258,13 @@ public function testCreateTableWithFulltextIndex() $table = new Table('fulltext_table'); $table->addOption('engine', 'MyISAM'); $table->addColumn('text', 'text'); - $table->addIndex(array('text'), 'fulltext_text'); + $table->addIndex(['text'], 'fulltext_text'); $index = $table->getIndex('fulltext_text'); $index->addFlag('fulltext'); $sql = $this->_platform->getCreateTableSQL($table); - self::assertEquals(array('CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql); + self::assertEquals(['CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'], $sql); } public function testCreateTableWithSpatialIndex() @@ -280,37 +272,37 @@ public function testCreateTableWithSpatialIndex() $table = new Table('spatial_table'); $table->addOption('engine', 'MyISAM'); $table->addColumn('point', 'text'); // This should be a point type - $table->addIndex(array('point'), 'spatial_text'); + $table->addIndex(['point'], 'spatial_text'); $index = $table->getIndex('spatial_text'); $index->addFlag('spatial'); $sql = $this->_platform->getCreateTableSQL($table); - self::assertEquals(array('CREATE TABLE spatial_table (point LONGTEXT NOT NULL, SPATIAL INDEX spatial_text (point)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql); + self::assertEquals(['CREATE TABLE spatial_table (point LONGTEXT NOT NULL, SPATIAL INDEX spatial_text (point)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'], $sql); } public function testClobTypeDeclarationSQL() { - self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 1))); - self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 255))); - self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 256))); - self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65535))); - self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65536))); - self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777215))); - self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777216))); - self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array())); + self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 1])); + self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 255])); + self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 256])); + self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 65535])); + self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 65536])); + self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 16777215])); + self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 16777216])); + self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL([])); } public function testBlobTypeDeclarationSQL() { - self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 1))); - self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 255))); - self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 256))); - self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65535))); - self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65536))); - self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777215))); - self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777216))); - self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array())); + self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 1])); + self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 255])); + self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 256])); + self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 65535])); + self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 65536])); + self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 16777215])); + self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 16777216])); + self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL([])); } /** @@ -321,16 +313,16 @@ public function testAlterTableAddPrimaryKey() $table = new Table('alter_table_add_pk'); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); - $table->addIndex(array('id'), 'idx_id'); + $table->addIndex(['id'], 'idx_id'); $comparator = new Comparator(); $diffTable = clone $table; $diffTable->dropIndex('idx_id'); - $diffTable->setPrimaryKey(array('id')); + $diffTable->setPrimaryKey(['id']); self::assertEquals( - array('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)) ); } @@ -340,23 +332,23 @@ public function testAlterTableAddPrimaryKey() */ public function testAlterPrimaryKeyWithAutoincrementColumn() { - $table = new Table("alter_primary_key"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('alter_primary_key'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); - $diffTable->setPrimaryKey(array('foo')); + $diffTable->setPrimaryKey(['foo']); self::assertEquals( - array( + [ 'ALTER TABLE alter_primary_key MODIFY id INT NOT NULL', '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)) ); } @@ -366,22 +358,22 @@ public function testAlterPrimaryKeyWithAutoincrementColumn() */ public function testDropPrimaryKeyWithAutoincrementColumn() { - $table = new Table("drop_primary_key"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('drop_primary_key'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'integer'); - $table->setPrimaryKey(array('id', 'foo')); + $table->setPrimaryKey(['id', 'foo']); $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); self::assertEquals( - array( + [ '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)) ); } @@ -391,24 +383,24 @@ public function testDropPrimaryKeyWithAutoincrementColumn() */ public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoincrementColumn() { - $table = new Table("tbl"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('tbl'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'integer'); - $table->setPrimaryKey(array('id', 'foo')); + $table->setPrimaryKey(['id', 'foo']); $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); - $diffTable->setPrimaryKey(array('id')); + $diffTable->setPrimaryKey(['id']); self::assertSame( - array( + [ 'ALTER TABLE tbl MODIFY id INT NOT NULL', 'ALTER TABLE tbl DROP PRIMARY KEY', 'ALTER TABLE tbl ADD PRIMARY KEY (id)', - ), + ], $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -418,24 +410,24 @@ public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoinc */ public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn() { - $table = new Table("tbl"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('tbl'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); - $diffTable->setPrimaryKey(array('id', 'foo')); + $diffTable->setPrimaryKey(['id', 'foo']); self::assertSame( - array( + [ 'ALTER TABLE tbl MODIFY id INT NOT NULL', 'ALTER TABLE tbl DROP PRIMARY KEY', 'ALTER TABLE tbl ADD PRIMARY KEY (id, foo)', - ), + ], $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -445,57 +437,55 @@ public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn */ public function testAddAutoIncrementPrimaryKey() { - $keyTable = new Table("foo"); - $keyTable->addColumn("id", "integer", array('autoincrement' => true)); - $keyTable->addColumn("baz", "string"); - $keyTable->setPrimaryKey(array("id")); + $keyTable = new Table('foo'); + $keyTable->addColumn('id', 'integer', ['autoincrement' => true]); + $keyTable->addColumn('baz', 'string'); + $keyTable->setPrimaryKey(['id']); - $oldTable = new Table("foo"); - $oldTable->addColumn("baz", "string"); + $oldTable = new Table('foo'); + $oldTable->addColumn('baz', 'string'); - $c = new \Doctrine\DBAL\Schema\Comparator; + $c = new Comparator(); $diff = $c->diffTable($oldTable, $keyTable); $sql = $this->_platform->getAlterTableSQL($diff); - self::assertEquals(array( - "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); } public function testNamedPrimaryKey() { - $diff = new TableDiff('mytable'); - $diff->changedIndexes['foo_index'] = new Index('foo_index', array('foo'), true, true); + $diff = new TableDiff('mytable'); + $diff->changedIndexes['foo_index'] = new Index('foo_index', ['foo'], true, true); $sql = $this->_platform->getAlterTableSQL($diff); - self::assertEquals(array( - "ALTER TABLE mytable DROP PRIMARY KEY", - "ALTER TABLE mytable ADD PRIMARY KEY (foo)", - ), $sql); + self::assertEquals([ + 'ALTER TABLE mytable DROP PRIMARY KEY', + 'ALTER TABLE mytable ADD PRIMARY KEY (foo)', + ], $sql); } public function testAlterPrimaryKeyWithNewColumn() { - $table = new Table("yolo"); + $table = new Table('yolo'); $table->addColumn('pkc1', 'integer'); $table->addColumn('col_a', 'integer'); - $table->setPrimaryKey(array('pkc1')); + $table->setPrimaryKey(['pkc1']); $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->addColumn('pkc2', 'integer'); $diffTable->dropPrimaryKey(); - $diffTable->setPrimaryKey(array('pkc1', 'pkc2')); + $diffTable->setPrimaryKey(['pkc1', 'pkc2']); self::assertSame( - array( + [ 'ALTER TABLE yolo DROP PRIMARY KEY', 'ALTER TABLE yolo ADD pkc2 INT NOT NULL', 'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)', - ), + ], $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -516,13 +506,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('VARBINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 65535))); + self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('VARBINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 65535])); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('BINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 65535))); + self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 65535])); } /** @@ -544,15 +534,15 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() { - $table = new Table("foreign_table"); + $table = new Table('foreign_table'); $table->addColumn('id', 'integer'); $table->addColumn('fk_id', 'integer'); - $table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id')); - $table->setPrimaryKey(array('id')); + $table->addForeignKeyConstraint('foreign_table', ['fk_id'], ['id']); + $table->setPrimaryKey(['id']); $table->addOption('engine', 'MyISAM'); self::assertSame( - array('CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), + ['CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'], $this->_platform->getCreateTableSQL( $table, AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS @@ -563,10 +553,10 @@ public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() $table->addOption('engine', 'InnoDB'); self::assertSame( - array( + [ 'CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', - 'ALTER TABLE foreign_table ADD CONSTRAINT FK_5690FFE2A57719D0 FOREIGN KEY (fk_id) REFERENCES foreign_table (id)' - ), + 'ALTER TABLE foreign_table ADD CONSTRAINT FK_5690FFE2A57719D0 FOREIGN KEY (fk_id) REFERENCES foreign_table (id)', + ], $this->_platform->getCreateTableSQL( $table, AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS @@ -576,20 +566,20 @@ public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines() { - $table = new Table("foreign_table"); + $table = new Table('foreign_table'); $table->addColumn('id', 'integer'); $table->addColumn('fk_id', 'integer'); - $table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id')); - $table->setPrimaryKey(array('id')); + $table->addForeignKeyConstraint('foreign_table', ['fk_id'], ['id']); + $table->setPrimaryKey(['id']); $table->addOption('engine', 'MyISAM'); - $addedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'foo', array('id'), 'fk_add')); - $changedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'bar', array('id'), 'fk_change')); - $removedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'baz', array('id'), 'fk_remove')); + $addedForeignKeys = [new ForeignKeyConstraint(['fk_id'], 'foo', ['id'], 'fk_add')]; + $changedForeignKeys = [new ForeignKeyConstraint(['fk_id'], 'bar', ['id'], 'fk_change')]; + $removedForeignKeys = [new ForeignKeyConstraint(['fk_id'], 'baz', ['id'], 'fk_remove')]; - $tableDiff = new TableDiff('foreign_table'); - $tableDiff->fromTable = $table; - $tableDiff->addedForeignKeys = $addedForeignKeys; + $tableDiff = new TableDiff('foreign_table'); + $tableDiff->fromTable = $table; + $tableDiff->addedForeignKeys = $addedForeignKeys; $tableDiff->changedForeignKeys = $changedForeignKeys; $tableDiff->removedForeignKeys = $removedForeignKeys; @@ -597,19 +587,19 @@ public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines( $table->addOption('engine', 'InnoDB'); - $tableDiff = new TableDiff('foreign_table'); - $tableDiff->fromTable = $table; - $tableDiff->addedForeignKeys = $addedForeignKeys; + $tableDiff = new TableDiff('foreign_table'); + $tableDiff->fromTable = $table; + $tableDiff->addedForeignKeys = $addedForeignKeys; $tableDiff->changedForeignKeys = $changedForeignKeys; $tableDiff->removedForeignKeys = $removedForeignKeys; self::assertSame( - array( + [ 'ALTER TABLE foreign_table DROP FOREIGN KEY fk_remove', 'ALTER TABLE foreign_table DROP FOREIGN KEY fk_change', 'ALTER TABLE foreign_table ADD CONSTRAINT fk_add FOREIGN KEY (fk_id) REFERENCES foo (id)', 'ALTER TABLE foreign_table ADD CONSTRAINT fk_change FOREIGN KEY (fk_id) REFERENCES bar (id)', - ), + ], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -619,10 +609,10 @@ public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines( */ protected function getAlterTableRenameIndexSQL() { - return array( + return [ 'DROP INDEX idx_foo ON mytable', 'CREATE INDEX idx_bar ON mytable (id)', - ); + ]; } /** @@ -630,12 +620,12 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'DROP INDEX `create` ON `table`', 'CREATE INDEX `select` ON `table` (id)', 'DROP INDEX `foo` ON `table`', 'CREATE INDEX `bar` ON `table` (id)', - ); + ]; } /** @@ -643,10 +633,10 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'DROP INDEX idx_foo ON myschema.mytable', 'CREATE INDEX idx_bar ON myschema.mytable (id)', - ); + ]; } /** @@ -654,12 +644,12 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'DROP INDEX `create` ON `schema`.`table`', 'CREATE INDEX `select` ON `schema`.`table` (id)', 'DROP INDEX `foo` ON `schema`.`table`', 'CREATE INDEX `bar` ON `schema`.`table` (id)', - ); + ]; } protected function getQuotesDropForeignKeySQL() @@ -674,22 +664,22 @@ protected function getQuotesDropConstraintSQL() public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() { - $table = new Table("text_blob_default_value"); - $table->addColumn('def_text', 'text', array('default' => 'def')); - $table->addColumn('def_text_null', 'text', array('notnull' => false, 'default' => 'def')); - $table->addColumn('def_blob', 'blob', array('default' => 'def')); - $table->addColumn('def_blob_null', 'blob', array('notnull' => false, 'default' => 'def')); + $table = new Table('text_blob_default_value'); + $table->addColumn('def_text', 'text', ['default' => 'def']); + $table->addColumn('def_text_null', 'text', ['notnull' => false, 'default' => 'def']); + $table->addColumn('def_blob', 'blob', ['default' => 'def']); + $table->addColumn('def_blob_null', 'blob', ['notnull' => false, 'default' => 'def']); self::assertSame( - array('CREATE TABLE text_blob_default_value (def_text LONGTEXT NOT NULL, def_text_null LONGTEXT DEFAULT NULL, def_blob LONGBLOB NOT NULL, def_blob_null LONGBLOB DEFAULT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'), + ['CREATE TABLE text_blob_default_value (def_text LONGTEXT NOT NULL, def_text_null LONGTEXT DEFAULT NULL, def_blob LONGBLOB NOT NULL, def_blob_null LONGBLOB DEFAULT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'], $this->_platform->getCreateTableSQL($table) ); $diffTable = clone $table; - $diffTable->changeColumn('def_text', array('default' => null)); - $diffTable->changeColumn('def_text_null', array('default' => null)); - $diffTable->changeColumn('def_blob', array('default' => null)); - $diffTable->changeColumn('def_blob_null', array('default' => null)); + $diffTable->changeColumn('def_text', ['default' => null]); + $diffTable->changeColumn('def_text_null', ['default' => null]); + $diffTable->changeColumn('def_blob', ['default' => null]); + $diffTable->changeColumn('def_blob_null', ['default' => null]); $comparator = new Comparator(); @@ -701,8 +691,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( - "ALTER TABLE mytable " . + return ['ALTER TABLE mytable ' . "CHANGE unquoted1 unquoted INT NOT NULL COMMENT 'Unquoted 1', " . "CHANGE unquoted2 `where` INT NOT NULL COMMENT 'Unquoted 2', " . "CHANGE unquoted3 `foo` INT NOT NULL COMMENT 'Unquoted 3', " . @@ -711,8 +700,8 @@ protected function getQuotedAlterTableRenameColumnSQL() "CHANGE `select` `bar` INT NOT NULL COMMENT 'Reserved keyword 3', " . "CHANGE quoted1 quoted INT NOT NULL COMMENT 'Quoted 1', " . "CHANGE quoted2 `and` INT NOT NULL COMMENT 'Quoted 2', " . - "CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'" - ); + "CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'", + ]; } /** @@ -720,15 +709,14 @@ protected function getQuotedAlterTableRenameColumnSQL() */ protected function getQuotedAlterTableChangeColumnLengthSQL() { - return array( - "ALTER TABLE mytable " . + return ['ALTER TABLE mytable ' . "CHANGE unquoted1 unquoted1 VARCHAR(255) NOT NULL COMMENT 'Unquoted 1', " . "CHANGE unquoted2 unquoted2 VARCHAR(255) NOT NULL COMMENT 'Unquoted 2', " . "CHANGE unquoted3 unquoted3 VARCHAR(255) NOT NULL COMMENT 'Unquoted 3', " . "CHANGE `create` `create` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 1', " . "CHANGE `table` `table` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 2', " . - "CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'" - ); + "CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'", + ]; } /** @@ -736,7 +724,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -744,9 +732,7 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( - "ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'", - ); + return ["ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'"]; } /** @@ -754,14 +740,14 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE `foo` DROP FOREIGN KEY fk1', 'ALTER TABLE `foo` DROP FOREIGN KEY fk2', 'ALTER TABLE `foo` RENAME TO `table`, ADD bloo INT NOT NULL, DROP baz, CHANGE bar bar INT DEFAULT NULL, ' . 'CHANGE id war INT NOT NULL', 'ALTER TABLE `table` ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', 'ALTER TABLE `table` ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ); + ]; } /** @@ -769,11 +755,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ "COMMENT ON COLUMN foo.bar IS 'comment'", "COMMENT ON COLUMN `Foo`.`BAR` IS 'comment'", "COMMENT ON COLUMN `select`.`from` IS 'comment'", - ); + ]; } /** @@ -805,9 +791,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() */ protected function getAlterStringToFixedStringSQL() { - return array( - 'ALTER TABLE mytable CHANGE name name CHAR(2) NOT NULL', - ); + return ['ALTER TABLE mytable CHANGE name name CHAR(2) NOT NULL']; } /** @@ -815,12 +799,12 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( + return [ 'ALTER TABLE mytable DROP FOREIGN KEY fk_foo', 'DROP INDEX idx_foo ON mytable', 'CREATE INDEX idx_foo_renamed ON mytable (foo)', 'ALTER TABLE mytable ADD CONSTRAINT fk_foo FOREIGN KEY (foo) REFERENCES foreign_table (id)', - ); + ]; } /** @@ -828,14 +812,14 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function getGeneratesDecimalTypeDeclarationSQL() { - return array( - array(array(), 'NUMERIC(10, 0)'), - array(array('unsigned' => true), 'NUMERIC(10, 0) UNSIGNED'), - array(array('unsigned' => false), 'NUMERIC(10, 0)'), - array(array('precision' => 5), 'NUMERIC(5, 0)'), - array(array('scale' => 5), 'NUMERIC(10, 5)'), - array(array('precision' => 8, 'scale' => 2), 'NUMERIC(8, 2)'), - ); + return [ + [[], 'NUMERIC(10, 0)'], + [['unsigned' => true], 'NUMERIC(10, 0) UNSIGNED'], + [['unsigned' => false], 'NUMERIC(10, 0)'], + [['precision' => 5], 'NUMERIC(5, 0)'], + [['scale' => 5], 'NUMERIC(10, 5)'], + [['precision' => 8, 'scale' => 2], 'NUMERIC(8, 2)'], + ]; } /** @@ -843,14 +827,14 @@ public function getGeneratesDecimalTypeDeclarationSQL() */ public function getGeneratesFloatDeclarationSQL() { - return array( - array(array(), 'DOUBLE PRECISION'), - array(array('unsigned' => true), 'DOUBLE PRECISION UNSIGNED'), - array(array('unsigned' => false), 'DOUBLE PRECISION'), - array(array('precision' => 5), 'DOUBLE PRECISION'), - array(array('scale' => 5), 'DOUBLE PRECISION'), - array(array('precision' => 8, 'scale' => 2), 'DOUBLE PRECISION'), - ); + return [ + [[], 'DOUBLE PRECISION'], + [['unsigned' => true], 'DOUBLE PRECISION UNSIGNED'], + [['unsigned' => false], 'DOUBLE PRECISION'], + [['precision' => 5], 'DOUBLE PRECISION'], + [['scale' => 5], 'DOUBLE PRECISION'], + [['precision' => 8, 'scale' => 2], 'DOUBLE PRECISION'], + ]; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index a0b0ea33741..9b303a6e76e 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -13,17 +13,16 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\Types\CommentedType; use function get_class; use function implode; use function sprintf; use function str_repeat; -abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase +abstract class AbstractPlatformTestCase extends DbalTestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ protected $_platform; abstract public function createPlatform(); @@ -38,13 +37,13 @@ protected function setUp() */ public function testQuoteIdentifier() { - if ($this->_platform->getName() == "mssql") { + if ($this->_platform->getName() === 'mssql') { $this->markTestSkipped('Not working this way on mssql.'); } $c = $this->_platform->getIdentifierQuoteCharacter(); - self::assertEquals($c."test".$c, $this->_platform->quoteIdentifier("test")); - self::assertEquals($c."test".$c.".".$c."test".$c, $this->_platform->quoteIdentifier("test.test")); + self::assertEquals($c . 'test' . $c, $this->_platform->quoteIdentifier('test')); + self::assertEquals($c . 'test' . $c . '.' . $c . 'test' . $c, $this->_platform->quoteIdentifier('test.test')); self::assertEquals(str_repeat($c, 4), $this->_platform->quoteIdentifier($c)); } @@ -53,19 +52,18 @@ public function testQuoteIdentifier() */ public function testQuoteSingleIdentifier() { - if ($this->_platform->getName() == "mssql") { + if ($this->_platform->getName() === 'mssql') { $this->markTestSkipped('Not working this way on mssql.'); } $c = $this->_platform->getIdentifierQuoteCharacter(); - self::assertEquals($c."test".$c, $this->_platform->quoteSingleIdentifier("test")); - self::assertEquals($c."test.test".$c, $this->_platform->quoteSingleIdentifier("test.test")); + self::assertEquals($c . 'test' . $c, $this->_platform->quoteSingleIdentifier('test')); + self::assertEquals($c . 'test.test' . $c, $this->_platform->quoteSingleIdentifier('test.test')); self::assertEquals(str_repeat($c, 4), $this->_platform->quoteSingleIdentifier($c)); } /** * @group DBAL-1029 - * * @dataProvider getReturnsForeignKeyReferentialActionSQL */ public function testReturnsForeignKeyReferentialActionSQL($action, $expectedSQL) @@ -78,14 +76,14 @@ public function testReturnsForeignKeyReferentialActionSQL($action, $expectedSQL) */ public function getReturnsForeignKeyReferentialActionSQL() { - return array( - array('CASCADE', 'CASCADE'), - array('SET NULL', 'SET NULL'), - array('NO ACTION', 'NO ACTION'), - array('RESTRICT', 'RESTRICT'), - array('SET DEFAULT', 'SET DEFAULT'), - array('CaScAdE', 'CASCADE'), - ); + return [ + ['CASCADE', 'CASCADE'], + ['SET NULL', 'SET NULL'], + ['NO ACTION', 'NO ACTION'], + ['RESTRICT', 'RESTRICT'], + ['SET DEFAULT', 'SET DEFAULT'], + ['CaScAdE', 'CASCADE'], + ]; } public function testGetInvalidForeignKeyReferentialActionSQL() @@ -117,7 +115,7 @@ public function testRegisterUnknownDoctrineMappingType() */ public function testRegistersCommentedDoctrineMappingTypeImplicitly() { - if (!Type::hasType('my_commented')) { + if (! Type::hasType('my_commented')) { Type::addType('my_commented', CommentedType::class); } @@ -129,7 +127,6 @@ public function testRegistersCommentedDoctrineMappingTypeImplicitly() /** * @group DBAL-939 - * * @dataProvider getIsCommentedDoctrineType */ public function testIsCommentedDoctrineType(Type $type, $commented) @@ -141,15 +138,15 @@ public function getIsCommentedDoctrineType() { $this->setUp(); - $data = array(); + $data = []; foreach (Type::getTypesMap() as $typeName => $className) { $type = Type::getType($typeName); - $data[$typeName] = array( + $data[$typeName] = [ $type, $type->requiresSQLCommentHint($this->_platform), - ); + ]; } return $data; @@ -166,9 +163,9 @@ public function testCreateWithNoColumns() public function testGeneratesTableCreationSql() { $table = new Table('test'); - $table->addColumn('id', 'integer', array('notnull' => true, 'autoincrement' => true)); - $table->addColumn('test', 'string', array('notnull' => false, 'length' => 255)); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['notnull' => true, 'autoincrement' => true]); + $table->addColumn('test', 'string', ['notnull' => false, 'length' => 255]); + $table->setPrimaryKey(['id']); $sql = $this->_platform->getCreateTableSQL($table); self::assertEquals($this->getGenerateTableSql(), $sql[0]); @@ -179,9 +176,9 @@ abstract public function getGenerateTableSql(); public function testGenerateTableWithMultiColumnUniqueIndex() { $table = new Table('test'); - $table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255)); - $table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255)); - $table->addUniqueIndex(array("foo", "bar")); + $table->addColumn('foo', 'string', ['notnull' => false, 'length' => 255]); + $table->addColumn('bar', 'string', ['notnull' => false, 'length' => 255]); + $table->addUniqueIndex(['foo', 'bar']); $sql = $this->_platform->getCreateTableSQL($table); self::assertEquals($this->getGenerateTableWithMultiColumnUniqueIndexSql(), $sql); @@ -191,7 +188,7 @@ abstract public function getGenerateTableWithMultiColumnUniqueIndexSql(); public function testGeneratesIndexCreationSql() { - $indexDef = new \Doctrine\DBAL\Schema\Index('my_idx', array('user_name', 'last_login')); + $indexDef = new Index('my_idx', ['user_name', 'last_login']); self::assertEquals( $this->getGenerateIndexSql(), @@ -203,7 +200,7 @@ abstract public function getGenerateIndexSql(); public function testGeneratesUniqueIndexCreationSql() { - $indexDef = new \Doctrine\DBAL\Schema\Index('index_name', array('test', 'test2'), true); + $indexDef = new Index('index_name', ['test', 'test2'], true); $sql = $this->_platform->getCreateIndexSQL($indexDef, 'test'); self::assertEquals($this->getGenerateUniqueIndexSql(), $sql); @@ -213,20 +210,20 @@ abstract public function getGenerateUniqueIndexSql(); public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() { - $where = 'test IS NULL AND test2 IS NOT NULL'; - $indexDef = new \Doctrine\DBAL\Schema\Index('name', array('test', 'test2'), false, false, array(), array('where' => $where)); - $uniqueIndex = new \Doctrine\DBAL\Schema\Index('name', array('test', 'test2'), true, false, array(), array('where' => $where)); + $where = 'test IS NULL AND test2 IS NOT NULL'; + $indexDef = new Index('name', ['test', 'test2'], false, false, [], ['where' => $where]); + $uniqueIndex = new Index('name', ['test', 'test2'], true, false, [], ['where' => $where]); $expected = ' WHERE ' . $where; - $actuals = array(); + $actuals = []; if ($this->supportsInlineIndexDeclaration()) { - $actuals []= $this->_platform->getIndexDeclarationSQL('name', $indexDef); + $actuals[] = $this->_platform->getIndexDeclarationSQL('name', $indexDef); } - $actuals []= $this->_platform->getUniqueConstraintDeclarationSQL('name', $uniqueIndex); - $actuals []= $this->_platform->getCreateIndexSQL($indexDef, 'table'); + $actuals[] = $this->_platform->getUniqueConstraintDeclarationSQL('name', $uniqueIndex); + $actuals[] = $this->_platform->getCreateIndexSQL($indexDef, 'table'); foreach ($actuals as $actual) { if ($this->_platform->supportsPartialIndexes()) { @@ -239,7 +236,7 @@ public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() public function testGeneratesForeignKeyCreationSql() { - $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name_id'), 'other_table', array('id'), ''); + $fk = new ForeignKeyConstraint(['fk_name_id'], 'other_table', ['id'], ''); $sql = $this->_platform->getCreateForeignKeySQL($fk, 'test'); self::assertEquals($sql, $this->getGenerateForeignKeySql()); @@ -249,22 +246,22 @@ abstract public function getGenerateForeignKeySql(); public function testGeneratesConstraintCreationSql() { - $idx = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, false); + $idx = new Index('constraint_name', ['test'], true, false); $sql = $this->_platform->getCreateConstraintSQL($idx, 'test'); self::assertEquals($this->getGenerateConstraintUniqueIndexSql(), $sql); - $pk = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, true); + $pk = new Index('constraint_name', ['test'], true, true); $sql = $this->_platform->getCreateConstraintSQL($pk, 'test'); self::assertEquals($this->getGenerateConstraintPrimaryIndexSql(), $sql); - $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk'); + $fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk'); $sql = $this->_platform->getCreateConstraintSQL($fk, 'test'); self::assertEquals($this->getGenerateConstraintForeignKeySql($fk), $sql); } public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys() { - $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk'); + $fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk'); if ($this->_platform->supportsForeignKeyConstraints()) { self::assertInternalType( @@ -291,7 +288,7 @@ public function testGeneratesBitAndComparisonExpressionSql() self::assertEquals($this->getBitAndComparisonExpressionSql(2, 4), $sql); } - protected function getBitOrComparisonExpressionSql($value1, $value2) + protected function getBitOrComparisonExpressionSql($value1, $value2) { return '(' . $value1 . ' | ' . $value2 . ')'; } @@ -329,28 +326,34 @@ public function testGeneratesTableAlterationSql() $expectedSql = $this->getGenerateAlterTableSql(); $table = new Table('mytable'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'string'); $table->addColumn('bloo', 'boolean'); - $table->setPrimaryKey(array('id')); - - $tableDiff = new TableDiff('mytable'); - $tableDiff->fromTable = $table; - $tableDiff->newName = 'userlist'; - $tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('notnull' => false)); - $tableDiff->removedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', \Doctrine\DBAL\Types\Type::getType('integer')); - $tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'bar', new \Doctrine\DBAL\Schema\Column( - 'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'def') + $table->setPrimaryKey(['id']); + + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = $table; + $tableDiff->newName = 'userlist'; + $tableDiff->addedColumns['quota'] = new Column('quota', Type::getType('integer'), ['notnull' => false]); + $tableDiff->removedColumns['foo'] = new Column('foo', Type::getType('integer')); + $tableDiff->changedColumns['bar'] = new ColumnDiff( + 'bar', + new Column( + 'baz', + Type::getType('string'), + ['default' => 'def'] ), - array('type', 'notnull', 'default') + ['type', 'notnull', 'default'] ); - $tableDiff->changedColumns['bloo'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'bloo', new \Doctrine\DBAL\Schema\Column( - 'bloo', \Doctrine\DBAL\Types\Type::getType('boolean'), array('default' => false) + $tableDiff->changedColumns['bloo'] = new ColumnDiff( + 'bloo', + new Column( + 'bloo', + Type::getType('boolean'), + ['default' => false] ), - array('type', 'notnull', 'default') + ['type', 'notnull', 'default'] ); $sql = $this->_platform->getAlterTableSQL($tableDiff); @@ -360,14 +363,14 @@ public function testGeneratesTableAlterationSql() public function testGetCustomColumnDeclarationSql() { - $field = array('columnDefinition' => 'MEDIUMINT(6) UNSIGNED'); + $field = ['columnDefinition' => 'MEDIUMINT(6) UNSIGNED']; self::assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->_platform->getColumnDeclarationSQL('foo', $field)); } public function testGetCreateTableSqlDispatchEvent() { $listenerMock = $this->getMockBuilder('GetCreateTableSqlDispatchEvenListener') - ->setMethods(array('onSchemaCreateTable', 'onSchemaCreateTableColumn')) + ->setMethods(['onSchemaCreateTable', 'onSchemaCreateTableColumn']) ->getMock(); $listenerMock ->expects($this->once()) @@ -377,13 +380,13 @@ public function testGetCreateTableSqlDispatchEvent() ->method('onSchemaCreateTableColumn'); $eventManager = new EventManager(); - $eventManager->addEventListener(array(Events::onSchemaCreateTable, Events::onSchemaCreateTableColumn), $listenerMock); + $eventManager->addEventListener([Events::onSchemaCreateTable, Events::onSchemaCreateTableColumn], $listenerMock); $this->_platform->setEventManager($eventManager); $table = new Table('test'); - $table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255)); - $table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255)); + $table->addColumn('foo', 'string', ['notnull' => false, 'length' => 255]); + $table->addColumn('bar', 'string', ['notnull' => false, 'length' => 255]); $this->_platform->getCreateTableSQL($table); } @@ -391,14 +394,14 @@ public function testGetCreateTableSqlDispatchEvent() public function testGetDropTableSqlDispatchEvent() { $listenerMock = $this->getMockBuilder('GetDropTableSqlDispatchEventListener') - ->setMethods(array('onSchemaDropTable')) + ->setMethods(['onSchemaDropTable']) ->getMock(); $listenerMock ->expects($this->once()) ->method('onSchemaDropTable'); $eventManager = new EventManager(); - $eventManager->addEventListener(array(Events::onSchemaDropTable), $listenerMock); + $eventManager->addEventListener([Events::onSchemaDropTable], $listenerMock); $this->_platform->setEventManager($eventManager); @@ -407,13 +410,13 @@ public function testGetDropTableSqlDispatchEvent() public function testGetAlterTableSqlDispatchEvent() { - $events = array( + $events = [ 'onSchemaAlterTable', 'onSchemaAlterTableAddColumn', 'onSchemaAlterTableRemoveColumn', 'onSchemaAlterTableChangeColumn', - 'onSchemaAlterTableRenameColumn' - ); + 'onSchemaAlterTableRenameColumn', + ]; $listenerMock = $this->getMockBuilder('GetAlterTableSqlDispatchEvenListener') ->setMethods($events) @@ -435,13 +438,13 @@ public function testGetAlterTableSqlDispatchEvent() ->method('onSchemaAlterTableRenameColumn'); $eventManager = new EventManager(); - $events = array( + $events = [ Events::onSchemaAlterTable, Events::onSchemaAlterTableAddColumn, Events::onSchemaAlterTableRemoveColumn, Events::onSchemaAlterTableChangeColumn, - Events::onSchemaAlterTableRenameColumn - ); + Events::onSchemaAlterTableRenameColumn, + ]; $eventManager->addEventListener($events, $listenerMock); $this->_platform->setEventManager($eventManager); @@ -451,17 +454,20 @@ public function testGetAlterTableSqlDispatchEvent() $table->addColumn('changed', 'integer'); $table->addColumn('renamed', 'integer'); - $tableDiff = new TableDiff('mytable'); - $tableDiff->fromTable = $table; - $tableDiff->addedColumns['added'] = new \Doctrine\DBAL\Schema\Column('added', \Doctrine\DBAL\Types\Type::getType('integer'), array()); - $tableDiff->removedColumns['removed'] = new \Doctrine\DBAL\Schema\Column('removed', \Doctrine\DBAL\Types\Type::getType('integer'), array()); - $tableDiff->changedColumns['changed'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'changed', new \Doctrine\DBAL\Schema\Column( - 'changed2', \Doctrine\DBAL\Types\Type::getType('string'), array() + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = $table; + $tableDiff->addedColumns['added'] = new Column('added', Type::getType('integer'), []); + $tableDiff->removedColumns['removed'] = new Column('removed', Type::getType('integer'), []); + $tableDiff->changedColumns['changed'] = new ColumnDiff( + 'changed', + new Column( + 'changed2', + Type::getType('string'), + [] ), - array() + [] ); - $tableDiff->renamedColumns['renamed'] = new \Doctrine\DBAL\Schema\Column('renamed2', \Doctrine\DBAL\Types\Type::getType('integer'), array()); + $tableDiff->renamedColumns['renamed'] = new Column('renamed2', Type::getType('integer'), []); $this->_platform->getAlterTableSQL($tableDiff); } @@ -472,8 +478,8 @@ public function testGetAlterTableSqlDispatchEvent() public function testCreateTableColumnComments() { $table = new Table('test'); - $table->addColumn('id', 'integer', array('comment' => 'This is a comment')); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); + $table->setPrimaryKey(['id']); self::assertEquals($this->getCreateTableColumnCommentsSQL(), $this->_platform->getCreateTableSQL($table)); } @@ -483,19 +489,24 @@ public function testCreateTableColumnComments() */ public function testAlterTableColumnComments() { - $tableDiff = new TableDiff('mytable'); - $tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('comment' => 'A comment')); - $tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'foo', new \Doctrine\DBAL\Schema\Column( - 'foo', \Doctrine\DBAL\Types\Type::getType('string') + $tableDiff = new TableDiff('mytable'); + $tableDiff->addedColumns['quota'] = new Column('quota', Type::getType('integer'), ['comment' => 'A comment']); + $tableDiff->changedColumns['foo'] = new ColumnDiff( + 'foo', + new Column( + 'foo', + Type::getType('string') ), - array('comment') + ['comment'] ); - $tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'bar', new \Doctrine\DBAL\Schema\Column( - 'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('comment' => 'B comment') + $tableDiff->changedColumns['bar'] = new ColumnDiff( + 'bar', + new Column( + 'baz', + Type::getType('string'), + ['comment' => 'B comment'] ), - array('comment') + ['comment'] ); self::assertEquals($this->getAlterTableColumnCommentsSQL(), $this->_platform->getAlterTableSQL($tableDiff)); @@ -506,7 +517,7 @@ public function testCreateTableColumnTypeComments() $table = new Table('test'); $table->addColumn('id', 'integer'); $table->addColumn('data', 'array'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); self::assertEquals($this->getCreateTableColumnTypeCommentsSQL(), $this->_platform->getCreateTableSQL($table)); } @@ -529,10 +540,10 @@ public function getCreateTableColumnTypeCommentsSQL() public function testGetDefaultValueDeclarationSQL() { // non-timestamp value will get single quotes - $field = array( + $field = [ 'type' => Type::getType('string'), - 'default' => 'non_timestamp' - ); + 'default' => 'non_timestamp', + ]; self::assertEquals(" DEFAULT 'non_timestamp'", $this->_platform->getDefaultValueDeclarationSQL($field)); } @@ -558,11 +569,11 @@ public function testGetDefaultValueDeclarationSQLDateTime() : void public function testGetDefaultValueDeclarationSQLForIntegerTypes() { - foreach(array('bigint', 'integer', 'smallint') as $type) { - $field = array( + foreach (['bigint', 'integer', 'smallint'] as $type) { + $field = [ 'type' => Type::getType($type), - 'default' => 1 - ); + 'default' => 1, + ]; self::assertEquals( ' DEFAULT 1', @@ -608,7 +619,7 @@ public function testQuotedColumnInPrimaryKeyPropagation() { $table = new Table('`quoted`'); $table->addColumn('create', 'string'); - $table->setPrimaryKey(array('create')); + $table->setPrimaryKey(['create']); $sql = $this->_platform->getCreateTableSQL($table); self::assertEquals($this->getQuotedColumnInPrimaryKeySQL(), $sql); @@ -626,7 +637,7 @@ public function testQuotedColumnInIndexPropagation() { $table = new Table('`quoted`'); $table->addColumn('create', 'string'); - $table->addIndex(array('create')); + $table->addIndex(['create']); $sql = $this->_platform->getCreateTableSQL($table); self::assertEquals($this->getQuotedColumnInIndexSQL(), $sql); @@ -636,7 +647,7 @@ public function testQuotedNameInIndexSQL() { $table = new Table('test'); $table->addColumn('column1', 'string'); - $table->addIndex(array('column1'), '`key`'); + $table->addIndex(['column1'], '`key`'); $sql = $this->_platform->getCreateTableSQL($table); self::assertEquals($this->getQuotedNameInIndexSQL(), $sql); @@ -658,7 +669,7 @@ public function testQuotedColumnInForeignKeyPropagation() $foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). $foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). - $table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_RESERVED_KEYWORD'); + $table->addForeignKeyConstraint($foreignTable, ['create', 'foo', '`bar`'], ['create', 'bar', '`foo-bar`'], [], 'FK_WITH_RESERVED_KEYWORD'); // Foreign table with non-reserved keyword as name (does not need quotation). $foreignTable = new Table('foo'); @@ -666,7 +677,7 @@ public function testQuotedColumnInForeignKeyPropagation() $foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). $foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). - $table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_NON_RESERVED_KEYWORD'); + $table->addForeignKeyConstraint($foreignTable, ['create', 'foo', '`bar`'], ['create', 'bar', '`foo-bar`'], [], 'FK_WITH_NON_RESERVED_KEYWORD'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). $foreignTable = new Table('`foo-bar`'); @@ -674,7 +685,7 @@ public function testQuotedColumnInForeignKeyPropagation() $foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). $foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). - $table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_INTENDED_QUOTATION'); + $table->addForeignKeyConstraint($foreignTable, ['create', 'foo', '`bar`'], ['create', 'bar', '`foo-bar`'], [], 'FK_WITH_INTENDED_QUOTATION'); $sql = $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS); self::assertEquals($this->getQuotedColumnInForeignKeySQL(), $sql); @@ -685,7 +696,7 @@ public function testQuotedColumnInForeignKeyPropagation() */ public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL() { - $index = new Index('select', array('foo'), true); + $index = new Index('select', ['foo'], true); self::assertSame( $this->getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(), @@ -719,7 +730,7 @@ abstract protected function getQuotesReservedKeywordInTruncateTableSQL(); */ public function testQuotesReservedKeywordInIndexDeclarationSQL() { - $index = new Index('select', array('foo')); + $index = new Index('select', ['foo']); if (! $this->supportsInlineIndexDeclaration()) { $this->expectException('Doctrine\DBAL\DBALException'); @@ -770,13 +781,15 @@ public function testGetCreateSchemaSQL() */ public function testAlterTableChangeQuotedColumn() { - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable'); - $tableDiff->fromTable = new \Doctrine\DBAL\Schema\Table('mytable'); - $tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'select', new \Doctrine\DBAL\Schema\Column( - 'select', \Doctrine\DBAL\Types\Type::getType('string') + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = new Table('mytable'); + $tableDiff->changedColumns['foo'] = new ColumnDiff( + 'select', + new Column( + 'select', + Type::getType('string') ), - array('type') + ['type'] ); self::assertContains( @@ -827,7 +840,7 @@ protected function getBinaryMaxLength() */ public function testReturnsBinaryTypeDeclarationSQL() { - $this->_platform->getBinaryTypeDeclarationSQL(array()); + $this->_platform->getBinaryTypeDeclarationSQL([]); } public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() @@ -848,11 +861,11 @@ public function hasNativeJsonType() */ public function testReturnsJsonTypeDeclarationSQL() { - $column = array( + $column = [ 'length' => 666, 'notnull' => true, 'type' => Type::getType('json_array'), - ); + ]; self::assertSame( $this->_platform->getClobTypeDeclarationSQL($column), @@ -865,13 +878,13 @@ public function testReturnsJsonTypeDeclarationSQL() */ public function testAlterTableRenameIndex() { - $tableDiff = new TableDiff('mytable'); + $tableDiff = new TableDiff('mytable'); $tableDiff->fromTable = new Table('mytable'); $tableDiff->fromTable->addColumn('id', 'integer'); - $tableDiff->fromTable->setPrimaryKey(array('id')); - $tableDiff->renamedIndexes = array( - 'idx_foo' => new Index('idx_bar', array('id')) - ); + $tableDiff->fromTable->setPrimaryKey(['id']); + $tableDiff->renamedIndexes = [ + 'idx_foo' => new Index('idx_bar', ['id']), + ]; self::assertSame( $this->getAlterTableRenameIndexSQL(), @@ -884,10 +897,10 @@ public function testAlterTableRenameIndex() */ protected function getAlterTableRenameIndexSQL() { - return array( + return [ 'DROP INDEX idx_foo', 'CREATE INDEX idx_bar ON mytable (id)', - ); + ]; } /** @@ -895,14 +908,14 @@ protected function getAlterTableRenameIndexSQL() */ public function testQuotesAlterTableRenameIndex() { - $tableDiff = new TableDiff('table'); + $tableDiff = new TableDiff('table'); $tableDiff->fromTable = new Table('table'); $tableDiff->fromTable->addColumn('id', 'integer'); - $tableDiff->fromTable->setPrimaryKey(array('id')); - $tableDiff->renamedIndexes = array( - 'create' => new Index('select', array('id')), - '`foo`' => new Index('`bar`', array('id')), - ); + $tableDiff->fromTable->setPrimaryKey(['id']); + $tableDiff->renamedIndexes = [ + 'create' => new Index('select', ['id']), + '`foo`' => new Index('`bar`', ['id']), + ]; self::assertSame( $this->getQuotedAlterTableRenameIndexSQL(), @@ -915,12 +928,12 @@ public function testQuotesAlterTableRenameIndex() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'DROP INDEX "create"', 'CREATE INDEX "select" ON "table" (id)', 'DROP INDEX "foo"', 'CREATE INDEX "bar" ON "table" (id)', - ); + ]; } /** @@ -930,31 +943,31 @@ public function testQuotesAlterTableRenameColumn() { $fromTable = new Table('mytable'); - $fromTable->addColumn('unquoted1', 'integer', array('comment' => 'Unquoted 1')); - $fromTable->addColumn('unquoted2', 'integer', array('comment' => 'Unquoted 2')); - $fromTable->addColumn('unquoted3', 'integer', array('comment' => 'Unquoted 3')); + $fromTable->addColumn('unquoted1', 'integer', ['comment' => 'Unquoted 1']); + $fromTable->addColumn('unquoted2', 'integer', ['comment' => 'Unquoted 2']); + $fromTable->addColumn('unquoted3', 'integer', ['comment' => 'Unquoted 3']); - $fromTable->addColumn('create', 'integer', array('comment' => 'Reserved keyword 1')); - $fromTable->addColumn('table', 'integer', array('comment' => 'Reserved keyword 2')); - $fromTable->addColumn('select', 'integer', array('comment' => 'Reserved keyword 3')); + $fromTable->addColumn('create', 'integer', ['comment' => 'Reserved keyword 1']); + $fromTable->addColumn('table', 'integer', ['comment' => 'Reserved keyword 2']); + $fromTable->addColumn('select', 'integer', ['comment' => 'Reserved keyword 3']); - $fromTable->addColumn('`quoted1`', 'integer', array('comment' => 'Quoted 1')); - $fromTable->addColumn('`quoted2`', 'integer', array('comment' => 'Quoted 2')); - $fromTable->addColumn('`quoted3`', 'integer', array('comment' => 'Quoted 3')); + $fromTable->addColumn('`quoted1`', 'integer', ['comment' => 'Quoted 1']); + $fromTable->addColumn('`quoted2`', 'integer', ['comment' => 'Quoted 2']); + $fromTable->addColumn('`quoted3`', 'integer', ['comment' => 'Quoted 3']); $toTable = new Table('mytable'); - $toTable->addColumn('unquoted', 'integer', array('comment' => 'Unquoted 1')); // unquoted -> unquoted - $toTable->addColumn('where', 'integer', array('comment' => 'Unquoted 2')); // unquoted -> reserved keyword - $toTable->addColumn('`foo`', 'integer', array('comment' => 'Unquoted 3')); // unquoted -> quoted + $toTable->addColumn('unquoted', 'integer', ['comment' => 'Unquoted 1']); // unquoted -> unquoted + $toTable->addColumn('where', 'integer', ['comment' => 'Unquoted 2']); // unquoted -> reserved keyword + $toTable->addColumn('`foo`', 'integer', ['comment' => 'Unquoted 3']); // unquoted -> quoted - $toTable->addColumn('reserved_keyword', 'integer', array('comment' => 'Reserved keyword 1')); // reserved keyword -> unquoted - $toTable->addColumn('from', 'integer', array('comment' => 'Reserved keyword 2')); // reserved keyword -> reserved keyword - $toTable->addColumn('`bar`', 'integer', array('comment' => 'Reserved keyword 3')); // reserved keyword -> quoted + $toTable->addColumn('reserved_keyword', 'integer', ['comment' => 'Reserved keyword 1']); // reserved keyword -> unquoted + $toTable->addColumn('from', 'integer', ['comment' => 'Reserved keyword 2']); // reserved keyword -> reserved keyword + $toTable->addColumn('`bar`', 'integer', ['comment' => 'Reserved keyword 3']); // reserved keyword -> quoted - $toTable->addColumn('quoted', 'integer', array('comment' => 'Quoted 1')); // quoted -> unquoted - $toTable->addColumn('and', 'integer', array('comment' => 'Quoted 2')); // quoted -> reserved keyword - $toTable->addColumn('`baz`', 'integer', array('comment' => 'Quoted 3')); // quoted -> quoted + $toTable->addColumn('quoted', 'integer', ['comment' => 'Quoted 1']); // quoted -> unquoted + $toTable->addColumn('and', 'integer', ['comment' => 'Quoted 2']); // quoted -> reserved keyword + $toTable->addColumn('`baz`', 'integer', ['comment' => 'Quoted 3']); // quoted -> quoted $comparator = new Comparator(); @@ -980,23 +993,23 @@ public function testQuotesAlterTableChangeColumnLength() { $fromTable = new Table('mytable'); - $fromTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 10)); - $fromTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 10)); - $fromTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 10)); + $fromTable->addColumn('unquoted1', 'string', ['comment' => 'Unquoted 1', 'length' => 10]); + $fromTable->addColumn('unquoted2', 'string', ['comment' => 'Unquoted 2', 'length' => 10]); + $fromTable->addColumn('unquoted3', 'string', ['comment' => 'Unquoted 3', 'length' => 10]); - $fromTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 10)); - $fromTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 10)); - $fromTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 10)); + $fromTable->addColumn('create', 'string', ['comment' => 'Reserved keyword 1', 'length' => 10]); + $fromTable->addColumn('table', 'string', ['comment' => 'Reserved keyword 2', 'length' => 10]); + $fromTable->addColumn('select', 'string', ['comment' => 'Reserved keyword 3', 'length' => 10]); $toTable = new Table('mytable'); - $toTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 255)); - $toTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 255)); - $toTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 255)); + $toTable->addColumn('unquoted1', 'string', ['comment' => 'Unquoted 1', 'length' => 255]); + $toTable->addColumn('unquoted2', 'string', ['comment' => 'Unquoted 2', 'length' => 255]); + $toTable->addColumn('unquoted3', 'string', ['comment' => 'Unquoted 3', 'length' => 255]); - $toTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 255)); - $toTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 255)); - $toTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 255)); + $toTable->addColumn('create', 'string', ['comment' => 'Reserved keyword 1', 'length' => 255]); + $toTable->addColumn('table', 'string', ['comment' => 'Reserved keyword 2', 'length' => 255]); + $toTable->addColumn('select', 'string', ['comment' => 'Reserved keyword 3', 'length' => 255]); $comparator = new Comparator(); @@ -1020,13 +1033,13 @@ abstract protected function getQuotedAlterTableChangeColumnLengthSQL(); */ public function testAlterTableRenameIndexInSchema() { - $tableDiff = new TableDiff('myschema.mytable'); + $tableDiff = new TableDiff('myschema.mytable'); $tableDiff->fromTable = new Table('myschema.mytable'); $tableDiff->fromTable->addColumn('id', 'integer'); - $tableDiff->fromTable->setPrimaryKey(array('id')); - $tableDiff->renamedIndexes = array( - 'idx_foo' => new Index('idx_bar', array('id')) - ); + $tableDiff->fromTable->setPrimaryKey(['id']); + $tableDiff->renamedIndexes = [ + 'idx_foo' => new Index('idx_bar', ['id']), + ]; self::assertSame( $this->getAlterTableRenameIndexInSchemaSQL(), @@ -1039,10 +1052,10 @@ public function testAlterTableRenameIndexInSchema() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'DROP INDEX idx_foo', 'CREATE INDEX idx_bar ON myschema.mytable (id)', - ); + ]; } /** @@ -1050,14 +1063,14 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ public function testQuotesAlterTableRenameIndexInSchema() { - $tableDiff = new TableDiff('`schema`.table'); + $tableDiff = new TableDiff('`schema`.table'); $tableDiff->fromTable = new Table('`schema`.table'); $tableDiff->fromTable->addColumn('id', 'integer'); - $tableDiff->fromTable->setPrimaryKey(array('id')); - $tableDiff->renamedIndexes = array( - 'create' => new Index('select', array('id')), - '`foo`' => new Index('`bar`', array('id')), - ); + $tableDiff->fromTable->setPrimaryKey(['id']); + $tableDiff->renamedIndexes = [ + 'create' => new Index('select', ['id']), + '`foo`' => new Index('`bar`', ['id']), + ]; self::assertSame( $this->getQuotedAlterTableRenameIndexInSchemaSQL(), @@ -1070,12 +1083,12 @@ public function testQuotesAlterTableRenameIndexInSchema() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'DROP INDEX "schema"."create"', 'CREATE INDEX "select" ON "schema"."table" (id)', 'DROP INDEX "schema"."foo"', 'CREATE INDEX "bar" ON "schema"."table" (id)', - ); + ]; } /** @@ -1089,11 +1102,11 @@ public function testQuotesDropForeignKeySQL() ); } - $tableName = 'table'; - $table = new Table($tableName); + $tableName = 'table'; + $table = new Table($tableName); $foreignKeyName = 'select'; - $foreignKey = new ForeignKeyConstraint(array(), 'foo', array(), 'select'); - $expectedSql = $this->getQuotesDropForeignKeySQL(); + $foreignKey = new ForeignKeyConstraint([], 'foo', [], 'select'); + $expectedSql = $this->getQuotesDropForeignKeySQL(); self::assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKeyName, $tableName)); self::assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKey, $table)); @@ -1109,11 +1122,11 @@ protected function getQuotesDropForeignKeySQL() */ public function testQuotesDropConstraintSQL() { - $tableName = 'table'; - $table = new Table($tableName); + $tableName = 'table'; + $table = new Table($tableName); $constraintName = 'select'; - $constraint = new ForeignKeyConstraint(array(), 'foo', array(), 'select'); - $expectedSql = $this->getQuotesDropConstraintSQL(); + $constraint = new ForeignKeyConstraint([], 'foo', [], 'select'); + $expectedSql = $this->getQuotesDropConstraintSQL(); self::assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraintName, $tableName)); self::assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraint, $table)); @@ -1158,14 +1171,14 @@ public function testGetCommentOnColumnSQLWithQuoteCharacter() self::assertEquals( $this->getQuotedCommentOnColumnSQLWithQuoteCharacter(), - $this->_platform->getCommentOnColumnSQL('mytable', 'id', "It" . $c . "s a quote !") + $this->_platform->getCommentOnColumnSQL('mytable', 'id', 'It' . $c . 's a quote !') ); } /** - * @return array - * * @see testGetCommentOnColumnSQL + * + * @return array */ abstract protected function getCommentOnColumnSQL(); @@ -1176,17 +1189,16 @@ public function testGetCommentOnColumnSQL() { self::assertSame( $this->getCommentOnColumnSQL(), - array( + [ $this->_platform->getCommentOnColumnSQL('foo', 'bar', 'comment'), // regular identifiers $this->_platform->getCommentOnColumnSQL('`Foo`', '`BAR`', 'comment'), // explicitly quoted identifiers $this->_platform->getCommentOnColumnSQL('select', 'from', 'comment'), // reserved keyword identifiers - ) + ] ); } /** * @group DBAL-1176 - * * @dataProvider getGeneratesInlineColumnCommentSQL */ public function testGeneratesInlineColumnCommentSQL($comment, $expectedSql) @@ -1200,17 +1212,17 @@ public function testGeneratesInlineColumnCommentSQL($comment, $expectedSql) public function getGeneratesInlineColumnCommentSQL() { - return array( - 'regular comment' => array('Regular comment', $this->getInlineColumnRegularCommentSQL()), - 'comment requiring escaping' => array( + return [ + 'regular comment' => ['Regular comment', $this->getInlineColumnRegularCommentSQL()], + 'comment requiring escaping' => [ sprintf( 'Using inline comment delimiter %s works', $this->getInlineColumnCommentDelimiter() ), - $this->getInlineColumnCommentRequiringEscapingSQL() - ), - 'empty comment' => array('', $this->getInlineColumnEmptyCommentSQL()), - ); + $this->getInlineColumnCommentRequiringEscapingSQL(), + ], + 'empty comment' => ['', $this->getInlineColumnEmptyCommentSQL()], + ]; } protected function getInlineColumnCommentDelimiter() @@ -1284,12 +1296,11 @@ public function testQuoteStringLiteral() /** * @group DBAL-423 - * * @expectedException \Doctrine\DBAL\DBALException */ public function testReturnsGuidTypeDeclarationSQL() { - $this->_platform->getGuidTypeDeclarationSQL(array()); + $this->_platform->getGuidTypeDeclarationSQL([]); } /** @@ -1301,15 +1312,15 @@ public function testGeneratesAlterTableRenameColumnSQL() $table->addColumn( 'bar', 'integer', - array('notnull' => true, 'default' => 666, 'comment' => 'rename test') + ['notnull' => true, 'default' => 666, 'comment' => 'rename test'] ); - $tableDiff = new TableDiff('foo'); - $tableDiff->fromTable = $table; + $tableDiff = new TableDiff('foo'); + $tableDiff->fromTable = $table; $tableDiff->renamedColumns['bar'] = new Column( 'baz', Type::getType('integer'), - array('notnull' => true, 'default' => 666, 'comment' => 'rename test') + ['notnull' => true, 'default' => 666, 'comment' => 'rename test'] ); self::assertSame($this->getAlterTableRenameColumnSQL(), $this->_platform->getAlterTableSQL($tableDiff)); @@ -1332,24 +1343,24 @@ public function testQuotesTableIdentifiersInAlterTableSQL() $table->addColumn('fk3', 'integer'); $table->addColumn('bar', 'integer'); $table->addColumn('baz', 'integer'); - $table->addForeignKeyConstraint('fk_table', array('fk'), array('id'), array(), 'fk1'); - $table->addForeignKeyConstraint('fk_table', array('fk2'), array('id'), array(), 'fk2'); + $table->addForeignKeyConstraint('fk_table', ['fk'], ['id'], [], 'fk1'); + $table->addForeignKeyConstraint('fk_table', ['fk2'], ['id'], [], 'fk2'); - $tableDiff = new TableDiff('"foo"'); - $tableDiff->fromTable = $table; - $tableDiff->newName = 'table'; - $tableDiff->addedColumns['bloo'] = new Column('bloo', Type::getType('integer')); + $tableDiff = new TableDiff('"foo"'); + $tableDiff->fromTable = $table; + $tableDiff->newName = 'table'; + $tableDiff->addedColumns['bloo'] = new Column('bloo', Type::getType('integer')); $tableDiff->changedColumns['bar'] = new ColumnDiff( 'bar', - new Column('bar', Type::getType('integer'), array('notnull' => false)), - array('notnull'), + new Column('bar', Type::getType('integer'), ['notnull' => false]), + ['notnull'], $table->getColumn('bar') ); - $tableDiff->renamedColumns['id'] = new Column('war', Type::getType('integer')); + $tableDiff->renamedColumns['id'] = new Column('war', Type::getType('integer')); $tableDiff->removedColumns['baz'] = new Column('baz', Type::getType('integer')); - $tableDiff->addedForeignKeys[] = new ForeignKeyConstraint(array('fk3'), 'fk_table', array('id'), 'fk_add'); - $tableDiff->changedForeignKeys[] = new ForeignKeyConstraint(array('fk2'), 'fk_table2', array('id'), 'fk2'); - $tableDiff->removedForeignKeys[] = new ForeignKeyConstraint(array('fk'), 'fk_table', array('id'), 'fk1'); + $tableDiff->addedForeignKeys[] = new ForeignKeyConstraint(['fk3'], 'fk_table', ['id'], 'fk_add'); + $tableDiff->changedForeignKeys[] = new ForeignKeyConstraint(['fk2'], 'fk_table2', ['id'], 'fk2'); + $tableDiff->removedForeignKeys[] = new ForeignKeyConstraint(['fk'], 'fk_table', ['id'], 'fk1'); self::assertSame( $this->getQuotesTableIdentifiersInAlterTableSQL(), @@ -1367,18 +1378,20 @@ abstract protected function getQuotesTableIdentifiersInAlterTableSQL(); */ public function testAlterStringToFixedString() { - $table = new Table('mytable'); - $table->addColumn('name', 'string', array('length' => 2)); + $table->addColumn('name', 'string', ['length' => 2]); - $tableDiff = new TableDiff('mytable'); + $tableDiff = new TableDiff('mytable'); $tableDiff->fromTable = $table; - $tableDiff->changedColumns['name'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'name', new \Doctrine\DBAL\Schema\Column( - 'name', \Doctrine\DBAL\Types\Type::getType('string'), array('fixed' => true, 'length' => 2) + $tableDiff->changedColumns['name'] = new ColumnDiff( + 'name', + new Column( + 'name', + Type::getType('string'), + ['fixed' => true, 'length' => 2] ), - array('fixed') + ['fixed'] ); $sql = $this->_platform->getAlterTableSQL($tableDiff); @@ -1400,20 +1413,20 @@ public function testGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { $foreignTable = new Table('foreign_table'); $foreignTable->addColumn('id', 'integer'); - $foreignTable->setPrimaryKey(array('id')); + $foreignTable->setPrimaryKey(['id']); $primaryTable = new Table('mytable'); $primaryTable->addColumn('foo', 'integer'); $primaryTable->addColumn('bar', 'integer'); $primaryTable->addColumn('baz', 'integer'); - $primaryTable->addIndex(array('foo'), 'idx_foo'); - $primaryTable->addIndex(array('bar'), 'idx_bar'); - $primaryTable->addForeignKeyConstraint($foreignTable, array('foo'), array('id'), array(), 'fk_foo'); - $primaryTable->addForeignKeyConstraint($foreignTable, array('bar'), array('id'), array(), 'fk_bar'); + $primaryTable->addIndex(['foo'], 'idx_foo'); + $primaryTable->addIndex(['bar'], 'idx_bar'); + $primaryTable->addForeignKeyConstraint($foreignTable, ['foo'], ['id'], [], 'fk_foo'); + $primaryTable->addForeignKeyConstraint($foreignTable, ['bar'], ['id'], [], 'fk_bar'); - $tableDiff = new TableDiff('mytable'); - $tableDiff->fromTable = $primaryTable; - $tableDiff->renamedIndexes['idx_foo'] = new Index('idx_foo_renamed', array('foo')); + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = $primaryTable; + $tableDiff->renamedIndexes['idx_foo'] = new Index('idx_foo_renamed', ['foo']); self::assertSame( $this->getGeneratesAlterTableRenameIndexUsedByForeignKeySQL(), @@ -1428,7 +1441,6 @@ abstract protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL /** * @group DBAL-1082 - * * @dataProvider getGeneratesDecimalTypeDeclarationSQL */ public function testGeneratesDecimalTypeDeclarationSQL(array $column, $expectedSql) @@ -1441,19 +1453,18 @@ public function testGeneratesDecimalTypeDeclarationSQL(array $column, $expectedS */ public function getGeneratesDecimalTypeDeclarationSQL() { - return array( - array(array(), 'NUMERIC(10, 0)'), - array(array('unsigned' => true), 'NUMERIC(10, 0)'), - array(array('unsigned' => false), 'NUMERIC(10, 0)'), - array(array('precision' => 5), 'NUMERIC(5, 0)'), - array(array('scale' => 5), 'NUMERIC(10, 5)'), - array(array('precision' => 8, 'scale' => 2), 'NUMERIC(8, 2)'), - ); + return [ + [[], 'NUMERIC(10, 0)'], + [['unsigned' => true], 'NUMERIC(10, 0)'], + [['unsigned' => false], 'NUMERIC(10, 0)'], + [['precision' => 5], 'NUMERIC(5, 0)'], + [['scale' => 5], 'NUMERIC(10, 5)'], + [['precision' => 8, 'scale' => 2], 'NUMERIC(8, 2)'], + ]; } /** * @group DBAL-1082 - * * @dataProvider getGeneratesFloatDeclarationSQL */ public function testGeneratesFloatDeclarationSQL(array $column, $expectedSql) @@ -1466,14 +1477,14 @@ public function testGeneratesFloatDeclarationSQL(array $column, $expectedSql) */ public function getGeneratesFloatDeclarationSQL() { - return array( - array(array(), 'DOUBLE PRECISION'), - array(array('unsigned' => true), 'DOUBLE PRECISION'), - array(array('unsigned' => false), 'DOUBLE PRECISION'), - array(array('precision' => 5), 'DOUBLE PRECISION'), - array(array('scale' => 5), 'DOUBLE PRECISION'), - array(array('precision' => 8, 'scale' => 2), 'DOUBLE PRECISION'), - ); + return [ + [[], 'DOUBLE PRECISION'], + [['unsigned' => true], 'DOUBLE PRECISION'], + [['unsigned' => false], 'DOUBLE PRECISION'], + [['precision' => 5], 'DOUBLE PRECISION'], + [['scale' => 5], 'DOUBLE PRECISION'], + [['precision' => 8, 'scale' => 2], 'DOUBLE PRECISION'], + ]; } public function testItEscapesStringsForLike() : void diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index bca9063c55c..06b1604912b 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -3,7 +3,10 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\Schema\Column; +use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Comparator; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; @@ -18,15 +21,15 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', - 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)' - ); + 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', + ]; } public function getGenerateAlterTableSql() { - return array( + return [ 'ALTER TABLE mytable ADD quota INT DEFAULT NULL', 'ALTER TABLE mytable DROP foo', 'ALTER TABLE mytable ALTER bar TYPE VARCHAR(255)', @@ -36,7 +39,7 @@ public function getGenerateAlterTableSql() "ALTER TABLE mytable ALTER bloo SET DEFAULT 'false'", 'ALTER TABLE mytable ALTER bloo SET NOT NULL', 'ALTER TABLE mytable RENAME TO userlist', - ); + ]; } public function getGenerateIndexSql() @@ -51,51 +54,75 @@ public function getGenerateForeignKeySql() public function testGeneratesForeignKeySqlForNonStandardOptions() { - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('onDelete' => 'CASCADE') + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['onDelete' => 'CASCADE'] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('match' => 'full') + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['match' => 'full'] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full NOT DEFERRABLE INITIALLY IMMEDIATE", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full NOT DEFERRABLE INITIALLY IMMEDIATE', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('deferrable' => true) + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['deferrable' => true] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) DEFERRABLE INITIALLY IMMEDIATE", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) DEFERRABLE INITIALLY IMMEDIATE', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('deferred' => true) + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['deferred' => true] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('feferred' => true) + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['feferred' => true] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('deferrable' => true, 'deferred' => true, 'match' => 'full') + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['deferrable' => true, 'deferred' => true, 'match' => 'full'] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full DEFERRABLE INITIALLY DEFERRED", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full DEFERRABLE INITIALLY DEFERRED', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); } @@ -138,11 +165,11 @@ public function testGeneratesDDLSnippets() public function testGenerateTableWithAutoincrement() { - $table = new \Doctrine\DBAL\Schema\Table('autoinc_table'); + $table = new Table('autoinc_table'); $column = $table->addColumn('id', 'integer'); $column->setAutoincrement(true); - self::assertEquals(array('CREATE TABLE autoinc_table (id SERIAL NOT NULL)'), $this->_platform->getCreateTableSQL($table)); + self::assertEquals(['CREATE TABLE autoinc_table (id SERIAL NOT NULL)'], $this->_platform->getCreateTableSQL($table)); } public static function serialTypes() : array @@ -159,7 +186,7 @@ public static function serialTypes() : array */ public function testGenerateTableWithAutoincrementDoesNotSetDefault(string $type, string $definition) : void { - $table = new \Doctrine\DBAL\Schema\Table('autoinc_table_notnull'); + $table = new Table('autoinc_table_notnull'); $column = $table->addColumn('id', $type); $column->setAutoIncrement(true); $column->setNotNull(false); @@ -175,7 +202,7 @@ public function testGenerateTableWithAutoincrementDoesNotSetDefault(string $type */ public function testCreateTableWithAutoincrementAndNotNullAddsConstraint(string $type, string $definition) : void { - $table = new \Doctrine\DBAL\Schema\Table('autoinc_table_notnull_enabled'); + $table = new Table('autoinc_table_notnull_enabled'); $column = $table->addColumn('id', $type); $column->setAutoIncrement(true); $column->setNotNull(true); @@ -206,17 +233,18 @@ public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'INT', - $this->_platform->getIntegerTypeDeclarationSQL(array()) + $this->_platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'SERIAL', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true) - )); + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + ); self::assertEquals( 'SERIAL', $this->_platform->getIntegerTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true) - )); + ['autoincrement' => true, 'primary' => true] + ) + ); } public function testGeneratesTypeDeclarationForStrings() @@ -224,16 +252,17 @@ public function testGeneratesTypeDeclarationForStrings() self::assertEquals( 'CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL( - array('length' => 10, 'fixed' => true)) + ['length' => 10, 'fixed' => true] + ) ); self::assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)), + $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL(array()), + $this->_platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } @@ -245,7 +274,7 @@ public function getGenerateUniqueIndexSql() public function testGeneratesSequenceSqlCommands() { - $sequence = new \Doctrine\DBAL\Schema\Sequence('myseq', 20, 1); + $sequence = new Sequence('myseq', 20, 1); self::assertEquals( 'CREATE SEQUENCE myseq INCREMENT BY 20 MINVALUE 1 START 1', $this->_platform->getCreateSequenceSQL($sequence) @@ -307,71 +336,69 @@ public function testModifyLimitQueryWithEmptyOffset() public function getCreateTableColumnCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))", + return [ + 'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))', "COMMENT ON COLUMN test.id IS 'This is a comment'", - ); + ]; } public function getAlterTableColumnCommentsSQL() { - return array( - "ALTER TABLE mytable ADD quota INT NOT NULL", + return [ + 'ALTER TABLE mytable ADD quota INT NOT NULL', "COMMENT ON COLUMN mytable.quota IS 'A comment'", - "COMMENT ON COLUMN mytable.foo IS NULL", + 'COMMENT ON COLUMN mytable.foo IS NULL', "COMMENT ON COLUMN mytable.baz IS 'B comment'", - ); + ]; } public function getCreateTableColumnTypeCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))", - "COMMENT ON COLUMN test.data IS '(DC2Type:array)'" - ); + return [ + 'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))', + "COMMENT ON COLUMN test.data IS '(DC2Type:array)'", + ]; } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))', - ); + return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; } protected function getQuotedColumnInIndexSQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', - ); + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', 'CREATE INDEX "key" ON test (column1)', - ); + ]; } protected function getQuotedColumnInForeignKeySQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL)', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE', - ); + ]; } /** - * @group DBAL-457 - * @dataProvider pgBooleanProvider - * * @param string $databaseValue * @param string $preparedStatementValue * @param int $integerValue * @param bool $booleanValue + * + * @group DBAL-457 + * @dataProvider pgBooleanProvider */ public function testConvertBooleanAsLiteralStrings( $databaseValue, @@ -400,21 +427,20 @@ public function testConvertBooleanAsLiteralIntegers() } /** - * @group DBAL-630 - * @dataProvider pgBooleanProvider - * * @param string $databaseValue * @param string $preparedStatementValue * @param int $integerValue * @param bool $booleanValue + * + * @group DBAL-630 + * @dataProvider pgBooleanProvider */ public function testConvertBooleanAsDatabaseValueStrings( $databaseValue, $preparedStatementValue, $integerValue, $booleanValue - ) - { + ) { $platform = $this->createPlatform(); self::assertSame($integerValue, $platform->convertBooleansToDatabaseValue($booleanValue)); @@ -433,12 +459,12 @@ public function testConvertBooleanAsDatabaseValueIntegers() } /** - * @dataProvider pgBooleanProvider - * * @param string $databaseValue * @param string $prepareStatementValue * @param int $integerValue * @param bool $booleanValue + * + * @dataProvider pgBooleanProvider */ public function testConvertFromBoolean($databaseValue, $prepareStatementValue, $integerValue, $booleanValue) { @@ -453,60 +479,71 @@ public function testConvertFromBoolean($databaseValue, $prepareStatementValue, $ */ public function testThrowsExceptionWithInvalidBooleanLiteral() { - $platform = $this->createPlatform()->convertBooleansToDatabaseValue("my-bool"); + $platform = $this->createPlatform()->convertBooleansToDatabaseValue('my-bool'); } public function testGetCreateSchemaSQL() { $schemaName = 'schema'; - $sql = $this->_platform->getCreateSchemaSQL($schemaName); + $sql = $this->_platform->getCreateSchemaSQL($schemaName); self::assertEquals('CREATE SCHEMA ' . $schemaName, $sql); } public function testAlterDecimalPrecisionScale() { - $table = new Table('mytable'); $table->addColumn('dfoo1', 'decimal'); - $table->addColumn('dfoo2', 'decimal', array('precision' => 10, 'scale' => 6)); - $table->addColumn('dfoo3', 'decimal', array('precision' => 10, 'scale' => 6)); - $table->addColumn('dfoo4', 'decimal', array('precision' => 10, 'scale' => 6)); + $table->addColumn('dfoo2', 'decimal', ['precision' => 10, 'scale' => 6]); + $table->addColumn('dfoo3', 'decimal', ['precision' => 10, 'scale' => 6]); + $table->addColumn('dfoo4', 'decimal', ['precision' => 10, 'scale' => 6]); - $tableDiff = new TableDiff('mytable'); + $tableDiff = new TableDiff('mytable'); $tableDiff->fromTable = $table; - $tableDiff->changedColumns['dloo1'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'dloo1', new \Doctrine\DBAL\Schema\Column( - 'dloo1', \Doctrine\DBAL\Types\Type::getType('decimal'), array('precision' => 16, 'scale' => 6) + $tableDiff->changedColumns['dloo1'] = new ColumnDiff( + 'dloo1', + new Column( + 'dloo1', + Type::getType('decimal'), + ['precision' => 16, 'scale' => 6] ), - array('precision') - ); - $tableDiff->changedColumns['dloo2'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'dloo2', new \Doctrine\DBAL\Schema\Column( - 'dloo2', \Doctrine\DBAL\Types\Type::getType('decimal'), array('precision' => 10, 'scale' => 4) + ['precision'] + ); + $tableDiff->changedColumns['dloo2'] = new ColumnDiff( + 'dloo2', + new Column( + 'dloo2', + Type::getType('decimal'), + ['precision' => 10, 'scale' => 4] ), - array('scale') - ); - $tableDiff->changedColumns['dloo3'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'dloo3', new \Doctrine\DBAL\Schema\Column( - 'dloo3', \Doctrine\DBAL\Types\Type::getType('decimal'), array('precision' => 10, 'scale' => 6) + ['scale'] + ); + $tableDiff->changedColumns['dloo3'] = new ColumnDiff( + 'dloo3', + new Column( + 'dloo3', + Type::getType('decimal'), + ['precision' => 10, 'scale' => 6] ), - array() - ); - $tableDiff->changedColumns['dloo4'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'dloo4', new \Doctrine\DBAL\Schema\Column( - 'dloo4', \Doctrine\DBAL\Types\Type::getType('decimal'), array('precision' => 16, 'scale' => 8) + [] + ); + $tableDiff->changedColumns['dloo4'] = new ColumnDiff( + 'dloo4', + new Column( + 'dloo4', + Type::getType('decimal'), + ['precision' => 16, 'scale' => 8] ), - array('precision', 'scale') + ['precision', 'scale'] ); $sql = $this->_platform->getAlterTableSQL($tableDiff); - $expectedSql = array( + $expectedSql = [ 'ALTER TABLE mytable ALTER dloo1 TYPE NUMERIC(16, 6)', 'ALTER TABLE mytable ALTER dloo2 TYPE NUMERIC(10, 4)', 'ALTER TABLE mytable ALTER dloo4 TYPE NUMERIC(16, 8)', - ); + ]; self::assertEquals($expectedSql, $sql); } @@ -518,22 +555,22 @@ public function testDroppingConstraintsBeforeColumns() { $newTable = new Table('mytable'); $newTable->addColumn('id', 'integer'); - $newTable->setPrimaryKey(array('id')); + $newTable->setPrimaryKey(['id']); $oldTable = clone $newTable; $oldTable->addColumn('parent_id', 'integer'); - $oldTable->addUnnamedForeignKeyConstraint('mytable', array('parent_id'), array('id')); + $oldTable->addUnnamedForeignKeyConstraint('mytable', ['parent_id'], ['id']); - $comparator = new \Doctrine\DBAL\Schema\Comparator(); - $tableDiff = $comparator->diffTable($oldTable, $newTable); + $comparator = new Comparator(); + $tableDiff = $comparator->diffTable($oldTable, $newTable); $sql = $this->_platform->getAlterTableSQL($tableDiff); - $expectedSql = array( + $expectedSql = [ 'ALTER TABLE mytable DROP CONSTRAINT FK_6B2BD609727ACA70', 'DROP INDEX IDX_6B2BD609727ACA70', 'ALTER TABLE mytable DROP parent_id', - ); + ]; self::assertEquals($expectedSql, $sql); } @@ -560,15 +597,15 @@ public function testReturnsIdentitySequenceName() */ public function testCreateSequenceWithCache($cacheSize, $expectedSql) { - $sequence = new \Doctrine\DBAL\Schema\Sequence('foo', 1, 1, $cacheSize); + $sequence = new Sequence('foo', 1, 1, $cacheSize); self::assertContains($expectedSql, $this->_platform->getCreateSequenceSQL($sequence)); } public function dataCreateSequenceWithCache() { - return array( - array(3, 'CACHE 3') - ); + return [ + [3, 'CACHE 3'], + ]; } protected function getBinaryDefaultLength() @@ -583,24 +620,24 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 9999999))); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 9999999])); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 9999999))); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999])); } public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() { $table1 = new Table('mytable'); $table1->addColumn('column_varbinary', 'binary'); - $table1->addColumn('column_binary', 'binary', array('fixed' => true)); + $table1->addColumn('column_binary', 'binary', ['fixed' => true]); $table1->addColumn('column_blob', 'blob'); $table2 = new Table('mytable'); - $table2->addColumn('column_varbinary', 'binary', array('fixed' => true)); + $table2->addColumn('column_varbinary', 'binary', ['fixed' => true]); $table2->addColumn('column_binary', 'binary'); $table2->addColumn('column_blob', 'binary'); @@ -612,9 +649,9 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() self::assertEmpty($this->_platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); $table2 = new Table('mytable'); - $table2->addColumn('column_varbinary', 'binary', array('length' => 42)); + $table2->addColumn('column_varbinary', 'binary', ['length' => 42]); $table2->addColumn('column_binary', 'blob'); - $table2->addColumn('column_blob', 'binary', array('length' => 11, 'fixed' => true)); + $table2->addColumn('column_blob', 'binary', ['length' => 11, 'fixed' => true]); // VARBINARY -> VARBINARY with changed length // BINARY -> BLOB @@ -623,7 +660,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() $table2 = new Table('mytable'); $table2->addColumn('column_varbinary', 'blob'); - $table2->addColumn('column_binary', 'binary', array('length' => 42, 'fixed' => true)); + $table2->addColumn('column_binary', 'binary', ['length' => 42, 'fixed' => true]); $table2->addColumn('column_blob', 'blob'); // VARBINARY -> BLOB @@ -637,9 +674,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() */ protected function getAlterTableRenameIndexSQL() { - return array( - 'ALTER INDEX idx_foo RENAME TO idx_bar', - ); + return ['ALTER INDEX idx_foo RENAME TO idx_bar']; } /** @@ -647,38 +682,39 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'ALTER INDEX "create" RENAME TO "select"', 'ALTER INDEX "foo" RENAME TO "bar"', - ); + ]; } /** * PostgreSQL boolean strings provider + * * @return array */ public function pgBooleanProvider() { - return array( + return [ // Database value, prepared statement value, boolean integer value, boolean value. - array(true, 'true', 1, true), - array('t', 'true', 1, true), - array('true', 'true', 1, true), - array('y', 'true', 1, true), - array('yes', 'true', 1, true), - array('on', 'true', 1, true), - array('1', 'true', 1, true), - - array(false, 'false', 0, false), - array('f', 'false', 0, false), - array('false', 'false', 0, false), - array( 'n', 'false', 0, false), - array('no', 'false', 0, false), - array('off', 'false', 0, false), - array('0', 'false', 0, false), - - array(null, 'NULL', null, null) - ); + [true, 'true', 1, true], + ['t', 'true', 1, true], + ['true', 'true', 1, true], + ['y', 'true', 1, true], + ['yes', 'true', 1, true], + ['on', 'true', 1, true], + ['1', 'true', 1, true], + + [false, 'false', 0, false], + ['f', 'false', 0, false], + ['false', 'false', 0, false], + [ 'n', 'false', 0, false], + ['no', 'false', 0, false], + ['off', 'false', 0, false], + ['0', 'false', 0, false], + + [null, 'NULL', null, null], + ]; } /** @@ -686,7 +722,7 @@ public function pgBooleanProvider() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( + return [ 'ALTER TABLE mytable RENAME COLUMN unquoted1 TO unquoted', 'ALTER TABLE mytable RENAME COLUMN unquoted2 TO "where"', 'ALTER TABLE mytable RENAME COLUMN unquoted3 TO "foo"', @@ -696,7 +732,7 @@ protected function getQuotedAlterTableRenameColumnSQL() 'ALTER TABLE mytable RENAME COLUMN quoted1 TO quoted', 'ALTER TABLE mytable RENAME COLUMN quoted2 TO "and"', 'ALTER TABLE mytable RENAME COLUMN quoted3 TO "baz"', - ); + ]; } /** @@ -704,14 +740,14 @@ protected function getQuotedAlterTableRenameColumnSQL() */ protected function getQuotedAlterTableChangeColumnLengthSQL() { - return array( + return [ 'ALTER TABLE mytable ALTER unquoted1 TYPE VARCHAR(255)', 'ALTER TABLE mytable ALTER unquoted2 TYPE VARCHAR(255)', 'ALTER TABLE mytable ALTER unquoted3 TYPE VARCHAR(255)', 'ALTER TABLE mytable ALTER "create" TYPE VARCHAR(255)', 'ALTER TABLE mytable ALTER "table" TYPE VARCHAR(255)', 'ALTER TABLE mytable ALTER "select" TYPE VARCHAR(255)', - ); + ]; } /** @@ -719,9 +755,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - 'ALTER INDEX myschema.idx_foo RENAME TO idx_bar', - ); + return ['ALTER INDEX myschema.idx_foo RENAME TO idx_bar']; } /** @@ -729,10 +763,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'ALTER INDEX "schema"."create" RENAME TO "select"', 'ALTER INDEX "schema"."foo" RENAME TO "bar"', - ); + ]; } protected function getQuotesDropForeignKeySQL() @@ -743,7 +777,7 @@ protected function getQuotesDropForeignKeySQL() public function testGetNullCommentOnColumnSQL() { self::assertEquals( - "COMMENT ON COLUMN mytable.id IS NULL", + 'COMMENT ON COLUMN mytable.id IS NULL', $this->_platform->getCommentOnColumnSQL('mytable', 'id', null) ); } @@ -753,7 +787,7 @@ public function testGetNullCommentOnColumnSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('UUID', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('UUID', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -761,9 +795,7 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( - 'ALTER TABLE foo RENAME COLUMN bar TO baz', - ); + return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; } /** @@ -771,7 +803,7 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE "foo" DROP CONSTRAINT fk1', 'ALTER TABLE "foo" DROP CONSTRAINT fk2', 'ALTER TABLE "foo" ADD bloo INT NOT NULL', @@ -783,7 +815,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() 'INITIALLY IMMEDIATE', 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id) NOT DEFERRABLE ' . 'INITIALLY IMMEDIATE', - ); + ]; } /** @@ -791,11 +823,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', 'COMMENT ON COLUMN "select"."from" IS \'comment\'', - ); + ]; } /** @@ -803,8 +835,8 @@ protected function getCommentOnColumnSQL() */ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() { - $table1 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer')))); - $table2 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer'), array('comment' => 'baz')))); + $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); + $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); $comparator = new Comparator(); @@ -812,9 +844,7 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); self::assertSame( - array( - 'COMMENT ON COLUMN "foo"."bar" IS \'baz\'', - ), + ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -848,9 +878,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() */ protected function getAlterStringToFixedStringSQL() { - return array( - 'ALTER TABLE mytable ALTER name TYPE CHAR(2)', - ); + return ['ALTER TABLE mytable ALTER name TYPE CHAR(2)']; } /** @@ -858,9 +886,7 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - 'ALTER INDEX idx_foo RENAME TO idx_foo_renamed', - ); + return ['ALTER INDEX idx_foo RENAME TO idx_foo_renamed']; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 72864db1250..ef75fa7dfe6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -2,8 +2,10 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; +use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; @@ -19,15 +21,15 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo NVARCHAR(255), bar NVARCHAR(255))', - 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar) WHERE foo IS NOT NULL AND bar IS NOT NULL' - ); + 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar) WHERE foo IS NOT NULL AND bar IS NOT NULL', + ]; } public function getGenerateAlterTableSql() { - return array( + return [ 'ALTER TABLE mytable ADD quota INT', 'ALTER TABLE mytable DROP COLUMN foo', 'ALTER TABLE mytable ALTER COLUMN baz NVARCHAR(255) NOT NULL', @@ -38,11 +40,11 @@ public function getGenerateAlterTableSql() "DECLARE @sql NVARCHAR(MAX) = N''; " . "SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' " . "+ REPLACE(dc.name, '6B2BD609', 'E2B58069') + ''', ''OBJECT'';' " . - "FROM sys.default_constraints dc " . - "JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id " . + 'FROM sys.default_constraints dc ' . + 'JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id ' . "WHERE tbl.name = 'userlist';" . - "EXEC sp_executesql @sql" - ); + 'EXEC sp_executesql @sql', + ]; } /** @@ -95,41 +97,43 @@ public function testGeneratesDDLSnippets() public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( - 'INT', - $this->_platform->getIntegerTypeDeclarationSQL(array()) + 'INT', + $this->_platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( - 'INT IDENTITY', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true) - )); + 'INT IDENTITY', + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + ); self::assertEquals( - 'INT IDENTITY', - $this->_platform->getIntegerTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true) - )); + 'INT IDENTITY', + $this->_platform->getIntegerTypeDeclarationSQL( + ['autoincrement' => true, 'primary' => true] + ) + ); } public function testGeneratesTypeDeclarationsForStrings() { self::assertEquals( - 'NCHAR(10)', - $this->_platform->getVarcharTypeDeclarationSQL( - array('length' => 10, 'fixed' => true) - )); + 'NCHAR(10)', + $this->_platform->getVarcharTypeDeclarationSQL( + ['length' => 10, 'fixed' => true] + ) + ); self::assertEquals( - 'NVARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)), - 'Variable string declaration is not correct' + 'NVARCHAR(50)', + $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), + 'Variable string declaration is not correct' ); self::assertEquals( - 'NVARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL(array()), - 'Long string declaration is not correct' + 'NVARCHAR(255)', + $this->_platform->getVarcharTypeDeclarationSQL([]), + 'Long string declaration is not correct' ); - self::assertSame('VARCHAR(MAX)', $this->_platform->getClobTypeDeclarationSQL(array())); + self::assertSame('VARCHAR(MAX)', $this->_platform->getClobTypeDeclarationSQL([])); self::assertSame( 'VARCHAR(MAX)', - $this->_platform->getClobTypeDeclarationSQL(array('length' => 5, 'fixed' => true)) + $this->_platform->getClobTypeDeclarationSQL(['length' => 5, 'fixed' => true]) ); } @@ -175,114 +179,114 @@ public function getGenerateForeignKeySql() public function testModifyLimitQuery() { - $querySql = 'SELECT * FROM user'; + $querySql = 'SELECT * FROM user'; $alteredSql = 'SELECT TOP 10 * FROM user'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 0); + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 0); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithEmptyOffset() { - $querySql = 'SELECT * FROM user'; + $querySql = 'SELECT * FROM user'; $alteredSql = 'SELECT TOP 10 * FROM user'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithOffset() { - if ( ! $this->_platform->supportsLimitOffset()) { + if (! $this->_platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); } - $querySql = 'SELECT * FROM user ORDER BY username DESC'; + $querySql = 'SELECT * FROM user ORDER BY username DESC'; $alteredSql = 'SELECT TOP 15 * FROM user ORDER BY username DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); } public function testModifyLimitQueryWithAscOrderBy() { - $querySql = 'SELECT * FROM user ORDER BY username ASC'; + $querySql = 'SELECT * FROM user ORDER BY username ASC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username ASC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithLowercaseOrderBy() { - $querySql = 'SELECT * FROM user order by username'; + $querySql = 'SELECT * FROM user order by username'; $alteredSql = 'SELECT TOP 10 * FROM user order by username'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithDescOrderBy() { - $querySql = 'SELECT * FROM user ORDER BY username DESC'; + $querySql = 'SELECT * FROM user ORDER BY username DESC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithMultipleOrderBy() { - $querySql = 'SELECT * FROM user ORDER BY username DESC, usereamil ASC'; + $querySql = 'SELECT * FROM user ORDER BY username DESC, usereamil ASC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username DESC, usereamil ASC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithSubSelect() { - $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result'; + $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result'; $alteredSql = 'SELECT TOP 10 * FROM (SELECT u.id as uid, u.name as uname) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithSubSelectAndOrder() { - $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC) dctrn_result'; + $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC) dctrn_result'; $alteredSql = 'SELECT TOP 10 * FROM (SELECT u.id as uid, u.name as uname) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); - $querySql = 'SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC) dctrn_result'; + $querySql = 'SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC) dctrn_result'; $alteredSql = 'SELECT TOP 10 * FROM (SELECT u.id, u.name) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithSubSelectAndMultipleOrder() { - if ( ! $this->_platform->supportsLimitOffset()) { + if (! $this->_platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); } - $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC, id ASC) dctrn_result'; + $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC, id ASC) dctrn_result'; $alteredSql = 'SELECT TOP 15 * FROM (SELECT u.id as uid, u.name as uname) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); - $querySql = 'SELECT * FROM (SELECT u.id uid, u.name uname ORDER BY u.name DESC, id ASC) dctrn_result'; + $querySql = 'SELECT * FROM (SELECT u.id uid, u.name uname ORDER BY u.name DESC, id ASC) dctrn_result'; $alteredSql = 'SELECT TOP 15 * FROM (SELECT u.id uid, u.name uname) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); - $querySql = 'SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC, id ASC) dctrn_result'; + $querySql = 'SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC, id ASC) dctrn_result'; $alteredSql = 'SELECT TOP 15 * FROM (SELECT u.id, u.name) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); } public function testModifyLimitQueryWithFromColumnNames() { - $querySql = 'SELECT a.fromFoo, fromBar FROM foo'; + $querySql = 'SELECT a.fromFoo, fromBar FROM foo'; $alteredSql = 'SELECT TOP 10 a.fromFoo, fromBar FROM foo'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -291,15 +295,15 @@ public function testModifyLimitQueryWithFromColumnNames() */ public function testModifyLimitQueryWithExtraLongQuery() { - $query = 'SELECT table1.column1, table2.column2, table3.column3, table4.column4, table5.column5, table6.column6, table7.column7, table8.column8 FROM table1, table2, table3, table4, table5, table6, table7, table8 '; - $query.= 'WHERE (table1.column1 = table2.column2) AND (table1.column1 = table3.column3) AND (table1.column1 = table4.column4) AND (table1.column1 = table5.column5) AND (table1.column1 = table6.column6) AND (table1.column1 = table7.column7) AND (table1.column1 = table8.column8) AND (table2.column2 = table3.column3) AND (table2.column2 = table4.column4) AND (table2.column2 = table5.column5) AND (table2.column2 = table6.column6) '; - $query.= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; - $query.= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; + $query = 'SELECT table1.column1, table2.column2, table3.column3, table4.column4, table5.column5, table6.column6, table7.column7, table8.column8 FROM table1, table2, table3, table4, table5, table6, table7, table8 '; + $query .= 'WHERE (table1.column1 = table2.column2) AND (table1.column1 = table3.column3) AND (table1.column1 = table4.column4) AND (table1.column1 = table5.column5) AND (table1.column1 = table6.column6) AND (table1.column1 = table7.column7) AND (table1.column1 = table8.column8) AND (table2.column2 = table3.column3) AND (table2.column2 = table4.column4) AND (table2.column2 = table5.column5) AND (table2.column2 = table6.column6) '; + $query .= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; + $query .= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; - $alteredSql = 'SELECT TOP 10 table1.column1, table2.column2, table3.column3, table4.column4, table5.column5, table6.column6, table7.column7, table8.column8 FROM table1, table2, table3, table4, table5, table6, table7, table8 '; - $alteredSql.= 'WHERE (table1.column1 = table2.column2) AND (table1.column1 = table3.column3) AND (table1.column1 = table4.column4) AND (table1.column1 = table5.column5) AND (table1.column1 = table6.column6) AND (table1.column1 = table7.column7) AND (table1.column1 = table8.column8) AND (table2.column2 = table3.column3) AND (table2.column2 = table4.column4) AND (table2.column2 = table5.column5) AND (table2.column2 = table6.column6) '; - $alteredSql.= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; - $alteredSql.= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; + $alteredSql = 'SELECT TOP 10 table1.column1, table2.column2, table3.column3, table4.column4, table5.column5, table6.column6, table7.column7, table8.column8 FROM table1, table2, table3, table4, table5, table6, table7, table8 '; + $alteredSql .= 'WHERE (table1.column1 = table2.column2) AND (table1.column1 = table3.column3) AND (table1.column1 = table4.column4) AND (table1.column1 = table5.column5) AND (table1.column1 = table6.column6) AND (table1.column1 = table7.column7) AND (table1.column1 = table8.column8) AND (table2.column2 = table3.column3) AND (table2.column2 = table4.column4) AND (table2.column2 = table5.column5) AND (table2.column2 = table6.column6) '; + $alteredSql .= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; + $alteredSql .= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; $sql = $this->_platform->modifyLimitQuery($query, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); @@ -310,7 +314,7 @@ public function testModifyLimitQueryWithExtraLongQuery() */ public function testModifyLimitQueryWithOrderByClause() { - if ( ! $this->_platform->supportsLimitOffset()) { + if (! $this->_platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); } @@ -326,21 +330,21 @@ public function testModifyLimitQueryWithOrderByClause() */ public function testModifyLimitQueryWithSubSelectInSelectList() { - $querySql = "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + $querySql = 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled'"; - $alteredSql = "SELECT TOP 10 " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + $alteredSql = 'SELECT TOP 10 ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled'"; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -350,27 +354,27 @@ public function testModifyLimitQueryWithSubSelectInSelectList() */ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() { - if ( ! $this->_platform->supportsLimitOffset()) { + if (! $this->_platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); } - $querySql = "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + $querySql = 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled' " . - "ORDER BY u.username DESC"; - $alteredSql = "SELECT TOP 15 " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + 'ORDER BY u.username DESC'; + $alteredSql = 'SELECT TOP 15 ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled' " . - "ORDER BY u.username DESC"; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + 'ORDER BY u.username DESC'; + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); } @@ -379,102 +383,102 @@ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() */ public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() { - $querySql = "SELECT " . - "MAX(heading_id) aliased, " . - "code " . - "FROM operator_model_operator " . - "GROUP BY code " . - "ORDER BY MAX(heading_id) DESC"; - $alteredSql = "SELECT TOP 1 " . - "MAX(heading_id) aliased, " . - "code " . - "FROM operator_model_operator " . - "GROUP BY code " . - "ORDER BY MAX(heading_id) DESC"; - $sql = $this->_platform->modifyLimitQuery($querySql, 1, 0); + $querySql = 'SELECT ' . + 'MAX(heading_id) aliased, ' . + 'code ' . + 'FROM operator_model_operator ' . + 'GROUP BY code ' . + 'ORDER BY MAX(heading_id) DESC'; + $alteredSql = 'SELECT TOP 1 ' . + 'MAX(heading_id) aliased, ' . + 'code ' . + 'FROM operator_model_operator ' . + 'GROUP BY code ' . + 'ORDER BY MAX(heading_id) DESC'; + $sql = $this->_platform->modifyLimitQuery($querySql, 1, 0); $this->expectCteWithMaxRowNum($alteredSql, 1, $sql); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable() { - $querySql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id " - . "ORDER BY t1.id ASC" - . ") dctrn_result " - . "ORDER BY id_0 ASC"; - $alteredSql = "SELECT DISTINCT TOP 5 id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY id_0 ASC"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id ' + . 'ORDER BY t1.id ASC' + . ') dctrn_result ' + . 'ORDER BY id_0 ASC'; + $alteredSql = 'SELECT DISTINCT TOP 5 id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY id_0 ASC'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable() { - $querySql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id " - . "ORDER BY t2.name ASC" - . ") dctrn_result " - . "ORDER BY name_1 ASC"; - $alteredSql = "SELECT DISTINCT TOP 5 id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id ' + . 'ORDER BY t2.name ASC' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC'; + $alteredSql = 'SELECT DISTINCT TOP 5 id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables() { - $querySql = "SELECT DISTINCT id_0, name_1, foo_2 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id " - . "ORDER BY t2.name ASC, t2.foo DESC" - . ") dctrn_result " - . "ORDER BY name_1 ASC, foo_2 DESC"; - $alteredSql = "SELECT DISTINCT TOP 5 id_0, name_1, foo_2 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC, foo_2 DESC"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1, foo_2 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id ' + . 'ORDER BY t2.name ASC, t2.foo DESC' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC, foo_2 DESC'; + $alteredSql = 'SELECT DISTINCT TOP 5 id_0, name_1, foo_2 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC, foo_2 DESC'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } public function testModifyLimitSubquerySimple() { - $querySql = "SELECT DISTINCT id_0 FROM " - . "(SELECT k0_.id AS id_0, k0_.field AS field_1 " - . "FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result"; - $alteredSql = "SELECT DISTINCT TOP 20 id_0 FROM (SELECT k0_.id AS id_0, k0_.field AS field_1 " - . "FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result"; - $sql = $this->_platform->modifyLimitQuery($querySql, 20); + $querySql = 'SELECT DISTINCT id_0 FROM ' + . '(SELECT k0_.id AS id_0, k0_.field AS field_1 ' + . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result'; + $alteredSql = 'SELECT DISTINCT TOP 20 id_0 FROM (SELECT k0_.id AS id_0, k0_.field AS field_1 ' + . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result'; + $sql = $this->_platform->modifyLimitQuery($querySql, 20); $this->expectCteWithMaxRowNum($alteredSql, 20, $sql); } @@ -503,7 +507,7 @@ public function testQuoteSingleIdentifier() */ public function testCreateClusteredIndex() { - $idx = new \Doctrine\DBAL\Schema\Index('idx', array('id')); + $idx = new Index('idx', ['id']); $idx->addFlag('clustered'); self::assertEquals('CREATE CLUSTERED INDEX idx ON tbl (id)', $this->_platform->getCreateIndexSQL($idx, 'tbl')); } @@ -513,12 +517,12 @@ public function testCreateClusteredIndex() */ public function testCreateNonClusteredPrimaryKeyInTable() { - $table = new \Doctrine\DBAL\Schema\Table("tbl"); - $table->addColumn("id", "integer"); - $table->setPrimaryKey(Array("id")); + $table = new Table('tbl'); + $table->addColumn('id', 'integer'); + $table->setPrimaryKey(['id']); $table->getIndex('primary')->addFlag('nonclustered'); - self::assertEquals(array('CREATE TABLE tbl (id INT NOT NULL, PRIMARY KEY NONCLUSTERED (id))'), $this->_platform->getCreateTableSQL($table)); + self::assertEquals(['CREATE TABLE tbl (id INT NOT NULL, PRIMARY KEY NONCLUSTERED (id))'], $this->_platform->getCreateTableSQL($table)); } /** @@ -526,54 +530,52 @@ public function testCreateNonClusteredPrimaryKeyInTable() */ public function testCreateNonClusteredPrimaryKey() { - $idx = new \Doctrine\DBAL\Schema\Index('idx', array('id'), false, true); + $idx = new Index('idx', ['id'], false, true); $idx->addFlag('nonclustered'); self::assertEquals('ALTER TABLE tbl ADD PRIMARY KEY NONCLUSTERED (id)', $this->_platform->getCreatePrimaryKeySQL($idx, 'tbl')); } public function testAlterAddPrimaryKey() { - $idx = new \Doctrine\DBAL\Schema\Index('idx', array('id'), false, true); + $idx = new Index('idx', ['id'], false, true); self::assertEquals('ALTER TABLE tbl ADD PRIMARY KEY (id)', $this->_platform->getCreateIndexSQL($idx, 'tbl')); } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - 'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, PRIMARY KEY ([create]))', - ); + return ['CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, PRIMARY KEY ([create]))']; } protected function getQuotedColumnInIndexSQL() { - return array( + return [ 'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL)', 'CREATE INDEX IDX_22660D028FD6E0FB ON [quoted] ([create])', - ); + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 NVARCHAR(255) NOT NULL)', 'CREATE INDEX [key] ON test (column1)', - ); + ]; } protected function getQuotedColumnInForeignKeySQL() { - return array( + return [ 'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, foo NVARCHAR(255) NOT NULL, [bar] NVARCHAR(255) NOT NULL)', 'ALTER TABLE [quoted] ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ([create], foo, [bar]) REFERENCES [foreign] ([create], bar, [foo-bar])', 'ALTER TABLE [quoted] ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ([create], foo, [bar]) REFERENCES foo ([create], bar, [foo-bar])', 'ALTER TABLE [quoted] ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ([create], foo, [bar]) REFERENCES [foo-bar] ([create], bar, [foo-bar])', - ); + ]; } public function testGetCreateSchemaSQL() { $schemaName = 'schema'; - $sql = $this->_platform->getCreateSchemaSQL($schemaName); + $sql = $this->_platform->getCreateSchemaSQL($schemaName); self::assertEquals('CREATE SCHEMA ' . $schemaName, $sql); } @@ -639,10 +641,10 @@ public function testAlterTableWithSchemaUpdateColumnComments() */ public function getCreateTableColumnCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))", + return [ + 'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))', "EXEC sp_addextendedproperty N'MS_Description', N'This is a comment', N'SCHEMA', 'dbo', N'TABLE', 'test', N'COLUMN', id", - ); + ]; } /** @@ -650,12 +652,12 @@ public function getCreateTableColumnCommentsSQL() */ public function getAlterTableColumnCommentsSQL() { - return array( - "ALTER TABLE mytable ADD quota INT NOT NULL", + return [ + 'ALTER TABLE mytable ADD quota INT NOT NULL', "EXEC sp_addextendedproperty N'MS_Description', N'A comment', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', quota", // todo //"EXEC sp_addextendedproperty N'MS_Description', N'B comment', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', baz", - ); + ]; } /** @@ -663,10 +665,10 @@ public function getAlterTableColumnCommentsSQL() */ public function getCreateTableColumnTypeCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, data VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))", + return [ + 'CREATE TABLE test (id INT NOT NULL, data VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))', "EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:array)', N'SCHEMA', 'dbo', N'TABLE', 'test', N'COLUMN', data", - ); + ]; } /** @@ -675,24 +677,24 @@ public function getCreateTableColumnTypeCommentsSQL() public function testGeneratesCreateTableSQLWithColumnComments() { $table = new Table('mytable'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->addColumn('comment_null', 'integer', array('comment' => null)); - $table->addColumn('comment_false', 'integer', array('comment' => false)); - $table->addColumn('comment_empty_string', 'integer', array('comment' => '')); - $table->addColumn('comment_integer_0', 'integer', array('comment' => 0)); - $table->addColumn('comment_float_0', 'integer', array('comment' => 0.0)); - $table->addColumn('comment_string_0', 'integer', array('comment' => '0')); - $table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!')); - $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitly quoted columns!')); - $table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->addColumn('comment_null', 'integer', ['comment' => null]); + $table->addColumn('comment_false', 'integer', ['comment' => false]); + $table->addColumn('comment_empty_string', 'integer', ['comment' => '']); + $table->addColumn('comment_integer_0', 'integer', ['comment' => 0]); + $table->addColumn('comment_float_0', 'integer', ['comment' => 0.0]); + $table->addColumn('comment_string_0', 'integer', ['comment' => '0']); + $table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']); + $table->addColumn('`comment_quoted`', 'integer', ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!']); + $table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']); $table->addColumn('commented_type', 'object'); - $table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.')); - $table->addColumn('comment_with_string_literal_char', 'string', array('comment' => "O'Reilly")); - $table->setPrimaryKey(array('id')); + $table->addColumn('commented_type_with_comment', 'array', ['comment' => 'Doctrine array type.']); + $table->addColumn('comment_with_string_literal_char', 'string', ['comment' => "O'Reilly"]); + $table->setPrimaryKey(['id']); self::assertEquals( - array( - "CREATE TABLE mytable (id INT IDENTITY NOT NULL, comment_null INT NOT NULL, comment_false INT NOT NULL, comment_empty_string INT NOT NULL, comment_integer_0 INT NOT NULL, comment_float_0 INT NOT NULL, comment_string_0 INT NOT NULL, comment INT NOT NULL, [comment_quoted] INT NOT NULL, [create] INT NOT NULL, commented_type VARCHAR(MAX) NOT NULL, commented_type_with_comment VARCHAR(MAX) NOT NULL, comment_with_string_literal_char NVARCHAR(255) NOT NULL, PRIMARY KEY (id))", + [ + 'CREATE TABLE mytable (id INT IDENTITY NOT NULL, comment_null INT NOT NULL, comment_false INT NOT NULL, comment_empty_string INT NOT NULL, comment_integer_0 INT NOT NULL, comment_float_0 INT NOT NULL, comment_string_0 INT NOT NULL, comment INT NOT NULL, [comment_quoted] INT NOT NULL, [create] INT NOT NULL, commented_type VARCHAR(MAX) NOT NULL, commented_type_with_comment VARCHAR(MAX) NOT NULL, comment_with_string_literal_char NVARCHAR(255) NOT NULL, PRIMARY KEY (id))', "EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_integer_0", "EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_float_0", "EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_string_0", @@ -702,7 +704,7 @@ public function testGeneratesCreateTableSQLWithColumnComments() "EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type", "EXEC sp_addextendedproperty N'MS_Description', N'Doctrine array type.(DC2Type:array)', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type_with_comment", "EXEC sp_addextendedproperty N'MS_Description', N'O''Reilly', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_with_string_literal_char", - ), + ], $this->_platform->getCreateTableSQL($table) ); } @@ -714,108 +716,108 @@ public function testGeneratesCreateTableSQLWithColumnComments() public function testGeneratesAlterTableSQLWithColumnComments() { $table = new Table('mytable'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->addColumn('comment_null', 'integer', array('comment' => null)); - $table->addColumn('comment_false', 'integer', array('comment' => false)); - $table->addColumn('comment_empty_string', 'integer', array('comment' => '')); - $table->addColumn('comment_integer_0', 'integer', array('comment' => 0)); - $table->addColumn('comment_float_0', 'integer', array('comment' => 0.0)); - $table->addColumn('comment_string_0', 'integer', array('comment' => '0')); - $table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!')); - $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitly quoted columns!')); - $table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->addColumn('comment_null', 'integer', ['comment' => null]); + $table->addColumn('comment_false', 'integer', ['comment' => false]); + $table->addColumn('comment_empty_string', 'integer', ['comment' => '']); + $table->addColumn('comment_integer_0', 'integer', ['comment' => 0]); + $table->addColumn('comment_float_0', 'integer', ['comment' => 0.0]); + $table->addColumn('comment_string_0', 'integer', ['comment' => '0']); + $table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']); + $table->addColumn('`comment_quoted`', 'integer', ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!']); + $table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']); $table->addColumn('commented_type', 'object'); - $table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.')); - $table->addColumn('comment_with_string_literal_quote_char', 'array', array('comment' => "O'Reilly")); - $table->setPrimaryKey(array('id')); - - $tableDiff = new TableDiff('mytable'); - $tableDiff->fromTable = $table; - $tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer')); - $tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), array('comment' => null)); - $tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), array('comment' => false)); - $tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), array('comment' => '')); - $tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), array('comment' => 0)); - $tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), array('comment' => 0.0)); - $tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), array('comment' => '0')); - $tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), array('comment' => 'Doctrine')); - $tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), array('comment' => 'rulez')); - $tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), array('comment' => '666')); - $tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object')); - $tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), array('comment' => '666')); - $tableDiff->addedColumns['added_comment_with_string_literal_char'] = new Column('added_comment_with_string_literal_char', Type::getType('string'), array('comment' => "''")); - - $tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), array('comment' => 'Double for real!')); + $table->addColumn('commented_type_with_comment', 'array', ['comment' => 'Doctrine array type.']); + $table->addColumn('comment_with_string_literal_quote_char', 'array', ['comment' => "O'Reilly"]); + $table->setPrimaryKey(['id']); + + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = $table; + $tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer')); + $tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), ['comment' => null]); + $tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), ['comment' => false]); + $tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), ['comment' => '']); + $tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), ['comment' => 0]); + $tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), ['comment' => 0.0]); + $tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), ['comment' => '0']); + $tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), ['comment' => 'Doctrine']); + $tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), ['comment' => 'rulez']); + $tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), ['comment' => '666']); + $tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object')); + $tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), ['comment' => '666']); + $tableDiff->addedColumns['added_comment_with_string_literal_char'] = new Column('added_comment_with_string_literal_char', Type::getType('string'), ['comment' => "''"]); + + $tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), ['comment' => 'Double for real!']); // Add comment to non-commented column. $tableDiff->changedColumns['id'] = new ColumnDiff( 'id', - new Column('id', Type::getType('integer'), array('autoincrement' => true, 'comment' => 'primary')), - array('comment'), - new Column('id', Type::getType('integer'), array('autoincrement' => true)) + new Column('id', Type::getType('integer'), ['autoincrement' => true, 'comment' => 'primary']), + ['comment'], + new Column('id', Type::getType('integer'), ['autoincrement' => true]) ); // Remove comment from null-commented column. $tableDiff->changedColumns['comment_null'] = new ColumnDiff( 'comment_null', new Column('comment_null', Type::getType('string')), - array('type'), - new Column('comment_null', Type::getType('integer'), array('comment' => null)) + ['type'], + new Column('comment_null', Type::getType('integer'), ['comment' => null]) ); // Add comment to false-commented column. $tableDiff->changedColumns['comment_false'] = new ColumnDiff( 'comment_false', - new Column('comment_false', Type::getType('integer'), array('comment' => 'false')), - array('comment'), - new Column('comment_false', Type::getType('integer'), array('comment' => false)) + new Column('comment_false', Type::getType('integer'), ['comment' => 'false']), + ['comment'], + new Column('comment_false', Type::getType('integer'), ['comment' => false]) ); // Change type to custom type from empty string commented column. $tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff( 'comment_empty_string', new Column('comment_empty_string', Type::getType('object')), - array('type'), - new Column('comment_empty_string', Type::getType('integer'), array('comment' => '')) + ['type'], + new Column('comment_empty_string', Type::getType('integer'), ['comment' => '']) ); // Change comment to false-comment from zero-string commented column. $tableDiff->changedColumns['comment_string_0'] = new ColumnDiff( 'comment_string_0', - new Column('comment_string_0', Type::getType('integer'), array('comment' => false)), - array('comment'), - new Column('comment_string_0', Type::getType('integer'), array('comment' => '0')) + new Column('comment_string_0', Type::getType('integer'), ['comment' => false]), + ['comment'], + new Column('comment_string_0', Type::getType('integer'), ['comment' => '0']) ); // Remove comment from regular commented column. $tableDiff->changedColumns['comment'] = new ColumnDiff( 'comment', new Column('comment', Type::getType('integer')), - array('comment'), - new Column('comment', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!')) + ['comment'], + new Column('comment', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']) ); // Change comment and change type to custom type from regular commented column. $tableDiff->changedColumns['`comment_quoted`'] = new ColumnDiff( '`comment_quoted`', - new Column('`comment_quoted`', Type::getType('array'), array('comment' => 'Doctrine array.')), - array('comment', 'type'), - new Column('`comment_quoted`', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!')) + new Column('`comment_quoted`', Type::getType('array'), ['comment' => 'Doctrine array.']), + ['comment', 'type'], + new Column('`comment_quoted`', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']) ); // Remove comment and change type to custom type from regular commented column. $tableDiff->changedColumns['create'] = new ColumnDiff( 'create', new Column('create', Type::getType('object')), - array('comment', 'type'), - new Column('create', Type::getType('integer'), array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')) + ['comment', 'type'], + new Column('create', Type::getType('integer'), ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']) ); // Add comment and change custom type to regular type from non-commented column. $tableDiff->changedColumns['commented_type'] = new ColumnDiff( 'commented_type', - new Column('commented_type', Type::getType('integer'), array('comment' => 'foo')), - array('comment', 'type'), + new Column('commented_type', Type::getType('integer'), ['comment' => 'foo']), + ['comment', 'type'], new Column('commented_type', Type::getType('object')) ); @@ -823,45 +825,45 @@ public function testGeneratesAlterTableSQLWithColumnComments() $tableDiff->changedColumns['commented_type_with_comment'] = new ColumnDiff( 'commented_type_with_comment', new Column('commented_type_with_comment', Type::getType('array')), - array('comment'), - new Column('commented_type_with_comment', Type::getType('array'), array('comment' => 'Doctrine array type.')) + ['comment'], + new Column('commented_type_with_comment', Type::getType('array'), ['comment' => 'Doctrine array type.']) ); // Change comment from comment with string literal char column. $tableDiff->changedColumns['comment_with_string_literal_char'] = new ColumnDiff( 'comment_with_string_literal_char', - new Column('comment_with_string_literal_char', Type::getType('string'), array('comment' => "'")), - array('comment'), - new Column('comment_with_string_literal_char', Type::getType('array'), array('comment' => "O'Reilly")) + new Column('comment_with_string_literal_char', Type::getType('string'), ['comment' => "'"]), + ['comment'], + new Column('comment_with_string_literal_char', Type::getType('array'), ['comment' => "O'Reilly"]) ); - $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), array('comment' => 0)); + $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), ['comment' => 0]); self::assertEquals( - array( + [ // Renamed columns. "sp_RENAME 'mytable.comment_float_0', 'comment_double_0', 'COLUMN'", // Added columns. - "ALTER TABLE mytable ADD added_comment_none INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_null INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_false INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_empty_string INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_integer_0 INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_float_0 INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_string_0 INT NOT NULL", - "ALTER TABLE mytable ADD added_comment INT NOT NULL", - "ALTER TABLE mytable ADD [added_comment_quoted] INT NOT NULL", - "ALTER TABLE mytable ADD [select] INT NOT NULL", - "ALTER TABLE mytable ADD added_commented_type VARCHAR(MAX) NOT NULL", - "ALTER TABLE mytable ADD added_commented_type_with_comment VARCHAR(MAX) NOT NULL", - "ALTER TABLE mytable ADD added_comment_with_string_literal_char NVARCHAR(255) NOT NULL", - "ALTER TABLE mytable DROP COLUMN comment_integer_0", - "ALTER TABLE mytable ALTER COLUMN comment_null NVARCHAR(255) NOT NULL", - "ALTER TABLE mytable ALTER COLUMN comment_empty_string VARCHAR(MAX) NOT NULL", - "ALTER TABLE mytable ALTER COLUMN [comment_quoted] VARCHAR(MAX) NOT NULL", - "ALTER TABLE mytable ALTER COLUMN [create] VARCHAR(MAX) NOT NULL", - "ALTER TABLE mytable ALTER COLUMN commented_type INT NOT NULL", + 'ALTER TABLE mytable ADD added_comment_none INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_null INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_false INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_empty_string INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_integer_0 INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_float_0 INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_string_0 INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment INT NOT NULL', + 'ALTER TABLE mytable ADD [added_comment_quoted] INT NOT NULL', + 'ALTER TABLE mytable ADD [select] INT NOT NULL', + 'ALTER TABLE mytable ADD added_commented_type VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ADD added_commented_type_with_comment VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ADD added_comment_with_string_literal_char NVARCHAR(255) NOT NULL', + 'ALTER TABLE mytable DROP COLUMN comment_integer_0', + 'ALTER TABLE mytable ALTER COLUMN comment_null NVARCHAR(255) NOT NULL', + 'ALTER TABLE mytable ALTER COLUMN comment_empty_string VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ALTER COLUMN [comment_quoted] VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ALTER COLUMN [create] VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ALTER COLUMN commented_type INT NOT NULL', // Added columns. "EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_comment_integer_0", @@ -885,7 +887,7 @@ public function testGeneratesAlterTableSQLWithColumnComments() "EXEC sp_updateextendedproperty N'MS_Description', N'foo', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type", "EXEC sp_updateextendedproperty N'MS_Description', N'(DC2Type:array)', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type_with_comment", "EXEC sp_updateextendedproperty N'MS_Description', N'''', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_with_string_literal_char", - ), + ], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -978,13 +980,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('VARBINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 8000))); + self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('VARBINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 8000])); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('BINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 8000))); + self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 8000])); } /** @@ -1002,9 +1004,7 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() */ protected function getAlterTableRenameIndexSQL() { - return array( - "EXEC sp_RENAME N'mytable.idx_foo', N'idx_bar', N'INDEX'", - ); + return ["EXEC sp_RENAME N'mytable.idx_foo', N'idx_bar', N'INDEX'"]; } /** @@ -1012,10 +1012,10 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ "EXEC sp_RENAME N'[table].[create]', N'[select]', N'INDEX'", "EXEC sp_RENAME N'[table].[foo]', N'[bar]', N'INDEX'", - ); + ]; } /** @@ -1026,37 +1026,37 @@ public function testChangeColumnsTypeWithDefaultValue() $tableName = 'column_def_change_type'; $table = new Table($tableName); - $table->addColumn('col_int', 'smallint', array('default' => 666)); - $table->addColumn('col_string', 'string', array('default' => 'foo')); + $table->addColumn('col_int', 'smallint', ['default' => 666]); + $table->addColumn('col_string', 'string', ['default' => 'foo']); - $tableDiff = new TableDiff($tableName); - $tableDiff->fromTable = $table; + $tableDiff = new TableDiff($tableName); + $tableDiff->fromTable = $table; $tableDiff->changedColumns['col_int'] = new ColumnDiff( 'col_int', - new Column('col_int', Type::getType('integer'), array('default' => 666)), - array('type'), - new Column('col_int', Type::getType('smallint'), array('default' => 666)) + new Column('col_int', Type::getType('integer'), ['default' => 666]), + ['type'], + new Column('col_int', Type::getType('smallint'), ['default' => 666]) ); $tableDiff->changedColumns['col_string'] = new ColumnDiff( 'col_string', - new Column('col_string', Type::getType('string'), array('default' => 666, 'fixed' => true)), - array('fixed'), - new Column('col_string', Type::getType('string'), array('default' => 666)) + new Column('col_string', Type::getType('string'), ['default' => 666, 'fixed' => true]), + ['fixed'], + new Column('col_string', Type::getType('string'), ['default' => 666]) ); $expected = $this->_platform->getAlterTableSQL($tableDiff); self::assertSame( $expected, - array( + [ 'ALTER TABLE column_def_change_type DROP CONSTRAINT DF_829302E0_FA2CB292', 'ALTER TABLE column_def_change_type ALTER COLUMN col_int INT NOT NULL', 'ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_FA2CB292 DEFAULT 666 FOR col_int', 'ALTER TABLE column_def_change_type DROP CONSTRAINT DF_829302E0_2725A6D0', 'ALTER TABLE column_def_change_type ALTER COLUMN col_string NCHAR(255) NOT NULL', "ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_2725A6D0 DEFAULT '666' FOR col_string", - ) + ] ); } @@ -1065,7 +1065,7 @@ public function testChangeColumnsTypeWithDefaultValue() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( + return [ "sp_RENAME 'mytable.unquoted1', 'unquoted', 'COLUMN'", "sp_RENAME 'mytable.unquoted2', '[where]', 'COLUMN'", "sp_RENAME 'mytable.unquoted3', '[foo]', 'COLUMN'", @@ -1075,7 +1075,7 @@ protected function getQuotedAlterTableRenameColumnSQL() "sp_RENAME 'mytable.quoted1', 'quoted', 'COLUMN'", "sp_RENAME 'mytable.quoted2', '[and]', 'COLUMN'", "sp_RENAME 'mytable.quoted3', '[baz]', 'COLUMN'", - ); + ]; } /** @@ -1091,9 +1091,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - "EXEC sp_RENAME N'myschema.mytable.idx_foo', N'idx_bar', N'INDEX'", - ); + return ["EXEC sp_RENAME N'myschema.mytable.idx_foo', N'idx_bar', N'INDEX'"]; } /** @@ -1101,10 +1099,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ "EXEC sp_RENAME N'[schema].[table].[create]', N'[select]', N'INDEX'", "EXEC sp_RENAME N'[schema].[table].[foo]', N'[bar]', N'INDEX'", - ); + ]; } protected function getQuotesDropForeignKeySQL() @@ -1128,16 +1126,16 @@ public function testGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL($t public function getGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL() { - return array( + return [ // Unquoted identifiers non-reserved keywords. - array('mytable', array('name' => 'mycolumn', 'default' => 'foo'), " CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR mycolumn"), + ['mytable', ['name' => 'mycolumn', 'default' => 'foo'], " CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR mycolumn"], // Quoted identifiers non-reserved keywords. - array('`mytable`', array('name' => '`mycolumn`', 'default' => 'foo'), " CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR [mycolumn]"), + ['`mytable`', ['name' => '`mycolumn`', 'default' => 'foo'], " CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR [mycolumn]"], // Unquoted identifiers reserved keywords. - array('table', array('name' => 'select', 'default' => 'foo'), " CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"), + ['table', ['name' => 'select', 'default' => 'foo'], " CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"], // Quoted identifiers reserved keywords. - array('`table`', array('name' => '`select`', 'default' => 'foo'), " CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"), - ); + ['`table`', ['name' => '`select`', 'default' => 'foo'], " CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"], + ]; } /** @@ -1151,40 +1149,40 @@ public function testGeneratesIdentifierNamesInCreateTableSQL($table, $expectedSq public function getGeneratesIdentifierNamesInCreateTableSQL() { - return array( + return [ // Unquoted identifiers non-reserved keywords. - array( - new Table('mytable', array(new Column('mycolumn', Type::getType('string'), array('default' => 'foo')))), - array( + [ + new Table('mytable', [new Column('mycolumn', Type::getType('string'), ['default' => 'foo'])]), + [ 'CREATE TABLE mytable (mycolumn NVARCHAR(255) NOT NULL)', - "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR mycolumn" - ) - ), + "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR mycolumn", + ], + ], // Quoted identifiers reserved keywords. - array( - new Table('`mytable`', array(new Column('`mycolumn`', Type::getType('string'), array('default' => 'foo')))), - array( + [ + new Table('`mytable`', [new Column('`mycolumn`', Type::getType('string'), ['default' => 'foo'])]), + [ 'CREATE TABLE [mytable] ([mycolumn] NVARCHAR(255) NOT NULL)', - "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR [mycolumn]" - ) - ), + "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR [mycolumn]", + ], + ], // Unquoted identifiers reserved keywords. - array( - new Table('table', array(new Column('select', Type::getType('string'), array('default' => 'foo')))), - array( + [ + new Table('table', [new Column('select', Type::getType('string'), ['default' => 'foo'])]), + [ 'CREATE TABLE [table] ([select] NVARCHAR(255) NOT NULL)', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]" - ) - ), + "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]", + ], + ], // Quoted identifiers reserved keywords. - array( - new Table('`table`', array(new Column('`select`', Type::getType('string'), array('default' => 'foo')))), - array( + [ + new Table('`table`', [new Column('`select`', Type::getType('string'), ['default' => 'foo'])]), + [ 'CREATE TABLE [table] ([select] NVARCHAR(255) NOT NULL)', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]" - ) - ), - ); + "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]", + ], + ], + ]; } /** @@ -1198,104 +1196,104 @@ public function testGeneratesIdentifierNamesInAlterTableSQL($tableDiff, $expecte public function getGeneratesIdentifierNamesInAlterTableSQL() { - return array( + return [ // Unquoted identifiers non-reserved keywords. - array( + [ new TableDiff( 'mytable', - array(new Column('addcolumn', Type::getType('string'), array('default' => 'foo'))), - array( + [new Column('addcolumn', Type::getType('string'), ['default' => 'foo'])], + [ 'mycolumn' => new ColumnDiff( 'mycolumn', - new Column('mycolumn', Type::getType('string'), array('default' => 'bar')), - array('default'), - new Column('mycolumn', Type::getType('string'), array('default' => 'foo')) - ) - ), - array(new Column('removecolumn', Type::getType('string'), array('default' => 'foo'))) + new Column('mycolumn', Type::getType('string'), ['default' => 'bar']), + ['default'], + new Column('mycolumn', Type::getType('string'), ['default' => 'foo']) + ), + ], + [new Column('removecolumn', Type::getType('string'), ['default' => 'foo'])] ), - array( + [ 'ALTER TABLE mytable ADD addcolumn NVARCHAR(255) NOT NULL', "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_4AD86123 DEFAULT 'foo' FOR addcolumn", 'ALTER TABLE mytable DROP COLUMN removecolumn', 'ALTER TABLE mytable DROP CONSTRAINT DF_6B2BD609_9BADD926', 'ALTER TABLE mytable ALTER COLUMN mycolumn NVARCHAR(255) NOT NULL', - "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR mycolumn" - ) - ), + "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR mycolumn", + ], + ], // Quoted identifiers non-reserved keywords. - array( + [ new TableDiff( '`mytable`', - array(new Column('`addcolumn`', Type::getType('string'), array('default' => 'foo'))), - array( + [new Column('`addcolumn`', Type::getType('string'), ['default' => 'foo'])], + [ 'mycolumn' => new ColumnDiff( '`mycolumn`', - new Column('`mycolumn`', Type::getType('string'), array('default' => 'bar')), - array('default'), - new Column('`mycolumn`', Type::getType('string'), array('default' => 'foo')) - ) - ), - array(new Column('`removecolumn`', Type::getType('string'), array('default' => 'foo'))) + new Column('`mycolumn`', Type::getType('string'), ['default' => 'bar']), + ['default'], + new Column('`mycolumn`', Type::getType('string'), ['default' => 'foo']) + ), + ], + [new Column('`removecolumn`', Type::getType('string'), ['default' => 'foo'])] ), - array( + [ 'ALTER TABLE [mytable] ADD [addcolumn] NVARCHAR(255) NOT NULL', "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_4AD86123 DEFAULT 'foo' FOR [addcolumn]", 'ALTER TABLE [mytable] DROP COLUMN [removecolumn]', 'ALTER TABLE [mytable] DROP CONSTRAINT DF_6B2BD609_9BADD926', 'ALTER TABLE [mytable] ALTER COLUMN [mycolumn] NVARCHAR(255) NOT NULL', - "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR [mycolumn]" - ) - ), + "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR [mycolumn]", + ], + ], // Unquoted identifiers reserved keywords. - array( + [ new TableDiff( 'table', - array(new Column('add', Type::getType('string'), array('default' => 'foo'))), - array( + [new Column('add', Type::getType('string'), ['default' => 'foo'])], + [ 'select' => new ColumnDiff( 'select', - new Column('select', Type::getType('string'), array('default' => 'bar')), - array('default'), - new Column('select', Type::getType('string'), array('default' => 'foo')) - ) - ), - array(new Column('drop', Type::getType('string'), array('default' => 'foo'))) + new Column('select', Type::getType('string'), ['default' => 'bar']), + ['default'], + new Column('select', Type::getType('string'), ['default' => 'foo']) + ), + ], + [new Column('drop', Type::getType('string'), ['default' => 'foo'])] ), - array( + [ 'ALTER TABLE [table] ADD [add] NVARCHAR(255) NOT NULL', "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_FD1A73E7 DEFAULT 'foo' FOR [add]", 'ALTER TABLE [table] DROP COLUMN [drop]', 'ALTER TABLE [table] DROP CONSTRAINT DF_F6298F46_4BF2EAC0', 'ALTER TABLE [table] ALTER COLUMN [select] NVARCHAR(255) NOT NULL', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]" - ) - ), + "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]", + ], + ], // Quoted identifiers reserved keywords. - array( + [ new TableDiff( '`table`', - array(new Column('`add`', Type::getType('string'), array('default' => 'foo'))), - array( + [new Column('`add`', Type::getType('string'), ['default' => 'foo'])], + [ 'select' => new ColumnDiff( '`select`', - new Column('`select`', Type::getType('string'), array('default' => 'bar')), - array('default'), - new Column('`select`', Type::getType('string'), array('default' => 'foo')) - ) - ), - array(new Column('`drop`', Type::getType('string'), array('default' => 'foo'))) + new Column('`select`', Type::getType('string'), ['default' => 'bar']), + ['default'], + new Column('`select`', Type::getType('string'), ['default' => 'foo']) + ), + ], + [new Column('`drop`', Type::getType('string'), ['default' => 'foo'])] ), - array( + [ 'ALTER TABLE [table] ADD [add] NVARCHAR(255) NOT NULL', "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_FD1A73E7 DEFAULT 'foo' FOR [add]", 'ALTER TABLE [table] DROP COLUMN [drop]', 'ALTER TABLE [table] DROP CONSTRAINT DF_F6298F46_4BF2EAC0', 'ALTER TABLE [table] ALTER COLUMN [select] NVARCHAR(255) NOT NULL', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]" - ) - ), - ); + "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]", + ], + ], + ]; } /** @@ -1303,7 +1301,7 @@ public function getGeneratesIdentifierNamesInAlterTableSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -1311,11 +1309,11 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( + return [ "sp_RENAME 'foo.bar', 'baz', 'COLUMN'", 'ALTER TABLE foo DROP CONSTRAINT DF_8C736521_76FF8CAA', 'ALTER TABLE foo ADD CONSTRAINT DF_8C736521_78240498 DEFAULT 666 FOR baz', - ); + ]; } /** @@ -1323,7 +1321,7 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE [foo] DROP CONSTRAINT fk1', 'ALTER TABLE [foo] DROP CONSTRAINT fk2', "sp_RENAME '[foo].id', 'war', 'COLUMN'", @@ -1337,7 +1335,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() "WHERE tbl.name = 'table';EXEC sp_executesql @sql", 'ALTER TABLE [table] ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', 'ALTER TABLE [table] ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ); + ]; } /** @@ -1345,11 +1343,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ "COMMENT ON COLUMN foo.bar IS 'comment'", "COMMENT ON COLUMN [Foo].[BAR] IS 'comment'", "COMMENT ON COLUMN [select].[from] IS 'comment'", - ); + ]; } /** @@ -1357,14 +1355,14 @@ protected function getCommentOnColumnSQL() */ public function getReturnsForeignKeyReferentialActionSQL() { - return array( - array('CASCADE', 'CASCADE'), - array('SET NULL', 'SET NULL'), - array('NO ACTION', 'NO ACTION'), - array('RESTRICT', 'NO ACTION'), - array('SET DEFAULT', 'SET DEFAULT'), - array('CaScAdE', 'CASCADE'), - ); + return [ + ['CASCADE', 'CASCADE'], + ['SET NULL', 'SET NULL'], + ['NO ACTION', 'NO ACTION'], + ['RESTRICT', 'NO ACTION'], + ['SET DEFAULT', 'SET DEFAULT'], + ['CaScAdE', 'CASCADE'], + ]; } /** @@ -1396,9 +1394,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() */ protected function getAlterStringToFixedStringSQL() { - return array( - 'ALTER TABLE mytable ALTER COLUMN name NCHAR(2) NOT NULL', - ); + return ['ALTER TABLE mytable ALTER COLUMN name NCHAR(2) NOT NULL']; } /** @@ -1406,21 +1402,19 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - "EXEC sp_RENAME N'mytable.idx_foo', N'idx_foo_renamed', N'INDEX'", - ); + return ["EXEC sp_RENAME N'mytable.idx_foo', N'idx_foo_renamed', N'INDEX'"]; } public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() { - $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC)'; + $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC)'; $alteredSql = 'SELECT TOP 10 * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC)'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); - $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; + $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; $alteredSql = 'SELECT TOP 10 * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php index 5373b3f640d..841021b9653 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php @@ -13,9 +13,7 @@ class DB2PlatformTest extends AbstractPlatformTestCase { - /** - * @var \Doctrine\DBAL\Platforms\DB2Platform - */ + /** @var DB2Platform */ protected $_platform; public function createPlatform() @@ -25,19 +23,19 @@ public function createPlatform() public function getGenerateAlterTableSql() { - return array( - "ALTER TABLE mytable ALTER COLUMN baz SET DATA TYPE VARCHAR(255)", - "ALTER TABLE mytable ALTER COLUMN baz SET NOT NULL", + return [ + 'ALTER TABLE mytable ALTER COLUMN baz SET DATA TYPE VARCHAR(255)', + 'ALTER TABLE mytable ALTER COLUMN baz SET NOT NULL', "ALTER TABLE mytable ALTER COLUMN baz SET DEFAULT 'def'", - "ALTER TABLE mytable ALTER COLUMN bloo SET DATA TYPE SMALLINT", - "ALTER TABLE mytable ALTER COLUMN bloo SET NOT NULL", + 'ALTER TABLE mytable ALTER COLUMN bloo SET DATA TYPE SMALLINT', + 'ALTER TABLE mytable ALTER COLUMN bloo SET NOT NULL', "ALTER TABLE mytable ALTER COLUMN bloo SET DEFAULT '0'", - "ALTER TABLE mytable " . - "ADD COLUMN quota INTEGER DEFAULT NULL " . - "DROP COLUMN foo", + 'ALTER TABLE mytable ' . + 'ADD COLUMN quota INTEGER DEFAULT NULL ' . + 'DROP COLUMN foo', "CALL SYSPROC.ADMIN_CMD ('REORG TABLE mytable')", 'RENAME TABLE mytable TO userlist', - ); + ]; } public function getGenerateForeignKeySql() @@ -57,10 +55,10 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', - 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)' - ); + 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', + ]; } public function getGenerateUniqueIndexSql() @@ -70,35 +68,33 @@ public function getGenerateUniqueIndexSql() protected function getQuotedColumnInForeignKeySQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL)', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar")', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar")', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar")', - ); + ]; } protected function getQuotedColumnInIndexSQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', - 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")' - ); + 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', 'CREATE INDEX "key" ON test (column1)', - ); + ]; } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))' - ); + return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; } protected function getBitAndComparisonExpressionSql($value1, $value2) @@ -106,37 +102,37 @@ protected function getBitAndComparisonExpressionSql($value1, $value2) return 'BITAND(' . $value1 . ', ' . $value2 . ')'; } - protected function getBitOrComparisonExpressionSql($value1, $value2) + protected function getBitOrComparisonExpressionSql($value1, $value2) { return 'BITOR(' . $value1 . ', ' . $value2 . ')'; } public function getCreateTableColumnCommentsSQL() { - return array( - "CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))", + return [ + 'CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))', "COMMENT ON COLUMN test.id IS 'This is a comment'", - ); + ]; } public function getAlterTableColumnCommentsSQL() { - return array( - "ALTER TABLE mytable " . - "ADD COLUMN quota INTEGER NOT NULL WITH DEFAULT", + return [ + 'ALTER TABLE mytable ' . + 'ADD COLUMN quota INTEGER NOT NULL WITH DEFAULT', "CALL SYSPROC.ADMIN_CMD ('REORG TABLE mytable')", "COMMENT ON COLUMN mytable.quota IS 'A comment'", "COMMENT ON COLUMN mytable.foo IS ''", "COMMENT ON COLUMN mytable.baz IS 'B comment'", - ); + ]; } public function getCreateTableColumnTypeCommentsSQL() { - return array( + return [ 'CREATE TABLE test (id INTEGER NOT NULL, "data" CLOB(1M) NOT NULL, PRIMARY KEY(id))', 'COMMENT ON COLUMN test."data" IS \'(DC2Type:array)\'', - ); + ]; } public function testHasCorrectPlatformName() @@ -148,17 +144,17 @@ public function testGeneratesCreateTableSQLWithCommonIndexes() { $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addColumn('name', 'string', array('length' => 50)); - $table->setPrimaryKey(array('id')); - $table->addIndex(array('name')); - $table->addIndex(array('id', 'name'), 'composite_idx'); + $table->addColumn('name', 'string', ['length' => 50]); + $table->setPrimaryKey(['id']); + $table->addIndex(['name']); + $table->addIndex(['id', 'name'], 'composite_idx'); self::assertEquals( - array( + [ 'CREATE TABLE test (id INTEGER NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id))', 'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)', - 'CREATE INDEX composite_idx ON test (id, name)' - ), + 'CREATE INDEX composite_idx ON test (id, name)', + ], $this->_platform->getCreateTableSQL($table) ); } @@ -169,22 +165,22 @@ public function testGeneratesCreateTableSQLWithForeignKeyConstraints() $table->addColumn('id', 'integer'); $table->addColumn('fk_1', 'integer'); $table->addColumn('fk_2', 'integer'); - $table->setPrimaryKey(array('id')); - $table->addForeignKeyConstraint('foreign_table', array('fk_1', 'fk_2'), array('pk_1', 'pk_2')); + $table->setPrimaryKey(['id']); + $table->addForeignKeyConstraint('foreign_table', ['fk_1', 'fk_2'], ['pk_1', 'pk_2']); $table->addForeignKeyConstraint( 'foreign_table2', - array('fk_1', 'fk_2'), - array('pk_1', 'pk_2'), - array(), + ['fk_1', 'fk_2'], + ['pk_1', 'pk_2'], + [], 'named_fk' ); self::assertEquals( - array( + [ 'CREATE TABLE test (id INTEGER NOT NULL, fk_1 INTEGER NOT NULL, fk_2 INTEGER NOT NULL)', 'ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2)', 'ALTER TABLE test ADD CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2)', - ), + ], $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS) ); } @@ -193,52 +189,44 @@ public function testGeneratesCreateTableSQLWithCheckConstraints() { $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addColumn('check_max', 'integer', array('platformOptions' => array('max' => 10))); - $table->addColumn('check_min', 'integer', array('platformOptions' => array('min' => 10))); - $table->setPrimaryKey(array('id')); + $table->addColumn('check_max', 'integer', ['platformOptions' => ['max' => 10]]); + $table->addColumn('check_min', 'integer', ['platformOptions' => ['min' => 10]]); + $table->setPrimaryKey(['id']); self::assertEquals( - array( - 'CREATE TABLE test (id INTEGER NOT NULL, check_max INTEGER NOT NULL, check_min INTEGER NOT NULL, PRIMARY KEY(id), CHECK (check_max <= 10), CHECK (check_min >= 10))' - ), + ['CREATE TABLE test (id INTEGER NOT NULL, check_max INTEGER NOT NULL, check_min INTEGER NOT NULL, PRIMARY KEY(id), CHECK (check_max <= 10), CHECK (check_min >= 10))'], $this->_platform->getCreateTableSQL($table) ); } public function testGeneratesColumnTypesDeclarationSQL() { - $fullColumnDef = array( + $fullColumnDef = [ 'length' => 10, 'fixed' => true, 'unsigned' => true, - 'autoincrement' => true - ); + 'autoincrement' => true, + ]; - self::assertEquals('VARCHAR(255)', $this->_platform->getVarcharTypeDeclarationSQL(array())); - self::assertEquals('VARCHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 10))); + self::assertEquals('VARCHAR(255)', $this->_platform->getVarcharTypeDeclarationSQL([])); + self::assertEquals('VARCHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL(['length' => 10])); self::assertEquals('CHAR(254)', $this->_platform->getVarcharTypeDeclarationSQL(['fixed' => true])); self::assertEquals('CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array())); - self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL([])); + self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('SMALLINT GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getSmallIntTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL(array())); - self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL([])); + self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('INTEGER GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getIntegerTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array())); - self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL([])); + self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('BIGINT GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getBigIntTypeDeclarationSQL($fullColumnDef)); self::assertEquals('BLOB(1M)', $this->_platform->getBlobTypeDeclarationSQL($fullColumnDef)); self::assertEquals('SMALLINT', $this->_platform->getBooleanTypeDeclarationSQL($fullColumnDef)); self::assertEquals('CLOB(1M)', $this->_platform->getClobTypeDeclarationSQL($fullColumnDef)); self::assertEquals('DATE', $this->_platform->getDateTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('TIMESTAMP(0) WITH DEFAULT', $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true))); + self::assertEquals('TIMESTAMP(0) WITH DEFAULT', $this->_platform->getDateTimeTypeDeclarationSQL(['version' => true])); self::assertEquals('TIMESTAMP(0)', $this->_platform->getDateTimeTypeDeclarationSQL($fullColumnDef)); self::assertEquals('TIME', $this->_platform->getTimeTypeDeclarationSQL($fullColumnDef)); } @@ -291,15 +279,15 @@ public function getIsCommentedDoctrineType() { $data = parent::getIsCommentedDoctrineType(); - $data[Type::BOOLEAN] = array(Type::getType(Type::BOOLEAN), true); + $data[Type::BOOLEAN] = [Type::getType(Type::BOOLEAN), true]; return $data; } public function testGeneratesDDLSnippets() { - self::assertEquals("CREATE DATABASE foobar", $this->_platform->getCreateDatabaseSQL('foobar')); - self::assertEquals("DROP DATABASE foobar", $this->_platform->getDropDatabaseSQL('foobar')); + self::assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar')); + self::assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar')); self::assertEquals('DECLARE GLOBAL TEMPORARY TABLE', $this->_platform->getCreateTemporaryTableSnippetSQL()); self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->_platform->getTruncateTableSQL('foobar')); self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->_platform->getTruncateTableSQL('foobar'), true); @@ -314,7 +302,7 @@ public function testGeneratesCreateUnnamedPrimaryKeySQL() self::assertEquals( 'ALTER TABLE foo ADD PRIMARY KEY (a, b)', $this->_platform->getCreatePrimaryKeySQL( - new Index('any_pk_name', array('a', 'b'), true, true), + new Index('any_pk_name', ['a', 'b'], true, true), 'foo' ) ); @@ -442,9 +430,7 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() */ protected function getAlterTableRenameIndexSQL() { - return array( - 'RENAME INDEX idx_foo TO idx_bar', - ); + return ['RENAME INDEX idx_foo TO idx_bar']; } /** @@ -452,10 +438,10 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'RENAME INDEX "create" TO "select"', 'RENAME INDEX "foo" TO "bar"', - ); + ]; } /** @@ -463,8 +449,7 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( - 'ALTER TABLE mytable ' . + return ['ALTER TABLE mytable ' . 'RENAME COLUMN unquoted1 TO unquoted ' . 'RENAME COLUMN unquoted2 TO "where" ' . 'RENAME COLUMN unquoted3 TO "foo" ' . @@ -473,8 +458,8 @@ protected function getQuotedAlterTableRenameColumnSQL() 'RENAME COLUMN "select" TO "bar" ' . 'RENAME COLUMN quoted1 TO quoted ' . 'RENAME COLUMN quoted2 TO "and" ' . - 'RENAME COLUMN quoted3 TO "baz"' - ); + 'RENAME COLUMN quoted3 TO "baz"', + ]; } /** @@ -490,9 +475,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - 'RENAME INDEX myschema.idx_foo TO idx_bar', - ); + return ['RENAME INDEX myschema.idx_foo TO idx_bar']; } /** @@ -500,10 +483,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'RENAME INDEX "schema"."create" TO "select"', 'RENAME INDEX "schema"."foo" TO "bar"', - ); + ]; } /** @@ -511,7 +494,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -519,9 +502,7 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( - 'ALTER TABLE foo RENAME COLUMN bar TO baz', - ); + return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; } /** @@ -529,7 +510,7 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE "foo" DROP FOREIGN KEY fk1', 'ALTER TABLE "foo" DROP FOREIGN KEY fk2', 'ALTER TABLE "foo" ' . @@ -541,7 +522,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() 'RENAME TABLE "foo" TO "table"', 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ); + ]; } /** @@ -549,27 +530,26 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', 'COMMENT ON COLUMN "select"."from" IS \'comment\'', - ); + ]; } /** * @group DBAL-944 - * * @dataProvider getGeneratesAlterColumnSQL */ public function testGeneratesAlterColumnSQL($changedProperty, Column $column, $expectedSQLClause = null) { - $tableDiff = new TableDiff('foo'); - $tableDiff->fromTable = new Table('foo'); - $tableDiff->changedColumns['bar'] = new ColumnDiff('bar', $column, array($changedProperty)); + $tableDiff = new TableDiff('foo'); + $tableDiff->fromTable = new Table('foo'); + $tableDiff->changedColumns['bar'] = new ColumnDiff('bar', $column, [$changedProperty]); - $expectedSQL = array(); + $expectedSQL = []; - if (null !== $expectedSQLClause) { + if ($expectedSQLClause !== null) { $expectedSQL[] = 'ALTER TABLE foo ALTER COLUMN bar ' . $expectedSQLClause; } @@ -583,63 +563,63 @@ public function testGeneratesAlterColumnSQL($changedProperty, Column $column, $e */ public function getGeneratesAlterColumnSQL() { - return array( - array( + return [ + [ 'columnDefinition', - new Column('bar', Type::getType('decimal'), array('columnDefinition' => 'MONEY NOT NULL')), - 'MONEY NOT NULL' - ), - array( + new Column('bar', Type::getType('decimal'), ['columnDefinition' => 'MONEY NOT NULL']), + 'MONEY NOT NULL', + ], + [ 'type', new Column('bar', Type::getType('integer')), - 'SET DATA TYPE INTEGER' - ), - array( + 'SET DATA TYPE INTEGER', + ], + [ 'length', - new Column('bar', Type::getType('string'), array('length' => 100)), - 'SET DATA TYPE VARCHAR(100)' - ), - array( + new Column('bar', Type::getType('string'), ['length' => 100]), + 'SET DATA TYPE VARCHAR(100)', + ], + [ 'precision', - new Column('bar', Type::getType('decimal'), array('precision' => 10, 'scale' => 2)), - 'SET DATA TYPE NUMERIC(10, 2)' - ), - array( + new Column('bar', Type::getType('decimal'), ['precision' => 10, 'scale' => 2]), + 'SET DATA TYPE NUMERIC(10, 2)', + ], + [ 'scale', - new Column('bar', Type::getType('decimal'), array('precision' => 5, 'scale' => 4)), - 'SET DATA TYPE NUMERIC(5, 4)' - ), - array( + new Column('bar', Type::getType('decimal'), ['precision' => 5, 'scale' => 4]), + 'SET DATA TYPE NUMERIC(5, 4)', + ], + [ 'fixed', - new Column('bar', Type::getType('string'), array('length' => 20, 'fixed' => true)), - 'SET DATA TYPE CHAR(20)' - ), - array( + new Column('bar', Type::getType('string'), ['length' => 20, 'fixed' => true]), + 'SET DATA TYPE CHAR(20)', + ], + [ 'notnull', - new Column('bar', Type::getType('string'), array('notnull' => true)), - 'SET NOT NULL' - ), - array( + new Column('bar', Type::getType('string'), ['notnull' => true]), + 'SET NOT NULL', + ], + [ 'notnull', - new Column('bar', Type::getType('string'), array('notnull' => false)), - 'DROP NOT NULL' - ), - array( + new Column('bar', Type::getType('string'), ['notnull' => false]), + 'DROP NOT NULL', + ], + [ 'default', - new Column('bar', Type::getType('string'), array('default' => 'foo')), - "SET DEFAULT 'foo'" - ), - array( + new Column('bar', Type::getType('string'), ['default' => 'foo']), + "SET DEFAULT 'foo'", + ], + [ 'default', - new Column('bar', Type::getType('integer'), array('autoincrement' => true, 'default' => 666)), - null - ), - array( + new Column('bar', Type::getType('integer'), ['autoincrement' => true, 'default' => 666]), + null, + ], + [ 'default', new Column('bar', Type::getType('string')), - "DROP DEFAULT" - ), - ); + 'DROP DEFAULT', + ], + ]; } /** @@ -687,10 +667,10 @@ protected function supportsCommentOnStatement() */ protected function getAlterStringToFixedStringSQL() { - return array( + return [ 'ALTER TABLE mytable ALTER COLUMN name SET DATA TYPE CHAR(2)', 'CALL SYSPROC.ADMIN_CMD (\'REORG TABLE mytable\')', - ); + ]; } /** @@ -698,9 +678,7 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - 'RENAME INDEX idx_foo TO idx_foo_renamed', - ); + return ['RENAME INDEX idx_foo TO idx_foo_renamed']; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php index 138a55ef714..95938f477c1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php @@ -22,6 +22,7 @@ public function testHasNativeJsonType() : void /** * From MariaDB 10.2.7, JSON type is an alias to LONGTEXT + * * @link https://mariadb.com/kb/en/library/json-data-type/ */ public function testReturnsJsonTypeDeclarationSQL() : void diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php index 2ea04fe75a8..bef9aa6a545 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php @@ -22,7 +22,7 @@ public function testHasNativeJsonType() public function testReturnsJsonTypeDeclarationSQL() { - self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(array())); + self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL([])); } public function testInitializesJsonTypeMapping() @@ -36,9 +36,7 @@ public function testInitializesJsonTypeMapping() */ protected function getAlterTableRenameIndexSQL() { - return array( - 'ALTER TABLE mytable RENAME INDEX idx_foo TO idx_bar', - ); + return ['ALTER TABLE mytable RENAME INDEX idx_foo TO idx_bar']; } /** @@ -46,10 +44,10 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'ALTER TABLE `table` RENAME INDEX `create` TO `select`', 'ALTER TABLE `table` RENAME INDEX `foo` TO `bar`', - ); + ]; } /** @@ -57,9 +55,7 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - 'ALTER TABLE myschema.mytable RENAME INDEX idx_foo TO idx_bar', - ); + return ['ALTER TABLE myschema.mytable RENAME INDEX idx_foo TO idx_bar']; } /** @@ -67,10 +63,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'ALTER TABLE `schema`.`table` RENAME INDEX `create` TO `select`', 'ALTER TABLE `schema`.`table` RENAME INDEX `foo` TO `bar`', - ); + ]; } /** @@ -78,8 +74,6 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - 'ALTER TABLE mytable RENAME INDEX idx_foo TO idx_foo_renamed', - ); + return ['ALTER TABLE mytable RENAME INDEX idx_foo TO idx_foo_renamed']; } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php index 2dc3a7ce28e..3372ef94051 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php @@ -9,7 +9,7 @@ class MySqlPlatformTest extends AbstractMySQLPlatformTestCase { public function createPlatform() { - return new MysqlPlatform; + return new MysqlPlatform(); } public function testHasCorrectDefaultTransactionIsolationLevel() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 5e270b4a1e7..da210021a85 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -5,9 +5,12 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\Column; +use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\Type; use function array_walk; @@ -67,7 +70,7 @@ public function testInvalidIdentifiers($identifier) public function createPlatform() { - return new OraclePlatform; + return new OraclePlatform(); } public function getGenerateTableSql() @@ -77,20 +80,20 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo VARCHAR2(255) DEFAULT NULL NULL, bar VARCHAR2(255) DEFAULT NULL NULL)', 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', - ); + ]; } public function getGenerateAlterTableSql() { - return array( + return [ 'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL NULL)', "ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL, bloo NUMBER(1) DEFAULT '0' NOT NULL)", - "ALTER TABLE mytable DROP (foo)", - "ALTER TABLE mytable RENAME TO userlist", - ); + 'ALTER TABLE mytable DROP (foo)', + 'ALTER TABLE mytable RENAME TO userlist', + ]; } /** @@ -149,17 +152,18 @@ public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'NUMBER(10)', - $this->_platform->getIntegerTypeDeclarationSQL(array()) + $this->_platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'NUMBER(10)', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true) - )); + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + ); self::assertEquals( 'NUMBER(10)', $this->_platform->getIntegerTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true) - )); + ['autoincrement' => true, 'primary' => true] + ) + ); } public function testGeneratesTypeDeclarationsForStrings() @@ -167,16 +171,17 @@ public function testGeneratesTypeDeclarationsForStrings() self::assertEquals( 'CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL( - array('length' => 10, 'fixed' => true) - )); + ['length' => 10, 'fixed' => true] + ) + ); self::assertEquals( 'VARCHAR2(50)', - $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)), + $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR2(255)', - $this->_platform->getVarcharTypeDeclarationSQL(array()), + $this->_platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } @@ -221,12 +226,11 @@ public function getGenerateForeignKeySql() /** * @group DBAL-1097 - * * @dataProvider getGeneratesAdvancedForeignKeyOptionsSQLData */ public function testGeneratesAdvancedForeignKeyOptionsSQL(array $options, $expectedSql) { - $foreignKey = new ForeignKeyConstraint(array('foo'), 'foreign_table', array('bar'), null, $options); + $foreignKey = new ForeignKeyConstraint(['foo'], 'foreign_table', ['bar'], null, $options); self::assertSame($expectedSql, $this->_platform->getAdvancedForeignKeyOptionsSQL($foreignKey)); } @@ -236,14 +240,14 @@ public function testGeneratesAdvancedForeignKeyOptionsSQL(array $options, $expec */ public function getGeneratesAdvancedForeignKeyOptionsSQLData() { - return array( - array(array(), ''), - array(array('onUpdate' => 'CASCADE'), ''), - array(array('onDelete' => 'CASCADE'), ' ON DELETE CASCADE'), - array(array('onDelete' => 'NO ACTION'), ''), - array(array('onDelete' => 'RESTRICT'), ''), - array(array('onUpdate' => 'SET NULL', 'onDelete' => 'SET NULL'), ' ON DELETE SET NULL'), - ); + return [ + [[], ''], + [['onUpdate' => 'CASCADE'], ''], + [['onDelete' => 'CASCADE'], ' ON DELETE CASCADE'], + [['onDelete' => 'NO ACTION'], ''], + [['onDelete' => 'RESTRICT'], ''], + [['onUpdate' => 'SET NULL', 'onDelete' => 'SET NULL'], ' ON DELETE SET NULL'], + ]; } /** @@ -251,13 +255,13 @@ public function getGeneratesAdvancedForeignKeyOptionsSQLData() */ public function getReturnsForeignKeyReferentialActionSQL() { - return array( - array('CASCADE', 'CASCADE'), - array('SET NULL', 'SET NULL'), - array('NO ACTION', ''), - array('RESTRICT', ''), - array('CaScAdE', 'CASCADE'), - ); + return [ + ['CASCADE', 'CASCADE'], + ['SET NULL', 'SET NULL'], + ['NO ACTION', ''], + ['RESTRICT', ''], + ['CaScAdE', 'CASCADE'], + ]; } public function testModifyLimitQuery() @@ -299,56 +303,56 @@ public function testModifyLimitQueryWithDescOrderBy() public function testGenerateTableWithAutoincrement() { $columnName = strtoupper('id' . uniqid()); - $tableName = strtoupper('table' . uniqid()); - $table = new \Doctrine\DBAL\Schema\Table($tableName); - $column = $table->addColumn($columnName, 'integer'); + $tableName = strtoupper('table' . uniqid()); + $table = new Table($tableName); + $column = $table->addColumn($columnName, 'integer'); $column->setAutoincrement(true); - $targets = array( + $targets = [ "CREATE TABLE {$tableName} ({$columnName} NUMBER(10) NOT NULL)", "DECLARE constraints_Count NUMBER; BEGIN SELECT COUNT(CONSTRAINT_NAME) INTO constraints_Count FROM USER_CONSTRAINTS WHERE TABLE_NAME = '{$tableName}' AND CONSTRAINT_TYPE = 'P'; IF constraints_Count = 0 OR constraints_Count = '' THEN EXECUTE IMMEDIATE 'ALTER TABLE {$tableName} ADD CONSTRAINT {$tableName}_AI_PK PRIMARY KEY ({$columnName})'; END IF; END;", "CREATE SEQUENCE {$tableName}_SEQ START WITH 1 MINVALUE 1 INCREMENT BY 1", - "CREATE TRIGGER {$tableName}_AI_PK BEFORE INSERT ON {$tableName} FOR EACH ROW DECLARE last_Sequence NUMBER; last_InsertID NUMBER; BEGIN SELECT {$tableName}_SEQ.NEXTVAL INTO :NEW.{$columnName} FROM DUAL; IF (:NEW.{$columnName} IS NULL OR :NEW.{$columnName} = 0) THEN SELECT {$tableName}_SEQ.NEXTVAL INTO :NEW.{$columnName} FROM DUAL; ELSE SELECT NVL(Last_Number, 0) INTO last_Sequence FROM User_Sequences WHERE Sequence_Name = '{$tableName}_SEQ'; SELECT :NEW.{$columnName} INTO last_InsertID FROM DUAL; WHILE (last_InsertID > last_Sequence) LOOP SELECT {$tableName}_SEQ.NEXTVAL INTO last_Sequence FROM DUAL; END LOOP; END IF; END;" - ); + "CREATE TRIGGER {$tableName}_AI_PK BEFORE INSERT ON {$tableName} FOR EACH ROW DECLARE last_Sequence NUMBER; last_InsertID NUMBER; BEGIN SELECT {$tableName}_SEQ.NEXTVAL INTO :NEW.{$columnName} FROM DUAL; IF (:NEW.{$columnName} IS NULL OR :NEW.{$columnName} = 0) THEN SELECT {$tableName}_SEQ.NEXTVAL INTO :NEW.{$columnName} FROM DUAL; ELSE SELECT NVL(Last_Number, 0) INTO last_Sequence FROM User_Sequences WHERE Sequence_Name = '{$tableName}_SEQ'; SELECT :NEW.{$columnName} INTO last_InsertID FROM DUAL; WHILE (last_InsertID > last_Sequence) LOOP SELECT {$tableName}_SEQ.NEXTVAL INTO last_Sequence FROM DUAL; END LOOP; END IF; END;", + ]; $statements = $this->_platform->getCreateTableSQL($table); //strip all the whitespace from the statements - array_walk($statements, function(&$value){ - $value = preg_replace('/\s+/', ' ',$value); + array_walk($statements, static function (&$value) { + $value = preg_replace('/\s+/', ' ', $value); }); - foreach($targets as $key => $sql){ - self::assertArrayHasKey($key,$statements); + foreach ($targets as $key => $sql) { + self::assertArrayHasKey($key, $statements); self::assertEquals($sql, $statements[$key]); } } public function getCreateTableColumnCommentsSQL() { - return array( - "CREATE TABLE test (id NUMBER(10) NOT NULL, PRIMARY KEY(id))", + return [ + 'CREATE TABLE test (id NUMBER(10) NOT NULL, PRIMARY KEY(id))', "COMMENT ON COLUMN test.id IS 'This is a comment'", - ); + ]; } public function getCreateTableColumnTypeCommentsSQL() { - return array( - "CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))", - "COMMENT ON COLUMN test.data IS '(DC2Type:array)'" - ); + return [ + 'CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))', + "COMMENT ON COLUMN test.data IS '(DC2Type:array)'", + ]; } public function getAlterTableColumnCommentsSQL() { - return array( - "ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)", + return [ + 'ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)', "COMMENT ON COLUMN mytable.quota IS 'A comment'", "COMMENT ON COLUMN mytable.foo IS ''", "COMMENT ON COLUMN mytable.baz IS 'B comment'", - ); + ]; } public function getBitAndComparisonExpressionSql($value1, $value2) { - return 'BITAND('.$value1 . ', ' . $value2 . ')'; + return 'BITAND(' . $value1 . ', ' . $value2 . ')'; } public function getBitOrComparisonExpressionSql($value1, $value2) @@ -360,33 +364,33 @@ public function getBitOrComparisonExpressionSql($value1, $value2) protected function getQuotedColumnInPrimaryKeySQL() { - return array('CREATE TABLE "quoted" ("create" VARCHAR2(255) NOT NULL, PRIMARY KEY("create"))'); + return ['CREATE TABLE "quoted" ("create" VARCHAR2(255) NOT NULL, PRIMARY KEY("create"))']; } protected function getQuotedColumnInIndexSQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR2(255) NOT NULL)', 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', - ); + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 VARCHAR2(255) NOT NULL)', 'CREATE INDEX "key" ON test (column1)', - ); + ]; } protected function getQuotedColumnInForeignKeySQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR2(255) NOT NULL, foo VARCHAR2(255) NOT NULL, "bar" VARCHAR2(255) NOT NULL)', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foreign ("create", bar, "foo-bar")', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar")', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar")', - ); + ]; } /** @@ -395,29 +399,36 @@ protected function getQuotedColumnInForeignKeySQL() */ public function testAlterTableNotNULL() { - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable'); - $tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'foo', new \Doctrine\DBAL\Schema\Column( - 'foo', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'bla', 'notnull' => true) + $tableDiff = new TableDiff('mytable'); + $tableDiff->changedColumns['foo'] = new ColumnDiff( + 'foo', + new Column( + 'foo', + Type::getType('string'), + ['default' => 'bla', 'notnull' => true] ), - array('type') - ); - $tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'bar', new \Doctrine\DBAL\Schema\Column( - 'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'bla', 'notnull' => true) + ['type'] + ); + $tableDiff->changedColumns['bar'] = new ColumnDiff( + 'bar', + new Column( + 'baz', + Type::getType('string'), + ['default' => 'bla', 'notnull' => true] ), - array('type', 'notnull') - ); - $tableDiff->changedColumns['metar'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'metar', new \Doctrine\DBAL\Schema\Column( - 'metar', \Doctrine\DBAL\Types\Type::getType('string'), array('length' => 2000, 'notnull' => false) + ['type', 'notnull'] + ); + $tableDiff->changedColumns['metar'] = new ColumnDiff( + 'metar', + new Column( + 'metar', + Type::getType('string'), + ['length' => 2000, 'notnull' => false] ), - array('notnull') + ['notnull'] ); - $expectedSql = array( - "ALTER TABLE mytable MODIFY (foo VARCHAR2(255) DEFAULT 'bla', baz VARCHAR2(255) DEFAULT 'bla' NOT NULL, metar VARCHAR2(2000) DEFAULT NULL NULL)", - ); + $expectedSql = ["ALTER TABLE mytable MODIFY (foo VARCHAR2(255) DEFAULT 'bla', baz VARCHAR2(255) DEFAULT 'bla' NOT NULL, metar VARCHAR2(2000) DEFAULT NULL NULL)"]; self::assertEquals($expectedSql, $this->_platform->getAlterTableSQL($tableDiff)); } @@ -443,13 +454,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('RAW(255)', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 2000))); + self::assertSame('RAW(255)', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 2000])); - self::assertSame('RAW(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 2000))); + self::assertSame('RAW(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 2000])); } /** @@ -466,10 +477,10 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() { $table1 = new Table('mytable'); $table1->addColumn('column_varbinary', 'binary'); - $table1->addColumn('column_binary', 'binary', array('fixed' => true)); + $table1->addColumn('column_binary', 'binary', ['fixed' => true]); $table2 = new Table('mytable'); - $table2->addColumn('column_varbinary', 'binary', array('fixed' => true)); + $table2->addColumn('column_varbinary', 'binary', ['fixed' => true]); $table2->addColumn('column_binary', 'binary'); $comparator = new Comparator(); @@ -505,17 +516,17 @@ public function testReturnsIdentitySequenceName() */ public function testCreateSequenceWithCache($cacheSize, $expectedSql) { - $sequence = new \Doctrine\DBAL\Schema\Sequence('foo', 1, 1, $cacheSize); + $sequence = new Sequence('foo', 1, 1, $cacheSize); self::assertContains($expectedSql, $this->_platform->getCreateSequenceSQL($sequence)); } public function dataCreateSequenceWithCache() { - return array( - array(1, 'NOCACHE'), - array(0, 'NOCACHE'), - array(3, 'CACHE 3') - ); + return [ + [1, 'NOCACHE'], + [0, 'NOCACHE'], + [3, 'CACHE 3'], + ]; } /** @@ -523,9 +534,7 @@ public function dataCreateSequenceWithCache() */ protected function getAlterTableRenameIndexSQL() { - return array( - 'ALTER INDEX idx_foo RENAME TO idx_bar', - ); + return ['ALTER INDEX idx_foo RENAME TO idx_bar']; } /** @@ -533,10 +542,10 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'ALTER INDEX "create" RENAME TO "select"', 'ALTER INDEX "foo" RENAME TO "bar"', - ); + ]; } /** @@ -544,7 +553,7 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( + return [ 'ALTER TABLE mytable RENAME COLUMN unquoted1 TO unquoted', 'ALTER TABLE mytable RENAME COLUMN unquoted2 TO "where"', 'ALTER TABLE mytable RENAME COLUMN unquoted3 TO "foo"', @@ -554,7 +563,7 @@ protected function getQuotedAlterTableRenameColumnSQL() 'ALTER TABLE mytable RENAME COLUMN quoted1 TO quoted', 'ALTER TABLE mytable RENAME COLUMN quoted2 TO "and"', 'ALTER TABLE mytable RENAME COLUMN quoted3 TO "baz"', - ); + ]; } /** @@ -570,9 +579,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - 'ALTER INDEX myschema.idx_foo RENAME TO idx_bar', - ); + return ['ALTER INDEX myschema.idx_foo RENAME TO idx_bar']; } /** @@ -580,10 +587,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'ALTER INDEX "schema"."create" RENAME TO "select"', 'ALTER INDEX "schema"."foo" RENAME TO "bar"', - ); + ]; } protected function getQuotesDropForeignKeySQL() @@ -596,7 +603,7 @@ protected function getQuotesDropForeignKeySQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -604,9 +611,7 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( - 'ALTER TABLE foo RENAME COLUMN bar TO baz', - ); + return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; } /** @@ -620,32 +625,32 @@ public function testReturnsDropAutoincrementSQL($table, $expectedSql) public function getReturnsDropAutoincrementSQL() { - return array( - array( + return [ + [ 'myTable', - array( + [ 'DROP TRIGGER MYTABLE_AI_PK', 'DROP SEQUENCE MYTABLE_SEQ', 'ALTER TABLE MYTABLE DROP CONSTRAINT MYTABLE_AI_PK', - ) - ), - array( + ], + ], + [ '"myTable"', - array( + [ 'DROP TRIGGER "myTable_AI_PK"', 'DROP SEQUENCE "myTable_SEQ"', 'ALTER TABLE "myTable" DROP CONSTRAINT "myTable_AI_PK"', - ) - ), - array( + ], + ], + [ 'table', - array( + [ 'DROP TRIGGER TABLE_AI_PK', 'DROP SEQUENCE TABLE_SEQ', 'ALTER TABLE "TABLE" DROP CONSTRAINT TABLE_AI_PK', - ) - ), - ); + ], + ], + ]; } /** @@ -653,7 +658,7 @@ public function getReturnsDropAutoincrementSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE "foo" DROP CONSTRAINT fk1', 'ALTER TABLE "foo" DROP CONSTRAINT fk2', 'ALTER TABLE "foo" ADD (bloo NUMBER(10) NOT NULL)', @@ -663,7 +668,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() 'ALTER TABLE "foo" RENAME TO "table"', 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ); + ]; } /** @@ -671,11 +676,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', 'COMMENT ON COLUMN "select"."from" IS \'comment\'', - ); + ]; } /** @@ -683,8 +688,8 @@ protected function getCommentOnColumnSQL() */ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() { - $table1 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer')))); - $table2 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer'), array('comment' => 'baz')))); + $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); + $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); $comparator = new Comparator(); @@ -692,9 +697,7 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); self::assertSame( - array( - 'COMMENT ON COLUMN "foo"."bar" IS \'baz\'', - ), + ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -702,7 +705,7 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() public function testQuotedTableNames() { $table = new Table('"test"'); - $table->addColumn('"id"', 'integer', array('autoincrement' => true)); + $table->addColumn('"id"', 'integer', ['autoincrement' => true]); // assert tabel self::assertTrue($table->isQuoted()); @@ -753,8 +756,8 @@ public function testReturnsGetListTableColumnsSQL($database, $expectedSql) public function getReturnsGetListTableColumnsSQL() { - return array( - array( + return [ + [ null, "SELECT c.*, ( @@ -765,9 +768,9 @@ public function getReturnsGetListTableColumnsSQL() ) AS comments FROM user_tab_columns c WHERE c.table_name = 'test' - ORDER BY c.column_id" - ), - array( + ORDER BY c.column_id", + ], + [ '/', "SELECT c.*, ( @@ -778,9 +781,9 @@ public function getReturnsGetListTableColumnsSQL() ) AS comments FROM user_tab_columns c WHERE c.table_name = 'test' - ORDER BY c.column_id" - ), - array( + ORDER BY c.column_id", + ], + [ 'scott', "SELECT c.*, ( @@ -791,9 +794,9 @@ public function getReturnsGetListTableColumnsSQL() ) AS comments FROM all_tab_columns c WHERE c.table_name = 'test' AND c.owner = 'SCOTT' - ORDER BY c.column_id" - ), - ); + ORDER BY c.column_id", + ], + ]; } /** @@ -825,9 +828,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() */ protected function getAlterStringToFixedStringSQL() { - return array( - 'ALTER TABLE mytable MODIFY (name CHAR(2) DEFAULT NULL)', - ); + return ['ALTER TABLE mytable MODIFY (name CHAR(2) DEFAULT NULL)']; } /** @@ -835,9 +836,7 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - 'ALTER INDEX idx_foo RENAME TO idx_foo_renamed', - ); + return ['ALTER INDEX idx_foo RENAME TO idx_foo_renamed']; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php index 0189dbdfe36..48297877125 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php @@ -28,24 +28,24 @@ public function testHasNativeJsonType() */ public function testReturnsJsonTypeDeclarationSQL() { - self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(array())); + self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL([])); } public function testReturnsSmallIntTypeDeclarationSQL() { self::assertSame( 'SMALLSERIAL', - $this->_platform->getSmallIntTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getSmallIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertSame( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL(array('autoincrement' => false)) + $this->_platform->getSmallIntTypeDeclarationSQL(['autoincrement' => false]) ); self::assertSame( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL(array()) + $this->_platform->getSmallIntTypeDeclarationSQL([]) ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php index d566007afc2..673a724ecdc 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php @@ -18,8 +18,8 @@ public function createPlatform() public function testReturnsJsonTypeDeclarationSQL() { parent::testReturnsJsonTypeDeclarationSQL(); - self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(array('jsonb' => false))); - self::assertSame('JSONB', $this->_platform->getJsonTypeDeclarationSQL(array('jsonb' => true))); + self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(['jsonb' => false])); + self::assertSame('JSONB', $this->_platform->getJsonTypeDeclarationSQL(['jsonb' => true])); } public function testInitializesJsonTypeMapping() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php index 6db159df48e..4022eb0ff04 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php @@ -8,7 +8,7 @@ class PostgreSqlPlatformTest extends AbstractPostgreSqlPlatformTestCase { public function createPlatform() { - return new PostgreSqlPlatform; + return new PostgreSqlPlatform(); } public function testSupportsPartialIndexes() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php b/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php index bf1ad773238..22ab967fd7e 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php @@ -2,43 +2,41 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\Keywords\MySQLKeywords; use Doctrine\DBAL\Platforms\Keywords\ReservedKeywordsValidator; use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalTestCase; -class ReservedKeywordsValidatorTest extends \Doctrine\Tests\DbalTestCase +class ReservedKeywordsValidatorTest extends DbalTestCase { - /** - * @var ReservedKeywordsValidator - */ + /** @var ReservedKeywordsValidator */ private $validator; protected function setUp() { - $this->validator = new ReservedKeywordsValidator(array( - new \Doctrine\DBAL\Platforms\Keywords\MySQLKeywords() - )); + $this->validator = new ReservedKeywordsValidator([new MySQLKeywords()]); } public function testReservedTableName() { - $table = new Table("TABLE"); + $table = new Table('TABLE'); $this->validator->acceptTable($table); self::assertEquals( - array('Table TABLE keyword violations: MySQL'), + ['Table TABLE keyword violations: MySQL'], $this->validator->getViolations() ); } public function testReservedColumnName() { - $table = new Table("TABLE"); + $table = new Table('TABLE'); $column = $table->addColumn('table', 'string'); $this->validator->acceptColumn($table, $column); self::assertEquals( - array('Table TABLE column table keyword violations: MySQL'), + ['Table TABLE column table keyword violations: MySQL'], $this->validator->getViolations() ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php index c59a9b1ac12..c384d16de45 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php @@ -6,14 +6,12 @@ class SQLAnywhere11PlatformTest extends SQLAnywherePlatformTest { - /** - * @var \Doctrine\DBAL\Platforms\SQLAnywhere11Platform - */ + /** @var SQLAnywhere11Platform */ protected $_platform; public function createPlatform() { - return new SQLAnywhere11Platform; + return new SQLAnywhere11Platform(); } public function testDoesNotSupportRegexp() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php index 4c6763ae124..4219c9d0514 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php @@ -8,14 +8,12 @@ class SQLAnywhere12PlatformTest extends SQLAnywhere11PlatformTest { - /** - * @var \Doctrine\DBAL\Platforms\SQLAnywhere12Platform - */ + /** @var SQLAnywhere12Platform */ protected $_platform; public function createPlatform() { - return new SQLAnywhere12Platform; + return new SQLAnywhere12Platform(); } public function testDoesNotSupportSequences() @@ -48,7 +46,7 @@ public function testGeneratesSequenceSqlCommands() $this->_platform->getDropSequenceSQL($sequence) ); self::assertEquals( - "SELECT myseq.NEXTVAL", + 'SELECT myseq.NEXTVAL', $this->_platform->getSequenceNextValSQL('myseq') ); self::assertEquals( @@ -61,12 +59,12 @@ public function testGeneratesDateTimeTzColumnTypeDeclarationSQL() { self::assertEquals( 'TIMESTAMP WITH TIME ZONE', - $this->_platform->getDateTimeTzTypeDeclarationSQL(array( + $this->_platform->getDateTimeTzTypeDeclarationSQL([ 'length' => 10, 'fixed' => true, 'unsigned' => true, - 'autoincrement' => true - )) + 'autoincrement' => true, + ]) ); } @@ -88,10 +86,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], true, false, - array('virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload') + ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload'] ), 'footable' ) @@ -101,10 +99,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, false, - array('virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload') + ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload'] ), 'footable' ) @@ -116,10 +114,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, true, - array('with_nulls_not_distinct') + ['with_nulls_not_distinct'] ), 'footable' ) @@ -131,10 +129,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, false, - array('with_nulls_not_distinct') + ['with_nulls_not_distinct'] ), 'footable' ) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php index c66bb5177ab..bbf99527f65 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php @@ -9,7 +9,7 @@ class SQLAnywhere16PlatformTest extends SQLAnywhere12PlatformTest { public function createPlatform() { - return new SQLAnywhere16Platform; + return new SQLAnywhere16Platform(); } public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() @@ -19,10 +19,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], true, false, - array('with_nulls_distinct') + ['with_nulls_distinct'] ), 'footable' ) @@ -34,10 +34,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, true, - array('with_nulls_distinct') + ['with_nulls_distinct'] ), 'footable' ) @@ -49,10 +49,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, false, - array('with_nulls_distinct') + ['with_nulls_distinct'] ), 'footable' ) @@ -68,10 +68,10 @@ public function testThrowsExceptionOnInvalidWithNullsNotDistinctIndexOptions() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, false, - array('with_nulls_distinct', 'with_nulls_not_distinct') + ['with_nulls_distinct', 'with_nulls_not_distinct'] ), 'footable' ); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 6c514b55f53..7c6d161c371 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\DBAL\Platforms; -use Doctrine\DBAL\Connection; use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLAnywherePlatform; @@ -22,22 +21,20 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase { - /** - * @var \Doctrine\DBAL\Platforms\SQLAnywherePlatform - */ + /** @var SQLAnywherePlatform */ protected $_platform; public function createPlatform() { - return new SQLAnywherePlatform; + return new SQLAnywherePlatform(); } public function getGenerateAlterTableSql() { - return array( + return [ "ALTER TABLE mytable ADD quota INT DEFAULT NULL, DROP foo, ALTER baz VARCHAR(1) DEFAULT 'def' NOT NULL, ALTER bloo BIT DEFAULT '0' NOT NULL", - 'ALTER TABLE mytable RENAME userlist' - ); + 'ALTER TABLE mytable RENAME userlist', + ]; } public function getGenerateForeignKeySql() @@ -57,10 +54,10 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', - 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)' - ); + 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', + ]; } public function getGenerateUniqueIndexSql() @@ -70,58 +67,54 @@ public function getGenerateUniqueIndexSql() protected function getQuotedColumnInForeignKeySQL() { - return array( - 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL, CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar"))', - ); + return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL, CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar"))']; } protected function getQuotedColumnInIndexSQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', - 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")' - ); + 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', 'CREATE INDEX "key" ON test (column1)', - ); + ]; } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY ("create"))' - ); + return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY ("create"))']; } public function getCreateTableColumnCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))", + return [ + 'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))', "COMMENT ON COLUMN test.id IS 'This is a comment'", - ); + ]; } public function getAlterTableColumnCommentsSQL() { - return array( - "ALTER TABLE mytable ADD quota INT NOT NULL", + return [ + 'ALTER TABLE mytable ADD quota INT NOT NULL', "COMMENT ON COLUMN mytable.quota IS 'A comment'", - "COMMENT ON COLUMN mytable.foo IS NULL", + 'COMMENT ON COLUMN mytable.foo IS NULL', "COMMENT ON COLUMN mytable.baz IS 'B comment'", - ); + ]; } public function getCreateTableColumnTypeCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY (id))", - "COMMENT ON COLUMN test.data IS '(DC2Type:array)'" - ); + return [ + 'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY (id))', + "COMMENT ON COLUMN test.data IS '(DC2Type:array)'", + ]; } public function testHasCorrectPlatformName() @@ -133,17 +126,17 @@ public function testGeneratesCreateTableSQLWithCommonIndexes() { $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addColumn('name', 'string', array('length' => 50)); - $table->setPrimaryKey(array('id')); - $table->addIndex(array('name')); - $table->addIndex(array('id', 'name'), 'composite_idx'); + $table->addColumn('name', 'string', ['length' => 50]); + $table->setPrimaryKey(['id']); + $table->addIndex(['name']); + $table->addIndex(['id', 'name'], 'composite_idx'); self::assertEquals( - array( + [ 'CREATE TABLE test (id INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY (id))', 'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)', - 'CREATE INDEX composite_idx ON test (id, name)' - ), + 'CREATE INDEX composite_idx ON test (id, name)', + ], $this->_platform->getCreateTableSQL($table) ); } @@ -154,22 +147,21 @@ public function testGeneratesCreateTableSQLWithForeignKeyConstraints() $table->addColumn('id', 'integer'); $table->addColumn('fk_1', 'integer'); $table->addColumn('fk_2', 'integer'); - $table->setPrimaryKey(array('id')); - $table->addForeignKeyConstraint('foreign_table', array('fk_1', 'fk_2'), array('pk_1', 'pk_2')); + $table->setPrimaryKey(['id']); + $table->addForeignKeyConstraint('foreign_table', ['fk_1', 'fk_2'], ['pk_1', 'pk_2']); $table->addForeignKeyConstraint( 'foreign_table2', - array('fk_1', 'fk_2'), - array('pk_1', 'pk_2'), - array(), + ['fk_1', 'fk_2'], + ['pk_1', 'pk_2'], + [], 'named_fk' ); self::assertEquals( - array( - 'CREATE TABLE test (id INT NOT NULL, fk_1 INT NOT NULL, fk_2 INT NOT NULL, ' . + ['CREATE TABLE test (id INT NOT NULL, fk_1 INT NOT NULL, fk_2 INT NOT NULL, ' . 'CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2), ' . - 'CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2))' - ), + 'CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2))', + ], $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS) ); } @@ -178,14 +170,12 @@ public function testGeneratesCreateTableSQLWithCheckConstraints() { $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addColumn('check_max', 'integer', array('platformOptions' => array('max' => 10))); - $table->addColumn('check_min', 'integer', array('platformOptions' => array('min' => 10))); - $table->setPrimaryKey(array('id')); + $table->addColumn('check_max', 'integer', ['platformOptions' => ['max' => 10]]); + $table->addColumn('check_min', 'integer', ['platformOptions' => ['min' => 10]]); + $table->setPrimaryKey(['id']); self::assertEquals( - array( - 'CREATE TABLE test (id INT NOT NULL, check_max INT NOT NULL, check_min INT NOT NULL, PRIMARY KEY (id), CHECK (check_max <= 10), CHECK (check_min >= 10))' - ), + ['CREATE TABLE test (id INT NOT NULL, check_max INT NOT NULL, check_min INT NOT NULL, PRIMARY KEY (id), CHECK (check_max <= 10), CHECK (check_min >= 10))'], $this->_platform->getCreateTableSQL($table) ); } @@ -193,20 +183,18 @@ public function testGeneratesCreateTableSQLWithCheckConstraints() public function testGeneratesTableAlterationWithRemovedColumnCommentSql() { $table = new Table('mytable'); - $table->addColumn('foo', 'string', array('comment' => 'foo comment')); + $table->addColumn('foo', 'string', ['comment' => 'foo comment']); - $tableDiff = new TableDiff('mytable'); - $tableDiff->fromTable = $table; + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = $table; $tableDiff->changedColumns['foo'] = new ColumnDiff( 'foo', new Column('foo', Type::getType('string')), - array('comment') + ['comment'] ); self::assertEquals( - array( - "COMMENT ON COLUMN mytable.foo IS NULL" - ), + ['COMMENT ON COLUMN mytable.foo IS NULL'], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -216,7 +204,7 @@ public function testGeneratesTableAlterationWithRemovedColumnCommentSql() */ public function testAppendsLockHint($lockMode, $lockHint) { - $fromClause = 'FROM users'; + $fromClause = 'FROM users'; $expectedResult = $fromClause . $lockHint; self::assertSame($expectedResult, $this->_platform->appendLockHint($fromClause, $lockMode)); @@ -224,15 +212,15 @@ public function testAppendsLockHint($lockMode, $lockHint) public function getLockHints() { - return array( - array(null, ''), - array(false, ''), - array(true, ''), - array(LockMode::NONE, ' WITH (NOLOCK)'), - array(LockMode::OPTIMISTIC, ''), - array(LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'), - array(LockMode::PESSIMISTIC_WRITE, ' WITH (XLOCK)'), - ); + return [ + [null, ''], + [false, ''], + [true, ''], + [LockMode::NONE, ' WITH (NOLOCK)'], + [LockMode::OPTIMISTIC, ''], + [LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'], + [LockMode::PESSIMISTIC_WRITE, ' WITH (XLOCK)'], + ]; } public function testHasCorrectMaxIdentifierLength() @@ -243,8 +231,8 @@ public function testHasCorrectMaxIdentifierLength() public function testFixesSchemaElementNames() { $maxIdentifierLength = $this->_platform->getMaxIdentifierLength(); - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $schemaElementName = ''; + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $schemaElementName = ''; for ($i = 0; $i < $maxIdentifierLength + 100; $i++) { $schemaElementName .= $characters[mt_rand(0, strlen($characters) - 1)]; @@ -264,27 +252,21 @@ public function testFixesSchemaElementNames() public function testGeneratesColumnTypesDeclarationSQL() { - $fullColumnDef = array( + $fullColumnDef = [ 'length' => 10, 'fixed' => true, 'unsigned' => true, - 'autoincrement' => true - ); + 'autoincrement' => true, + ]; - self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array())); - self::assertEquals('UNSIGNED SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL([])); + self::assertEquals('UNSIGNED SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('UNSIGNED SMALLINT IDENTITY', $this->_platform->getSmallIntTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('INT', $this->_platform->getIntegerTypeDeclarationSQL(array())); - self::assertEquals('UNSIGNED INT', $this->_platform->getIntegerTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('INT', $this->_platform->getIntegerTypeDeclarationSQL([])); + self::assertEquals('UNSIGNED INT', $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('UNSIGNED INT IDENTITY', $this->_platform->getIntegerTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array())); - self::assertEquals('UNSIGNED BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL([])); + self::assertEquals('UNSIGNED BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('UNSIGNED BIGINT IDENTITY', $this->_platform->getBigIntTypeDeclarationSQL($fullColumnDef)); self::assertEquals('LONG BINARY', $this->_platform->getBlobTypeDeclarationSQL($fullColumnDef)); self::assertEquals('BIT', $this->_platform->getBooleanTypeDeclarationSQL($fullColumnDef)); @@ -331,14 +313,14 @@ public function testGeneratesPrimaryKeyDeclarationSQL() self::assertEquals( 'CONSTRAINT pk PRIMARY KEY CLUSTERED (a, b)', $this->_platform->getPrimaryKeyDeclarationSQL( - new Index(null, array('a', 'b'), true, true, array('clustered')), + new Index(null, ['a', 'b'], true, true, ['clustered']), 'pk' ) ); self::assertEquals( 'PRIMARY KEY (a, b)', $this->_platform->getPrimaryKeyDeclarationSQL( - new Index(null, array('a', 'b'), true, true) + new Index(null, ['a', 'b'], true, true) ) ); } @@ -347,7 +329,7 @@ public function testCannotGeneratePrimaryKeyDeclarationSQLWithEmptyColumns() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getPrimaryKeyDeclarationSQL(new Index('pk', array(), true, true)); + $this->_platform->getPrimaryKeyDeclarationSQL(new Index('pk', [], true, true)); } public function testGeneratesCreateUnnamedPrimaryKeySQL() @@ -355,14 +337,14 @@ public function testGeneratesCreateUnnamedPrimaryKeySQL() self::assertEquals( 'ALTER TABLE foo ADD PRIMARY KEY CLUSTERED (a, b)', $this->_platform->getCreatePrimaryKeySQL( - new Index('pk', array('a', 'b'), true, true, array('clustered')), + new Index('pk', ['a', 'b'], true, true, ['clustered']), 'foo' ) ); self::assertEquals( 'ALTER TABLE foo ADD PRIMARY KEY (a, b)', $this->_platform->getCreatePrimaryKeySQL( - new Index('any_pk_name', array('a', 'b'), true, true), + new Index('any_pk_name', ['a', 'b'], true, true), new Table('foo') ) ); @@ -374,12 +356,12 @@ public function testGeneratesUniqueConstraintDeclarationSQL() 'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)', $this->_platform->getUniqueConstraintDeclarationSQL( 'unique_constraint', - new Index(null, array('a', 'b'), true, false, array('clustered')) + new Index(null, ['a', 'b'], true, false, ['clustered']) ) ); self::assertEquals( 'UNIQUE (a, b)', - $this->_platform->getUniqueConstraintDeclarationSQL(null, new Index(null, array('a', 'b'), true, false)) + $this->_platform->getUniqueConstraintDeclarationSQL(null, new Index(null, ['a', 'b'], true, false)) ); } @@ -387,7 +369,7 @@ public function testCannotGenerateUniqueConstraintDeclarationSQLWithEmptyColumns { $this->expectException('\InvalidArgumentException'); - $this->_platform->getUniqueConstraintDeclarationSQL('constr', new Index('constr', array(), true)); + $this->_platform->getUniqueConstraintDeclarationSQL('constr', new Index('constr', [], true)); } public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL() @@ -398,21 +380,21 @@ public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL 'REFERENCES foreign_table (c, d) ' . 'MATCH UNIQUE SIMPLE ON UPDATE CASCADE ON DELETE SET NULL CHECK ON COMMIT CLUSTERED FOR OLAP WORKLOAD', $this->_platform->getForeignKeyDeclarationSQL( - new ForeignKeyConstraint(array('a', 'b'), 'foreign_table', array('c', 'd'), 'fk', array( + new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd'], 'fk', [ 'notnull' => true, 'match' => SQLAnywherePlatform::FOREIGN_KEY_MATCH_SIMPLE_UNIQUE, 'onUpdate' => 'CASCADE', 'onDelete' => 'SET NULL', 'check_on_commit' => true, 'clustered' => true, - 'for_olap_workload' => true - )) + 'for_olap_workload' => true, + ]) ) ); self::assertEquals( 'FOREIGN KEY (a, b) REFERENCES foreign_table (c, d)', $this->_platform->getForeignKeyDeclarationSQL( - new ForeignKeyConstraint(array('a', 'b'), 'foreign_table', array('c', 'd')) + new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd']) ) ); } @@ -435,26 +417,26 @@ public function testCannotGenerateInvalidForeignKeyMatchClauseSQL() public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(array(), 'foreign_tbl', array('c', 'd'))); + $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint([], 'foreign_tbl', ['c', 'd'])); } public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignColumns() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(array('a', 'b'), 'foreign_tbl', array())); + $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], 'foreign_tbl', [])); } public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignTableName() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(array('a', 'b'), '', array('c', 'd'))); + $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], '', ['c', 'd'])); } public function testCannotGenerateCommonIndexWithCreateConstraintSQL() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getCreateConstraintSQL(new Index('fooindex', array()), new Table('footable')); + $this->_platform->getCreateConstraintSQL(new Index('fooindex', []), new Table('footable')); } public function testCannotGenerateCustomConstraintWithCreateConstraintSQL() @@ -471,10 +453,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], true, false, - array('virtual', 'clustered', 'for_olap_workload') + ['virtual', 'clustered', 'for_olap_workload'] ), 'footable' ) @@ -485,12 +467,12 @@ public function testDoesNotSupportIndexDeclarationInCreateAlterTableStatements() { $this->expectException('\Doctrine\DBAL\DBALException'); - $this->_platform->getIndexDeclarationSQL('index', new Index('index', array())); + $this->_platform->getIndexDeclarationSQL('index', new Index('index', [])); } public function testGeneratesDropIndexSQL() { - $index = new Index('fooindex', array()); + $index = new Index('fooindex', []); self::assertEquals('DROP INDEX fooindex', $this->_platform->getDropIndexSQL($index)); self::assertEquals('DROP INDEX footable.fooindex', $this->_platform->getDropIndexSQL($index, 'footable')); @@ -504,14 +486,14 @@ public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getDropIndexSQL(array('index'), 'table'); + $this->_platform->getDropIndexSQL(['index'], 'table'); } public function testCannotGenerateDropIndexSQLWithInvalidTableParameter() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getDropIndexSQL('index', array('table')); + $this->_platform->getDropIndexSQL('index', ['table']); } public function testGeneratesSQLSnippets() @@ -542,8 +524,8 @@ public function testGeneratesSQLSnippets() self::assertEquals("DATEADD(SECOND, -1 * 1, '1987/05/02')", $this->_platform->getDateSubSecondsExpression("'1987/05/02'", 1)); self::assertEquals("DATEADD(WEEK, -1 * 3, '1987/05/02')", $this->_platform->getDateSubWeeksExpression("'1987/05/02'", 3)); self::assertEquals("DATEADD(YEAR, -1 * 10, '1987/05/02')", $this->_platform->getDateSubYearsExpression("'1987/05/02'", 10)); - self::assertEquals("Y-m-d H:i:s.u", $this->_platform->getDateTimeFormatString()); - self::assertEquals("H:i:s.u", $this->_platform->getTimeFormatString()); + self::assertEquals('Y-m-d H:i:s.u', $this->_platform->getDateTimeFormatString()); + self::assertEquals('H:i:s.u', $this->_platform->getTimeFormatString()); self::assertEquals('', $this->_platform->getForUpdateSQL()); self::assertEquals('NEWID()', $this->_platform->getGuidExpression()); self::assertEquals('LOCATE(string_column, substring_column)', $this->_platform->getLocateExpression('string_column', 'substring_column')); @@ -788,13 +770,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('VARBINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 32767))); + self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('VARBINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 32767])); - self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('BINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 32767))); + self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 32767])); } /** @@ -812,9 +794,7 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() */ protected function getAlterTableRenameIndexSQL() { - return array( - 'ALTER INDEX idx_foo ON mytable RENAME TO idx_bar', - ); + return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_bar']; } /** @@ -822,10 +802,10 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'ALTER INDEX "create" ON "table" RENAME TO "select"', 'ALTER INDEX "foo" ON "table" RENAME TO "bar"', - ); + ]; } /** @@ -833,7 +813,7 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( + return [ 'ALTER TABLE mytable RENAME unquoted1 TO unquoted', 'ALTER TABLE mytable RENAME unquoted2 TO "where"', 'ALTER TABLE mytable RENAME unquoted3 TO "foo"', @@ -843,7 +823,7 @@ protected function getQuotedAlterTableRenameColumnSQL() 'ALTER TABLE mytable RENAME quoted1 TO quoted', 'ALTER TABLE mytable RENAME quoted2 TO "and"', 'ALTER TABLE mytable RENAME quoted3 TO "baz"', - ); + ]; } /** @@ -859,9 +839,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - 'ALTER INDEX idx_foo ON myschema.mytable RENAME TO idx_bar', - ); + return ['ALTER INDEX idx_foo ON myschema.mytable RENAME TO idx_bar']; } /** @@ -869,10 +847,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'ALTER INDEX "create" ON "schema"."table" RENAME TO "select"', 'ALTER INDEX "foo" ON "schema"."table" RENAME TO "bar"', - ); + ]; } /** @@ -880,7 +858,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -888,9 +866,7 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( - 'ALTER TABLE foo RENAME bar TO baz', - ); + return ['ALTER TABLE foo RENAME bar TO baz']; } /** @@ -898,7 +874,7 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE "foo" DROP FOREIGN KEY fk1', 'ALTER TABLE "foo" DROP FOREIGN KEY fk2', 'ALTER TABLE "foo" RENAME id TO war', @@ -906,7 +882,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() 'ALTER TABLE "foo" RENAME "table"', 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ); + ]; } /** @@ -914,11 +890,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', 'COMMENT ON COLUMN "select"."from" IS \'comment\'', - ); + ]; } /** @@ -926,8 +902,8 @@ protected function getCommentOnColumnSQL() */ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() { - $table1 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer')))); - $table2 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer'), array('comment' => 'baz')))); + $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); + $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); $comparator = new Comparator(); @@ -935,9 +911,7 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); self::assertSame( - array( - 'COMMENT ON COLUMN "foo"."bar" IS \'baz\'', - ), + ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -947,14 +921,14 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() */ public function getReturnsForeignKeyReferentialActionSQL() { - return array( - array('CASCADE', 'CASCADE'), - array('SET NULL', 'SET NULL'), - array('NO ACTION', 'RESTRICT'), - array('RESTRICT', 'RESTRICT'), - array('SET DEFAULT', 'SET DEFAULT'), - array('CaScAdE', 'CASCADE'), - ); + return [ + ['CASCADE', 'CASCADE'], + ['SET NULL', 'SET NULL'], + ['NO ACTION', 'RESTRICT'], + ['RESTRICT', 'RESTRICT'], + ['SET DEFAULT', 'SET DEFAULT'], + ['CaScAdE', 'CASCADE'], + ]; } /** @@ -994,9 +968,7 @@ protected function supportsInlineIndexDeclaration() */ protected function getAlterStringToFixedStringSQL() { - return array( - 'ALTER TABLE mytable ALTER name CHAR(2) NOT NULL', - ); + return ['ALTER TABLE mytable ALTER name CHAR(2) NOT NULL']; } /** @@ -1004,9 +976,7 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - 'ALTER INDEX idx_foo ON mytable RENAME TO idx_foo_renamed', - ); + return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_foo_renamed']; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php index f1b93e0eb48..e42aaeb8eaf 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\SQLAzurePlatform; +use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalTestCase; /** @@ -9,23 +11,21 @@ */ class SQLAzurePlatformTest extends DbalTestCase { - /** - * @var \Doctrine\DBAL\Platforms\SQLAzurePlatform - */ + /** @var SQLAzurePlatform */ private $platform; protected function setUp() { - $this->platform = new \Doctrine\DBAL\Platforms\SQLAzurePlatform(); + $this->platform = new SQLAzurePlatform(); } public function testCreateFederatedOnTable() { - $table = new \Doctrine\DBAL\Schema\Table("tbl"); - $table->addColumn("id", "integer"); + $table = new Table('tbl'); + $table->addColumn('id', 'integer'); $table->addOption('azure.federatedOnDistributionName', 'TblId'); $table->addOption('azure.federatedOnColumnName', 'id'); - self::assertEquals(array('CREATE TABLE tbl (id INT NOT NULL) FEDERATED ON (TblId = id)'), $this->platform->getCreateTableSQL($table)); + self::assertEquals(['CREATE TABLE tbl (id INT NOT NULL) FEDERATED ON (TblId = id)'], $this->platform->getCreateTableSQL($table)); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php index 3670c4a80a6..024bf65de93 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php @@ -8,7 +8,7 @@ class SQLServer2008PlatformTest extends AbstractSQLServerPlatformTestCase { public function createPlatform() { - return new SQLServer2008Platform; + return new SQLServer2008Platform(); } public function testGeneratesTypeDeclarationForDateTimeTz() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php index 69e0840b629..00dcdf24cb6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Schema\Sequence; @@ -9,7 +10,7 @@ class SQLServer2012PlatformTest extends AbstractSQLServerPlatformTestCase { public function createPlatform() { - return new SQLServer2012Platform; + return new SQLServer2012Platform(); } public function testSupportsSequences() @@ -38,7 +39,7 @@ public function testGeneratesSequenceSqlCommands() $this->_platform->getDropSequenceSQL('myseq') ); self::assertEquals( - "SELECT NEXT VALUE FOR myseq", + 'SELECT NEXT VALUE FOR myseq', $this->_platform->getSequenceNextValSQL('myseq') ); } @@ -124,19 +125,18 @@ public function testModifyLimitQueryWithFromColumnNames() */ public function testModifyLimitQueryWithExtraLongQuery() { - $query = 'SELECT table1.column1, table2.column2, table3.column3, table4.column4, table5.column5, table6.column6, table7.column7, table8.column8 FROM table1, table2, table3, table4, table5, table6, table7, table8 '; - $query.= 'WHERE (table1.column1 = table2.column2) AND (table1.column1 = table3.column3) AND (table1.column1 = table4.column4) AND (table1.column1 = table5.column5) AND (table1.column1 = table6.column6) AND (table1.column1 = table7.column7) AND (table1.column1 = table8.column8) AND (table2.column2 = table3.column3) AND (table2.column2 = table4.column4) AND (table2.column2 = table5.column5) AND (table2.column2 = table6.column6) '; - $query.= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; - $query.= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; + $query = 'SELECT table1.column1, table2.column2, table3.column3, table4.column4, table5.column5, table6.column6, table7.column7, table8.column8 FROM table1, table2, table3, table4, table5, table6, table7, table8 '; + $query .= 'WHERE (table1.column1 = table2.column2) AND (table1.column1 = table3.column3) AND (table1.column1 = table4.column4) AND (table1.column1 = table5.column5) AND (table1.column1 = table6.column6) AND (table1.column1 = table7.column7) AND (table1.column1 = table8.column8) AND (table2.column2 = table3.column3) AND (table2.column2 = table4.column4) AND (table2.column2 = table5.column5) AND (table2.column2 = table6.column6) '; + $query .= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; + $query .= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; $sql = $this->_platform->modifyLimitQuery($query, 10); - $expected = 'SELECT table1.column1, table2.column2, table3.column3, table4.column4, table5.column5, table6.column6, table7.column7, table8.column8 FROM table1, table2, table3, table4, table5, table6, table7, table8 '; - $expected.= 'WHERE (table1.column1 = table2.column2) AND (table1.column1 = table3.column3) AND (table1.column1 = table4.column4) AND (table1.column1 = table5.column5) AND (table1.column1 = table6.column6) AND (table1.column1 = table7.column7) AND (table1.column1 = table8.column8) AND (table2.column2 = table3.column3) AND (table2.column2 = table4.column4) AND (table2.column2 = table5.column5) AND (table2.column2 = table6.column6) '; - $expected.= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; - $expected.= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8) '; - $expected.= 'ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; - + $expected = 'SELECT table1.column1, table2.column2, table3.column3, table4.column4, table5.column5, table6.column6, table7.column7, table8.column8 FROM table1, table2, table3, table4, table5, table6, table7, table8 '; + $expected .= 'WHERE (table1.column1 = table2.column2) AND (table1.column1 = table3.column3) AND (table1.column1 = table4.column4) AND (table1.column1 = table5.column5) AND (table1.column1 = table6.column6) AND (table1.column1 = table7.column7) AND (table1.column1 = table8.column8) AND (table2.column2 = table3.column3) AND (table2.column2 = table4.column4) AND (table2.column2 = table5.column5) AND (table2.column2 = table6.column6) '; + $expected .= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; + $expected .= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8) '; + $expected .= 'ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; self::assertEquals($expected, $sql); } @@ -159,26 +159,26 @@ public function testModifyLimitQueryWithOrderByClause() public function testModifyLimitQueryWithSubSelectInSelectList() { $sql = $this->_platform->modifyLimitQuery( - "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled'", 10 ); self::assertEquals( - "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled' " . - "ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY", + 'ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql ); } @@ -189,28 +189,28 @@ public function testModifyLimitQueryWithSubSelectInSelectList() public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() { $sql = $this->_platform->modifyLimitQuery( - "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled' " . - "ORDER BY u.username DESC", + 'ORDER BY u.username DESC', 10, 5 ); self::assertEquals( - "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled' " . - "ORDER BY u.username DESC " . - "OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY", + 'ORDER BY u.username DESC ' . + 'OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY', $sql ); } @@ -221,154 +221,154 @@ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() { $sql = $this->_platform->modifyLimitQuery( - "SELECT " . - "MAX(heading_id) aliased, " . - "code " . - "FROM operator_model_operator " . - "GROUP BY code " . - "ORDER BY MAX(heading_id) DESC", + 'SELECT ' . + 'MAX(heading_id) aliased, ' . + 'code ' . + 'FROM operator_model_operator ' . + 'GROUP BY code ' . + 'ORDER BY MAX(heading_id) DESC', 1, 0 ); self::assertEquals( - "SELECT " . - "MAX(heading_id) aliased, " . - "code " . - "FROM operator_model_operator " . - "GROUP BY code " . - "ORDER BY MAX(heading_id) DESC " . - "OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY", + 'SELECT ' . + 'MAX(heading_id) aliased, ' . + 'code ' . + 'FROM operator_model_operator ' . + 'GROUP BY code ' . + 'ORDER BY MAX(heading_id) DESC ' . + 'OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY', $sql ); } public function testModifyLimitQueryWithFromSubquery() { - $sql = $this->_platform->modifyLimitQuery("SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result", 10); + $sql = $this->_platform->modifyLimitQuery('SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result', 10); - $expected = "SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY 1 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"; + $expected = 'SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY 1 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; self::assertEquals($sql, $expected); } public function testModifyLimitQueryWithFromSubqueryAndOrder() { - $sql = $this->_platform->modifyLimitQuery("SELECT DISTINCT id_0, value_1 FROM (SELECT k0_.id AS id_0, k0_.value AS value_1 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY value_1 DESC", 10); + $sql = $this->_platform->modifyLimitQuery('SELECT DISTINCT id_0, value_1 FROM (SELECT k0_.id AS id_0, k0_.value AS value_1 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY value_1 DESC', 10); - $expected = "SELECT DISTINCT id_0, value_1 FROM (SELECT k0_.id AS id_0, k0_.value AS value_1 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY value_1 DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"; + $expected = 'SELECT DISTINCT id_0, value_1 FROM (SELECT k0_.id AS id_0, k0_.value AS value_1 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY value_1 DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; self::assertEquals($sql, $expected); } public function testModifyLimitQueryWithComplexOrderByExpression() { - $sql = $this->_platform->modifyLimitQuery("SELECT * FROM table ORDER BY (table.x * table.y) DESC", 10); + $sql = $this->_platform->modifyLimitQuery('SELECT * FROM table ORDER BY (table.x * table.y) DESC', 10); - $expected = "SELECT * FROM table ORDER BY (table.x * table.y) DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"; + $expected = 'SELECT * FROM table ORDER BY (table.x * table.y) DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; self::assertEquals($sql, $expected); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable() { - $querySql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY id_0 ASC"; - $alteredSql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY id_0 ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY id_0 ASC'; + $alteredSql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY id_0 ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); self::assertEquals($alteredSql, $sql); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable() { - $querySql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC"; - $alteredSql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC'; + $alteredSql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); self::assertEquals($alteredSql, $sql); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables() { - $querySql = "SELECT DISTINCT id_0, name_1, foo_2 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC, foo_2 DESC"; - $alteredSql = "SELECT DISTINCT id_0, name_1, foo_2 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC, foo_2 DESC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1, foo_2 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC, foo_2 DESC'; + $alteredSql = 'SELECT DISTINCT id_0, name_1, foo_2 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC, foo_2 DESC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); self::assertEquals($alteredSql, $sql); } public function testModifyLimitSubquerySimple() { - $querySql = "SELECT DISTINCT id_0 FROM " - . "(SELECT k0_.id AS id_0, k0_.field AS field_1 " - . "FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result"; - $alteredSql = "SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0, k0_.field AS field_1 " - . "FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result ORDER BY 1 OFFSET 0 ROWS FETCH NEXT 20 ROWS ONLY"; - $sql = $this->_platform->modifyLimitQuery($querySql, 20); + $querySql = 'SELECT DISTINCT id_0 FROM ' + . '(SELECT k0_.id AS id_0, k0_.field AS field_1 ' + . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result'; + $alteredSql = 'SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0, k0_.field AS field_1 ' + . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result ORDER BY 1 OFFSET 0 ROWS FETCH NEXT 20 ROWS ONLY'; + $sql = $this->_platform->modifyLimitQuery($querySql, 20); self::assertEquals($alteredSql, $sql); } public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() { - $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC)'; + $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC)'; $expectedSql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); self::assertEquals($expectedSql, $sql); - $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; + $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; $expectedSql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); self::assertEquals($expectedSql, $sql); } public function testModifyLimitQueryWithNewlineBeforeOrderBy() { - $querySql = "SELECT * FROM test\nORDER BY col DESC"; + $querySql = "SELECT * FROM test\nORDER BY col DESC"; $expectedSql = "SELECT * FROM test\nORDER BY col DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); self::assertEquals($expectedSql, $sql); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php index f8b42f61819..eeaf5171bf3 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php @@ -7,10 +7,9 @@ class SQLServerPlatformTest extends AbstractSQLServerPlatformTestCase { - public function createPlatform() { - return new SQLServerPlatform; + return new SQLServerPlatform(); } /** @@ -36,15 +35,15 @@ public function testScrubInnerOrderBy($query, $limit, $offset, $expectedResult) public function getLockHints() { - return array( - array(null, ''), - array(false, ''), - array(true, ''), - array(LockMode::NONE, ' WITH (NOLOCK)'), - array(LockMode::OPTIMISTIC, ''), - array(LockMode::PESSIMISTIC_READ, ' WITH (HOLDLOCK, ROWLOCK)'), - array(LockMode::PESSIMISTIC_WRITE, ' WITH (UPDLOCK, ROWLOCK)'), - ); + return [ + [null, ''], + [false, ''], + [true, ''], + [LockMode::NONE, ' WITH (NOLOCK)'], + [LockMode::OPTIMISTIC, ''], + [LockMode::PESSIMISTIC_READ, ' WITH (HOLDLOCK, ROWLOCK)'], + [LockMode::PESSIMISTIC_WRITE, ' WITH (UPDLOCK, ROWLOCK)'], + ]; } public function getModifyLimitQueries() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index 3975b8fd2c7..67abba9fca5 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -14,7 +14,7 @@ class SqlitePlatformTest extends AbstractPlatformTestCase { public function createPlatform() { - return new SqlitePlatform; + return new SqlitePlatform(); } public function getGenerateTableSql() @@ -24,10 +24,10 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', - ); + ]; } public function testGeneratesSqlSnippets() @@ -66,7 +66,7 @@ public function testIgnoresUnsignedIntegerDeclarationForAutoIncrementalIntegers( { self::assertSame( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true)) + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); } @@ -78,24 +78,25 @@ public function testGeneratesTypeDeclarationForTinyIntegers() { self::assertEquals( 'TINYINT', - $this->_platform->getTinyIntTypeDeclarationSQL(array()) + $this->_platform->getTinyIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getTinyIntTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getTinyIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', $this->_platform->getTinyIntTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true)) + ['autoincrement' => true, 'primary' => true] + ) ); self::assertEquals( 'TINYINT', - $this->_platform->getTinyIntTypeDeclarationSQL(array('unsigned' => false)) + $this->_platform->getTinyIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'TINYINT UNSIGNED', - $this->_platform->getTinyIntTypeDeclarationSQL(array('unsigned' => true)) + $this->_platform->getTinyIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -107,28 +108,29 @@ public function testGeneratesTypeDeclarationForSmallIntegers() { self::assertEquals( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL(array()) + $this->_platform->getSmallIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getSmallIntTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getSmallIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getTinyIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true)) + $this->_platform->getTinyIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', $this->_platform->getSmallIntTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true)) + ['autoincrement' => true, 'primary' => true] + ) ); self::assertEquals( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL(array('unsigned' => false)) + $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'SMALLINT UNSIGNED', - $this->_platform->getSmallIntTypeDeclarationSQL(array('unsigned' => true)) + $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -140,28 +142,29 @@ public function testGeneratesTypeDeclarationForMediumIntegers() { self::assertEquals( 'MEDIUMINT', - $this->_platform->getMediumIntTypeDeclarationSQL(array()) + $this->_platform->getMediumIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getMediumIntTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getMediumIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getMediumIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true)) + $this->_platform->getMediumIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', $this->_platform->getMediumIntTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true)) + ['autoincrement' => true, 'primary' => true] + ) ); self::assertEquals( 'MEDIUMINT', - $this->_platform->getMediumIntTypeDeclarationSQL(array('unsigned' => false)) + $this->_platform->getMediumIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'MEDIUMINT UNSIGNED', - $this->_platform->getMediumIntTypeDeclarationSQL(array('unsigned' => true)) + $this->_platform->getMediumIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -169,28 +172,29 @@ public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'INTEGER', - $this->_platform->getIntegerTypeDeclarationSQL(array()) + $this->_platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true)) + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', $this->_platform->getIntegerTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true)) + ['autoincrement' => true, 'primary' => true] + ) ); self::assertEquals( 'INTEGER', - $this->_platform->getIntegerTypeDeclarationSQL(array('unsigned' => false)) + $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'INTEGER UNSIGNED', - $this->_platform->getIntegerTypeDeclarationSQL(array('unsigned' => true)) + $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => true]) ); } @@ -202,28 +206,29 @@ public function testGeneratesTypeDeclarationForBigIntegers() { self::assertEquals( 'BIGINT', - $this->_platform->getBigIntTypeDeclarationSQL(array()) + $this->_platform->getBigIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getBigIntTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getBigIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getBigIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true)) + $this->_platform->getBigIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', $this->_platform->getBigIntTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true)) + ['autoincrement' => true, 'primary' => true] + ) ); self::assertEquals( 'BIGINT', - $this->_platform->getBigIntTypeDeclarationSQL(array('unsigned' => false)) + $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'BIGINT UNSIGNED', - $this->_platform->getBigIntTypeDeclarationSQL(array('unsigned' => true)) + $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -232,16 +237,17 @@ public function testGeneratesTypeDeclarationForStrings() self::assertEquals( 'CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL( - array('length' => 10, 'fixed' => true)) + ['length' => 10, 'fixed' => true] + ) ); self::assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)), + $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL(array()), + $this->_platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } @@ -297,14 +303,14 @@ public function testModifyLimitQueryWithOffsetAndEmptyLimit() public function getGenerateAlterTableSql() { - return array( - "CREATE TEMPORARY TABLE __temp__mytable AS SELECT id, bar, bloo FROM mytable", - "DROP TABLE mytable", + return [ + 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT id, bar, bloo FROM mytable', + 'DROP TABLE mytable', "CREATE TABLE mytable (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, baz VARCHAR(255) DEFAULT 'def' NOT NULL, bloo BOOLEAN DEFAULT '0' NOT NULL, quota INTEGER DEFAULT NULL)", - "INSERT INTO mytable (id, baz, bloo) SELECT id, bar, bloo FROM __temp__mytable", - "DROP TABLE __temp__mytable", - "ALTER TABLE mytable RENAME TO userlist", - ); + 'INSERT INTO mytable (id, baz, bloo) SELECT id, bar, bloo FROM __temp__mytable', + 'DROP TABLE __temp__mytable', + 'ALTER TABLE mytable RENAME TO userlist', + ]; } /** @@ -312,9 +318,9 @@ public function getGenerateAlterTableSql() */ public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey() { - $table = new \Doctrine\DBAL\Schema\Table('test'); - $table->addColumn('"like"', 'integer', array('notnull' => true, 'autoincrement' => true)); - $table->setPrimaryKey(array('"like"')); + $table = new Table('test'); + $table->addColumn('"like"', 'integer', ['notnull' => true, 'autoincrement' => true]); + $table->setPrimaryKey(['"like"']); $createTableSQL = $this->_platform->getCreateTableSQL($table); self::assertEquals( @@ -325,14 +331,14 @@ public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey() public function testAlterTableAddColumns() { - $diff = new TableDiff('user'); - $diff->addedColumns['foo'] = new Column('foo', Type::getType('string')); - $diff->addedColumns['count'] = new Column('count', Type::getType('integer'), array('notnull' => false, 'default' => 1)); + $diff = new TableDiff('user'); + $diff->addedColumns['foo'] = new Column('foo', Type::getType('string')); + $diff->addedColumns['count'] = new Column('count', Type::getType('integer'), ['notnull' => false, 'default' => 1]); - $expected = array( + $expected = [ 'ALTER TABLE user ADD COLUMN foo VARCHAR(255) NOT NULL', 'ALTER TABLE user ADD COLUMN count INTEGER DEFAULT 1', - ); + ]; self::assertEquals($expected, $this->_platform->getAlterTableSQL($diff)); } @@ -349,12 +355,11 @@ public function testAlterTableAddComplexColumns(TableDiff $diff) : void public function complexDiffProvider() : array { - $date = new TableDiff('user'); - $date->addedColumns['time'] = new Column('time', Type::getType('date'), array('default' => 'CURRENT_DATE')); + $date = new TableDiff('user'); + $date->addedColumns['time'] = new Column('time', Type::getType('date'), ['default' => 'CURRENT_DATE']); - - $id = new TableDiff('user'); - $id->addedColumns['id'] = new Column('id', Type::getType('integer'), array('autoincrement' => true)); + $id = new TableDiff('user'); + $id->addedColumns['id'] = new Column('id', Type::getType('integer'), ['autoincrement' => true]); return [ 'date column with default value' => [$date], @@ -369,12 +374,12 @@ public function testCreateTableWithDeferredForeignKeys() $table->addColumn('article', 'integer'); $table->addColumn('post', 'integer'); $table->addColumn('parent', 'integer'); - $table->setPrimaryKey(array('id')); - $table->addForeignKeyConstraint('article', array('article'), array('id'), array('deferrable' => true)); - $table->addForeignKeyConstraint('post', array('post'), array('id'), array('deferred' => true)); - $table->addForeignKeyConstraint('user', array('parent'), array('id'), array('deferrable' => true, 'deferred' => true)); + $table->setPrimaryKey(['id']); + $table->addForeignKeyConstraint('article', ['article'], ['id'], ['deferrable' => true]); + $table->addForeignKeyConstraint('post', ['post'], ['id'], ['deferred' => true]); + $table->addForeignKeyConstraint('user', ['parent'], ['id'], ['deferrable' => true, 'deferred' => true]); - $sql = array( + $sql = [ 'CREATE TABLE user (' . 'id INTEGER NOT NULL, article INTEGER NOT NULL, post INTEGER NOT NULL, parent INTEGER NOT NULL' . ', PRIMARY KEY(id)' @@ -385,7 +390,7 @@ public function testCreateTableWithDeferredForeignKeys() 'CREATE INDEX IDX_8D93D64923A0E66 ON user (article)', 'CREATE INDEX IDX_8D93D6495A8A6C8D ON user (post)', 'CREATE INDEX IDX_8D93D6493D8E604F ON user (parent)', - ); + ]; self::assertEquals($sql, $this->_platform->getCreateTableSQL($table)); } @@ -397,21 +402,21 @@ public function testAlterTable() $table->addColumn('article', 'integer'); $table->addColumn('post', 'integer'); $table->addColumn('parent', 'integer'); - $table->setPrimaryKey(array('id')); - $table->addForeignKeyConstraint('article', array('article'), array('id'), array('deferrable' => true)); - $table->addForeignKeyConstraint('post', array('post'), array('id'), array('deferred' => true)); - $table->addForeignKeyConstraint('user', array('parent'), array('id'), array('deferrable' => true, 'deferred' => true)); - $table->addIndex(array('article', 'post'), 'index1'); - - $diff = new TableDiff('user'); - $diff->fromTable = $table; - $diff->newName = 'client'; - $diff->renamedColumns['id'] = new \Doctrine\DBAL\Schema\Column('key', \Doctrine\DBAL\Types\Type::getType('integer'), array()); - $diff->renamedColumns['post'] = new \Doctrine\DBAL\Schema\Column('comment', \Doctrine\DBAL\Types\Type::getType('integer'), array()); - $diff->removedColumns['parent'] = new \Doctrine\DBAL\Schema\Column('comment', \Doctrine\DBAL\Types\Type::getType('integer'), array()); + $table->setPrimaryKey(['id']); + $table->addForeignKeyConstraint('article', ['article'], ['id'], ['deferrable' => true]); + $table->addForeignKeyConstraint('post', ['post'], ['id'], ['deferred' => true]); + $table->addForeignKeyConstraint('user', ['parent'], ['id'], ['deferrable' => true, 'deferred' => true]); + $table->addIndex(['article', 'post'], 'index1'); + + $diff = new TableDiff('user'); + $diff->fromTable = $table; + $diff->newName = 'client'; + $diff->renamedColumns['id'] = new Column('key', Type::getType('integer'), []); + $diff->renamedColumns['post'] = new Column('comment', Type::getType('integer'), []); + $diff->removedColumns['parent'] = new Column('comment', Type::getType('integer'), []); $diff->removedIndexes['index1'] = $table->getIndex('index1'); - $sql = array( + $sql = [ 'DROP INDEX IDX_8D93D64923A0E66', 'DROP INDEX IDX_8D93D6495A8A6C8D', 'DROP INDEX IDX_8D93D6493D8E604F', @@ -429,43 +434,41 @@ public function testAlterTable() 'ALTER TABLE user RENAME TO client', 'CREATE INDEX IDX_8D93D64923A0E66 ON client (article)', 'CREATE INDEX IDX_8D93D6495A8A6C8D ON client (comment)', - ); + ]; self::assertEquals($sql, $this->_platform->getAlterTableSQL($diff)); } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))', - ); + return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; } protected function getQuotedColumnInIndexSQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', - ); + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', 'CREATE INDEX "key" ON test (column1)', - ); + ]; } protected function getQuotedColumnInForeignKeySQL() { - return array( + return [ 'CREATE TABLE "quoted" (' . '"create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL, ' . 'CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE, ' . 'CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE, ' . 'CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE)', - ); + ]; } protected function getBinaryDefaultLength() @@ -480,13 +483,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 9999999))); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 9999999])); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 9999999))); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999])); } /** @@ -494,14 +497,14 @@ public function testReturnsBinaryTypeDeclarationSQL() */ protected function getAlterTableRenameIndexSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT id FROM mytable', 'DROP TABLE mytable', 'CREATE TABLE mytable (id INTEGER NOT NULL, PRIMARY KEY(id))', 'INSERT INTO mytable (id) SELECT id FROM __temp__mytable', 'DROP TABLE __temp__mytable', 'CREATE INDEX idx_bar ON mytable (id)', - ); + ]; } /** @@ -509,7 +512,7 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__table AS SELECT id FROM "table"', 'DROP TABLE "table"', 'CREATE TABLE "table" (id INTEGER NOT NULL, PRIMARY KEY(id))', @@ -517,7 +520,7 @@ protected function getQuotedAlterTableRenameIndexSQL() 'DROP TABLE __temp__table', 'CREATE INDEX "select" ON "table" (id)', 'CREATE INDEX "bar" ON "table" (id)', - ); + ]; } /** @@ -525,7 +528,7 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM mytable', 'DROP TABLE mytable', 'CREATE TABLE mytable (unquoted INTEGER NOT NULL --Unquoted 1 @@ -540,7 +543,7 @@ protected function getQuotedAlterTableRenameColumnSQL() )', 'INSERT INTO mytable (unquoted, "where", "foo", reserved_keyword, "from", "bar", quoted, "and", "baz") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM __temp__mytable', 'DROP TABLE __temp__mytable', - ); + ]; } /** @@ -548,7 +551,7 @@ protected function getQuotedAlterTableRenameColumnSQL() */ protected function getQuotedAlterTableChangeColumnLengthSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM mytable', 'DROP TABLE mytable', 'CREATE TABLE mytable (unquoted1 VARCHAR(255) NOT NULL --Unquoted 1 @@ -560,7 +563,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() )', 'INSERT INTO mytable (unquoted1, unquoted2, unquoted3, "create", "table", "select") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM __temp__mytable', 'DROP TABLE __temp__mytable', - ); + ]; } /** @@ -590,7 +593,7 @@ public function testQuotesAlterTableRenameIndexInSchema() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -598,14 +601,14 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__foo AS SELECT bar FROM foo', 'DROP TABLE foo', 'CREATE TABLE foo (baz INTEGER DEFAULT 666 NOT NULL --rename test )', 'INSERT INTO foo (baz) SELECT bar FROM __temp__foo', 'DROP TABLE __temp__foo', - ); + ]; } /** @@ -613,7 +616,7 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'DROP INDEX IDX_8C736521A81E660E', 'DROP INDEX IDX_8C736521FDC58D6C', 'CREATE TEMPORARY TABLE __temp__foo AS SELECT fk, fk2, id, fk3, bar FROM "foo"', @@ -627,7 +630,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() 'ALTER TABLE "foo" RENAME TO "table"', 'CREATE INDEX IDX_8C736521A81E660E ON "table" (fk)', 'CREATE INDEX IDX_8C736521FDC58D6C ON "table" (fk2)', - ); + ]; } /** @@ -635,11 +638,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', 'COMMENT ON COLUMN "select"."from" IS \'comment\'', - ); + ]; } protected function getInlineColumnCommentDelimiter() @@ -691,13 +694,13 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() */ protected function getAlterStringToFixedStringSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT name FROM mytable', 'DROP TABLE mytable', 'CREATE TABLE mytable (name CHAR(2) NOT NULL)', 'INSERT INTO mytable (name) SELECT name FROM __temp__mytable', 'DROP TABLE __temp__mytable', - ); + ]; } /** @@ -705,7 +708,7 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( + return [ 'DROP INDEX idx_foo', 'DROP INDEX idx_bar', 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT foo, bar, baz FROM mytable', @@ -715,7 +718,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() 'DROP TABLE __temp__mytable', 'CREATE INDEX idx_bar ON mytable (bar)', 'CREATE INDEX idx_foo_renamed ON mytable (foo)', - ); + ]; } /** diff --git a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php index 83775e13f2e..5a783ef6415 100644 --- a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php @@ -6,23 +6,19 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Portability\Connection; use Doctrine\DBAL\Portability\Statement; +use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function iterator_to_array; -class StatementTest extends \Doctrine\Tests\DbalTestCase +class StatementTest extends DbalTestCase { - /** - * @var \Doctrine\DBAL\Portability\Connection|\PHPUnit_Framework_MockObject_MockObject - */ + /** @var Connection|PHPUnit_Framework_MockObject_MockObject */ protected $conn; - /** - * @var \Doctrine\DBAL\Portability\Statement - */ + /** @var Statement */ protected $stmt; - /** - * @var \Doctrine\DBAL\Driver\Statement|\PHPUnit_Framework_MockObject_MockObject - */ + /** @var \Doctrine\DBAL\Driver\Statement|PHPUnit_Framework_MockObject_MockObject */ protected $wrappedStmt; /** @@ -100,7 +96,7 @@ public function testErrorCode() public function testErrorInfo() { - $errorInfo = array('666', 'Evil error.'); + $errorInfo = ['666', 'Evil error.']; $this->wrappedStmt->expects($this->once()) ->method('errorInfo') @@ -111,10 +107,10 @@ public function testErrorInfo() public function testExecute() { - $params = array( + $params = [ 'foo', - 'bar' - ); + 'bar', + ]; $this->wrappedStmt->expects($this->once()) ->method('execute') @@ -128,7 +124,7 @@ public function testSetFetchMode() { $fetchMode = FetchMode::CUSTOM_OBJECT; $arg1 = 'MyClass'; - $arg2 = array(1, 2); + $arg2 = [1, 2]; $this->wrappedStmt->expects($this->once()) ->method('setFetchMode') @@ -161,7 +157,7 @@ public function testRowCount() } /** - * @return \Doctrine\DBAL\Portability\Connection|\PHPUnit_Framework_MockObject_MockObject + * @return Connection|PHPUnit_Framework_MockObject_MockObject */ protected function createConnection() { @@ -171,10 +167,7 @@ protected function createConnection() } /** - * @param \Doctrine\DBAL\Driver\Statement $wrappedStatement - * @param \Doctrine\DBAL\Portability\Connection $connection - * - * @return \Doctrine\DBAL\Portability\Statement + * @return Statement */ protected function createStatement(\Doctrine\DBAL\Driver\Statement $wrappedStatement, Connection $connection) { @@ -182,7 +175,7 @@ protected function createStatement(\Doctrine\DBAL\Driver\Statement $wrappedState } /** - * @return \Doctrine\DBAL\Driver\Statement|\PHPUnit_Framework_MockObject_MockObject + * @return \Doctrine\DBAL\Driver\Statement|PHPUnit_Framework_MockObject_MockObject */ protected function createWrappedStatement() { diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php index 2ae9d0087e4..512dfb08224 100644 --- a/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php @@ -3,15 +3,16 @@ namespace Doctrine\Tests\DBAL\Query\Expression; use Doctrine\DBAL\Query\Expression\CompositeExpression; +use Doctrine\Tests\DbalTestCase; /** * @group DBAL-12 */ -class CompositeExpressionTest extends \Doctrine\Tests\DbalTestCase +class CompositeExpressionTest extends DbalTestCase { public function testCount() { - $expr = new CompositeExpression(CompositeExpression::TYPE_OR, array('u.group_id = 1')); + $expr = new CompositeExpression(CompositeExpression::TYPE_OR, ['u.group_id = 1']); self::assertCount(1, $expr); @@ -22,15 +23,15 @@ public function testCount() public function testAdd() { - $expr = new CompositeExpression(CompositeExpression::TYPE_OR, array('u.group_id = 1')); + $expr = new CompositeExpression(CompositeExpression::TYPE_OR, ['u.group_id = 1']); self::assertCount(1, $expr); - $expr->add(new CompositeExpression(CompositeExpression::TYPE_AND, array())); + $expr->add(new CompositeExpression(CompositeExpression::TYPE_AND, [])); self::assertCount(1, $expr); - $expr->add(new CompositeExpression(CompositeExpression::TYPE_OR, array('u.user_id = 1'))); + $expr->add(new CompositeExpression(CompositeExpression::TYPE_OR, ['u.user_id = 1'])); self::assertCount(2, $expr); @@ -55,49 +56,49 @@ public function testCompositeUsageAndGeneration($type, $parts, $expects) public function provideDataForConvertToString() { - return array( - array( + return [ + [ CompositeExpression::TYPE_AND, - array('u.user = 1'), - 'u.user = 1' - ), - array( + ['u.user = 1'], + 'u.user = 1', + ], + [ CompositeExpression::TYPE_AND, - array('u.user = 1', 'u.group_id = 1'), - '(u.user = 1) AND (u.group_id = 1)' - ), - array( + ['u.user = 1', 'u.group_id = 1'], + '(u.user = 1) AND (u.group_id = 1)', + ], + [ CompositeExpression::TYPE_OR, - array('u.user = 1'), - 'u.user = 1' - ), - array( + ['u.user = 1'], + 'u.user = 1', + ], + [ CompositeExpression::TYPE_OR, - array('u.group_id = 1', 'u.group_id = 2'), - '(u.group_id = 1) OR (u.group_id = 2)' - ), - array( + ['u.group_id = 1', 'u.group_id = 2'], + '(u.group_id = 1) OR (u.group_id = 2)', + ], + [ CompositeExpression::TYPE_AND, - array( + [ 'u.user = 1', new CompositeExpression( CompositeExpression::TYPE_OR, - array('u.group_id = 1', 'u.group_id = 2') - ) - ), - '(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))' - ), - array( + ['u.group_id = 1', 'u.group_id = 2'] + ), + ], + '(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))', + ], + [ CompositeExpression::TYPE_OR, - array( + [ 'u.group_id = 1', new CompositeExpression( CompositeExpression::TYPE_AND, - array('u.user = 1', 'u.group_id = 2') - ) - ), - '(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))' - ), - ); + ['u.user = 1', 'u.group_id = 2'] + ), + ], + '(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))', + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php index d4a1d111942..1fe2ac97416 100644 --- a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php @@ -4,15 +4,14 @@ use Doctrine\DBAL\Query\Expression\CompositeExpression; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; +use Doctrine\Tests\DbalTestCase; /** * @group DBAL-12 */ -class ExpressionBuilderTest extends \Doctrine\Tests\DbalTestCase +class ExpressionBuilderTest extends DbalTestCase { - /** - * @var ExpressionBuilder - */ + /** @var ExpressionBuilder */ protected $expr; protected function setUp() @@ -42,44 +41,44 @@ public function testAndX($parts, $expected) public function provideDataForAndX() { - return array( - array( - array('u.user = 1'), - 'u.user = 1' - ), - array( - array('u.user = 1', 'u.group_id = 1'), - '(u.user = 1) AND (u.group_id = 1)' - ), - array( - array('u.user = 1'), - 'u.user = 1' - ), - array( - array('u.group_id = 1', 'u.group_id = 2'), - '(u.group_id = 1) AND (u.group_id = 2)' - ), - array( - array( + return [ + [ + ['u.user = 1'], + 'u.user = 1', + ], + [ + ['u.user = 1', 'u.group_id = 1'], + '(u.user = 1) AND (u.group_id = 1)', + ], + [ + ['u.user = 1'], + 'u.user = 1', + ], + [ + ['u.group_id = 1', 'u.group_id = 2'], + '(u.group_id = 1) AND (u.group_id = 2)', + ], + [ + [ 'u.user = 1', new CompositeExpression( CompositeExpression::TYPE_OR, - array('u.group_id = 1', 'u.group_id = 2') - ) - ), - '(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))' - ), - array( - array( + ['u.group_id = 1', 'u.group_id = 2'] + ), + ], + '(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))', + ], + [ + [ 'u.group_id = 1', new CompositeExpression( CompositeExpression::TYPE_AND, - array('u.user = 1', 'u.group_id = 2') - ) - ), - '(u.group_id = 1) AND ((u.user = 1) AND (u.group_id = 2))' - ), - ); + ['u.user = 1', 'u.group_id = 2'] + ), + ], + '(u.group_id = 1) AND ((u.user = 1) AND (u.group_id = 2))', + ], + ]; } /** @@ -98,44 +97,44 @@ public function testOrX($parts, $expected) public function provideDataForOrX() { - return array( - array( - array('u.user = 1'), - 'u.user = 1' - ), - array( - array('u.user = 1', 'u.group_id = 1'), - '(u.user = 1) OR (u.group_id = 1)' - ), - array( - array('u.user = 1'), - 'u.user = 1' - ), - array( - array('u.group_id = 1', 'u.group_id = 2'), - '(u.group_id = 1) OR (u.group_id = 2)' - ), - array( - array( + return [ + [ + ['u.user = 1'], + 'u.user = 1', + ], + [ + ['u.user = 1', 'u.group_id = 1'], + '(u.user = 1) OR (u.group_id = 1)', + ], + [ + ['u.user = 1'], + 'u.user = 1', + ], + [ + ['u.group_id = 1', 'u.group_id = 2'], + '(u.group_id = 1) OR (u.group_id = 2)', + ], + [ + [ 'u.user = 1', new CompositeExpression( CompositeExpression::TYPE_OR, - array('u.group_id = 1', 'u.group_id = 2') - ) - ), - '(u.user = 1) OR ((u.group_id = 1) OR (u.group_id = 2))' - ), - array( - array( + ['u.group_id = 1', 'u.group_id = 2'] + ), + ], + '(u.user = 1) OR ((u.group_id = 1) OR (u.group_id = 2))', + ], + [ + [ 'u.group_id = 1', new CompositeExpression( CompositeExpression::TYPE_AND, - array('u.user = 1', 'u.group_id = 2') - ) - ), - '(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))' - ), - ); + ['u.user = 1', 'u.group_id = 2'] + ), + ], + '(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))', + ], + ]; } /** @@ -150,14 +149,14 @@ public function testComparison($leftExpr, $operator, $rightExpr, $expected) public function provideDataForComparison() { - return array( - array('u.user_id', ExpressionBuilder::EQ, '1', 'u.user_id = 1'), - array('u.user_id', ExpressionBuilder::NEQ, '1', 'u.user_id <> 1'), - array('u.salary', ExpressionBuilder::LT, '10000', 'u.salary < 10000'), - array('u.salary', ExpressionBuilder::LTE, '10000', 'u.salary <= 10000'), - array('u.salary', ExpressionBuilder::GT, '10000', 'u.salary > 10000'), - array('u.salary', ExpressionBuilder::GTE, '10000', 'u.salary >= 10000'), - ); + return [ + ['u.user_id', ExpressionBuilder::EQ, '1', 'u.user_id = 1'], + ['u.user_id', ExpressionBuilder::NEQ, '1', 'u.user_id <> 1'], + ['u.salary', ExpressionBuilder::LT, '10000', 'u.salary < 10000'], + ['u.salary', ExpressionBuilder::LTE, '10000', 'u.salary <= 10000'], + ['u.salary', ExpressionBuilder::GT, '10000', 'u.salary > 10000'], + ['u.salary', ExpressionBuilder::GTE, '10000', 'u.salary >= 10000'], + ]; } public function testEq() @@ -202,7 +201,7 @@ public function testIsNotNull() public function testIn() { - self::assertEquals('u.groups IN (1, 3, 4, 7)', $this->expr->in('u.groups', array(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() @@ -212,7 +211,7 @@ public function testInWithPlaceholder() public function testNotIn() { - self::assertEquals('u.groups NOT IN (1, 3, 4, 7)', $this->expr->notIn('u.groups', array(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() diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php index 97145d53d3a..1bbb61e8a06 100644 --- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php @@ -2,18 +2,18 @@ namespace Doctrine\Tests\DBAL\Query; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Query\QueryBuilder; +use Doctrine\Tests\DbalTestCase; /** * @group DBAL-12 */ -class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase +class QueryBuilderTest extends DbalTestCase { - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ protected $conn; protected function setUp() @@ -58,7 +58,7 @@ public function testSelectWithSimpleWhere() ->from('users', 'u') ->where($expr->andX($expr->eq('u.nickname', '?'))); - self::assertEquals("SELECT u.id FROM users u WHERE u.nickname = ?", (string) $qb); + self::assertEquals('SELECT u.id FROM users u WHERE u.nickname = ?', (string) $qb); } public function testSelectWithLeftJoin() @@ -181,7 +181,7 @@ public function testSelectEmptyGroupBy() $expr = $qb->expr(); $qb->select('u.*', 'p.*') - ->groupBy(array()) + ->groupBy([]) ->from('users', 'u'); self::assertEquals('SELECT u.*, p.* FROM users u', (string) $qb); @@ -193,7 +193,7 @@ public function testSelectEmptyAddGroupBy() $expr = $qb->expr(); $qb->select('u.*', 'p.*') - ->addGroupBy(array()) + ->addGroupBy([]) ->from('users', 'u'); self::assertEquals('SELECT u.*, p.* FROM users u', (string) $qb); @@ -348,7 +348,7 @@ public function testSelectAddAddOrderBy() public function testEmptySelect() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb2 = $qb->select(); self::assertSame($qb, $qb2); @@ -369,7 +369,7 @@ public function testSelectAddSelect() public function testEmptyAddSelect() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb2 = $qb->addSelect(); self::assertSame($qb, $qb2); @@ -391,7 +391,7 @@ public function testSelectMultipleFrom() public function testUpdate() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->update('users', 'u') ->set('u.foo', '?') ->set('u.bar', '?'); @@ -402,7 +402,7 @@ public function testUpdate() public function testUpdateWithoutAlias() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->update('users') ->set('foo', '?') ->set('bar', '?'); @@ -412,7 +412,7 @@ public function testUpdateWithoutAlias() public function testUpdateWhere() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->update('users', 'u') ->set('u.foo', '?') ->where('u.foo = ?'); @@ -422,7 +422,7 @@ public function testUpdateWhere() public function testEmptyUpdate() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb2 = $qb->update(); self::assertEquals(QueryBuilder::UPDATE, $qb->getType()); @@ -431,7 +431,7 @@ public function testEmptyUpdate() public function testDelete() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->delete('users', 'u'); self::assertEquals(QueryBuilder::DELETE, $qb->getType()); @@ -440,7 +440,7 @@ public function testDelete() public function testDeleteWithoutAlias() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->delete('users'); self::assertEquals(QueryBuilder::DELETE, $qb->getType()); @@ -449,7 +449,7 @@ public function testDeleteWithoutAlias() public function testDeleteWhere() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->delete('users', 'u') ->where('u.foo = ?'); @@ -458,7 +458,7 @@ public function testDeleteWhere() public function testEmptyDelete() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb2 = $qb->delete(); self::assertEquals(QueryBuilder::DELETE, $qb->getType()); @@ -470,10 +470,10 @@ public function testInsertValues() $qb = new QueryBuilder($this->conn); $qb->insert('users') ->values( - array( + [ 'foo' => '?', - 'bar' => '?' - ) + 'bar' => '?', + ] ); self::assertEquals(QueryBuilder::INSERT, $qb->getType()); @@ -485,16 +485,16 @@ public function testInsertReplaceValues() $qb = new QueryBuilder($this->conn); $qb->insert('users') ->values( - array( + [ 'foo' => '?', - 'bar' => '?' - ) + 'bar' => '?', + ] ) ->values( - array( + [ 'bar' => '?', - 'foo' => '?' - ) + 'foo' => '?', + ] ); self::assertEquals(QueryBuilder::INSERT, $qb->getType()); @@ -518,9 +518,7 @@ public function testInsertValuesSetValue() $qb = new QueryBuilder($this->conn); $qb->insert('users') ->values( - array( - 'foo' => '?' - ) + ['foo' => '?'] ) ->setValue('bar', '?'); @@ -530,7 +528,7 @@ public function testInsertValuesSetValue() public function testEmptyInsert() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb2 = $qb->insert(); self::assertEquals(QueryBuilder::INSERT, $qb->getType()); @@ -539,13 +537,13 @@ public function testEmptyInsert() public function testGetConnection() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); self::assertSame($this->conn, $qb->getConnection()); } public function testGetState() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); self::assertEquals(QueryBuilder::STATE_CLEAN, $qb->getState()); @@ -561,7 +559,7 @@ public function testGetState() public function testSetMaxResults() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->setMaxResults(10); self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState()); @@ -570,7 +568,7 @@ public function testSetMaxResults() public function testSetFirstResult() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->setFirstResult(10); self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState()); @@ -579,7 +577,7 @@ public function testSetFirstResult() public function testResetQueryPart() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where('u.name = ?'); @@ -590,18 +588,18 @@ public function testResetQueryPart() public function testResetQueryParts() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where('u.name = ?')->orderBy('u.name'); self::assertEquals('SELECT u.* FROM users u WHERE u.name = ? ORDER BY u.name ASC', (string) $qb); - $qb->resetQueryParts(array('where', 'orderBy')); + $qb->resetQueryParts(['where', 'orderBy']); self::assertEquals('SELECT u.* FROM users u', (string) $qb); } public function testCreateNamedParameter() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where( $qb->expr()->eq('u.name', $qb->createNamedParameter(10, ParameterType::INTEGER)) @@ -614,7 +612,7 @@ public function testCreateNamedParameter() public function testCreateNamedParameterCustomPlaceholder() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where( $qb->expr()->eq('u.name', $qb->createNamedParameter(10, ParameterType::INTEGER, ':test')) @@ -627,7 +625,7 @@ public function testCreateNamedParameterCustomPlaceholder() public function testCreatePositionalParameter() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where( $qb->expr()->eq('u.name', $qb->createPositionalParameter(10, ParameterType::INTEGER)) @@ -785,7 +783,7 @@ public function testSelectWithSimpleWhereWithoutTableAlias() ->from('users') ->where('awesome=9001'); - self::assertEquals("SELECT id, name FROM users WHERE awesome=9001", (string) $qb); + self::assertEquals('SELECT id, name FROM users WHERE awesome=9001', (string) $qb); } public function testComplexSelectWithoutTableAliases() @@ -823,7 +821,7 @@ public function testSelectAllFromTableWithoutTableAlias() $qb->select('users.*') ->from('users'); - self::assertEquals("SELECT users.* FROM users", (string) $qb); + self::assertEquals('SELECT users.* FROM users', (string) $qb); } public function testSelectAllWithoutTableAlias() @@ -833,7 +831,7 @@ public function testSelectAllWithoutTableAlias() $qb->select('*') ->from('users'); - self::assertEquals("SELECT * FROM users", (string) $qb); + self::assertEquals('SELECT * FROM users', (string) $qb); } /** @@ -866,12 +864,12 @@ public function testGetParameterTypes() $qb->select('*')->from('users'); - self::assertSame(array(), $qb->getParameterTypes()); + self::assertSame([], $qb->getParameterTypes()); $qb->where('name = :name'); $qb->setParameter('name', 'foo'); - self::assertSame(array(), $qb->getParameterTypes()); + self::assertSame([], $qb->getParameterTypes()); $qb->setParameter('name', 'foo', ParameterType::STRING); diff --git a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php index 0e057953b8a..09b518dcf21 100644 --- a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php +++ b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php @@ -5,60 +5,61 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\SQLParserUtils; +use Doctrine\Tests\DbalTestCase; /** * @group DBAL-78 * @group DDC-1372 */ -class SQLParserUtilsTest extends \Doctrine\Tests\DbalTestCase +class SQLParserUtilsTest extends DbalTestCase { public function dataGetPlaceholderPositions() { - return array( + return [ // none - array('SELECT * FROM Foo', true, array()), - array('SELECT * FROM Foo', false, array()), + ['SELECT * FROM Foo', true, []], + ['SELECT * FROM Foo', false, []], // Positionals - array('SELECT ?', true, array(7)), - array('SELECT * FROM Foo WHERE bar IN (?, ?, ?)', true, array(32, 35, 38)), - array('SELECT ? FROM ?', true, array(7, 14)), - array('SELECT "?" FROM foo', true, array()), - array("SELECT '?' FROM foo", true, array()), - array("SELECT `?` FROM foo", true, array()), // Ticket DBAL-552 - array("SELECT [?] FROM foo", true, array()), - array("SELECT 'Doctrine\DBAL?' FROM foo", true, array()), // Ticket DBAL-558 - array('SELECT "Doctrine\DBAL?" FROM foo', true, array()), // Ticket DBAL-558 - array('SELECT `Doctrine\DBAL?` FROM foo', true, array()), // Ticket DBAL-558 - array('SELECT [Doctrine\DBAL?] FROM foo', true, array()), // Ticket DBAL-558 - array('SELECT "?" FROM foo WHERE bar = ?', true, array(32)), - array("SELECT '?' FROM foo WHERE bar = ?", true, array(32)), - array("SELECT `?` FROM foo WHERE bar = ?", true, array(32)), // Ticket DBAL-552 - array("SELECT [?] FROM foo WHERE bar = ?", true, array(32)), - array('SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[?])', true, array(56)), // Ticket GH-2295 - array("SELECT 'Doctrine\DBAL?' FROM foo WHERE bar = ?", true, array(45)), // Ticket DBAL-558 - array('SELECT "Doctrine\DBAL?" FROM foo WHERE bar = ?', true, array(45)), // Ticket DBAL-558 - array('SELECT `Doctrine\DBAL?` FROM foo WHERE bar = ?', true, array(45)), // Ticket DBAL-558 - array('SELECT [Doctrine\DBAL?] FROM foo WHERE bar = ?', true, array(45)), // Ticket DBAL-558 - array("SELECT * FROM FOO WHERE bar = 'it\\'s a trap? \\\\' OR bar = ?\nAND baz = \"\\\"quote\\\" me on it? \\\\\" OR baz = ?", true, array(58, 104)), - array('SELECT * FROM foo WHERE foo = ? AND bar = ?', true, array(1 => 42, 0 => 30)), // explicit keys + ['SELECT ?', true, [7]], + ['SELECT * FROM Foo WHERE bar IN (?, ?, ?)', true, [32, 35, 38]], + ['SELECT ? FROM ?', true, [7, 14]], + ['SELECT "?" FROM foo', true, []], + ["SELECT '?' FROM foo", true, []], + ['SELECT `?` FROM foo', true, []], // Ticket DBAL-552 + ['SELECT [?] FROM foo', true, []], + ["SELECT 'Doctrine\DBAL?' FROM foo", true, []], // Ticket DBAL-558 + ['SELECT "Doctrine\DBAL?" FROM foo', true, []], // Ticket DBAL-558 + ['SELECT `Doctrine\DBAL?` FROM foo', true, []], // Ticket DBAL-558 + ['SELECT [Doctrine\DBAL?] FROM foo', true, []], // Ticket DBAL-558 + ['SELECT "?" FROM foo WHERE bar = ?', true, [32]], + ["SELECT '?' FROM foo WHERE bar = ?", true, [32]], + ['SELECT `?` FROM foo WHERE bar = ?', true, [32]], // Ticket DBAL-552 + ['SELECT [?] FROM foo WHERE bar = ?', true, [32]], + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[?])', true, [56]], // Ticket GH-2295 + ["SELECT 'Doctrine\DBAL?' FROM foo WHERE bar = ?", true, [45]], // Ticket DBAL-558 + ['SELECT "Doctrine\DBAL?" FROM foo WHERE bar = ?', true, [45]], // Ticket DBAL-558 + ['SELECT `Doctrine\DBAL?` FROM foo WHERE bar = ?', true, [45]], // Ticket DBAL-558 + ['SELECT [Doctrine\DBAL?] FROM foo WHERE bar = ?', true, [45]], // Ticket DBAL-558 + ["SELECT * FROM FOO WHERE bar = 'it\\'s a trap? \\\\' OR bar = ?\nAND baz = \"\\\"quote\\\" me on it? \\\\\" OR baz = ?", true, [58, 104]], + ['SELECT * FROM foo WHERE foo = ? AND bar = ?', true, [1 => 42, 0 => 30]], // explicit keys // named - array('SELECT :foo FROM :bar', false, array(7 => 'foo', 17 => 'bar')), - array('SELECT * FROM Foo WHERE bar IN (:name1, :name2)', false, array(32 => 'name1', 40 => 'name2')), - array('SELECT ":foo" FROM Foo WHERE bar IN (:name1, :name2)', false, array(37 => 'name1', 45 => 'name2')), - array("SELECT ':foo' FROM Foo WHERE bar IN (:name1, :name2)", false, array(37 => 'name1', 45 => 'name2')), - array('SELECT :foo_id', false, array(7 => 'foo_id')), // Ticket DBAL-231 - array('SELECT @rank := 1', false, array()), // Ticket DBAL-398 - array('SELECT @rank := 1 AS rank, :foo AS foo FROM :bar', false, array(27 => 'foo', 44 => 'bar')), // Ticket DBAL-398 - array('SELECT * FROM Foo WHERE bar > :start_date AND baz > :start_date', false, array(30 => 'start_date', 52 => 'start_date')), // Ticket GH-113 - array('SELECT foo::date as date FROM Foo WHERE bar > :start_date AND baz > :start_date', false, array(46 => 'start_date', 68 => 'start_date')), // Ticket GH-259 - array('SELECT `d.ns:col_name` FROM my_table d WHERE `d.date` >= :param1', false, array(57 => 'param1')), // Ticket DBAL-552 - array('SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', false, array(57 => 'param1')), // Ticket DBAL-552 + ['SELECT :foo FROM :bar', false, [7 => 'foo', 17 => 'bar']], + ['SELECT * FROM Foo WHERE bar IN (:name1, :name2)', false, [32 => 'name1', 40 => 'name2']], + ['SELECT ":foo" FROM Foo WHERE bar IN (:name1, :name2)', false, [37 => 'name1', 45 => 'name2']], + ["SELECT ':foo' FROM Foo WHERE bar IN (:name1, :name2)", false, [37 => 'name1', 45 => 'name2']], + ['SELECT :foo_id', false, [7 => 'foo_id']], // Ticket DBAL-231 + ['SELECT @rank := 1', false, []], // Ticket DBAL-398 + ['SELECT @rank := 1 AS rank, :foo AS foo FROM :bar', false, [27 => 'foo', 44 => 'bar']], // Ticket DBAL-398 + ['SELECT * FROM Foo WHERE bar > :start_date AND baz > :start_date', false, [30 => 'start_date', 52 => 'start_date']], // Ticket GH-113 + ['SELECT foo::date as date FROM Foo WHERE bar > :start_date AND baz > :start_date', false, [46 => 'start_date', 68 => 'start_date']], // Ticket GH-259 + ['SELECT `d.ns:col_name` FROM my_table d WHERE `d.date` >= :param1', false, [57 => 'param1']], // Ticket DBAL-552 + ['SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', false, [57 => 'param1']], // Ticket DBAL-552 ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', false, [56 => 'foo']], // Ticket GH-2295 ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, array[:foo])', false, [56 => 'foo']], - array( -<<<'SQLDATA' + [ + <<<'SQLDATA' SELECT * FROM foo WHERE bar = ':not_a_param1 ''":not_a_param2"''' OR bar=:a_param1 @@ -67,15 +68,21 @@ public function dataGetPlaceholderPositions() OR bar='' OR bar=:a_param3 SQLDATA - , false, array(74 => 'a_param1', 91 => 'a_param2', 190 => 'a_param3') - ), - array("SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE '\\\\') AND (data.description LIKE :condition_1 ESCAPE '\\\\') ORDER BY id ASC", false, array(121 => 'condition_0', 174 => 'condition_1')), - array('SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE "\\\\") ORDER BY id ASC', false, array(121 => 'condition_0', 174 => 'condition_1')), - array('SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE \'\\\\\') ORDER BY id ASC', false, array(121 => 'condition_0', 174 => 'condition_1')), - array('SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE `\\\\`) AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, array(121 => 'condition_0', 174 => 'condition_1')), - array('SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE \'\\\\\') AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, array(121 => 'condition_0', 174 => 'condition_1')), + , + false, + [ + 74 => 'a_param1', + 91 => 'a_param2', + 190 => 'a_param3', + ], + ], + ["SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE '\\\\') AND (data.description LIKE :condition_1 ESCAPE '\\\\') ORDER BY id ASC", false, [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE "\\\\") ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE \'\\\\\') ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE `\\\\`) AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE \'\\\\\') AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], - ); + ]; } /** @@ -89,120 +96,120 @@ public function testGetPlaceholderPositions($query, $isPositional, $expectedPara public function dataExpandListParameters() { - return array( + return [ // Positional: Very simple with one needle - array( - "SELECT * FROM Foo WHERE foo IN (?)", - array(array(1, 2, 3)), - array(Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (?)', + [[1, 2, 3]], + [Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?)', - array(1, 2, 3), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + [1, 2, 3], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Positional: One non-list before d one after list-needle - array( - "SELECT * FROM Foo WHERE foo = ? AND bar IN (?)", - array("string", array(1, 2, 3)), - array(ParameterType::STRING, Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?)', + ['string', [1, 2, 3]], + [ParameterType::STRING, Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?)', - array("string", 1, 2, 3), - array(ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + ['string', 1, 2, 3], + [ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Positional: One non-list after list-needle - array( - "SELECT * FROM Foo WHERE bar IN (?) AND baz = ?", - array(array(1, 2, 3), "foo"), - array(Connection::PARAM_INT_ARRAY, ParameterType::STRING), + [ + 'SELECT * FROM Foo WHERE bar IN (?) AND baz = ?', + [[1, 2, 3], 'foo'], + [Connection::PARAM_INT_ARRAY, ParameterType::STRING], 'SELECT * FROM Foo WHERE bar IN (?, ?, ?) AND baz = ?', - array(1, 2, 3, "foo"), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) - ), + [1, 2, 3, 'foo'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], + ], // Positional: One non-list before and one after list-needle - array( - "SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ?", - array(1, array(1, 2, 3), 4), - array(ParameterType::INTEGER, Connection::PARAM_INT_ARRAY, ParameterType::INTEGER), + [ + 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ?', + [1, [1, 2, 3], 4], + [ParameterType::INTEGER, Connection::PARAM_INT_ARRAY, ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ?', - array(1, 1, 2, 3, 4), - array( + [1, 1, 2, 3, 4], + [ ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, - ) - ), + ], + ], // Positional: Two lists - array( - "SELECT * FROM Foo WHERE foo IN (?, ?)", - array(array(1, 2, 3), array(4, 5)), - array(Connection::PARAM_INT_ARRAY, Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (?, ?)', + [[1, 2, 3], [4, 5]], + [Connection::PARAM_INT_ARRAY, Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?, ?, ?)', - array(1, 2, 3, 4, 5), - array( + [1, 2, 3, 4, 5], + [ ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, - ) - ), + ], + ], // Positional: Empty "integer" array DDC-1978 - array( - "SELECT * FROM Foo WHERE foo IN (?)", - array(array()), - array(Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (?)', + [[]], + [Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (NULL)', - array(), - array() - ), + [], + [], + ], // Positional: Empty "str" array DDC-1978 - array( - "SELECT * FROM Foo WHERE foo IN (?)", - array(array()), - array(Connection::PARAM_STR_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (?)', + [[]], + [Connection::PARAM_STR_ARRAY], 'SELECT * FROM Foo WHERE foo IN (NULL)', - array(), - array() - ), + [], + [], + ], // Positional: explicit keys for params and types - array( - "SELECT * FROM Foo WHERE foo = ? AND bar = ? AND baz = ?", - array(1 => 'bar', 2 => 'baz', 0 => 1), - array(2 => ParameterType::STRING, 1 => ParameterType::STRING), + [ 'SELECT * FROM Foo WHERE foo = ? AND bar = ? AND baz = ?', - array(1 => 'bar', 0 => 1, 2 => 'baz'), - array(1 => ParameterType::STRING, 2 => ParameterType::STRING), - ), + [1 => 'bar', 2 => 'baz', 0 => 1], + [2 => ParameterType::STRING, 1 => ParameterType::STRING], + 'SELECT * FROM Foo WHERE foo = ? AND bar = ? AND baz = ?', + [1 => 'bar', 0 => 1, 2 => 'baz'], + [1 => ParameterType::STRING, 2 => ParameterType::STRING], + ], // Positional: explicit keys for array params and array types - array( - "SELECT * FROM Foo WHERE foo IN (?) AND bar IN (?) AND baz = ?", - array(1 => array('bar1', 'bar2'), 2 => true, 0 => array(1, 2, 3)), - array(2 => ParameterType::BOOLEAN, 1 => Connection::PARAM_STR_ARRAY, 0 => Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (?) AND bar IN (?) AND baz = ?', + [1 => ['bar1', 'bar2'], 2 => true, 0 => [1, 2, 3]], + [2 => ParameterType::BOOLEAN, 1 => Connection::PARAM_STR_ARRAY, 0 => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND bar IN (?, ?) AND baz = ?', - array(1, 2, 3, 'bar1', 'bar2', true), - array( + [1, 2, 3, 'bar1', 'bar2', true], + [ ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING, ParameterType::STRING, ParameterType::BOOLEAN, - ) - ), + ], + ], // Positional starts from 1: One non-list before and one after list-needle - array( - "SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ? AND foo IN (?)", - array(1 => 1, 2 => array(1, 2, 3), 3 => 4, 4 => array(5, 6)), - array( + [ + 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ? AND foo IN (?)', + [1 => 1, 2 => [1, 2, 3], 3 => 4, 4 => [5, 6]], + [ 1 => ParameterType::INTEGER, 2 => Connection::PARAM_INT_ARRAY, 3 => ParameterType::INTEGER, 4 => Connection::PARAM_INT_ARRAY, - ), + ], 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ? AND foo IN (?, ?)', - array(1, 1, 2, 3, 4, 5, 6), - array( + [1, 1, 2, 3, 4, 5, 6], + [ ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, @@ -210,194 +217,194 @@ public function dataExpandListParameters() ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, - ) - ), + ], + ], // Named parameters : Very simple with param int - array( - "SELECT * FROM Foo WHERE foo = :foo", - array('foo'=>1), - array('foo' => ParameterType::INTEGER), + [ + 'SELECT * FROM Foo WHERE foo = :foo', + ['foo' => 1], + ['foo' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ?', - array(1), - array(ParameterType::INTEGER), - ), + [1], + [ParameterType::INTEGER], + ], // Named parameters : Very simple with param int and string - array( - "SELECT * FROM Foo WHERE foo = :foo AND bar = :bar", - array('bar'=>'Some String','foo'=>1), - array('foo' => ParameterType::INTEGER, 'bar' => ParameterType::STRING), + [ + 'SELECT * FROM Foo WHERE foo = :foo AND bar = :bar', + ['bar' => 'Some String','foo' => 1], + ['foo' => ParameterType::INTEGER, 'bar' => ParameterType::STRING], 'SELECT * FROM Foo WHERE foo = ? AND bar = ?', - array(1,'Some String'), - array(ParameterType::INTEGER, ParameterType::STRING) - ), + [1,'Some String'], + [ParameterType::INTEGER, ParameterType::STRING], + ], // Named parameters : Very simple with one needle - array( - "SELECT * FROM Foo WHERE foo IN (:foo)", - array('foo'=>array(1, 2, 3)), - array('foo'=>Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (:foo)', + ['foo' => [1, 2, 3]], + ['foo' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?)', - array(1, 2, 3), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER), - ), + [1, 2, 3], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters: One non-list before d one after list-needle - array( - "SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar)", - array('foo'=>"string", 'bar'=>array(1, 2, 3)), - array('foo' => ParameterType::STRING, 'bar' => Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar)', + ['foo' => 'string', 'bar' => [1, 2, 3]], + ['foo' => ParameterType::STRING, 'bar' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?)', - array("string", 1, 2, 3), - array(ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + ['string', 1, 2, 3], + [ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters: One non-list after list-needle - array( - "SELECT * FROM Foo WHERE bar IN (:bar) AND baz = :baz", - array('bar'=>array(1, 2, 3), 'baz'=>"foo"), - array('bar'=>Connection::PARAM_INT_ARRAY, 'baz'=>ParameterType::STRING), + [ + 'SELECT * FROM Foo WHERE bar IN (:bar) AND baz = :baz', + ['bar' => [1, 2, 3], 'baz' => 'foo'], + ['bar' => Connection::PARAM_INT_ARRAY, 'baz' => ParameterType::STRING], 'SELECT * FROM Foo WHERE bar IN (?, ?, ?) AND baz = ?', - array(1, 2, 3, "foo"), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) - ), + [1, 2, 3, 'foo'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], + ], // Named parameters: One non-list before and one after list-needle - array( - "SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar) AND baz = :baz", - array('bar'=>array(1, 2, 3),'foo'=>1, 'baz'=>4), - array('bar'=>Connection::PARAM_INT_ARRAY, 'foo'=>ParameterType::INTEGER, 'baz'=>ParameterType::INTEGER), + [ + 'SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar) AND baz = :baz', + ['bar' => [1, 2, 3],'foo' => 1, 'baz' => 4], + ['bar' => Connection::PARAM_INT_ARRAY, 'foo' => ParameterType::INTEGER, 'baz' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ?', - array(1, 1, 2, 3, 4), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + [1, 1, 2, 3, 4], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters: Two lists - array( - "SELECT * FROM Foo WHERE foo IN (:a, :b)", - array('b'=>array(4, 5),'a'=>array(1, 2, 3)), - array('a'=>Connection::PARAM_INT_ARRAY, 'b'=>Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (:a, :b)', + ['b' => [4, 5],'a' => [1, 2, 3]], + ['a' => Connection::PARAM_INT_ARRAY, 'b' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?, ?, ?)', - array(1, 2, 3, 4, 5), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + [1, 2, 3, 4, 5], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters : With the same name arg type string - array( - "SELECT * FROM Foo WHERE foo <> :arg AND bar = :arg", - array('arg'=>"Some String"), - array('arg'=>ParameterType::STRING), + [ + 'SELECT * FROM Foo WHERE foo <> :arg AND bar = :arg', + ['arg' => 'Some String'], + ['arg' => ParameterType::STRING], 'SELECT * FROM Foo WHERE foo <> ? AND bar = ?', - array("Some String","Some String"), - array(ParameterType::STRING,ParameterType::STRING,) - ), + ['Some String','Some String'], + [ParameterType::STRING,ParameterType::STRING], + ], // Named parameters : With the same name arg - array( - "SELECT * FROM Foo WHERE foo IN (:arg) AND NOT bar IN (:arg)", - array('arg'=>array(1, 2, 3)), - array('arg'=>Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (:arg) AND NOT bar IN (:arg)', + ['arg' => [1, 2, 3]], + ['arg' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND NOT bar IN (?, ?, ?)', - array(1, 2, 3, 1, 2, 3), - array(ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER,ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER) - ), + [1, 2, 3, 1, 2, 3], + [ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER,ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters : Same name, other name in between DBAL-299 - array( - "SELECT * FROM Foo WHERE (:foo = 2) AND (:bar = 3) AND (:foo = 2)", - array('foo'=>2,'bar'=>3), - array('foo'=>ParameterType::INTEGER,'bar'=>ParameterType::INTEGER), + [ + 'SELECT * FROM Foo WHERE (:foo = 2) AND (:bar = 3) AND (:foo = 2)', + ['foo' => 2,'bar' => 3], + ['foo' => ParameterType::INTEGER,'bar' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE (? = 2) AND (? = 3) AND (? = 2)', - array(2, 3, 2), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + [2, 3, 2], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters : Empty "integer" array DDC-1978 - array( - "SELECT * FROM Foo WHERE foo IN (:foo)", - array('foo'=>array()), - array('foo'=>Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (:foo)', + ['foo' => []], + ['foo' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (NULL)', - array(), - array() - ), + [], + [], + ], // Named parameters : Two empty "str" array DDC-1978 - array( - "SELECT * FROM Foo WHERE foo IN (:foo) OR bar IN (:bar)", - array('foo'=>array(), 'bar'=>array()), - array('foo'=>Connection::PARAM_STR_ARRAY, 'bar'=>Connection::PARAM_STR_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar IN (:bar)', + ['foo' => [], 'bar' => []], + ['foo' => Connection::PARAM_STR_ARRAY, 'bar' => Connection::PARAM_STR_ARRAY], 'SELECT * FROM Foo WHERE foo IN (NULL) OR bar IN (NULL)', - array(), - array() - ), - array( - "SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar OR baz = :baz", - array('foo' => array(1, 2), 'bar' => 'bar', 'baz' => 'baz'), - array('foo' => Connection::PARAM_INT_ARRAY, 'baz' => 'string'), + [], + [], + ], + [ + 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar OR baz = :baz', + ['foo' => [1, 2], 'bar' => 'bar', 'baz' => 'baz'], + ['foo' => Connection::PARAM_INT_ARRAY, 'baz' => 'string'], 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ? OR baz = ?', - array(1, 2, 'bar', 'baz'), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING, 'string') - ), - array( - "SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar", - array('foo' => array(1, 2), 'bar' => 'bar'), - array('foo' => Connection::PARAM_INT_ARRAY), + [1, 2, 'bar', 'baz'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING, 'string'], + ], + [ + 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar', + ['foo' => [1, 2], 'bar' => 'bar'], + ['foo' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', - array(1, 2, 'bar'), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) - ), + [1, 2, 'bar'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], + ], // Params/types with colons - array( - "SELECT * FROM Foo WHERE foo = :foo OR bar = :bar", - array(':foo' => 'foo', ':bar' => 'bar'), - array(':foo' => ParameterType::INTEGER), + [ + 'SELECT * FROM Foo WHERE foo = :foo OR bar = :bar', + [':foo' => 'foo', ':bar' => 'bar'], + [':foo' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ? OR bar = ?', - array('foo', 'bar'), - array(ParameterType::INTEGER, ParameterType::STRING) - ), - array( - "SELECT * FROM Foo WHERE foo = :foo OR bar = :bar", - array(':foo' => 'foo', ':bar' => 'bar'), - array(':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER), + ['foo', 'bar'], + [ParameterType::INTEGER, ParameterType::STRING], + ], + [ + 'SELECT * FROM Foo WHERE foo = :foo OR bar = :bar', + [':foo' => 'foo', ':bar' => 'bar'], + [':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ? OR bar = ?', - array('foo', 'bar'), - array(ParameterType::INTEGER, ParameterType::INTEGER) - ), - array( - "SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar", - array(':foo' => array(1, 2), ':bar' => 'bar'), - array('foo' => Connection::PARAM_INT_ARRAY), + ['foo', 'bar'], + [ParameterType::INTEGER, ParameterType::INTEGER], + ], + [ + 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar', + [':foo' => [1, 2], ':bar' => 'bar'], + ['foo' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', - array(1, 2, 'bar'), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) - ), - array( - "SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar", - array('foo' => array(1, 2), 'bar' => 'bar'), - array(':foo' => Connection::PARAM_INT_ARRAY), + [1, 2, 'bar'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], + ], + [ + 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar', + ['foo' => [1, 2], 'bar' => 'bar'], + [':foo' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', - array(1, 2, 'bar'), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) - ), + [1, 2, 'bar'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], + ], // DBAL-522 - null valued parameters are not considered - array( + [ 'INSERT INTO Foo (foo, bar) values (:foo, :bar)', - array('foo' => 1, 'bar' => null), - array(':foo' => ParameterType::INTEGER, ':bar' => ParameterType::NULL), + ['foo' => 1, 'bar' => null], + [':foo' => ParameterType::INTEGER, ':bar' => ParameterType::NULL], 'INSERT INTO Foo (foo, bar) values (?, ?)', - array(1, null), - array(ParameterType::INTEGER, ParameterType::NULL) - ), - array( + [1, null], + [ParameterType::INTEGER, ParameterType::NULL], + ], + [ 'INSERT INTO Foo (foo, bar) values (?, ?)', - array(1, null), - array(ParameterType::INTEGER, ParameterType::NULL), + [1, null], + [ParameterType::INTEGER, ParameterType::NULL], 'INSERT INTO Foo (foo, bar) values (?, ?)', - array(1, null), - array(ParameterType::INTEGER, ParameterType::NULL) - ), + [1, null], + [ParameterType::INTEGER, ParameterType::NULL], + ], // DBAL-1205 - Escaped single quotes SQL- and C-Style - array( + [ "SELECT * FROM Foo WHERE foo = :foo||''':not_a_param''\\'' OR bar = ''':not_a_param''\\'':bar", - array(':foo' => 1, ':bar' => 2), - array(':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER), + [':foo' => 1, ':bar' => 2], + [':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ?||\'\'\':not_a_param\'\'\\\'\' OR bar = \'\'\':not_a_param\'\'\\\'\'?', - array(1, 2), - array(ParameterType::INTEGER, ParameterType::INTEGER) - ), - ); + [1, 2], + [ParameterType::INTEGER, ParameterType::INTEGER], + ], + ]; } /** @@ -405,53 +412,53 @@ public function dataExpandListParameters() */ public function testExpandListParameters($q, $p, $t, $expectedQuery, $expectedParams, $expectedTypes) { - list($query, $params, $types) = SQLParserUtils::expandListParameters($q, $p, $t); + [$query, $params, $types] = SQLParserUtils::expandListParameters($q, $p, $t); - self::assertEquals($expectedQuery, $query, "Query was not rewritten correctly."); - self::assertEquals($expectedParams, $params, "Params dont match"); - self::assertEquals($expectedTypes, $types, "Types dont match"); + self::assertEquals($expectedQuery, $query, 'Query was not rewritten correctly.'); + self::assertEquals($expectedParams, $params, 'Params dont match'); + self::assertEquals($expectedTypes, $types, 'Types dont match'); } public function dataQueryWithMissingParameters() { - return array( - array( - "SELECT * FROM foo WHERE bar = :param", - array('other' => 'val'), - array(), - ), - array( - "SELECT * FROM foo WHERE bar = :param", - array(), - array(), - ), - array( - "SELECT * FROM foo WHERE bar = :param", - array(), - array('param' => Connection::PARAM_INT_ARRAY), - ), - array( - "SELECT * FROM foo WHERE bar = :param", - array(), - array(':param' => Connection::PARAM_INT_ARRAY), - ), - array( - "SELECT * FROM foo WHERE bar = :param", - array(), - array('bar' => Connection::PARAM_INT_ARRAY), - ), - array( - "SELECT * FROM foo WHERE bar = :param", - array('bar' => 'value'), - array('bar' => Connection::PARAM_INT_ARRAY), - ), - ); + return [ + [ + 'SELECT * FROM foo WHERE bar = :param', + ['other' => 'val'], + [], + ], + [ + 'SELECT * FROM foo WHERE bar = :param', + [], + [], + ], + [ + 'SELECT * FROM foo WHERE bar = :param', + [], + ['param' => Connection::PARAM_INT_ARRAY], + ], + [ + 'SELECT * FROM foo WHERE bar = :param', + [], + [':param' => Connection::PARAM_INT_ARRAY], + ], + [ + 'SELECT * FROM foo WHERE bar = :param', + [], + ['bar' => Connection::PARAM_INT_ARRAY], + ], + [ + 'SELECT * FROM foo WHERE bar = :param', + ['bar' => 'value'], + ['bar' => Connection::PARAM_INT_ARRAY], + ], + ]; } /** * @dataProvider dataQueryWithMissingParameters */ - public function testExceptionIsThrownForMissingParam($query, $params, $types = array()) + public function testExceptionIsThrownForMissingParam($query, $params, $types = []) { $this->expectException('Doctrine\DBAL\SQLParserUtilsException'); $this->expectExceptionMessage('Value for :param not found in params array. Params array key should be "param"'); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php index 13bf74f6aff..046118f91fa 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php @@ -5,8 +5,9 @@ use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; -class ColumnDiffTest extends \PHPUnit\Framework\TestCase +class ColumnDiffTest extends TestCase { /** * @group DBAL-1255 @@ -14,15 +15,15 @@ class ColumnDiffTest extends \PHPUnit\Framework\TestCase public function testPreservesOldColumnNameQuotation() { $fromColumn = new Column('"foo"', Type::getType(Type::INTEGER)); - $toColumn = new Column('bar', Type::getType(Type::INTEGER)); + $toColumn = new Column('bar', Type::getType(Type::INTEGER)); - $columnDiff = new ColumnDiff('"foo"', $toColumn, array()); + $columnDiff = new ColumnDiff('"foo"', $toColumn, []); self::assertTrue($columnDiff->getOldColumnName()->isQuoted()); - $columnDiff = new ColumnDiff('"foo"', $toColumn, array(), $fromColumn); + $columnDiff = new ColumnDiff('"foo"', $toColumn, [], $fromColumn); self::assertTrue($columnDiff->getOldColumnName()->isQuoted()); - $columnDiff = new ColumnDiff('foo', $toColumn, array(), $fromColumn); + $columnDiff = new ColumnDiff('foo', $toColumn, [], $fromColumn); self::assertTrue($columnDiff->getOldColumnName()->isQuoted()); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php index c78595442fa..51fe749e28e 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php @@ -2,17 +2,20 @@ namespace Doctrine\Tests\DBAL\Schema; -use Doctrine\DBAL\Exception\InvalidArgumentException; +use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; -class ColumnTest extends \PHPUnit\Framework\TestCase +class ColumnTest extends TestCase { public function testGet() { $column = $this->createColumn(); - self::assertEquals("foo", $column->getName()); + self::assertEquals('foo', $column->getName()); self::assertSame(Type::getType('string'), $column->getType()); self::assertEquals(200, $column->getLength()); @@ -21,14 +24,14 @@ public function testGet() self::assertTrue($column->getUnsigned()); self::assertFalse($column->getNotNull()); self::assertTrue($column->getFixed()); - self::assertEquals("baz", $column->getDefault()); + self::assertEquals('baz', $column->getDefault()); - self::assertEquals(array('foo' => 'bar'), $column->getPlatformOptions()); + self::assertEquals(['foo' => 'bar'], $column->getPlatformOptions()); self::assertTrue($column->hasPlatformOption('foo')); self::assertEquals('bar', $column->getPlatformOption('foo')); self::assertFalse($column->hasPlatformOption('bar')); - self::assertEquals(array('bar' => 'baz'), $column->getCustomSchemaOptions()); + self::assertEquals(['bar' => 'baz'], $column->getCustomSchemaOptions()); self::assertTrue($column->hasCustomSchemaOption('bar')); self::assertEquals('baz', $column->getCustomSchemaOption('bar')); self::assertFalse($column->hasCustomSchemaOption('foo')); @@ -36,7 +39,7 @@ public function testGet() public function testToArray() { - $expected = array( + $expected = [ 'name' => 'foo', 'type' => Type::getType('string'), 'default' => 'baz', @@ -50,8 +53,8 @@ public function testToArray() 'columnDefinition' => null, 'comment' => null, 'foo' => 'bar', - 'bar' => 'baz' - ); + 'bar' => 'baz', + ]; self::assertEquals($expected, $this->createColumn()->toArray()); } @@ -83,7 +86,7 @@ public function testOptionsShouldNotBeIgnored() : void */ public function createColumn() { - $options = array( + $options = [ 'length' => 200, 'precision' => 5, 'scale' => 2, @@ -91,12 +94,12 @@ public function createColumn() 'notnull' => false, 'fixed' => true, 'default' => 'baz', - 'platformOptions' => array('foo' => 'bar'), - 'customSchemaOptions' => array('bar' => 'baz'), - ); + 'platformOptions' => ['foo' => 'bar'], + 'customSchemaOptions' => ['bar' => 'baz'], + ]; $string = Type::getType('string'); - return new Column("foo", $string, $options); + return new Column('foo', $string, $options); } /** @@ -106,18 +109,18 @@ public function createColumn() public function testQuotedColumnName() { $string = Type::getType('string'); - $column = new Column("`bar`", $string, array()); + $column = new Column('`bar`', $string, []); - $mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform(); - $sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform(); + $mysqlPlatform = new MySqlPlatform(); + $sqlitePlatform = new SqlitePlatform(); self::assertEquals('bar', $column->getName()); self::assertEquals('`bar`', $column->getQuotedName($mysqlPlatform)); self::assertEquals('"bar"', $column->getQuotedName($sqlitePlatform)); - $column = new Column("[bar]", $string); + $column = new Column('[bar]', $string); - $sqlServerPlatform = new \Doctrine\DBAL\Platforms\SQLServerPlatform(); + $sqlServerPlatform = new SQLServerPlatform(); self::assertEquals('bar', $column->getName()); self::assertEquals('[bar]', $column->getQuotedName($sqlServerPlatform)); @@ -129,7 +132,7 @@ public function testQuotedColumnName() */ public function testIsQuoted($columnName, $isQuoted) { - $type = Type::getType('string'); + $type = Type::getType('string'); $column = new Column($columnName, $type); self::assertSame($isQuoted, $column->isQuoted()); @@ -137,12 +140,12 @@ public function testIsQuoted($columnName, $isQuoted) public function getIsQuoted() { - return array( - array('bar', false), - array('`bar`', true), - array('"bar"', true), - array('[bar]', true), - ); + return [ + ['bar', false], + ['`bar`', true], + ['"bar"', true], + ['[bar]', true], + ]; } /** @@ -150,11 +153,11 @@ public function getIsQuoted() */ public function testColumnComment() { - $column = new Column("bar", Type::getType('string')); + $column = new Column('bar', Type::getType('string')); self::assertNull($column->getComment()); - $column->setComment("foo"); - self::assertEquals("foo", $column->getComment()); + $column->setComment('foo'); + self::assertEquals('foo', $column->getComment()); $columnArray = $column->toArray(); self::assertArrayHasKey('comment', $columnArray); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 24d097c3006..b0b27d09d79 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -31,169 +31,176 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; use function array_keys; /** - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org - * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @since 2.0 - * @version $Revision$ - * @author Benjamin Eberlei */ -class ComparatorTest extends \PHPUnit\Framework\TestCase +class ComparatorTest extends TestCase { public function testCompareSame1() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( - 'integerfield1' => new Column('integerfield1', Type::getType('integer' ) ), - ) + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ + 'integerfield1' => new Column('integerfield1', Type::getType('integer')), + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( - 'integerfield1' => new Column('integerfield1', Type::getType('integer') ), - ) + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ + 'integerfield1' => new Column('integerfield1', Type::getType('integer')), + ] ), - ) ); + ]); - $expected = new SchemaDiff(); + $expected = new SchemaDiff(); $expected->fromSchema = $schema1; - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareSame2() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield2' => new Column('integerfield2', Type::getType('integer')), 'integerfield1' => new Column('integerfield1', Type::getType('integer')), - ) + ] ), - ) ); + ]); - $expected = new SchemaDiff(); + $expected = new SchemaDiff(); $expected->fromSchema = $schema1; - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareMissingTable() { - $schemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig; - $table = new Table('bugdb', array ('integerfield1' => new Column('integerfield1', Type::getType('integer')))); + $schemaConfig = new SchemaConfig(); + $table = new Table('bugdb', ['integerfield1' => new Column('integerfield1', Type::getType('integer'))]); $table->setSchemaConfig($schemaConfig); - $schema1 = new Schema( array($table), array(), $schemaConfig ); - $schema2 = new Schema( array(), array(), $schemaConfig ); + $schema1 = new Schema([$table], [], $schemaConfig); + $schema2 = new Schema([], [], $schemaConfig); - $expected = new SchemaDiff( array(), array(), array('bugdb' => $table), $schema1 ); + $expected = new SchemaDiff([], [], ['bugdb' => $table], $schema1); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareNewTable() { - $schemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig; - $table = new Table('bugdb', array ('integerfield1' => new Column('integerfield1', Type::getType('integer')))); + $schemaConfig = new SchemaConfig(); + $table = new Table('bugdb', ['integerfield1' => new Column('integerfield1', Type::getType('integer'))]); $table->setSchemaConfig($schemaConfig); - $schema1 = new Schema( array(), array(), $schemaConfig ); - $schema2 = new Schema( array($table), array(), $schemaConfig ); + $schema1 = new Schema([], [], $schemaConfig); + $schema2 = new Schema([$table], [], $schemaConfig); - $expected = new SchemaDiff( array('bugdb' => $table), array(), array(), $schema1 ); + $expected = new SchemaDiff(['bugdb' => $table], [], [], $schema1); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareOnlyAutoincrementChanged() { - $column1 = new Column('foo', Type::getType('integer'), array('autoincrement' => true)); - $column2 = new Column('foo', Type::getType('integer'), array('autoincrement' => false)); + $column1 = new Column('foo', Type::getType('integer'), ['autoincrement' => true]); + $column2 = new Column('foo', Type::getType('integer'), ['autoincrement' => false]); - $comparator = new Comparator(); + $comparator = new Comparator(); $changedProperties = $comparator->diffColumn($column1, $column2); - self::assertEquals(array('autoincrement'), $changedProperties); + self::assertEquals(['autoincrement'], $changedProperties); } public function testCompareMissingField() { $missingColumn = new Column('integerfield1', Type::getType('integer')); - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => $missingColumn, 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff( 'bugdb', array(), array(), - array ( - 'integerfield1' => $missingColumn, - ) - ) - ) + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [], + [], + ['integerfield1' => $missingColumn] + ), + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareNewField() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), - ) + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff ('bugdb', - array ( + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [ 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareChangedColumns_ChangeType() @@ -202,8 +209,8 @@ public function testCompareChangedColumns_ChangeType() $column2 = new Column('charfield1', Type::getType('integer')); $c = new Comparator(); - self::assertEquals(array('type'), $c->diffColumn($column1, $column2)); - self::assertEquals(array(), $c->diffColumn($column1, $column1)); + self::assertEquals(['type'], $c->diffColumn($column1, $column2)); + self::assertEquals([], $c->diffColumn($column1, $column1)); } public function testCompareChangedColumns_ChangeCustomSchemaOption() @@ -218,216 +225,245 @@ public function testCompareChangedColumns_ChangeCustomSchemaOption() $column2->setCustomSchemaOption('foo2', 'bar2'); $c = new Comparator(); - self::assertEquals(array('foo1', 'foo2'), $c->diffColumn($column1, $column2)); - self::assertEquals(array(), $c->diffColumn($column1, $column1)); + self::assertEquals(['foo1', 'foo2'], $c->diffColumn($column1, $column2)); + self::assertEquals([], $c->diffColumn($column1, $column1)); } public function testCompareChangeColumns_MultipleNewColumnsRename() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('datefield1', 'datetime'); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('new_datefield1', 'datetime'); $tableB->addColumn('new_datefield2', 'datetime'); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); - self::assertCount(1, $tableDiff->renamedColumns, "we should have one rename datefield1 => new_datefield1."); + self::assertCount(1, $tableDiff->renamedColumns, 'we should have one rename datefield1 => new_datefield1.'); self::assertArrayHasKey('datefield1', $tableDiff->renamedColumns, "'datefield1' should be set to be renamed to new_datefield1"); self::assertCount(1, $tableDiff->addedColumns, "'new_datefield2' should be added"); self::assertArrayHasKey('new_datefield2', $tableDiff->addedColumns, "'new_datefield2' should be added, not created through renaming!"); - self::assertCount(0, $tableDiff->removedColumns, "Nothing should be removed."); - self::assertCount(0, $tableDiff->changedColumns, "Nothing should be changed as all fields old & new have diff names."); + self::assertCount(0, $tableDiff->removedColumns, 'Nothing should be removed.'); + self::assertCount(0, $tableDiff->changedColumns, 'Nothing should be changed as all fields old & new have diff names.'); } public function testCompareRemovedIndex() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', - array( - 'integerfield1' - ), + ], + [ + 'primary' => new Index( + 'primary', + ['integerfield1'], true - ) - ) + ), + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff( 'bugdb', array(), array(), array(), array(), array(), - array ( - 'primary' => new Index('primary', - array( - 'integerfield1' + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [], + [], + [], + [], + [], + [ + 'primary' => new Index( + 'primary', + ['integerfield1'], + true ), - true - ) - ) + ] ), - ) + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareNewIndex() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', - array( - 'integerfield1' - ), + ], + [ + 'primary' => new Index( + 'primary', + ['integerfield1'], true - ) - ) + ), + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff( 'bugdb', array(), array(), array(), - array ( - 'primary' => new Index('primary', - array( - 'integerfield1' - ), + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [], + [], + [], + [ + 'primary' => new Index( + 'primary', + ['integerfield1'], true - ) - ) + ), + ] ), - ) + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareChangedIndex() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', - array( - 'integerfield1' - ), + ], + [ + 'primary' => new Index( + 'primary', + ['integerfield1'], true - ) - ) + ), + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', - array('integerfield1', 'integerfield2'), + ], + [ + 'primary' => new Index( + 'primary', + ['integerfield1', 'integerfield2'], true - ) - ) + ), + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff( 'bugdb', array(), array(), array(), array(), - array ( - 'primary' => new Index('primary', - array( + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [], + [], + [], + [], + [ + 'primary' => new Index( + 'primary', + [ 'integerfield1', - 'integerfield2' - ), + 'integerfield2', + ], true - ) - ) + ), + ] ), - ) + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 )); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareChangedIndexFieldPositions() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', array('integerfield1', 'integerfield2'), true) - ) + ], + [ + 'primary' => new Index('primary', ['integerfield1', 'integerfield2'], true), + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', array('integerfield2', 'integerfield1'), true) - ) + ], + [ + 'primary' => new Index('primary', ['integerfield2', 'integerfield1'], true), + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff('bugdb', array(), array(), array(), array(), - array ( - 'primary' => new Index('primary', array('integerfield2', 'integerfield1'), true) - ) + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [], + [], + [], + [], + [ + 'primary' => new Index('primary', ['integerfield2', 'integerfield1'], true), + ] ), - ) + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 )); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareSequences() @@ -447,11 +483,11 @@ public function testCompareSequences() public function testRemovedSequence() { $schema1 = new Schema(); - $seq = $schema1->createSequence('foo'); + $seq = $schema1->createSequence('foo'); $schema2 = new Schema(); - $c = new Comparator(); + $c = new Comparator(); $diffSchema = $c->compare($schema1, $schema2); self::assertCount(1, $diffSchema->removedSequences); @@ -463,9 +499,9 @@ public function testAddedSequence() $schema1 = new Schema(); $schema2 = new Schema(); - $seq = $schema2->createSequence('foo'); + $seq = $schema2->createSequence('foo'); - $c = new Comparator(); + $c = new Comparator(); $diffSchema = $c->compare($schema1, $schema2); self::assertCount(1, $diffSchema->newSequences); @@ -474,17 +510,17 @@ public function testAddedSequence() public function testTableAddForeignKey() { - $tableForeign = new Table("bar"); + $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); - $table1 = new Table("foo"); + $table1 = new Table('foo'); $table1->addColumn('fk', 'integer'); - $table2 = new Table("foo"); + $table2 = new Table('foo'); $table2->addColumn('fk', 'integer'); - $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); + $table2->addForeignKeyConstraint($tableForeign, ['fk'], ['id']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($table1, $table2); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); @@ -493,17 +529,17 @@ public function testTableAddForeignKey() public function testTableRemoveForeignKey() { - $tableForeign = new Table("bar"); + $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); - $table1 = new Table("foo"); + $table1 = new Table('foo'); $table1->addColumn('fk', 'integer'); - $table2 = new Table("foo"); + $table2 = new Table('foo'); $table2->addColumn('fk', 'integer'); - $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); + $table2->addForeignKeyConstraint($tableForeign, ['fk'], ['id']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($table2, $table1); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); @@ -512,18 +548,18 @@ public function testTableRemoveForeignKey() public function testTableUpdateForeignKey() { - $tableForeign = new Table("bar"); + $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); - $table1 = new Table("foo"); + $table1 = new Table('foo'); $table1->addColumn('fk', 'integer'); - $table1->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); + $table1->addForeignKeyConstraint($tableForeign, ['fk'], ['id']); - $table2 = new Table("foo"); + $table2 = new Table('foo'); $table2->addColumn('fk', 'integer'); - $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id'), array('onUpdate' => 'CASCADE')); + $table2->addForeignKeyConstraint($tableForeign, ['fk'], ['id'], ['onUpdate' => 'CASCADE']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($table1, $table2); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); @@ -532,21 +568,21 @@ public function testTableUpdateForeignKey() public function testMovedForeignKeyForeignTable() { - $tableForeign = new Table("bar"); + $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); - $tableForeign2 = new Table("bar2"); + $tableForeign2 = new Table('bar2'); $tableForeign2->addColumn('id', 'integer'); - $table1 = new Table("foo"); + $table1 = new Table('foo'); $table1->addColumn('fk', 'integer'); - $table1->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); + $table1->addForeignKeyConstraint($tableForeign, ['fk'], ['id']); - $table2 = new Table("foo"); + $table2 = new Table('foo'); $table2->addColumn('fk', 'integer'); - $table2->addForeignKeyConstraint($tableForeign2, array('fk'), array('id')); + $table2->addForeignKeyConstraint($tableForeign2, ['fk'], ['id']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($table1, $table2); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); @@ -567,7 +603,7 @@ public function testTablesCaseInsensitive() $schemaB->createTable('Baz'); $schemaB->createTable('old'); - $c = new Comparator(); + $c = new Comparator(); $diff = $c->compare($schemaA, $schemaB); self::assertSchemaTableChangeCount($diff, 1, 0, 1); @@ -587,7 +623,7 @@ public function testSequencesCaseInsensitive() $schemaB->createSequence('baz'); $schemaB->createSequence('old'); - $c = new Comparator(); + $c = new Comparator(); $diff = $c->compare($schemaA, $schemaB); self::assertSchemaSequenceChangeCount($diff, 1, 0, 1); @@ -595,13 +631,13 @@ public function testSequencesCaseInsensitive() public function testCompareColumnCompareCaseInsensitive() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('id', 'integer'); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('ID', 'integer'); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); self::assertFalse($tableDiff); @@ -609,18 +645,18 @@ public function testCompareColumnCompareCaseInsensitive() public function testCompareIndexBasedOnPropertiesNotName() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('id', 'integer'); - $tableA->addIndex(array("id"), "foo_bar_idx"); + $tableA->addIndex(['id'], 'foo_bar_idx'); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('ID', 'integer'); - $tableB->addIndex(array("id"), "bar_foo_idx"); + $tableB->addIndex(['id'], 'bar_foo_idx'); - $c = new Comparator(); - $tableDiff = new TableDiff('foo'); - $tableDiff->fromTable = $tableA; - $tableDiff->renamedIndexes['foo_bar_idx'] = new Index('bar_foo_idx', array('id')); + $c = new Comparator(); + $tableDiff = new TableDiff('foo'); + $tableDiff->fromTable = $tableA; + $tableDiff->renamedIndexes['foo_bar_idx'] = new Index('bar_foo_idx', ['id']); self::assertEquals( $tableDiff, @@ -630,15 +666,15 @@ public function testCompareIndexBasedOnPropertiesNotName() public function testCompareForeignKeyBasedOnPropertiesNotName() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('id', 'integer'); - $tableA->addNamedForeignKeyConstraint('foo_constraint', 'bar', array('id'), array('id')); + $tableA->addNamedForeignKeyConstraint('foo_constraint', 'bar', ['id'], ['id']); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('ID', 'integer'); - $tableB->addNamedForeignKeyConstraint('bar_constraint', 'bar', array('id'), array('id')); + $tableB->addNamedForeignKeyConstraint('bar_constraint', 'bar', ['id'], ['id']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); self::assertFalse($tableDiff); @@ -646,8 +682,8 @@ public function testCompareForeignKeyBasedOnPropertiesNotName() public function testCompareForeignKey_RestrictNoAction_AreTheSame() { - $fk1 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'NO ACTION')); - $fk2 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'RESTRICT')); + $fk1 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'NO ACTION']); + $fk2 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'RESTRICT']); $c = new Comparator(); self::assertFalse($c->diffForeignKey($fk1, $fk2)); @@ -658,8 +694,8 @@ public function testCompareForeignKey_RestrictNoAction_AreTheSame() */ public function testCompareForeignKeyNamesUnqualified_AsNoSchemaInformationIsAvailable() { - $fk1 = new ForeignKeyConstraint(array("foo"), "foo.bar", array("baz"), "fk1"); - $fk2 = new ForeignKeyConstraint(array("foo"), "baz.bar", array("baz"), "fk1"); + $fk1 = new ForeignKeyConstraint(['foo'], 'foo.bar', ['baz'], 'fk1'); + $fk2 = new ForeignKeyConstraint(['foo'], 'baz.bar', ['baz'], 'fk1'); $c = new Comparator(); self::assertFalse($c->diffForeignKey($fk1, $fk2)); @@ -667,13 +703,13 @@ public function testCompareForeignKeyNamesUnqualified_AsNoSchemaInformationIsAva public function testDetectRenameColumn() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('foo', 'integer'); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('bar', 'integer'); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); self::assertCount(0, $tableDiff->addedColumns); @@ -691,14 +727,14 @@ public function testDetectRenameColumn() */ public function testDetectRenameColumnAmbiguous() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('foo', 'integer'); $tableA->addColumn('bar', 'integer'); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('baz', 'integer'); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); self::assertCount(1, $tableDiff->addedColumns, "'baz' should be added, not created through renaming!"); @@ -706,7 +742,7 @@ public function testDetectRenameColumnAmbiguous() self::assertCount(2, $tableDiff->removedColumns, "'foo' and 'bar' should both be dropped, an ambiguity exists which one could be renamed to 'baz'."); self::assertArrayHasKey('foo', $tableDiff->removedColumns, "'foo' should be removed."); self::assertArrayHasKey('bar', $tableDiff->removedColumns, "'bar' should be removed."); - self::assertCount(0, $tableDiff->renamedColumns, "no renamings should take place."); + self::assertCount(0, $tableDiff->renamedColumns, 'no renamings should take place.'); } /** @@ -719,12 +755,12 @@ public function testDetectRenameIndex() $table2 = clone $table1; - $table1->addIndex(array('foo'), 'idx_foo'); + $table1->addIndex(['foo'], 'idx_foo'); - $table2->addIndex(array('foo'), 'idx_bar'); + $table2->addIndex(['foo'], 'idx_bar'); $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($table1, $table2); + $tableDiff = $comparator->diffTable($table1, $table2); self::assertCount(0, $tableDiff->addedIndexes); self::assertCount(0, $tableDiff->removedIndexes); @@ -746,13 +782,13 @@ public function testDetectRenameIndexAmbiguous() $table2 = clone $table1; - $table1->addIndex(array('foo'), 'idx_foo'); - $table1->addIndex(array('foo'), 'idx_bar'); + $table1->addIndex(['foo'], 'idx_foo'); + $table1->addIndex(['foo'], 'idx_bar'); - $table2->addIndex(array('foo'), 'idx_baz'); + $table2->addIndex(['foo'], 'idx_baz'); $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($table1, $table2); + $tableDiff = $comparator->diffTable($table1, $table2); self::assertCount(1, $tableDiff->addedIndexes); self::assertArrayHasKey('idx_baz', $tableDiff->addedIndexes); @@ -766,13 +802,13 @@ public function testDetectChangeIdentifierType() { $this->markTestSkipped('DBAL-2 was reopened, this test cannot work anymore.'); - $tableA = new Table("foo"); - $tableA->addColumn('id', 'integer', array('autoincrement' => false)); + $tableA = new Table('foo'); + $tableA->addColumn('id', 'integer', ['autoincrement' => false]); - $tableB = new Table("foo"); - $tableB->addColumn('id', 'integer', array('autoincrement' => true)); + $tableB = new Table('foo'); + $tableB->addColumn('id', 'integer', ['autoincrement' => true]); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); @@ -785,25 +821,25 @@ public function testDetectChangeIdentifierType() */ public function testDiff() { - $table = new \Doctrine\DBAL\Schema\Table('twitter_users'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('twitter_users'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('twitterId', 'integer'); $table->addColumn('displayName', 'string'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); - $newtable = new \Doctrine\DBAL\Schema\Table('twitter_users'); - $newtable->addColumn('id', 'integer', array('autoincrement' => true)); + $newtable = new Table('twitter_users'); + $newtable->addColumn('id', 'integer', ['autoincrement' => true]); $newtable->addColumn('twitter_id', 'integer'); $newtable->addColumn('display_name', 'string'); $newtable->addColumn('logged_in_at', 'datetime'); - $newtable->setPrimaryKey(array('id')); + $newtable->setPrimaryKey(['id']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($table, $newtable); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); - self::assertEquals(array('twitterid', 'displayname'), array_keys($tableDiff->renamedColumns)); - self::assertEquals(array('logged_in_at'), array_keys($tableDiff->addedColumns)); + self::assertEquals(['twitterid', 'displayname'], array_keys($tableDiff->renamedColumns)); + self::assertEquals(['logged_in_at'], array_keys($tableDiff->addedColumns)); self::assertCount(0, $tableDiff->removedColumns); } @@ -813,17 +849,17 @@ public function testDiff() */ public function testChangedSequence() { - $schema = new Schema(); + $schema = new Schema(); $sequence = $schema->createSequence('baz'); $schemaNew = clone $schema; /* @var $schemaNew Schema */ $schemaNew->getSequence('baz')->setAllocationSize(20); - $c = new \Doctrine\DBAL\Schema\Comparator; + $c = new Comparator(); $diff = $c->compare($schema, $schemaNew); - self::assertSame($diff->changedSequences[0] , $schemaNew->getSequence('baz')); + self::assertSame($diff->changedSequences[0], $schemaNew->getSequence('baz')); } /** @@ -837,7 +873,7 @@ public function testDiffDecimalWithNullPrecision() $column2 = new Column('foo', Type::getType('decimal')); $c = new Comparator(); - self::assertEquals(array(), $c->diffColumn($column, $column2)); + self::assertEquals([], $c->diffColumn($column, $column2)); } /** @@ -846,15 +882,15 @@ public function testDiffDecimalWithNullPrecision() public function testFqnSchemaComparison() { $config = new SchemaConfig(); - $config->setName("foo"); + $config->setName('foo'); - $oldSchema = new Schema(array(), array(), $config); + $oldSchema = new Schema([], [], $config); $oldSchema->createTable('bar'); - $newSchema= new Schema(array(), array(), $config); + $newSchema = new Schema([], [], $config); $newSchema->createTable('foo.bar'); - $expected = new SchemaDiff(); + $expected = new SchemaDiff(); $expected->fromSchema = $oldSchema; self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema)); @@ -866,24 +902,24 @@ public function testFqnSchemaComparison() public function testNamespacesComparison() { $config = new SchemaConfig(); - $config->setName("schemaName"); + $config->setName('schemaName'); - $oldSchema = new Schema(array(), array(), $config); + $oldSchema = new Schema([], [], $config); $oldSchema->createTable('taz'); $oldSchema->createTable('war.tab'); - $newSchema= new Schema(array(), array(), $config); + $newSchema = new Schema([], [], $config); $newSchema->createTable('bar.tab'); $newSchema->createTable('baz.tab'); $newSchema->createTable('war.tab'); - $expected = new SchemaDiff(); - $expected->fromSchema = $oldSchema; - $expected->newNamespaces = array('bar' => 'bar', 'baz' => 'baz'); + $expected = new SchemaDiff(); + $expected->fromSchema = $oldSchema; + $expected->newNamespaces = ['bar' => 'bar', 'baz' => 'baz']; $diff = Comparator::compareSchemas($oldSchema, $newSchema); - self::assertEquals(array('bar' => 'bar', 'baz' => 'baz'), $diff->newNamespaces); + self::assertEquals(['bar' => 'bar', 'baz' => 'baz'], $diff->newNamespaces); self::assertCount(2, $diff->newTables); } @@ -893,15 +929,15 @@ public function testNamespacesComparison() public function testFqnSchemaComparisonDifferentSchemaNameButSameTableNoDiff() { $config = new SchemaConfig(); - $config->setName("foo"); + $config->setName('foo'); - $oldSchema = new Schema(array(), array(), $config); + $oldSchema = new Schema([], [], $config); $oldSchema->createTable('foo.bar'); $newSchema = new Schema(); $newSchema->createTable('bar'); - $expected = new SchemaDiff(); + $expected = new SchemaDiff(); $expected->fromSchema = $oldSchema; self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema)); @@ -913,14 +949,14 @@ public function testFqnSchemaComparisonDifferentSchemaNameButSameTableNoDiff() public function testFqnSchemaComparisonNoSchemaSame() { $config = new SchemaConfig(); - $config->setName("foo"); - $oldSchema = new Schema(array(), array(), $config); + $config->setName('foo'); + $oldSchema = new Schema([], [], $config); $oldSchema->createTable('bar'); $newSchema = new Schema(); $newSchema->createTable('bar'); - $expected = new SchemaDiff(); + $expected = new SchemaDiff(); $expected->fromSchema = $oldSchema; self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema)); @@ -932,17 +968,17 @@ public function testFqnSchemaComparisonNoSchemaSame() public function testAutoIncrementSequences() { $oldSchema = new Schema(); - $table = $oldSchema->createTable("foo"); - $table->addColumn("id", "integer", array("autoincrement" => true)); - $table->setPrimaryKey(array("id")); - $oldSchema->createSequence("foo_id_seq"); + $table = $oldSchema->createTable('foo'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); + $oldSchema->createSequence('foo_id_seq'); $newSchema = new Schema(); - $table = $newSchema->createTable("foo"); - $table->addColumn("id", "integer", array("autoincrement" => true)); - $table->setPrimaryKey(array("id")); + $table = $newSchema->createTable('foo'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); - $c = new Comparator(); + $c = new Comparator(); $diff = $c->compare($oldSchema, $newSchema); self::assertCount(0, $diff->removedSequences); @@ -956,17 +992,17 @@ public function testAutoIncrementSequences() public function testAutoIncrementNoSequences() { $oldSchema = new Schema(); - $table = $oldSchema->createTable("foo"); - $table->addColumn("id", "integer", array("autoincrement" => true)); - $table->setPrimaryKey(array("id")); + $table = $oldSchema->createTable('foo'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); $newSchema = new Schema(); - $table = $newSchema->createTable("foo"); - $table->addColumn("id", "integer", array("autoincrement" => true)); - $table->setPrimaryKey(array("id")); - $newSchema->createSequence("foo_id_seq"); + $table = $newSchema->createTable('foo'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); + $newSchema->createSequence('foo_id_seq'); - $c = new Comparator(); + $c = new Comparator(); $diff = $c->compare($oldSchema, $newSchema); self::assertCount(0, $diff->newSequences); @@ -992,8 +1028,8 @@ public function testAvoidMultipleDropForeignKey() $tableC->addColumn('table_a_id', 'integer'); $tableC->addColumn('table_b_id', 'integer'); - $tableC->addForeignKeyConstraint($tableA, array('table_a_id'), array('id')); - $tableC->addForeignKeyConstraint($tableB, array('table_b_id'), array('id')); + $tableC->addForeignKeyConstraint($tableA, ['table_a_id'], ['id']); + $tableC->addForeignKeyConstraint($tableB, ['table_b_id'], ['id']); $newSchema = new Schema(); @@ -1018,16 +1054,16 @@ public function testCompareChangedColumn() $tableFoo->addColumn('id', 'integer'); $newSchema = new Schema(); - $table = $newSchema->createTable('foo'); + $table = $newSchema->createTable('foo'); $table->addColumn('id', 'string'); - $expected = new SchemaDiff(); - $expected->fromSchema = $oldSchema; - $tableDiff = $expected->changedTables['foo'] = new TableDiff('foo'); - $tableDiff->fromTable = $tableFoo; - $columnDiff = $tableDiff->changedColumns['id'] = new ColumnDiff('id', $table->getColumn('id')); - $columnDiff->fromColumn = $tableFoo->getColumn('id'); - $columnDiff->changedProperties = array('type'); + $expected = new SchemaDiff(); + $expected->fromSchema = $oldSchema; + $tableDiff = $expected->changedTables['foo'] = new TableDiff('foo'); + $tableDiff->fromTable = $tableFoo; + $columnDiff = $tableDiff->changedColumns['id'] = new ColumnDiff('id', $table->getColumn('id')); + $columnDiff->fromColumn = $tableFoo->getColumn('id'); + $columnDiff->changedProperties = ['type']; self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema)); } @@ -1040,16 +1076,16 @@ public function testCompareChangedBinaryColumn() $tableFoo->addColumn('id', 'binary'); $newSchema = new Schema(); - $table = $newSchema->createTable('foo'); - $table->addColumn('id', 'binary', array('length' => 42, 'fixed' => true)); + $table = $newSchema->createTable('foo'); + $table->addColumn('id', 'binary', ['length' => 42, 'fixed' => true]); - $expected = new SchemaDiff(); - $expected->fromSchema = $oldSchema; - $tableDiff = $expected->changedTables['foo'] = new TableDiff('foo'); - $tableDiff->fromTable = $tableFoo; - $columnDiff = $tableDiff->changedColumns['id'] = new ColumnDiff('id', $table->getColumn('id')); - $columnDiff->fromColumn = $tableFoo->getColumn('id'); - $columnDiff->changedProperties = array('length', 'fixed'); + $expected = new SchemaDiff(); + $expected->fromSchema = $oldSchema; + $tableDiff = $expected->changedTables['foo'] = new TableDiff('foo'); + $tableDiff->fromTable = $tableFoo; + $columnDiff = $tableDiff->changedColumns['id'] = new ColumnDiff('id', $table->getColumn('id')); + $columnDiff->fromColumn = $tableFoo->getColumn('id'); + $columnDiff->changedProperties = ['length', 'fixed']; self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema)); } @@ -1059,11 +1095,11 @@ public function testCompareChangedBinaryColumn() */ public function testCompareQuotedAndUnquotedForeignKeyColumns() { - $fk1 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'NO ACTION')); - $fk2 = new ForeignKeyConstraint(array("`foo`"), "bar", array("`baz`"), "fk1", array('onDelete' => 'NO ACTION')); + $fk1 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'NO ACTION']); + $fk2 = new ForeignKeyConstraint(['`foo`'], 'bar', ['`baz`'], 'fk1', ['onDelete' => 'NO ACTION']); $comparator = new Comparator(); - $diff = $comparator->diffForeignKey($fk1, $fk2); + $diff = $comparator->diffForeignKey($fk1, $fk2); self::assertFalse($diff); } @@ -1074,7 +1110,7 @@ public function testCompareQuotedAndUnquotedForeignKeyColumns() * @param int $changeTableCount * @param int $removeTableCount */ - public function assertSchemaTableChangeCount($diff, $newTableCount=0, $changeTableCount=0, $removeTableCount=0) + public function assertSchemaTableChangeCount($diff, $newTableCount = 0, $changeTableCount = 0, $removeTableCount = 0) { self::assertCount($newTableCount, $diff->newTables); self::assertCount($changeTableCount, $diff->changedTables); @@ -1087,45 +1123,45 @@ public function assertSchemaTableChangeCount($diff, $newTableCount=0, $changeTab * @param int $changeSequenceCount * @param int $changeSequenceCount */ - public function assertSchemaSequenceChangeCount($diff, $newSequenceCount=0, $changeSequenceCount=0, $removeSequenceCount=0) + public function assertSchemaSequenceChangeCount($diff, $newSequenceCount = 0, $changeSequenceCount = 0, $removeSequenceCount = 0) { - self::assertCount($newSequenceCount, $diff->newSequences, "Expected number of new sequences is wrong."); - self::assertCount($changeSequenceCount, $diff->changedSequences, "Expected number of changed sequences is wrong."); - self::assertCount($removeSequenceCount, $diff->removedSequences, "Expected number of removed sequences is wrong."); + self::assertCount($newSequenceCount, $diff->newSequences, 'Expected number of new sequences is wrong.'); + self::assertCount($changeSequenceCount, $diff->changedSequences, 'Expected number of changed sequences is wrong.'); + self::assertCount($removeSequenceCount, $diff->removedSequences, 'Expected number of removed sequences is wrong.'); } public function testDiffColumnPlatformOptions() { - $column1 = new Column('foo', Type::getType('string'), array('platformOptions' => array('foo' => 'foo', 'bar' => 'bar'))); - $column2 = new Column('foo', Type::getType('string'), array('platformOptions' => array('foo' => 'foo', 'foobar' => 'foobar'))); - $column3 = new Column('foo', Type::getType('string'), array('platformOptions' => array('foo' => 'foo', 'bar' => 'rab'))); + $column1 = new Column('foo', Type::getType('string'), ['platformOptions' => ['foo' => 'foo', 'bar' => 'bar']]); + $column2 = new Column('foo', Type::getType('string'), ['platformOptions' => ['foo' => 'foo', 'foobar' => 'foobar']]); + $column3 = new Column('foo', Type::getType('string'), ['platformOptions' => ['foo' => 'foo', 'bar' => 'rab']]); $column4 = new Column('foo', Type::getType('string')); $comparator = new Comparator(); - self::assertEquals(array(), $comparator->diffColumn($column1, $column2)); - self::assertEquals(array(), $comparator->diffColumn($column2, $column1)); - self::assertEquals(array('bar'), $comparator->diffColumn($column1, $column3)); - self::assertEquals(array('bar'), $comparator->diffColumn($column3, $column1)); - self::assertEquals(array(), $comparator->diffColumn($column1, $column4)); - self::assertEquals(array(), $comparator->diffColumn($column4, $column1)); + self::assertEquals([], $comparator->diffColumn($column1, $column2)); + self::assertEquals([], $comparator->diffColumn($column2, $column1)); + self::assertEquals(['bar'], $comparator->diffColumn($column1, $column3)); + self::assertEquals(['bar'], $comparator->diffColumn($column3, $column1)); + self::assertEquals([], $comparator->diffColumn($column1, $column4)); + self::assertEquals([], $comparator->diffColumn($column4, $column1)); } public function testComplexDiffColumn() { - $column1 = new Column('foo', Type::getType('string'), array( - 'platformOptions' => array('foo' => 'foo'), - 'customSchemaOptions' => array('foo' => 'bar'), - )); + $column1 = new Column('foo', Type::getType('string'), [ + 'platformOptions' => ['foo' => 'foo'], + 'customSchemaOptions' => ['foo' => 'bar'], + ]); - $column2 = new Column('foo', Type::getType('string'), array( - 'platformOptions' => array('foo' => 'bar'), - )); + $column2 = new Column('foo', Type::getType('string'), [ + 'platformOptions' => ['foo' => 'bar'], + ]); $comparator = new Comparator(); - self::assertEquals(array(), $comparator->diffColumn($column1, $column2)); - self::assertEquals(array(), $comparator->diffColumn($column2, $column1)); + self::assertEquals([], $comparator->diffColumn($column1, $column2)); + self::assertEquals([], $comparator->diffColumn($column2, $column1)); } /** @@ -1135,15 +1171,15 @@ public function testComparesNamespaces() { $comparator = new Comparator(); $fromSchema = $this->getMockBuilder('Doctrine\DBAL\Schema\Schema') - ->setMethods(array('getNamespaces', 'hasNamespace')) + ->setMethods(['getNamespaces', 'hasNamespace']) ->getMock(); - $toSchema = $this->getMockBuilder('Doctrine\DBAL\Schema\Schema') - ->setMethods(array('getNamespaces', 'hasNamespace')) + $toSchema = $this->getMockBuilder('Doctrine\DBAL\Schema\Schema') + ->setMethods(['getNamespaces', 'hasNamespace']) ->getMock(); $fromSchema->expects($this->once()) ->method('getNamespaces') - ->will($this->returnValue(array('foo', 'bar'))); + ->will($this->returnValue(['foo', 'bar'])); $fromSchema->expects($this->at(0)) ->method('hasNamespace') @@ -1157,7 +1193,7 @@ public function testComparesNamespaces() $toSchema->expects($this->once()) ->method('getNamespaces') - ->will($this->returnValue(array('bar', 'baz'))); + ->will($this->returnValue(['bar', 'baz'])); $toSchema->expects($this->at(1)) ->method('hasNamespace') @@ -1169,10 +1205,10 @@ public function testComparesNamespaces() ->with('bar') ->will($this->returnValue(true)); - $expected = new SchemaDiff(); - $expected->fromSchema = $fromSchema; - $expected->newNamespaces = array('baz' => 'baz'); - $expected->removedNamespaces = array('foo' => 'foo'); + $expected = new SchemaDiff(); + $expected->fromSchema = $fromSchema; + $expected->newNamespaces = ['baz' => 'baz']; + $expected->removedNamespaces = ['foo' => 'foo']; self::assertEquals($expected, $comparator->compare($fromSchema, $toSchema)); } @@ -1181,15 +1217,15 @@ public function testCompareGuidColumns() { $comparator = new Comparator(); - $column1 = new Column('foo', Type::getType('guid'), array('comment' => 'GUID 1')); + $column1 = new Column('foo', Type::getType('guid'), ['comment' => 'GUID 1']); $column2 = new Column( 'foo', Type::getType('guid'), - array('notnull' => false, 'length' => '36', 'fixed' => true, 'default' => 'NEWID()', 'comment' => 'GUID 2.') + ['notnull' => false, 'length' => '36', 'fixed' => true, 'default' => 'NEWID()', 'comment' => 'GUID 2.'] ); - self::assertEquals(array('notnull', 'default', 'comment'), $comparator->diffColumn($column1, $column2)); - self::assertEquals(array('notnull', 'default', 'comment'), $comparator->diffColumn($column2, $column1)); + self::assertEquals(['notnull', 'default', 'comment'], $comparator->diffColumn($column1, $column2)); + self::assertEquals(['notnull', 'default', 'comment'], $comparator->diffColumn($column2, $column1)); } /** @@ -1199,12 +1235,12 @@ public function testCompareGuidColumns() */ public function testCompareColumnComments($comment1, $comment2, $equals) { - $column1 = new Column('foo', Type::getType('integer'), array('comment' => $comment1)); - $column2 = new Column('foo', Type::getType('integer'), array('comment' => $comment2)); + $column1 = new Column('foo', Type::getType('integer'), ['comment' => $comment1]); + $column2 = new Column('foo', Type::getType('integer'), ['comment' => $comment2]); $comparator = new Comparator(); - $expectedDiff = $equals ? array() : array('comment'); + $expectedDiff = $equals ? [] : ['comment']; $actualDiff = $comparator->diffColumn($column1, $column2); @@ -1217,66 +1253,74 @@ public function testCompareColumnComments($comment1, $comment2, $equals) public function getCompareColumnComments() { - return array( - array(null, null, true), - array('', '', true), - array(' ', ' ', true), - array('0', '0', true), - array('foo', 'foo', true), - - array(null, '', true), - array(null, ' ', false), - array(null, '0', false), - array(null, 'foo', false), - - array('', ' ', false), - array('', '0', false), - array('', 'foo', false), - - array(' ', '0', false), - array(' ', 'foo', false), - - array('0', 'foo', false), - ); + return [ + [null, null, true], + ['', '', true], + [' ', ' ', true], + ['0', '0', true], + ['foo', 'foo', true], + + [null, '', true], + [null, ' ', false], + [null, '0', false], + [null, 'foo', false], + + ['', ' ', false], + ['', '0', false], + ['', 'foo', false], + + [' ', '0', false], + [' ', 'foo', false], + + ['0', 'foo', false], + ]; } public function testForeignKeyRemovalWithRenamedLocalColumn() { - $fromSchema = new Schema( array( - 'table1' => new Table('table1', - array( + $fromSchema = new Schema([ + 'table1' => new Table( + 'table1', + [ 'id' => new Column('id', Type::getType('integer')), - )), - 'table2' => new Table('table2', - array( + ] + ), + 'table2' => new Table( + 'table2', + [ 'id' => new Column('id', Type::getType('integer')), - 'id_table1' => new Column('id_table1', Type::getType('integer')) - ), - array(), - array( - new ForeignKeyConstraint(array('id_table1'), 'table1', array('id'), 'fk_table2_table1') - )) - )); - $toSchema = new Schema( array( - 'table2' => new Table('table2', - array( + 'id_table1' => new Column('id_table1', Type::getType('integer')), + ], + [], + [ + new ForeignKeyConstraint(['id_table1'], 'table1', ['id'], 'fk_table2_table1'), + ] + ), + ]); + $toSchema = new Schema([ + 'table2' => new Table( + 'table2', + [ 'id' => new Column('id', Type::getType('integer')), - 'id_table3' => new Column('id_table3', Type::getType('integer')) - ), - array(), - array( - new ForeignKeyConstraint(array('id_table3'), 'table3', array('id'), 'fk_table2_table3') - )), - 'table3' => new Table('table3', - array( - 'id' => new Column('id', Type::getType('integer')) - )) - )); - $actual = Comparator::compareSchemas($fromSchema, $toSchema); - self::assertArrayHasKey("table2", $actual->changedTables); + 'id_table3' => new Column('id_table3', Type::getType('integer')), + ], + [], + [ + new ForeignKeyConstraint(['id_table3'], 'table3', ['id'], 'fk_table2_table3'), + ] + ), + 'table3' => new Table( + 'table3', + [ + 'id' => new Column('id', Type::getType('integer')), + ] + ), + ]); + $actual = Comparator::compareSchemas($fromSchema, $toSchema); + self::assertArrayHasKey('table2', $actual->changedTables); self::assertCount(1, $actual->orphanedForeignKeys); - self::assertEquals("fk_table2_table1", $actual->orphanedForeignKeys[0]->getName()); - self::assertCount(1, $actual->changedTables['table2']->addedForeignKeys, "FK to table3 should be added."); - self::assertEquals("table3", $actual->changedTables['table2']->addedForeignKeys[0]->getForeignTableName()); + self::assertEquals('fk_table2_table1', $actual->orphanedForeignKeys[0]->getName()); + self::assertCount(1, $actual->changedTables['table2']->addedForeignKeys, 'FK to table3 should be added.'); + self::assertEquals('table3', $actual->changedTables['table2']->addedForeignKeys[0]->getForeignTableName()); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php index d5592a4cbde..053ead6c1bc 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php @@ -8,28 +8,26 @@ use Doctrine\DBAL\Driver; use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Schema\DB2SchemaManager; +use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject; /** * @covers \Doctrine\DBAL\Schema\DB2SchemaManager */ -final class DB2SchemaManagerTest extends \PHPUnit\Framework\TestCase +final class DB2SchemaManagerTest extends TestCase { - /** - * @var Connection|\PHPUnit_Framework_MockObject_MockObject - */ + /** @var Connection|PHPUnit_Framework_MockObject_MockObject */ private $conn; - /** - * @var DB2SchemaManager - */ + /** @var DB2SchemaManager */ private $manager; protected function setUp() { - $eventManager = new EventManager(); - $driverMock = $this->createMock(Driver::class); - $platform = $this->createMock(DB2Platform::class); - $this->conn = $this + $eventManager = new EventManager(); + $driverMock = $this->createMock(Driver::class); + $platform = $this->createMock(DB2Platform::class); + $this->conn = $this ->getMockBuilder(Connection::class) ->setMethods(['fetchAll']) ->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager]) @@ -38,26 +36,20 @@ protected function setUp() } /** - * @group DBAL-2701 * @see https://github.com/doctrine/dbal/issues/2701 + * * @return void + * + * @group DBAL-2701 */ public function testListTableNamesFiltersAssetNamesCorrectly() { $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ - [ - 'name' => 'FOO', - ], - [ - 'name' => 'T_FOO', - ], - [ - 'name' => 'BAR', - ], - [ - 'name' => 'T_BAR', - ], + ['name' => 'FOO'], + ['name' => 'T_FOO'], + ['name' => 'BAR'], + ['name' => 'T_BAR'], ])); self::assertSame( diff --git a/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php b/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php index 291731bab6d..10bd92d52e6 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php @@ -3,17 +3,17 @@ namespace Doctrine\Tests\DBAL\Schema; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use PHPUnit\Framework\TestCase; -class ForeignKeyConstraintTest extends \PHPUnit\Framework\TestCase +class ForeignKeyConstraintTest extends TestCase { /** * @group DBAL-1062 - * * @dataProvider getIntersectsIndexColumnsData */ public function testIntersectsIndexColumns(array $indexColumns, $expectedResult) { - $foreignKey = new ForeignKeyConstraint(array('foo', 'bar'), 'foreign_table', array('fk_foo', 'fk_bar')); + $foreignKey = new ForeignKeyConstraint(['foo', 'bar'], 'foreign_table', ['fk_foo', 'fk_bar']); $index = $this->getMockBuilder('Doctrine\DBAL\Schema\Index') ->disableOriginalConstructor() @@ -30,27 +30,27 @@ public function testIntersectsIndexColumns(array $indexColumns, $expectedResult) */ public function getIntersectsIndexColumnsData() { - return array( - array(array('baz'), false), - array(array('baz', 'bloo'), false), + return [ + [['baz'], false], + [['baz', 'bloo'], false], - array(array('foo'), true), - array(array('bar'), true), + [['foo'], true], + [['bar'], true], - array(array('foo', 'bar'), true), - array(array('bar', 'foo'), true), + [['foo', 'bar'], true], + [['bar', 'foo'], true], - array(array('foo', 'baz'), true), - array(array('baz', 'foo'), true), + [['foo', 'baz'], true], + [['baz', 'foo'], true], - array(array('bar', 'baz'), true), - array(array('baz', 'bar'), true), + [['bar', 'baz'], true], + [['baz', 'bar'], true], - array(array('foo', 'bloo', 'baz'), true), - array(array('bloo', 'foo', 'baz'), true), - array(array('bloo', 'baz', 'foo'), true), + [['foo', 'bloo', 'baz'], true], + [['bloo', 'foo', 'baz'], true], + [['bloo', 'baz', 'foo'], true], - array(array('FOO'), true), - ); + [['FOO'], true], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php b/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php index 1f49fd5e14d..af962f95f95 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php @@ -3,21 +3,22 @@ namespace Doctrine\Tests\DBAL\Schema; use Doctrine\DBAL\Schema\Index; +use PHPUnit\Framework\TestCase; -class IndexTest extends \PHPUnit\Framework\TestCase +class IndexTest extends TestCase { - public function createIndex($unique = false, $primary = false, $options = array()) + public function createIndex($unique = false, $primary = false, $options = []) { - return new Index("foo", array("bar", "baz"), $unique, $primary, array(), $options); + return new Index('foo', ['bar', 'baz'], $unique, $primary, [], $options); } public function testCreateIndex() { $idx = $this->createIndex(); - self::assertEquals("foo", $idx->getName()); + self::assertEquals('foo', $idx->getName()); $columns = $idx->getColumns(); self::assertCount(2, $columns); - self::assertEquals(array("bar", "baz"), $columns); + self::assertEquals(['bar', 'baz'], $columns); self::assertFalse($idx->isUnique()); self::assertFalse($idx->isPrimary()); } @@ -69,7 +70,7 @@ public function testFulfilledByIndex() { $idx1 = $this->createIndex(); $idx2 = $this->createIndex(); - $pri = $this->createIndex(true, true); + $pri = $this->createIndex(true, true); $uniq = $this->createIndex(true); self::assertTrue($idx1->isFullfilledBy($idx2)); @@ -79,9 +80,9 @@ public function testFulfilledByIndex() public function testFulfilledWithPartial() { - $without = new Index('without', array('col1', 'col2'), true, false, array(), array()); - $partial = new Index('partial', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL')); - $another = new Index('another', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL')); + $without = new Index('without', ['col1', 'col2'], true, false, [], []); + $partial = new Index('partial', ['col1', 'col2'], true, false, [], ['where' => 'col1 IS NULL']); + $another = new Index('another', ['col1', 'col2'], true, false, [], ['where' => 'col1 IS NULL']); self::assertFalse($partial->isFullfilledBy($without)); self::assertFalse($without->isFullfilledBy($partial)); @@ -94,9 +95,9 @@ public function testFulfilledWithPartial() public function testOverrulesWithPartial() { - $without = new Index('without', array('col1', 'col2'), true, false, array(), array()); - $partial = new Index('partial', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL')); - $another = new Index('another', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL')); + $without = new Index('without', ['col1', 'col2'], true, false, [], []); + $partial = new Index('partial', ['col1', 'col2'], true, false, [], ['where' => 'col1 IS NULL']); + $another = new Index('another', ['col1', 'col2'], true, false, [], ['where' => 'col1 IS NULL']); self::assertFalse($partial->overrules($without)); self::assertFalse($without->overrules($partial)); @@ -119,7 +120,7 @@ public function testFlags() $idx1->addFlag('clustered'); self::assertTrue($idx1->hasFlag('clustered')); self::assertTrue($idx1->hasFlag('CLUSTERED')); - self::assertSame(array('clustered'), $idx1->getFlags()); + self::assertSame(['clustered'], $idx1->getFlags()); $idx1->removeFlag('clustered'); self::assertFalse($idx1->hasFlag('clustered')); @@ -131,14 +132,14 @@ public function testFlags() */ public function testIndexQuotes() { - $index = new Index("foo", array("`bar`", "`baz`")); + $index = new Index('foo', ['`bar`', '`baz`']); - self::assertTrue($index->spansColumns(array("bar", "baz"))); - self::assertTrue($index->hasColumnAtPosition("bar", 0)); - self::assertTrue($index->hasColumnAtPosition("baz", 1)); + self::assertTrue($index->spansColumns(['bar', 'baz'])); + self::assertTrue($index->hasColumnAtPosition('bar', 0)); + self::assertTrue($index->hasColumnAtPosition('baz', 1)); - self::assertFalse($index->hasColumnAtPosition("bar", 1)); - self::assertFalse($index->hasColumnAtPosition("baz", 0)); + self::assertFalse($index->hasColumnAtPosition('bar', 1)); + self::assertFalse($index->hasColumnAtPosition('baz', 0)); } public function testOptions() @@ -147,11 +148,11 @@ public function testOptions() self::assertFalse($idx1->hasOption('where')); self::assertEmpty($idx1->getOptions()); - $idx2 = $this->createIndex(false, false, array('where' => 'name IS NULL')); + $idx2 = $this->createIndex(false, false, ['where' => 'name IS NULL']); self::assertTrue($idx2->hasOption('where')); self::assertTrue($idx2->hasOption('WHERE')); self::assertSame('name IS NULL', $idx2->getOption('where')); self::assertSame('name IS NULL', $idx2->getOption('WHERE')); - self::assertSame(array('where' => 'name IS NULL'), $idx2->getOptions()); + self::assertSame(['where' => 'name IS NULL'], $idx2->getOptions()); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php index c5b7ad0dd77..9ae399c7a04 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php @@ -38,7 +38,7 @@ public function testTableOptions() : void { $eventManager = new EventManager(); $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - $platform = new \Doctrine\DBAL\Platforms\MySqlPlatform(); + $platform = new MySqlPlatform(); // default, no overrides $table = new Table('foobar', [new Column('aa', Type::getType('integer'))]); diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php index e8129d3a20f..2a3837140c0 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php @@ -5,14 +5,14 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\MySqlSchemaManager; +use PHPUnit\Framework\TestCase; use function array_map; -class MySqlSchemaManagerTest extends \PHPUnit\Framework\TestCase +class MySqlSchemaManagerTest extends TestCase { - /** - * @var \Doctrine\DBAL\Schema\AbstractSchemaManager - */ + /** @var AbstractSchemaManager */ private $manager; /** @var Connection */ @@ -20,12 +20,12 @@ class MySqlSchemaManagerTest extends \PHPUnit\Framework\TestCase protected function setUp() { - $eventManager = new EventManager(); - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - $platform = $this->createMock('Doctrine\DBAL\Platforms\MySqlPlatform'); - $this->conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('fetchAll')) - ->setConstructorArgs(array(array('platform' => $platform), $driverMock, new Configuration(), $eventManager)) + $eventManager = new EventManager(); + $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $platform = $this->createMock('Doctrine\DBAL\Platforms\MySqlPlatform'); + $this->conn = $this->getMockBuilder('Doctrine\DBAL\Connection') + ->setMethods(['fetchAll']) + ->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager]) ->getMock(); $this->manager = new MySqlSchemaManager($this->conn); } @@ -34,40 +34,40 @@ public function testCompositeForeignKeys() { $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue($this->getFKDefinition())); $fkeys = $this->manager->listTableForeignKeys('dummy'); - self::assertCount(1, $fkeys, "Table has to have one foreign key."); + self::assertCount(1, $fkeys, 'Table has to have one foreign key.'); self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]); - self::assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getLocalColumns())); - self::assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getForeignColumns())); + self::assertEquals(['column_1', 'column_2', 'column_3'], array_map('strtolower', $fkeys[0]->getLocalColumns())); + self::assertEquals(['column_1', 'column_2', 'column_3'], array_map('strtolower', $fkeys[0]->getForeignColumns())); } public function getFKDefinition() { - return array( - array( - "CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E", - "COLUMN_NAME" => "column_1", - "REFERENCED_TABLE_NAME" => "dummy", - "REFERENCED_COLUMN_NAME" => "column_1", - "update_rule" => "RESTRICT", - "delete_rule" => "RESTRICT", - ), - array( - "CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E", - "COLUMN_NAME" => "column_2", - "REFERENCED_TABLE_NAME" => "dummy", - "REFERENCED_COLUMN_NAME" => "column_2", - "update_rule" => "RESTRICT", - "delete_rule" => "RESTRICT", - ), - array( - "CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E", - "COLUMN_NAME" => "column_3", - "REFERENCED_TABLE_NAME" => "dummy", - "REFERENCED_COLUMN_NAME" => "column_3", - "update_rule" => "RESTRICT", - "delete_rule" => "RESTRICT", - ) - ); + return [ + [ + 'CONSTRAINT_NAME' => 'FK_C1B1712387FE737264DE5A5511B8B3E', + 'COLUMN_NAME' => 'column_1', + 'REFERENCED_TABLE_NAME' => 'dummy', + 'REFERENCED_COLUMN_NAME' => 'column_1', + 'update_rule' => 'RESTRICT', + 'delete_rule' => 'RESTRICT', + ], + [ + 'CONSTRAINT_NAME' => 'FK_C1B1712387FE737264DE5A5511B8B3E', + 'COLUMN_NAME' => 'column_2', + 'REFERENCED_TABLE_NAME' => 'dummy', + 'REFERENCED_COLUMN_NAME' => 'column_2', + 'update_rule' => 'RESTRICT', + 'delete_rule' => 'RESTRICT', + ], + [ + 'CONSTRAINT_NAME' => 'FK_C1B1712387FE737264DE5A5511B8B3E', + 'COLUMN_NAME' => 'column_3', + 'REFERENCED_TABLE_NAME' => 'dummy', + 'REFERENCED_COLUMN_NAME' => 'column_3', + 'update_rule' => 'RESTRICT', + 'delete_rule' => 'RESTRICT', + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php index ff8e9b32256..0d45a5ef5e5 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php @@ -2,44 +2,45 @@ namespace Doctrine\Tests\DBAL\Schema\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Table; +use PHPUnit\Framework\TestCase; -class MySQLSchemaTest extends \PHPUnit\Framework\TestCase +class MySQLSchemaTest extends TestCase { /** @var Comparator */ private $comparator; - /** - * - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $platform; protected function setUp() { $this->comparator = new Comparator(); - $this->platform = new \Doctrine\DBAL\Platforms\MySqlPlatform; + $this->platform = new MySqlPlatform(); } public function testSwitchPrimaryKeyOrder() { - $tableOld = new Table("test"); + $tableOld = new Table('test'); $tableOld->addColumn('foo_id', 'integer'); $tableOld->addColumn('bar_id', 'integer'); $tableNew = clone $tableOld; - $tableOld->setPrimaryKey(array('foo_id', 'bar_id')); - $tableNew->setPrimaryKey(array('bar_id', 'foo_id')); + $tableOld->setPrimaryKey(['foo_id', 'bar_id']); + $tableNew->setPrimaryKey(['bar_id', 'foo_id']); $diff = $this->comparator->diffTable($tableOld, $tableNew); - $sql = $this->platform->getAlterTableSQL($diff); + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals( - array( + [ 'ALTER TABLE test DROP PRIMARY KEY', - 'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)' - ), $sql + 'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)', + ], + $sql ); } @@ -48,16 +49,16 @@ public function testSwitchPrimaryKeyOrder() */ public function testGenerateForeignKeySQL() { - $tableOld = new Table("test"); + $tableOld = new Table('test'); $tableOld->addColumn('foo_id', 'integer'); - $tableOld->addUnnamedForeignKeyConstraint('test_foreign', array('foo_id'), array('foo_id')); + $tableOld->addUnnamedForeignKeyConstraint('test_foreign', ['foo_id'], ['foo_id']); - $sqls = array(); + $sqls = []; foreach ($tableOld->getForeignKeys() as $fk) { $sqls[] = $this->platform->getCreateForeignKeySQL($fk, $tableOld); } - self::assertEquals(array("ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C8E48560F FOREIGN KEY (foo_id) REFERENCES test_foreign (foo_id)"), $sqls); + self::assertEquals(['ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C8E48560F FOREIGN KEY (foo_id) REFERENCES test_foreign (foo_id)'], $sqls); } /** @@ -65,18 +66,18 @@ public function testGenerateForeignKeySQL() */ public function testClobNoAlterTable() { - $tableOld = new Table("test"); + $tableOld = new Table('test'); $tableOld->addColumn('id', 'integer'); - $tableOld->addColumn('description', 'string', array('length' => 65536)); + $tableOld->addColumn('description', 'string', ['length' => 65536]); $tableNew = clone $tableOld; - $tableNew->setPrimaryKey(array('id')); + $tableNew->setPrimaryKey(['id']); $diff = $this->comparator->diffTable($tableOld, $tableNew); - $sql = $this->platform->getAlterTableSQL($diff); + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals( - array('ALTER TABLE test ADD PRIMARY KEY (id)'), + ['ALTER TABLE test ADD PRIMARY KEY (id)'], $sql ); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php index 5541bb04396..b25f81601be 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php @@ -2,33 +2,35 @@ namespace Doctrine\Tests\DBAL\Schema; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\SchemaDiff; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; +use PHPUnit\Framework\TestCase; -class SchemaDiffTest extends \PHPUnit\Framework\TestCase +class SchemaDiffTest extends TestCase { public function testSchemaDiffToSql() { - $diff = $this->createSchemaDiff(); + $diff = $this->createSchemaDiff(); $platform = $this->createPlatform(true); $sql = $diff->toSql($platform); - $expected = array('create_schema', 'drop_orphan_fk', 'alter_seq', 'drop_seq', 'create_seq', 'create_table', 'create_foreign_key', 'drop_table', 'alter_table'); + $expected = ['create_schema', 'drop_orphan_fk', 'alter_seq', 'drop_seq', 'create_seq', 'create_table', 'create_foreign_key', 'drop_table', 'alter_table']; self::assertEquals($expected, $sql); } public function testSchemaDiffToSaveSql() { - $diff = $this->createSchemaDiff(); + $diff = $this->createSchemaDiff(); $platform = $this->createPlatform(false); $sql = $diff->toSaveSql($platform); - $expected = array('create_schema', 'alter_seq', 'create_seq', 'create_table', 'create_foreign_key', 'alter_table'); + $expected = ['create_schema', 'alter_seq', 'create_seq', 'create_table', 'create_foreign_key', 'alter_table']; self::assertEquals($expected, $sql); } @@ -63,7 +65,7 @@ public function createPlatform($unsafe = false) $platform->expects($this->exactly(1)) ->method('getCreateTableSql') ->with($this->isInstanceOf('Doctrine\DBAL\Schema\Table')) - ->will($this->returnValue(array('create_table'))); + ->will($this->returnValue(['create_table'])); $platform->expects($this->exactly(1)) ->method('getCreateForeignKeySQL') ->with($this->isInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint')) @@ -71,7 +73,7 @@ public function createPlatform($unsafe = false) $platform->expects($this->exactly(1)) ->method('getAlterTableSql') ->with($this->isInstanceOf('Doctrine\DBAL\Schema\TableDiff')) - ->will($this->returnValue(array('alter_table'))); + ->will($this->returnValue(['alter_table'])); if ($unsafe) { $platform->expects($this->exactly(1)) ->method('getDropForeignKeySql') @@ -95,18 +97,18 @@ public function createPlatform($unsafe = false) public function createSchemaDiff() { - $diff = new SchemaDiff(); - $diff->newNamespaces['foo_ns'] = 'foo_ns'; + $diff = new SchemaDiff(); + $diff->newNamespaces['foo_ns'] = 'foo_ns'; $diff->removedNamespaces['bar_ns'] = 'bar_ns'; $diff->changedSequences['foo_seq'] = new Sequence('foo_seq'); - $diff->newSequences['bar_seq'] = new Sequence('bar_seq'); + $diff->newSequences['bar_seq'] = new Sequence('bar_seq'); $diff->removedSequences['baz_seq'] = new Sequence('baz_seq'); - $diff->newTables['foo_table'] = new Table('foo_table'); - $diff->removedTables['bar_table'] = new Table('bar_table'); - $diff->changedTables['baz_table'] = new TableDiff('baz_table'); + $diff->newTables['foo_table'] = new Table('foo_table'); + $diff->removedTables['bar_table'] = new Table('bar_table'); + $diff->changedTables['baz_table'] = new TableDiff('baz_table'); $diff->newTables['foo_table']->addColumn('foreign_id', 'integer'); - $diff->newTables['foo_table']->addForeignKeyConstraint('foreign_table', array('foreign_id'), array('id')); - $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('id'), 'foreign_table', array('id')); + $diff->newTables['foo_table']->addForeignKeyConstraint('foreign_table', ['foreign_id'], ['id']); + $fk = new ForeignKeyConstraint(['id'], 'foreign_table', ['id']); $fk->setLocalTable(new Table('local_table')); $diff->orphanedForeignKeys[] = $fk; return $diff; diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php index 81db2c51e08..c9bad262d74 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php @@ -3,19 +3,21 @@ namespace Doctrine\Tests\DBAL\Schema; use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\SchemaConfig; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; +use PHPUnit\Framework\TestCase; use function current; use function strlen; -class SchemaTest extends \PHPUnit\Framework\TestCase +class SchemaTest extends TestCase { public function testAddTable() { - $tableName = "public.foo"; - $table = new Table($tableName); + $tableName = 'public.foo'; + $table = new Table($tableName); - $schema = new Schema(array($table)); + $schema = new Schema([$table]); self::assertTrue($schema->hasTable($tableName)); @@ -28,11 +30,11 @@ public function testAddTable() public function testTableMatchingCaseInsensitive() { - $table = new Table("Foo"); + $table = new Table('Foo'); - $schema = new Schema(array($table)); - self::assertTrue($schema->hasTable("foo")); - self::assertTrue($schema->hasTable("FOO")); + $schema = new Schema([$table]); + self::assertTrue($schema->hasTable('foo')); + self::assertTrue($schema->hasTable('FOO')); self::assertSame($table, $schema->getTable('FOO')); self::assertSame($table, $schema->getTable('foo')); @@ -41,70 +43,70 @@ public function testTableMatchingCaseInsensitive() public function testGetUnknownTableThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); $schema = new Schema(); - $schema->getTable("unknown"); + $schema->getTable('unknown'); } public function testCreateTableTwiceThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $tableName = "foo"; - $table = new Table($tableName); - $tables = array($table, $table); + $tableName = 'foo'; + $table = new Table($tableName); + $tables = [$table, $table]; $schema = new Schema($tables); } public function testRenameTable() { - $tableName = "foo"; - $table = new Table($tableName); - $schema = new Schema(array($table)); - - self::assertTrue($schema->hasTable("foo")); - $schema->renameTable("foo", "bar"); - self::assertFalse($schema->hasTable("foo")); - self::assertTrue($schema->hasTable("bar")); - self::assertSame($table, $schema->getTable("bar")); + $tableName = 'foo'; + $table = new Table($tableName); + $schema = new Schema([$table]); + + self::assertTrue($schema->hasTable('foo')); + $schema->renameTable('foo', 'bar'); + self::assertFalse($schema->hasTable('foo')); + self::assertTrue($schema->hasTable('bar')); + self::assertSame($table, $schema->getTable('bar')); } public function testDropTable() { - $tableName = "foo"; - $table = new Table($tableName); - $schema = new Schema(array($table)); + $tableName = 'foo'; + $table = new Table($tableName); + $schema = new Schema([$table]); - self::assertTrue($schema->hasTable("foo")); + self::assertTrue($schema->hasTable('foo')); - $schema->dropTable("foo"); + $schema->dropTable('foo'); - self::assertFalse($schema->hasTable("foo")); + self::assertFalse($schema->hasTable('foo')); } public function testCreateTable() { $schema = new Schema(); - self::assertFalse($schema->hasTable("foo")); + self::assertFalse($schema->hasTable('foo')); - $table = $schema->createTable("foo"); + $table = $schema->createTable('foo'); self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table); - self::assertEquals("foo", $table->getName()); - self::assertTrue($schema->hasTable("foo")); + self::assertEquals('foo', $table->getName()); + self::assertTrue($schema->hasTable('foo')); } public function testAddSequences() { - $sequence = new Sequence("a_seq", 1, 1); + $sequence = new Sequence('a_seq', 1, 1); - $schema = new Schema(array(), array($sequence)); + $schema = new Schema([], [$sequence]); - self::assertTrue($schema->hasSequence("a_seq")); - self::assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence("a_seq")); + self::assertTrue($schema->hasSequence('a_seq')); + self::assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence('a_seq')); $sequences = $schema->getSequences(); self::assertArrayHasKey('public.a_seq', $sequences); @@ -112,9 +114,9 @@ public function testAddSequences() public function testSequenceAccessCaseInsensitive() { - $sequence = new Sequence("a_Seq"); + $sequence = new Sequence('a_Seq'); - $schema = new Schema(array(), array($sequence)); + $schema = new Schema([], [$sequence]); self::assertTrue($schema->hasSequence('a_seq')); self::assertTrue($schema->hasSequence('a_Seq')); self::assertTrue($schema->hasSequence('A_SEQ')); @@ -126,23 +128,23 @@ public function testSequenceAccessCaseInsensitive() public function testGetUnknownSequenceThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); $schema = new Schema(); - $schema->getSequence("unknown"); + $schema->getSequence('unknown'); } public function testCreateSequence() { - $schema = new Schema(); + $schema = new Schema(); $sequence = $schema->createSequence('a_seq', 10, 20); self::assertEquals('a_seq', $sequence->getName()); self::assertEquals(10, $sequence->getAllocationSize()); self::assertEquals(20, $sequence->getInitialValue()); - self::assertTrue($schema->hasSequence("a_seq")); - self::assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence("a_seq")); + self::assertTrue($schema->hasSequence('a_seq')); + self::assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence('a_seq')); $sequences = $schema->getSequences(); self::assertArrayHasKey('public.a_seq', $sequences); @@ -150,32 +152,32 @@ public function testCreateSequence() public function testDropSequence() { - $sequence = new Sequence("a_seq", 1, 1); + $sequence = new Sequence('a_seq', 1, 1); - $schema = new Schema(array(), array($sequence)); + $schema = new Schema([], [$sequence]); - $schema->dropSequence("a_seq"); - self::assertFalse($schema->hasSequence("a_seq")); + $schema->dropSequence('a_seq'); + self::assertFalse($schema->hasSequence('a_seq')); } public function testAddSequenceTwiceThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $sequence = new Sequence("a_seq", 1, 1); + $sequence = new Sequence('a_seq', 1, 1); - $schema = new Schema(array(), array($sequence, $sequence)); + $schema = new Schema([], [$sequence, $sequence]); } public function testConfigMaxIdentifierLength() { - $schemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig(); + $schemaConfig = new SchemaConfig(); $schemaConfig->setMaxIdentifierLength(5); - $schema = new Schema(array(), array(), $schemaConfig); - $table = $schema->createTable("smalltable"); + $schema = new Schema([], [], $schemaConfig); + $table = $schema->createTable('smalltable'); $table->addColumn('long_id', 'integer'); - $table->addIndex(array('long_id')); + $table->addIndex(['long_id']); $index = current($table->getIndexes()); self::assertEquals(5, strlen($index->getName())); @@ -183,7 +185,7 @@ public function testConfigMaxIdentifierLength() public function testDeepClone() { - $schema = new Schema(); + $schema = new Schema(); $sequence = $schema->createSequence('baz'); $tableA = $schema->createTable('foo'); @@ -192,7 +194,7 @@ public function testDeepClone() $tableB = $schema->createTable('bar'); $tableB->addColumn('id', 'integer'); $tableB->addColumn('foo_id', 'integer'); - $tableB->addForeignKeyConstraint($tableA, array('foo_id'), array('id')); + $tableB->addForeignKeyConstraint($tableA, ['foo_id'], ['id']); $schemaNew = clone $schema; @@ -269,12 +271,11 @@ public function testCreatesNamespace() self::assertTrue($schema->hasNamespace('`bar`')); self::assertTrue($schema->hasNamespace('`BAR`')); - self::assertSame(array('foo' => 'foo', 'bar' => '`bar`'), $schema->getNamespaces()); + self::assertSame(['foo' => 'foo', 'bar' => '`bar`'], $schema->getNamespaces()); } /** * @group DBAL-669 - * * @expectedException \Doctrine\DBAL\Schema\SchemaException */ public function testThrowsExceptionOnCreatingNamespaceTwice() @@ -350,7 +351,7 @@ public function testCreatesNamespaceThroughAddingSequenceImplicitly() */ public function testVisitsVisitor() { - $schema = new Schema(); + $schema = new Schema(); $visitor = $this->createMock('Doctrine\DBAL\Schema\Visitor\Visitor'); $schema->createNamespace('foo'); @@ -396,7 +397,7 @@ public function testVisitsVisitor() */ public function testVisitsNamespaceVisitor() { - $schema = new Schema(); + $schema = new Schema(); $visitor = $this->createMock('Doctrine\DBAL\Schema\Visitor\AbstractVisitor'); $schema->createNamespace('foo'); diff --git a/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php b/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php index 9414830b48a..b3a72017c16 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php @@ -4,21 +4,22 @@ use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalTestCase; -class SequenceTest extends \Doctrine\Tests\DbalTestCase +class SequenceTest extends DbalTestCase { /** * @group DDC-1657 */ public function testIsAutoincrementFor() { - $table = new Table("foo"); - $table->addColumn("id", "integer", array("autoincrement" => true)); - $table->setPrimaryKey(array("id")); + $table = new Table('foo'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); - $sequence = new Sequence("foo_id_seq"); - $sequence2 = new Sequence("bar_id_seq"); - $sequence3 = new Sequence("other.foo_id_seq"); + $sequence = new Sequence('foo_id_seq'); + $sequence2 = new Sequence('bar_id_seq'); + $sequence3 = new Sequence('other.foo_id_seq'); self::assertTrue($sequence->isAutoIncrementsFor($table)); self::assertFalse($sequence2->isAutoIncrementsFor($table)); @@ -28,14 +29,14 @@ public function testIsAutoincrementFor() public function testIsAutoincrementForCaseInsensitive() { $table = new Table('foo'); - $table->addColumn('ID', 'integer', array('autoincrement' => true)); - $table->setPrimaryKey(array('ID')); + $table->addColumn('ID', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['ID']); - $sequence = new Sequence("foo_id_seq"); - $sequence1 = new Sequence("foo_ID_seq"); - $sequence2 = new Sequence("bar_id_seq"); - $sequence3 = new Sequence("bar_ID_seq"); - $sequence4 = new Sequence("other.foo_id_seq"); + $sequence = new Sequence('foo_id_seq'); + $sequence1 = new Sequence('foo_ID_seq'); + $sequence2 = new Sequence('bar_id_seq'); + $sequence3 = new Sequence('bar_ID_seq'); + $sequence4 = new Sequence('other.foo_id_seq'); self::assertTrue($sequence->isAutoIncrementsFor($table)); self::assertTrue($sequence1->isAutoIncrementsFor($table)); @@ -44,4 +45,3 @@ public function testIsAutoincrementForCaseInsensitive() self::assertFalse($sequence4->isAutoIncrementsFor($table)); } } - diff --git a/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php index 8a6759663e7..7b3031624af 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php @@ -5,12 +5,13 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\SqliteSchemaManager; +use PHPUnit\Framework\TestCase; +use ReflectionMethod; -class SqliteSchemaManagerTest extends \PHPUnit\Framework\TestCase +class SqliteSchemaManagerTest extends TestCase { /** * @dataProvider getDataColumnCollation - * * @group 2865 */ public function testParseColumnCollation(?string $collation, string $column, string $sql) : void @@ -19,7 +20,7 @@ public function testParseColumnCollation(?string $collation, string $column, str $conn->method('getDatabasePlatform')->willReturn(new SqlitePlatform()); $manager = new SqliteSchemaManager($conn); - $ref = new \ReflectionMethod($manager, 'parseColumnCollationFromSQL'); + $ref = new ReflectionMethod($manager, 'parseColumnCollationFromSQL'); $ref->setAccessible(true); self::assertSame($collation, $ref->invoke($manager, $column, $sql)); @@ -49,7 +50,6 @@ public function getDataColumnCollation() /** * @dataProvider getDataColumnComment - * * @group 2865 */ public function testParseColumnCommentFromSQL(?string $comment, string $column, string $sql) : void @@ -58,7 +58,7 @@ public function testParseColumnCommentFromSQL(?string $comment, string $column, $conn->method('getDatabasePlatform')->willReturn(new SqlitePlatform()); $manager = new SqliteSchemaManager($conn); - $ref = new \ReflectionMethod($manager, 'parseColumnCommentFromSQL'); + $ref = new ReflectionMethod($manager, 'parseColumnCommentFromSQL'); $ref->setAccessible(true); self::assertSame($comment, $ref->invoke($manager, $column, $sql)); @@ -68,40 +68,58 @@ public function getDataColumnComment() { return [ 'Single column with no comment' => [ - null, 'a', 'CREATE TABLE "a" ("a" TEXT DEFAULT "a" COLLATE RTRIM)', + null, + 'a', + 'CREATE TABLE "a" ("a" TEXT DEFAULT "a" COLLATE RTRIM)', ], 'Single column with type comment' => [ - '(DC2Type:x)', 'a', 'CREATE TABLE "a" ("a" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) + '(DC2Type:x)', + 'a', + 'CREATE TABLE "a" ("a" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) )', ], 'Multiple similar columns with type comment 1' => [ - null, 'b', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" TEXT DEFAULT "a" COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) + null, + 'b', + 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" TEXT DEFAULT "a" COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) )', ], 'Multiple similar columns with type comment 2' => [ - '(DC2Type:x)', 'b', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" TEXT DEFAULT "a" COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) + '(DC2Type:x)', + 'b', + 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" TEXT DEFAULT "a" COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) )', ], 'Multiple similar columns on different lines, with type comment 1' => [ - null, 'bb', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) + null, + 'bb', + 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) , "bb" TEXT DEFAULT "a" COLLATE RTRIM', ], 'Multiple similar columns on different lines, with type comment 2' => [ - '(DC2Type:x)', 'bb', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) + '(DC2Type:x)', + 'bb', + 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) , "b" TEXT DEFAULT "a" COLLATE RTRIM', ], 'Column with numeric but no comment 1' => [ - null, 'a', 'CREATE TABLE "a" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) + null, + 'a', + 'CREATE TABLE "a" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) , "c" CHAR(36) NOT NULL --(DC2Type:guid) )', ], 'Column with numeric but no comment 2' => [ - null, 'a', 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) + null, + 'a', + 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) , "c" CHAR(36) NOT NULL --(DC2Type:guid) )', ], 'Column with numeric but no comment 3' => [ - '(DC2Type:guid)', 'c', 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) + '(DC2Type:guid)', + 'c', + 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) , "c" CHAR(36) NOT NULL --(DC2Type:guid) )', ], diff --git a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php index 0071d217280..442c283ef59 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php @@ -22,70 +22,70 @@ use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer; +use PHPUnit\Framework\TestCase; /** * @requires extension pdo_sqlite */ -class SingleDatabaseSynchronizerTest extends \PHPUnit\Framework\TestCase +class SingleDatabaseSynchronizerTest extends TestCase { private $conn; private $synchronizer; protected function setUp() { - $this->conn = DriverManager::getConnection(array( + $this->conn = DriverManager::getConnection([ 'driver' => 'pdo_sqlite', 'memory' => true, - )); + ]); $this->synchronizer = new SingleDatabaseSynchronizer($this->conn); } public function testGetCreateSchema() { $schema = new Schema(); - $table = $schema->createTable('test'); + $table = $schema->createTable('test'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $sql = $this->synchronizer->getCreateSchema($schema); - self::assertEquals(array('CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'), $sql); + self::assertEquals(['CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'], $sql); } public function testGetUpdateSchema() { $schema = new Schema(); - $table = $schema->createTable('test'); + $table = $schema->createTable('test'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $sql = $this->synchronizer->getUpdateSchema($schema); - self::assertEquals(array('CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'), $sql); + self::assertEquals(['CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'], $sql); } public function testGetDropSchema() { $schema = new Schema(); - $table = $schema->createTable('test'); + $table = $schema->createTable('test'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $this->synchronizer->createSchema($schema); $sql = $this->synchronizer->getDropSchema($schema); - self::assertEquals(array('DROP TABLE test'), $sql); + self::assertEquals(['DROP TABLE test'], $sql); } public function testGetDropAllSchema() { $schema = new Schema(); - $table = $schema->createTable('test'); + $table = $schema->createTable('test'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $this->synchronizer->createSchema($schema); $sql = $this->synchronizer->getDropAllSchema(); - self::assertEquals(array('DROP TABLE test'), $sql); + self::assertEquals(['DROP TABLE test'], $sql); } } - diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php index f78d9519a12..097c9e2f1e1 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php @@ -5,8 +5,9 @@ use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use PHPUnit\Framework\TestCase; -class TableDiffTest extends \PHPUnit\Framework\TestCase +class TableDiffTest extends TestCase { /** * @group DBAL-1013 @@ -24,11 +25,11 @@ public function testReturnsName() public function testPrefersNameFromTableObject() { $platformMock = new MockPlatform(); - $tableMock = $this->getMockBuilder('Doctrine\DBAL\Schema\Table') + $tableMock = $this->getMockBuilder('Doctrine\DBAL\Schema\Table') ->disableOriginalConstructor() ->getMock(); - $tableDiff = new TableDiff('foo'); + $tableDiff = new TableDiff('foo'); $tableDiff->fromTable = $tableMock; $tableMock->expects($this->once()) diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index 9c4dee07eed..09cc4662f48 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -3,50 +3,53 @@ namespace Doctrine\Tests\DBAL\Schema; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalTestCase; use function array_shift; use function current; -class TableTest extends \Doctrine\Tests\DbalTestCase +class TableTest extends DbalTestCase { public function testCreateWithInvalidTableName() { $this->expectException(DBALException::class); - new \Doctrine\DBAL\Schema\Table(''); + new Table(''); } public function testGetName() { - $table = new Table("foo", array(), array(), array()); - self::assertEquals("foo", $table->getName()); + $table = new Table('foo', [], [], []); + self::assertEquals('foo', $table->getName()); } public function testColumns() { - $type = Type::getType('integer'); - $columns = array(); - $columns[] = new Column("foo", $type); - $columns[] = new Column("bar", $type); - $table = new Table("foo", $columns, array(), array()); + $type = Type::getType('integer'); + $columns = []; + $columns[] = new Column('foo', $type); + $columns[] = new Column('bar', $type); + $table = new Table('foo', $columns, [], []); - self::assertTrue($table->hasColumn("foo")); - self::assertTrue($table->hasColumn("bar")); - self::assertFalse($table->hasColumn("baz")); + self::assertTrue($table->hasColumn('foo')); + self::assertTrue($table->hasColumn('bar')); + self::assertFalse($table->hasColumn('baz')); - self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn("foo")); - self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn("bar")); + self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn('foo')); + self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn('bar')); self::assertCount(2, $table->getColumns()); } public function testColumnsCaseInsensitive() { - $table = new Table("foo"); + $table = new Table('foo'); $column = $table->addColumn('Foo', 'integer'); self::assertTrue($table->hasColumn('Foo')); @@ -62,74 +65,74 @@ public function testCreateColumn() { $type = Type::getType('integer'); - $table = new Table("foo"); + $table = new Table('foo'); - self::assertFalse($table->hasColumn("bar")); - $table->addColumn("bar", 'integer'); - self::assertTrue($table->hasColumn("bar")); - self::assertSame($type, $table->getColumn("bar")->getType()); + self::assertFalse($table->hasColumn('bar')); + $table->addColumn('bar', 'integer'); + self::assertTrue($table->hasColumn('bar')); + self::assertSame($type, $table->getColumn('bar')->getType()); } public function testDropColumn() { - $type = Type::getType('integer'); - $columns = array(); - $columns[] = new Column("foo", $type); - $columns[] = new Column("bar", $type); - $table = new Table("foo", $columns, array(), array()); + $type = Type::getType('integer'); + $columns = []; + $columns[] = new Column('foo', $type); + $columns[] = new Column('bar', $type); + $table = new Table('foo', $columns, [], []); - self::assertTrue($table->hasColumn("foo")); - self::assertTrue($table->hasColumn("bar")); + self::assertTrue($table->hasColumn('foo')); + self::assertTrue($table->hasColumn('bar')); - $table->dropColumn("foo")->dropColumn("bar"); + $table->dropColumn('foo')->dropColumn('bar'); - self::assertFalse($table->hasColumn("foo")); - self::assertFalse($table->hasColumn("bar")); + self::assertFalse($table->hasColumn('foo')); + self::assertFalse($table->hasColumn('bar')); } public function testGetUnknownColumnThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo", array(), array(), array()); + $table = new Table('foo', [], [], []); $table->getColumn('unknown'); } public function testAddColumnTwiceThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array(); - $columns[] = new Column("foo", $type); - $columns[] = new Column("foo", $type); - $table = new Table("foo", $columns, array(), array()); + $type = Type::getType('integer'); + $columns = []; + $columns[] = new Column('foo', $type); + $columns[] = new Column('foo', $type); + $table = new Table('foo', $columns, [], []); } public function testCreateIndex() { - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array(new Column("foo", $type), new Column("bar", $type), new Column("baz", $type)); - $table = new Table("foo", $columns); + $type = Type::getType('integer'); + $columns = [new Column('foo', $type), new Column('bar', $type), new Column('baz', $type)]; + $table = new Table('foo', $columns); - $table->addIndex(array("foo", "bar"), "foo_foo_bar_idx"); - $table->addUniqueIndex(array("bar", "baz"), "foo_bar_baz_uniq"); + $table->addIndex(['foo', 'bar'], 'foo_foo_bar_idx'); + $table->addUniqueIndex(['bar', 'baz'], 'foo_bar_baz_uniq'); - self::assertTrue($table->hasIndex("foo_foo_bar_idx")); - self::assertTrue($table->hasIndex("foo_bar_baz_uniq")); + self::assertTrue($table->hasIndex('foo_foo_bar_idx')); + self::assertTrue($table->hasIndex('foo_bar_baz_uniq')); } public function testIndexCaseInsensitive() { - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array( - new Column("foo", $type), - new Column("bar", $type), - new Column("baz", $type) - ); - $table = new Table("foo", $columns); + $type = Type::getType('integer'); + $columns = [ + new Column('foo', $type), + new Column('bar', $type), + new Column('baz', $type), + ]; + $table = new Table('foo', $columns); - $table->addIndex(array("foo", "bar", "baz"), "Foo_Idx"); + $table->addIndex(['foo', 'bar', 'baz'], 'Foo_Idx'); self::assertTrue($table->hasIndex('foo_idx')); self::assertTrue($table->hasIndex('Foo_Idx')); @@ -138,20 +141,20 @@ public function testIndexCaseInsensitive() public function testAddIndexes() { - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array( - new Column("foo", $type), - new Column("bar", $type), - ); - $indexes = array( - new Index("the_primary", array("foo"), true, true), - new Index("bar_idx", array("bar"), false, false), - ); - $table = new Table("foo", $columns, $indexes, array()); - - self::assertTrue($table->hasIndex("the_primary")); - self::assertTrue($table->hasIndex("bar_idx")); - self::assertFalse($table->hasIndex("some_idx")); + $type = Type::getType('integer'); + $columns = [ + new Column('foo', $type), + new Column('bar', $type), + ]; + $indexes = [ + new Index('the_primary', ['foo'], true, true), + new Index('bar_idx', ['bar'], false, false), + ]; + $table = new Table('foo', $columns, $indexes, []); + + self::assertTrue($table->hasIndex('the_primary')); + self::assertTrue($table->hasIndex('bar_idx')); + self::assertFalse($table->hasIndex('some_idx')); self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey()); self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('the_primary')); @@ -160,43 +163,43 @@ public function testAddIndexes() public function testGetUnknownIndexThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo", array(), array(), array()); - $table->getIndex("unknownIndex"); + $table = new Table('foo', [], [], []); + $table->getIndex('unknownIndex'); } public function testAddTwoPrimaryThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array(new Column("foo", $type), new Column("bar", $type)); - $indexes = array( - new Index("the_primary", array("foo"), true, true), - new Index("other_primary", array("bar"), true, true), - ); - $table = new Table("foo", $columns, $indexes, array()); + $type = Type::getType('integer'); + $columns = [new Column('foo', $type), new Column('bar', $type)]; + $indexes = [ + new Index('the_primary', ['foo'], true, true), + new Index('other_primary', ['bar'], true, true), + ]; + $table = new Table('foo', $columns, $indexes, []); } public function testAddTwoIndexesWithSameNameThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array(new Column("foo", $type), new Column("bar", $type)); - $indexes = array( - new Index("an_idx", array("foo"), false, false), - new Index("an_idx", array("bar"), false, false), - ); - $table = new Table("foo", $columns, $indexes, array()); + $type = Type::getType('integer'); + $columns = [new Column('foo', $type), new Column('bar', $type)]; + $indexes = [ + new Index('an_idx', ['foo'], false, false), + new Index('an_idx', ['bar'], false, false), + ]; + $table = new Table('foo', $columns, $indexes, []); } public function testConstraints() { - $constraint = new ForeignKeyConstraint(array(), "foo", array()); + $constraint = new ForeignKeyConstraint([], 'foo', []); - $tableA = new Table("foo", array(), array(), array($constraint)); + $tableA = new Table('foo', [], [], [$constraint]); $constraints = $tableA->getForeignKeys(); self::assertCount(1, $constraints); @@ -205,109 +208,109 @@ public function testConstraints() public function testOptions() { - $table = new Table("foo", array(), array(), array(), false, array("foo" => "bar")); + $table = new Table('foo', [], [], [], false, ['foo' => 'bar']); - self::assertTrue($table->hasOption("foo")); - self::assertEquals("bar", $table->getOption("foo")); + self::assertTrue($table->hasOption('foo')); + self::assertEquals('bar', $table->getOption('foo')); } public function testBuilderSetPrimaryKey() { - $table = new Table("foo"); + $table = new Table('foo'); - $table->addColumn("bar", 'integer'); - $table->setPrimaryKey(array("bar")); + $table->addColumn('bar', 'integer'); + $table->setPrimaryKey(['bar']); - self::assertTrue($table->hasIndex("primary")); + self::assertTrue($table->hasIndex('primary')); self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey()); - self::assertTrue($table->getIndex("primary")->isUnique()); - self::assertTrue($table->getIndex("primary")->isPrimary()); + self::assertTrue($table->getIndex('primary')->isUnique()); + self::assertTrue($table->getIndex('primary')->isPrimary()); } public function testBuilderAddUniqueIndex() { - $table = new Table("foo"); + $table = new Table('foo'); - $table->addColumn("bar", 'integer'); - $table->addUniqueIndex(array("bar"), "my_idx"); + $table->addColumn('bar', 'integer'); + $table->addUniqueIndex(['bar'], 'my_idx'); - self::assertTrue($table->hasIndex("my_idx")); - self::assertTrue($table->getIndex("my_idx")->isUnique()); - self::assertFalse($table->getIndex("my_idx")->isPrimary()); + self::assertTrue($table->hasIndex('my_idx')); + self::assertTrue($table->getIndex('my_idx')->isUnique()); + self::assertFalse($table->getIndex('my_idx')->isPrimary()); } public function testBuilderAddIndex() { - $table = new Table("foo"); + $table = new Table('foo'); - $table->addColumn("bar", 'integer'); - $table->addIndex(array("bar"), "my_idx"); + $table->addColumn('bar', 'integer'); + $table->addIndex(['bar'], 'my_idx'); - self::assertTrue($table->hasIndex("my_idx")); - self::assertFalse($table->getIndex("my_idx")->isUnique()); - self::assertFalse($table->getIndex("my_idx")->isPrimary()); + self::assertTrue($table->hasIndex('my_idx')); + self::assertFalse($table->getIndex('my_idx')->isUnique()); + self::assertFalse($table->getIndex('my_idx')->isPrimary()); } public function testBuilderAddIndexWithInvalidNameThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo"); - $table->addColumn("bar",'integer'); - $table->addIndex(array("bar"), "invalid name %&/"); + $table = new Table('foo'); + $table->addColumn('bar', 'integer'); + $table->addIndex(['bar'], 'invalid name %&/'); } public function testBuilderAddIndexWithUnknownColumnThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo"); - $table->addIndex(array("bar"), "invalidName"); + $table = new Table('foo'); + $table->addIndex(['bar'], 'invalidName'); } public function testBuilderOptions() { - $table = new Table("foo"); - $table->addOption("foo", "bar"); - self::assertTrue($table->hasOption("foo")); - self::assertEquals("bar", $table->getOption("foo")); + $table = new Table('foo'); + $table->addOption('foo', 'bar'); + self::assertTrue($table->hasOption('foo')); + self::assertEquals('bar', $table->getOption('foo')); } public function testAddForeignKeyConstraint_UnknownLocalColumn_ThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo"); - $table->addColumn("id", 'integer'); + $table = new Table('foo'); + $table->addColumn('id', 'integer'); - $foreignTable = new Table("bar"); - $foreignTable->addColumn("id", 'integer'); + $foreignTable = new Table('bar'); + $foreignTable->addColumn('id', 'integer'); - $table->addForeignKeyConstraint($foreignTable, array("foo"), array("id")); + $table->addForeignKeyConstraint($foreignTable, ['foo'], ['id']); } public function testAddForeignKeyConstraint_UnknownForeignColumn_ThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo"); - $table->addColumn("id", 'integer'); + $table = new Table('foo'); + $table->addColumn('id', 'integer'); - $foreignTable = new Table("bar"); - $foreignTable->addColumn("id", 'integer'); + $foreignTable = new Table('bar'); + $foreignTable->addColumn('id', 'integer'); - $table->addForeignKeyConstraint($foreignTable, array("id"), array("foo")); + $table->addForeignKeyConstraint($foreignTable, ['id'], ['foo']); } public function testAddForeignKeyConstraint() { - $table = new Table("foo"); - $table->addColumn("id", 'integer'); + $table = new Table('foo'); + $table->addColumn('id', 'integer'); - $foreignTable = new Table("bar"); - $foreignTable->addColumn("id", 'integer'); + $foreignTable = new Table('bar'); + $foreignTable->addColumn('id', 'integer'); - $table->addForeignKeyConstraint($foreignTable, array("id"), array("id"), array("foo" => "bar")); + $table->addForeignKeyConstraint($foreignTable, ['id'], ['id'], ['foo' => 'bar']); $constraints = $table->getForeignKeys(); self::assertCount(1, $constraints); @@ -315,30 +318,30 @@ public function testAddForeignKeyConstraint() self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $constraint); - self::assertTrue($constraint->hasOption("foo")); - self::assertEquals("bar", $constraint->getOption("foo")); + self::assertTrue($constraint->hasOption('foo')); + self::assertEquals('bar', $constraint->getOption('foo')); } public function testAddIndexWithCaseSensitiveColumnProblem() { - $table = new Table("foo"); - $table->addColumn("id", 'integer'); + $table = new Table('foo'); + $table->addColumn('id', 'integer'); - $table->addIndex(array("ID"), "my_idx"); + $table->addIndex(['ID'], 'my_idx'); self::assertTrue($table->hasIndex('my_idx')); - self::assertEquals(array("ID"), $table->getIndex("my_idx")->getColumns()); - self::assertTrue($table->getIndex('my_idx')->spansColumns(array('id'))); + self::assertEquals(['ID'], $table->getIndex('my_idx')->getColumns()); + self::assertTrue($table->getIndex('my_idx')->spansColumns(['id'])); } public function testAddPrimaryKey_ColumnsAreExplicitlySetToNotNull() { - $table = new Table("foo"); - $column = $table->addColumn("id", 'integer', array('notnull' => false)); + $table = new Table('foo'); + $column = $table->addColumn('id', 'integer', ['notnull' => false]); self::assertFalse($column->getNotnull()); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); self::assertTrue($column->getNotnull()); } @@ -348,9 +351,9 @@ public function testAddPrimaryKey_ColumnsAreExplicitlySetToNotNull() */ public function testAllowImplicitSchemaTableInAutogeneratedIndexNames() { - $table = new Table("foo.bar"); - $table->addColumn('baz', 'integer', array()); - $table->addIndex(array('baz')); + $table = new Table('foo.bar'); + $table->addColumn('baz', 'integer', []); + $table->addIndex(['baz']); self::assertCount(1, $table->getIndexes()); } @@ -360,20 +363,20 @@ public function testAllowImplicitSchemaTableInAutogeneratedIndexNames() */ public function testAddForeignKeyIndexImplicitly() { - $table = new Table("foo"); - $table->addColumn("id", 'integer'); + $table = new Table('foo'); + $table->addColumn('id', 'integer'); - $foreignTable = new Table("bar"); - $foreignTable->addColumn("id", 'integer'); + $foreignTable = new Table('bar'); + $foreignTable->addColumn('id', 'integer'); - $table->addForeignKeyConstraint($foreignTable, array("id"), array("id"), array("foo" => "bar")); + $table->addForeignKeyConstraint($foreignTable, ['id'], ['id'], ['foo' => 'bar']); $indexes = $table->getIndexes(); self::assertCount(1, $indexes); $index = current($indexes); self::assertTrue($table->hasIndex($index->getName())); - self::assertEquals(array('id'), $index->getColumns()); + self::assertEquals(['id'], $index->getColumns()); } /** @@ -383,16 +386,16 @@ public function testAddForeignKeyDoesNotCreateDuplicateIndex() { $table = new Table('foo'); $table->addColumn('bar', 'integer'); - $table->addIndex(array('bar'), 'bar_idx'); + $table->addIndex(['bar'], 'bar_idx'); $foreignTable = new Table('bar'); $foreignTable->addColumn('foo', 'integer'); - $table->addForeignKeyConstraint($foreignTable, array('bar'), array('foo')); + $table->addForeignKeyConstraint($foreignTable, ['bar'], ['foo']); self::assertCount(1, $table->getIndexes()); self::assertTrue($table->hasIndex('bar_idx')); - self::assertSame(array('bar'), $table->getIndex('bar_idx')->getColumns()); + self::assertSame(['bar'], $table->getIndex('bar_idx')->getColumns()); } /** @@ -404,22 +407,22 @@ public function testAddForeignKeyAddsImplicitIndexIfIndexColumnsDoNotSpan() $table->addColumn('bar', 'integer'); $table->addColumn('baz', 'string'); $table->addColumn('bloo', 'string'); - $table->addIndex(array('baz', 'bar'), 'composite_idx'); - $table->addIndex(array('bar', 'baz', 'bloo'), 'full_idx'); + $table->addIndex(['baz', 'bar'], 'composite_idx'); + $table->addIndex(['bar', 'baz', 'bloo'], 'full_idx'); $foreignTable = new Table('bar'); $foreignTable->addColumn('foo', 'integer'); $foreignTable->addColumn('baz', 'string'); - $table->addForeignKeyConstraint($foreignTable, array('bar', 'baz'), array('foo', 'baz')); + $table->addForeignKeyConstraint($foreignTable, ['bar', 'baz'], ['foo', 'baz']); self::assertCount(3, $table->getIndexes()); self::assertTrue($table->hasIndex('composite_idx')); self::assertTrue($table->hasIndex('full_idx')); self::assertTrue($table->hasIndex('idx_8c73652176ff8caa78240498')); - self::assertSame(array('baz', 'bar'), $table->getIndex('composite_idx')->getColumns()); - self::assertSame(array('bar', 'baz', 'bloo'), $table->getIndex('full_idx')->getColumns()); - self::assertSame(array('bar', 'baz'), $table->getIndex('idx_8c73652176ff8caa78240498')->getColumns()); + self::assertSame(['baz', 'bar'], $table->getIndex('composite_idx')->getColumns()); + self::assertSame(['bar', 'baz', 'bloo'], $table->getIndex('full_idx')->getColumns()); + self::assertSame(['bar', 'baz'], $table->getIndex('idx_8c73652176ff8caa78240498')->getColumns()); } /** @@ -428,15 +431,15 @@ public function testAddForeignKeyAddsImplicitIndexIfIndexColumnsDoNotSpan() */ public function testOverrulingIndexDoesNotDropOverruledIndex() { - $table = new Table("bar"); - $table->addColumn('baz', 'integer', array()); - $table->addIndex(array('baz')); + $table = new Table('bar'); + $table->addColumn('baz', 'integer', []); + $table->addIndex(['baz']); $indexes = $table->getIndexes(); self::assertCount(1, $indexes); $index = current($indexes); - $table->addUniqueIndex(array('baz')); + $table->addUniqueIndex(['baz']); self::assertCount(2, $table->getIndexes()); self::assertTrue($table->hasIndex($index->getName())); } @@ -448,14 +451,14 @@ public function testAllowsAddingDuplicateIndexesBasedOnColumns() { $table = new Table('foo'); $table->addColumn('bar', 'integer'); - $table->addIndex(array('bar'), 'bar_idx'); - $table->addIndex(array('bar'), 'duplicate_idx'); + $table->addIndex(['bar'], 'bar_idx'); + $table->addIndex(['bar'], 'duplicate_idx'); self::assertCount(2, $table->getIndexes()); self::assertTrue($table->hasIndex('bar_idx')); self::assertTrue($table->hasIndex('duplicate_idx')); - self::assertSame(array('bar'), $table->getIndex('bar_idx')->getColumns()); - self::assertSame(array('bar'), $table->getIndex('duplicate_idx')->getColumns()); + self::assertSame(['bar'], $table->getIndex('bar_idx')->getColumns()); + self::assertSame(['bar'], $table->getIndex('duplicate_idx')->getColumns()); } /** @@ -466,14 +469,14 @@ public function testAllowsAddingFulfillingIndexesBasedOnColumns() $table = new Table('foo'); $table->addColumn('bar', 'integer'); $table->addColumn('baz', 'string'); - $table->addIndex(array('bar'), 'bar_idx'); - $table->addIndex(array('bar', 'baz'), 'fulfilling_idx'); + $table->addIndex(['bar'], 'bar_idx'); + $table->addIndex(['bar', 'baz'], 'fulfilling_idx'); self::assertCount(2, $table->getIndexes()); self::assertTrue($table->hasIndex('bar_idx')); self::assertTrue($table->hasIndex('fulfilling_idx')); - self::assertSame(array('bar'), $table->getIndex('bar_idx')->getColumns()); - self::assertSame(array('bar', 'baz'), $table->getIndex('fulfilling_idx')->getColumns()); + self::assertSame(['bar'], $table->getIndex('bar_idx')->getColumns()); + self::assertSame(['bar', 'baz'], $table->getIndex('fulfilling_idx')->getColumns()); } /** @@ -482,14 +485,14 @@ public function testAllowsAddingFulfillingIndexesBasedOnColumns() */ public function testPrimaryKeyOverrulingUniqueIndexDoesNotDropUniqueIndex() { - $table = new Table("bar"); - $table->addColumn('baz', 'integer', array()); - $table->addUniqueIndex(array('baz'), 'idx_unique'); + $table = new Table('bar'); + $table->addColumn('baz', 'integer', []); + $table->addUniqueIndex(['baz'], 'idx_unique'); - $table->setPrimaryKey(array('baz')); + $table->setPrimaryKey(['baz']); $indexes = $table->getIndexes(); - self::assertCount(2, $indexes, "Table should only contain both the primary key table index and the unique one, even though it was overruled."); + self::assertCount(2, $indexes, 'Table should only contain both the primary key table index and the unique one, even though it was overruled.'); self::assertTrue($table->hasPrimaryKey()); self::assertTrue($table->hasIndex('idx_unique')); @@ -502,11 +505,11 @@ public function testAddingFulfillingRegularIndexOverridesImplicitForeignKeyConst $localTable = new Table('local'); $localTable->addColumn('id', 'integer'); - $localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); + $localTable->addForeignKeyConstraint($foreignTable, ['id'], ['id']); self::assertCount(1, $localTable->getIndexes()); - $localTable->addIndex(array('id'), 'explicit_idx'); + $localTable->addIndex(['id'], 'explicit_idx'); self::assertCount(1, $localTable->getIndexes()); self::assertTrue($localTable->hasIndex('explicit_idx')); @@ -519,11 +522,11 @@ public function testAddingFulfillingUniqueIndexOverridesImplicitForeignKeyConstr $localTable = new Table('local'); $localTable->addColumn('id', 'integer'); - $localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); + $localTable->addForeignKeyConstraint($foreignTable, ['id'], ['id']); self::assertCount(1, $localTable->getIndexes()); - $localTable->addUniqueIndex(array('id'), 'explicit_idx'); + $localTable->addUniqueIndex(['id'], 'explicit_idx'); self::assertCount(1, $localTable->getIndexes()); self::assertTrue($localTable->hasIndex('explicit_idx')); @@ -536,11 +539,11 @@ public function testAddingFulfillingPrimaryKeyOverridesImplicitForeignKeyConstra $localTable = new Table('local'); $localTable->addColumn('id', 'integer'); - $localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); + $localTable->addForeignKeyConstraint($foreignTable, ['id'], ['id']); self::assertCount(1, $localTable->getIndexes()); - $localTable->setPrimaryKey(array('id'), 'explicit_idx'); + $localTable->setPrimaryKey(['id'], 'explicit_idx'); self::assertCount(1, $localTable->getIndexes()); self::assertTrue($localTable->hasIndex('explicit_idx')); @@ -553,14 +556,14 @@ public function testAddingFulfillingExplicitIndexOverridingImplicitForeignKeyCon $localTable = new Table('local'); $localTable->addColumn('id', 'integer'); - $localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); + $localTable->addForeignKeyConstraint($foreignTable, ['id'], ['id']); self::assertCount(1, $localTable->getIndexes()); self::assertTrue($localTable->hasIndex('IDX_8BD688E8BF396750')); $implicitIndex = $localTable->getIndex('IDX_8BD688E8BF396750'); - $localTable->addIndex(array('id'), 'IDX_8BD688E8BF396750'); + $localTable->addIndex(['id'], 'IDX_8BD688E8BF396750'); self::assertCount(1, $localTable->getIndexes()); self::assertTrue($localTable->hasIndex('IDX_8BD688E8BF396750')); @@ -572,10 +575,10 @@ public function testAddingFulfillingExplicitIndexOverridingImplicitForeignKeyCon */ public function testQuotedTableName() { - $table = new Table("`bar`"); + $table = new Table('`bar`'); - $mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform(); - $sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform(); + $mysqlPlatform = new MySqlPlatform(); + $sqlitePlatform = new SqlitePlatform(); self::assertEquals('bar', $table->getName()); self::assertEquals('`bar`', $table->getQuotedName($mysqlPlatform)); @@ -587,12 +590,12 @@ public function testQuotedTableName() */ public function testTableHasPrimaryKey() { - $table = new Table("test"); + $table = new Table('test'); self::assertFalse($table->hasPrimaryKey()); - $table->addColumn("foo", "integer"); - $table->setPrimaryKey(array("foo")); + $table->addColumn('foo', 'integer'); + $table->setPrimaryKey(['foo']); self::assertTrue($table->hasPrimaryKey()); } @@ -602,7 +605,7 @@ public function testTableHasPrimaryKey() */ public function testAddIndexWithQuotedColumns() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('"foo"', 'integer'); $table->addColumn('bar', 'integer'); $table->addIndex(['"foo"', '"bar"']); @@ -615,10 +618,10 @@ public function testAddIndexWithQuotedColumns() */ public function testAddForeignKeyWithQuotedColumnsAndTable() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('"foo"', 'integer'); $table->addColumn('bar', 'integer'); - $table->addForeignKeyConstraint('"boing"', ['"foo"', '"bar"'], ["id"]); + $table->addForeignKeyConstraint('"boing"', ['"foo"', '"bar"'], ['id']); self::assertCount(1, $table->getForeignKeys()); } @@ -628,9 +631,9 @@ public function testAddForeignKeyWithQuotedColumnsAndTable() */ public function testQuoteSchemaPrefixed() { - $table = new Table("`test`.`test`"); - self::assertEquals("test.test", $table->getName()); - self::assertEquals("`test`.`test`", $table->getQuotedName(new \Doctrine\DBAL\Platforms\MySqlPlatform)); + $table = new Table('`test`.`test`'); + self::assertEquals('test.test', $table->getName()); + self::assertEquals('`test`.`test`', $table->getQuotedName(new MySqlPlatform())); } /** @@ -638,13 +641,13 @@ public function testQuoteSchemaPrefixed() */ public function testFullQualifiedTableName() { - $table = new Table("`test`.`test`"); - self::assertEquals('test.test', $table->getFullQualifiedName("test")); - self::assertEquals('test.test', $table->getFullQualifiedName("other")); + $table = new Table('`test`.`test`'); + self::assertEquals('test.test', $table->getFullQualifiedName('test')); + self::assertEquals('test.test', $table->getFullQualifiedName('other')); - $table = new Table("test"); - self::assertEquals('test.test', $table->getFullQualifiedName("test")); - self::assertEquals('other.test', $table->getFullQualifiedName("other")); + $table = new Table('test'); + self::assertEquals('test.test', $table->getFullQualifiedName('test')); + self::assertEquals('other.test', $table->getFullQualifiedName('other')); } /** @@ -652,9 +655,9 @@ public function testFullQualifiedTableName() */ public function testDropIndex() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addIndex(array('id'), 'idx'); + $table->addIndex(['id'], 'idx'); self::assertTrue($table->hasIndex('idx')); @@ -667,9 +670,9 @@ public function testDropIndex() */ public function testDropPrimaryKey() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); self::assertTrue($table->hasPrimaryKey()); @@ -682,14 +685,14 @@ public function testDropPrimaryKey() */ public function testRenameIndex() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'integer'); $table->addColumn('baz', 'integer'); - $table->setPrimaryKey(array('id'), 'pk'); - $table->addIndex(array('foo'), 'idx', array('flag')); - $table->addUniqueIndex(array('bar', 'baz'), 'uniq'); + $table->setPrimaryKey(['id'], 'pk'); + $table->addIndex(['foo'], 'idx', ['flag']); + $table->addUniqueIndex(['bar', 'baz'], 'uniq'); // Rename to custom name. self::assertSame($table, $table->renameIndex('pk', 'pk_new')); @@ -705,13 +708,13 @@ public function testRenameIndex() self::assertFalse($table->hasIndex('idx')); self::assertFalse($table->hasIndex('uniq')); - self::assertEquals(new Index('pk_new', array('id'), true, true), $table->getPrimaryKey()); - self::assertEquals(new Index('pk_new', array('id'), true, true), $table->getIndex('pk_new')); + self::assertEquals(new Index('pk_new', ['id'], true, true), $table->getPrimaryKey()); + self::assertEquals(new Index('pk_new', ['id'], true, true), $table->getIndex('pk_new')); self::assertEquals( - new Index('idx_new', array('foo'), false, false, array('flag')), + new Index('idx_new', ['foo'], false, false, ['flag']), $table->getIndex('idx_new') ); - self::assertEquals(new Index('uniq_new', array('bar', 'baz'), true), $table->getIndex('uniq_new')); + self::assertEquals(new Index('uniq_new', ['bar', 'baz'], true), $table->getIndex('uniq_new')); // Rename to auto-generated name. self::assertSame($table, $table->renameIndex('pk_new', null)); @@ -727,14 +730,14 @@ public function testRenameIndex() self::assertFalse($table->hasIndex('idx_new')); self::assertFalse($table->hasIndex('uniq_new')); - self::assertEquals(new Index('primary', array('id'), true, true), $table->getPrimaryKey()); - self::assertEquals(new Index('primary', array('id'), true, true), $table->getIndex('primary')); + self::assertEquals(new Index('primary', ['id'], true, true), $table->getPrimaryKey()); + self::assertEquals(new Index('primary', ['id'], true, true), $table->getIndex('primary')); self::assertEquals( - new Index('IDX_D87F7E0C8C736521', array('foo'), false, false, array('flag')), + new Index('IDX_D87F7E0C8C736521', ['foo'], false, false, ['flag']), $table->getIndex('IDX_D87F7E0C8C736521') ); self::assertEquals( - new Index('UNIQ_D87F7E0C76FF8CAA78240498', array('bar', 'baz'), true), + new Index('UNIQ_D87F7E0C76FF8CAA78240498', ['bar', 'baz'], true), $table->getIndex('UNIQ_D87F7E0C76FF8CAA78240498') ); @@ -756,11 +759,11 @@ public function testKeepsIndexOptionsOnRenamingRegularIndex() { $table = new Table('foo'); $table->addColumn('id', 'integer'); - $table->addIndex(array('id'), 'idx_bar', array(), array('where' => '1 = 1')); + $table->addIndex(['id'], 'idx_bar', [], ['where' => '1 = 1']); $table->renameIndex('idx_bar', 'idx_baz'); - self::assertSame(array('where' => '1 = 1'), $table->getIndex('idx_baz')->getOptions()); + self::assertSame(['where' => '1 = 1'], $table->getIndex('idx_baz')->getOptions()); } /** @@ -770,11 +773,11 @@ public function testKeepsIndexOptionsOnRenamingUniqueIndex() { $table = new Table('foo'); $table->addColumn('id', 'integer'); - $table->addUniqueIndex(array('id'), 'idx_bar', array('where' => '1 = 1')); + $table->addUniqueIndex(['id'], 'idx_bar', ['where' => '1 = 1']); $table->renameIndex('idx_bar', 'idx_baz'); - self::assertSame(array('where' => '1 = 1'), $table->getIndex('idx_baz')->getOptions()); + self::assertSame(['where' => '1 = 1'], $table->getIndex('idx_baz')->getOptions()); } /** @@ -783,9 +786,9 @@ public function testKeepsIndexOptionsOnRenamingUniqueIndex() */ public function testThrowsExceptionOnRenamingNonExistingIndex() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addIndex(array('id'), 'idx'); + $table->addIndex(['id'], 'idx'); $table->renameIndex('foo', 'bar'); } @@ -796,11 +799,11 @@ public function testThrowsExceptionOnRenamingNonExistingIndex() */ public function testThrowsExceptionOnRenamingToAlreadyExistingIndex() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); - $table->addIndex(array('id'), 'idx_id'); - $table->addIndex(array('foo'), 'idx_foo'); + $table->addIndex(['id'], 'idx_id'); + $table->addIndex(['foo'], 'idx_foo'); $table->renameIndex('idx_id', 'idx_foo'); } @@ -814,8 +817,8 @@ public function testNormalizesColumnNames($assetName) $table = new Table('test'); $table->addColumn($assetName, 'integer'); - $table->addIndex(array($assetName), $assetName); - $table->addForeignKeyConstraint('test', array($assetName), array($assetName), array(), $assetName); + $table->addIndex([$assetName], $assetName); + $table->addForeignKeyConstraint('test', [$assetName], [$assetName], [], $assetName); self::assertTrue($table->hasColumn($assetName)); self::assertTrue($table->hasColumn('foo')); @@ -865,15 +868,15 @@ public function testNormalizesColumnNames($assetName) public function getNormalizesAssetNames() { - return array( - array('foo'), - array('FOO'), - array('`foo`'), - array('`FOO`'), - array('"foo"'), - array('"FOO"'), - array('"foo"'), - array('"FOO"'), - ); + return [ + ['foo'], + ['FOO'], + ['`foo`'], + ['`FOO`'], + ['"foo"'], + ['"FOO"'], + ['"foo"'], + ['"FOO"'], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php index bc76b62010a..f94e1c1d019 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -2,18 +2,20 @@ namespace Doctrine\Tests\DBAL\Schema\Visitor; -use \Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector; - -class CreateSchemaSqlCollectorTest extends \PHPUnit\Framework\TestCase +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector; +use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject; + +class CreateSchemaSqlCollectorTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\PHPUnit_Framework_MockObject_MockObject - */ + /** @var AbstractPlatform|PHPUnit_Framework_MockObject_MockObject */ private $platformMock; - /** - * @var \Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector - */ + /** @var CreateSchemaSqlCollector */ private $visitor; /** @@ -25,19 +27,19 @@ protected function setUp() $this->platformMock = $this->getMockBuilder('Doctrine\DBAL\Platforms\AbstractPlatform') ->setMethods( - array( + [ 'getCreateForeignKeySQL', 'getCreateSchemaSQL', 'getCreateSequenceSQL', 'getCreateTableSQL', 'supportsForeignKeyConstraints', - 'supportsSchemas' - ) + 'supportsSchemas', + ] ) ->getMockForAbstractClass(); - $this->visitor = new CreateSchemaSqlCollector($this->platformMock); + $this->visitor = new CreateSchemaSqlCollector($this->platformMock); - foreach (array('getCreateSchemaSQL', 'getCreateTableSQL', 'getCreateForeignKeySQL', 'getCreateSequenceSQL') as $method) { + foreach (['getCreateSchemaSQL', 'getCreateTableSQL', 'getCreateForeignKeySQL', 'getCreateSequenceSQL'] as $method) { $this->platformMock->expects($this->any()) ->method($method) ->will($this->returnValue('foo')); @@ -60,7 +62,7 @@ public function testAcceptsNamespace() $this->visitor->acceptNamespace('foo'); - self::assertSame(array('foo'), $this->visitor->getQueries()); + self::assertSame(['foo'], $this->visitor->getQueries()); } public function testAcceptsTable() @@ -69,7 +71,7 @@ public function testAcceptsTable() $this->visitor->acceptTable($table); - self::assertSame(array('foo'), $this->visitor->getQueries()); + self::assertSame(['foo'], $this->visitor->getQueries()); } public function testAcceptsForeignKey() @@ -82,7 +84,7 @@ public function testAcceptsForeignKey() ->method('supportsForeignKeyConstraints') ->will($this->returnValue(true)); - $table = $this->createTableMock(); + $table = $this->createTableMock(); $foreignKey = $this->createForeignKeyConstraintMock(); $this->visitor->acceptForeignKey($table, $foreignKey); @@ -91,7 +93,7 @@ public function testAcceptsForeignKey() $this->visitor->acceptForeignKey($table, $foreignKey); - self::assertSame(array('foo'), $this->visitor->getQueries()); + self::assertSame(['foo'], $this->visitor->getQueries()); } public function testAcceptsSequences() @@ -100,20 +102,20 @@ public function testAcceptsSequences() $this->visitor->acceptSequence($sequence); - self::assertSame(array('foo'), $this->visitor->getQueries()); + self::assertSame(['foo'], $this->visitor->getQueries()); } public function testResetsQueries() { - foreach (array('supportsSchemas', 'supportsForeignKeyConstraints') as $method) { + foreach (['supportsSchemas', 'supportsForeignKeyConstraints'] as $method) { $this->platformMock->expects($this->any()) ->method($method) ->will($this->returnValue(true)); } - $table = $this->createTableMock(); + $table = $this->createTableMock(); $foreignKey = $this->createForeignKeyConstraintMock(); - $sequence = $this->createSequenceMock(); + $sequence = $this->createSequenceMock(); $this->visitor->acceptNamespace('foo'); $this->visitor->acceptTable($table); @@ -128,7 +130,7 @@ public function testResetsQueries() } /** - * @return \Doctrine\DBAL\Schema\ForeignKeyConstraint|\PHPUnit_Framework_MockObject_MockObject + * @return ForeignKeyConstraint|PHPUnit_Framework_MockObject_MockObject */ private function createForeignKeyConstraintMock() { @@ -138,7 +140,7 @@ private function createForeignKeyConstraintMock() } /** - * @return \Doctrine\DBAL\Schema\Sequence|\PHPUnit_Framework_MockObject_MockObject + * @return Sequence|PHPUnit_Framework_MockObject_MockObject */ private function createSequenceMock() { @@ -148,7 +150,7 @@ private function createSequenceMock() } /** - * @return \Doctrine\DBAL\Schema\Table|\PHPUnit_Framework_MockObject_MockObject + * @return Table|PHPUnit_Framework_MockObject_MockObject */ private function createTableMock() { diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php index 20e20127f04..c65996cab7b 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php @@ -3,11 +3,12 @@ namespace Doctrine\Tests\DBAL\Schema\Visitor; use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector; +use PHPUnit\Framework\TestCase; /** * @covers Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector */ -class DropSchemaSqlCollectorTest extends \PHPUnit\Framework\TestCase +class DropSchemaSqlCollectorTest extends TestCase { public function testGetQueriesUsesAcceptedForeignKeys() { @@ -18,7 +19,7 @@ public function testGetQueriesUsesAcceptedForeignKeys() $keyConstraintTwo = $this->getStubKeyConstraint('second'); $platform = $this->getMockBuilder('Doctrine\DBAL\Platforms\AbstractPlatform') - ->setMethods(array('getDropForeignKeySQL')) + ->setMethods(['getDropForeignKeySQL']) ->getMockForAbstractClass(); $collector = new DropSchemaSqlCollector($platform); @@ -60,11 +61,11 @@ private function getStubKeyConstraint($name) $constraint->expects($this->any()) ->method('getForeignColumns') - ->will($this->returnValue(array())); + ->will($this->returnValue([])); $constraint->expects($this->any()) ->method('getColumns') - ->will($this->returnValue(array())); + ->will($this->returnValue([])); return $constraint; } @@ -75,7 +76,7 @@ public function testGivenForeignKeyWithZeroLength_acceptForeignKeyThrowsExceptio $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform') ); - $this->expectException( 'Doctrine\DBAL\Schema\SchemaException' ); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); $collector->acceptForeignKey($this->getTableMock(), $this->getStubKeyConstraint('')); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php index 356295d56b9..c3e52b0ffaf 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php @@ -6,27 +6,28 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaConfig; use Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets; +use PHPUnit\Framework\TestCase; use function array_keys; -class RemoveNamespacedAssetsTest extends \PHPUnit\Framework\TestCase +class RemoveNamespacedAssetsTest extends TestCase { /** * @group DBAL-204 */ public function testRemoveNamespacedAssets() { - $config = new SchemaConfig; - $config->setName("test"); - $schema = new Schema(array(), array(), $config); + $config = new SchemaConfig(); + $config->setName('test'); + $schema = new Schema([], [], $config); - $schema->createTable("test.test"); - $schema->createTable("foo.bar"); - $schema->createTable("baz"); + $schema->createTable('test.test'); + $schema->createTable('foo.bar'); + $schema->createTable('baz'); $schema->visit(new RemoveNamespacedAssets()); $tables = $schema->getTables(); - self::assertEquals(array("test.test", "test.baz"), array_keys($tables), "Only 2 tables should be present, both in 'test' namespace."); + self::assertEquals(['test.test', 'test.baz'], array_keys($tables), "Only 2 tables should be present, both in 'test' namespace."); } /** @@ -34,22 +35,22 @@ public function testRemoveNamespacedAssets() */ public function testCleanupForeignKeys() { - $config = new SchemaConfig; - $config->setName("test"); - $schema = new Schema(array(), array(), $config); + $config = new SchemaConfig(); + $config->setName('test'); + $schema = new Schema([], [], $config); - $fooTable = $schema->createTable("foo.bar"); + $fooTable = $schema->createTable('foo.bar'); $fooTable->addColumn('id', 'integer'); - $testTable = $schema->createTable("test.test"); + $testTable = $schema->createTable('test.test'); $testTable->addColumn('id', 'integer'); - $testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id")); + $testTable->addForeignKeyConstraint('foo.bar', ['id'], ['id']); $schema->visit(new RemoveNamespacedAssets()); $sql = $schema->toSql(new MySqlPlatform()); - self::assertCount(1, $sql, "Just one CREATE TABLE statement, no foreign key and table to foo.bar"); + self::assertCount(1, $sql, 'Just one CREATE TABLE statement, no foreign key and table to foo.bar'); } /** @@ -57,21 +58,21 @@ public function testCleanupForeignKeys() */ public function testCleanupForeignKeysDifferentOrder() { - $config = new SchemaConfig; - $config->setName("test"); - $schema = new Schema(array(), array(), $config); + $config = new SchemaConfig(); + $config->setName('test'); + $schema = new Schema([], [], $config); - $testTable = $schema->createTable("test.test"); + $testTable = $schema->createTable('test.test'); $testTable->addColumn('id', 'integer'); - $fooTable = $schema->createTable("foo.bar"); + $fooTable = $schema->createTable('foo.bar'); $fooTable->addColumn('id', 'integer'); - $testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id")); + $testTable->addForeignKeyConstraint('foo.bar', ['id'], ['id']); $schema->visit(new RemoveNamespacedAssets()); $sql = $schema->toSql(new MySqlPlatform()); - self::assertCount(1, $sql, "Just one CREATE TABLE statement, no foreign key and table to foo.bar"); + self::assertCount(1, $sql, 'Just one CREATE TABLE statement, no foreign key and table to foo.bar'); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php index 96a441210e1..d326a817c0d 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php @@ -3,51 +3,52 @@ namespace Doctrine\Tests\DBAL\Schema\Visitor; use Doctrine\DBAL\Schema\Schema; +use PHPUnit\Framework\TestCase; -class SchemaSqlCollectorTest extends \PHPUnit\Framework\TestCase +class SchemaSqlCollectorTest extends TestCase { public function testCreateSchema() { $platformMock = $this->getMockBuilder('Doctrine\DBAL\Platforms\MySqlPlatform') - ->setMethods(array('getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql')) + ->setMethods(['getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql']) ->getMock(); $platformMock->expects($this->exactly(2)) ->method('getCreateTableSql') - ->will($this->returnValue(array("foo"))); + ->will($this->returnValue(['foo'])); $platformMock->expects($this->exactly(1)) ->method('getCreateSequenceSql') - ->will($this->returnValue("bar")); + ->will($this->returnValue('bar')); $platformMock->expects($this->exactly(1)) ->method('getCreateForeignKeySql') - ->will($this->returnValue("baz")); + ->will($this->returnValue('baz')); $schema = $this->createFixtureSchema(); $sql = $schema->toSql($platformMock); - self::assertEquals(array("foo", "foo", "bar", "baz"), $sql); + self::assertEquals(['foo', 'foo', 'bar', 'baz'], $sql); } public function testDropSchema() { $platformMock = $this->getMockBuilder('Doctrine\DBAL\Platforms\MySqlPlatform') - ->setMethods(array('getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql')) + ->setMethods(['getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql']) ->getMock(); $platformMock->expects($this->exactly(2)) ->method('getDropTableSql') - ->will($this->returnValue("tbl")); + ->will($this->returnValue('tbl')); $platformMock->expects($this->exactly(1)) ->method('getDropSequenceSql') - ->will($this->returnValue("seq")); + ->will($this->returnValue('seq')); $platformMock->expects($this->exactly(1)) ->method('getDropForeignKeySql') - ->will($this->returnValue("fk")); + ->will($this->returnValue('fk')); $schema = $this->createFixtureSchema(); $sql = $schema->toDropSql($platformMock); - self::assertEquals(array("fk", "seq", "tbl", "tbl"), $sql); + self::assertEquals(['fk', 'seq', 'tbl', 'tbl'], $sql); } /** @@ -56,18 +57,18 @@ public function testDropSchema() public function createFixtureSchema() { $schema = new Schema(); - $tableA = $schema->createTable("foo"); - $tableA->addColumn("id", 'integer'); - $tableA->addColumn("bar", 'string', array('length' => 255)); - $tableA->setPrimaryKey(array("id")); + $tableA = $schema->createTable('foo'); + $tableA->addColumn('id', 'integer'); + $tableA->addColumn('bar', 'string', ['length' => 255]); + $tableA->setPrimaryKey(['id']); - $schema->createSequence("foo_seq"); + $schema->createSequence('foo_seq'); - $tableB = $schema->createTable("bar"); - $tableB->addColumn("id", 'integer'); - $tableB->setPrimaryKey(array("id")); + $tableB = $schema->createTable('bar'); + $tableB->addColumn('id', 'integer'); + $tableB->setPrimaryKey(['id']); - $tableA->addForeignKeyConstraint($tableB, array("bar"), array("id")); + $tableA->addForeignKeyConstraint($tableB, ['bar'], ['id']); return $schema; } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php index 9c96cbfc975..0eafb7eae01 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -21,24 +21,25 @@ use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; +use PHPUnit\Framework\TestCase; /** * @requires extension pdo_sqlite */ -class PoolingShardConnectionTest extends \PHPUnit\Framework\TestCase +class PoolingShardConnectionTest extends TestCase { public function testConnect() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - array('id' => 2, 'memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ['id' => 2, 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertFalse($conn->isConnected(0)); $conn->connect(0); @@ -66,15 +67,15 @@ public function testNoGlobalServerException() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations."); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'shards' => array( - array('id' => 1, 'memory' => true), - array('id' => 2, 'memory' => true), - ), + 'shards' => [ + ['id' => 1, 'memory' => true], + ['id' => 2, 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); } public function testNoShardsServersException() @@ -82,12 +83,12 @@ public function testNoShardsServersException() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations."); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), + 'global' => ['memory' => true], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); } public function testNoShardsChoserException() @@ -95,15 +96,15 @@ public function testNoShardsChoserException() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Missing Shard Choser configuration 'shardChoser'"); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - array('id' => 2, 'memory' => true), - ), - )); + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ['id' => 2, 'memory' => true], + ], + ]); } public function testShardChoserWrongInstance() @@ -111,16 +112,16 @@ public function testShardChoserWrongInstance() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser"); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - array('id' => 2, 'memory' => true), - ), - 'shardChoser' => new \stdClass, - )); + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ['id' => 2, 'memory' => true], + ], + 'shardChoser' => new \stdClass(), + ]); } public function testShardNonNumericId() @@ -128,15 +129,15 @@ public function testShardNonNumericId() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Shard Id has to be a non-negative number.'); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 'foo', 'memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 'foo', 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); } public function testShardMissingId() @@ -144,15 +145,15 @@ public function testShardMissingId() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Missing 'id' for one configured shard. Please specify a unique shard-id."); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); } public function testDuplicateShardId() @@ -160,29 +161,29 @@ public function testDuplicateShardId() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Shard 1 is duplicated in the configuration.'); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - array('id' => 1, 'memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ['id' => 1, 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); } public function testSwitchShardWithOpenTransactionException() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); $conn->beginTransaction(); @@ -193,15 +194,15 @@ public function testSwitchShardWithOpenTransactionException() public function testGetActiveShardId() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertNull($conn->getActiveShardId()); @@ -217,55 +218,55 @@ public function testGetActiveShardId() public function testGetParamsOverride() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true, 'host' => 'localhost'), - 'shards' => array( - array('id' => 1, 'memory' => true, 'host' => 'foo'), - ), + 'global' => ['memory' => true, 'host' => 'localhost'], + 'shards' => [ + ['id' => 1, 'memory' => true, 'host' => 'foo'], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); - self::assertEquals(array( + self::assertEquals([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true, 'host' => 'localhost'), - 'shards' => array( - array('id' => 1, 'memory' => true, 'host' => 'foo'), - ), + 'global' => ['memory' => true, 'host' => 'localhost'], + 'shards' => [ + ['id' => 1, 'memory' => true, 'host' => 'foo'], + ], 'shardChoser' => new MultiTenantShardChoser(), 'memory' => true, 'host' => 'localhost', - ), $conn->getParams()); + ], $conn->getParams()); $conn->connect(1); - self::assertEquals(array( + self::assertEquals([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true, 'host' => 'localhost'), - 'shards' => array( - array('id' => 1, 'memory' => true, 'host' => 'foo'), - ), + 'global' => ['memory' => true, 'host' => 'localhost'], + 'shards' => [ + ['id' => 1, 'memory' => true, 'host' => 'foo'], + ], 'shardChoser' => new MultiTenantShardChoser(), 'id' => 1, 'memory' => true, 'host' => 'foo', - ), $conn->getParams()); + ], $conn->getParams()); } public function testGetHostOverride() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'host' => 'localhost', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true, 'host' => 'foo'), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true, 'host' => 'foo'], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertEquals('localhost', $conn->getHost()); @@ -275,16 +276,16 @@ public function testGetHostOverride() public function testGetPortOverride() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'port' => 3306, - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true, 'port' => 3307), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true, 'port' => 3307], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertEquals(3306, $conn->getPort()); @@ -294,16 +295,16 @@ public function testGetPortOverride() public function testGetUsernameOverride() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'user' => 'foo', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true, 'user' => 'bar'), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true, 'user' => 'bar'], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertEquals('foo', $conn->getUsername()); @@ -313,16 +314,16 @@ public function testGetUsernameOverride() public function testGetPasswordOverride() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'password' => 'foo', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true, 'password' => 'bar'), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true, 'password' => 'bar'], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertEquals('foo', $conn->getPassword()); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php index dccb1b1c53d..cc5809effab 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php @@ -19,13 +19,14 @@ namespace Doctrine\Tests\DBAL\Sharding; use Doctrine\DBAL\Sharding\PoolingShardManager; +use PHPUnit\Framework\TestCase; -class PoolingShardManagerTest extends \PHPUnit\Framework\TestCase +class PoolingShardManagerTest extends TestCase { private function createConnectionMock() { return $this->getMockBuilder('Doctrine\DBAL\Sharding\PoolingShardConnection') - ->setMethods(array('connect', 'getParams', 'fetchAll')) + ->setMethods(['connect', 'getParams', 'fetchAll']) ->disableOriginalConstructor() ->getMock(); } @@ -35,7 +36,9 @@ private function createPassthroughShardChoser() $mock = $this->createMock('Doctrine\DBAL\Sharding\ShardChoser\ShardChoser'); $mock->expects($this->any()) ->method('pickShard') - ->will($this->returnCallback(function($value) { return $value; })); + ->will($this->returnCallback(static function ($value) { + return $value; + })); return $mock; } @@ -44,7 +47,9 @@ private function createStaticShardChoser() $mock = $this->createMock('Doctrine\DBAL\Sharding\ShardChoser\ShardChoser'); $mock->expects($this->any()) ->method('pickShard') - ->will($this->returnCallback(function($value) { return 1; })); + ->will($this->returnCallback(static function ($value) { + return 1; + })); return $mock; } @@ -62,8 +67,8 @@ public function testSelectGlobal() public function testSelectShard() { $shardId = 10; - $conn = $this->createConnectionMock(); - $conn->expects($this->at(0))->method('getParams')->will($this->returnValue(array('shardChoser' => $this->createPassthroughShardChoser()))); + $conn = $this->createConnectionMock(); + $conn->expects($this->at(0))->method('getParams')->will($this->returnValue(['shardChoser' => $this->createPassthroughShardChoser()])); $conn->expects($this->at(1))->method('connect')->with($this->equalTo($shardId)); $shardManager = new PoolingShardManager($conn); @@ -77,73 +82,73 @@ public function testGetShards() $conn = $this->createConnectionMock(); $conn->expects($this->any())->method('getParams')->will( $this->returnValue( - array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createPassthroughShardChoser()) + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createPassthroughShardChoser()] ) ); $shardManager = new PoolingShardManager($conn); - $shards = $shardManager->getShards(); + $shards = $shardManager->getShards(); - self::assertEquals(array(array('id' => 1), array('id' => 2)), $shards); + self::assertEquals([['id' => 1], ['id' => 2]], $shards); } public function testQueryAll() { - $sql = "SELECT * FROM table"; - $params = array(1); - $types = array(1); + $sql = 'SELECT * FROM table'; + $params = [1]; + $types = [1]; $conn = $this->createConnectionMock(); $conn->expects($this->at(0))->method('getParams')->will($this->returnValue( - array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createPassthroughShardChoser()) + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createPassthroughShardChoser()] )); $conn->expects($this->at(1))->method('getParams')->will($this->returnValue( - array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createPassthroughShardChoser()) + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createPassthroughShardChoser()] )); $conn->expects($this->at(2))->method('connect')->with($this->equalTo(1)); $conn->expects($this->at(3)) ->method('fetchAll') ->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) - ->will($this->returnValue(array( array('id' => 1) ) )); + ->will($this->returnValue([ ['id' => 1] ])); $conn->expects($this->at(4))->method('connect')->with($this->equalTo(2)); $conn->expects($this->at(5)) ->method('fetchAll') ->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) - ->will($this->returnValue(array( array('id' => 2) ) )); + ->will($this->returnValue([ ['id' => 2] ])); $shardManager = new PoolingShardManager($conn); - $result = $shardManager->queryAll($sql, $params, $types); + $result = $shardManager->queryAll($sql, $params, $types); - self::assertEquals(array(array('id' => 1), array('id' => 2)), $result); + self::assertEquals([['id' => 1], ['id' => 2]], $result); } public function testQueryAllWithStaticShardChoser() { - $sql = "SELECT * FROM table"; - $params = array(1); - $types = array(1); + $sql = 'SELECT * FROM table'; + $params = [1]; + $types = [1]; $conn = $this->createConnectionMock(); $conn->expects($this->at(0))->method('getParams')->will($this->returnValue( - array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createStaticShardChoser()) + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createStaticShardChoser()] )); $conn->expects($this->at(1))->method('getParams')->will($this->returnValue( - array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createStaticShardChoser()) + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createStaticShardChoser()] )); $conn->expects($this->at(2))->method('connect')->with($this->equalTo(1)); $conn->expects($this->at(3)) ->method('fetchAll') ->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) - ->will($this->returnValue(array( array('id' => 1) ) )); + ->will($this->returnValue([ ['id' => 1] ])); $conn->expects($this->at(4))->method('connect')->with($this->equalTo(2)); $conn->expects($this->at(5)) ->method('fetchAll') ->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) - ->will($this->returnValue(array( array('id' => 2) ) )); + ->will($this->returnValue([ ['id' => 2] ])); $shardManager = new PoolingShardManager($conn); - $result = $shardManager->queryAll($sql, $params, $types); + $result = $shardManager->queryAll($sql, $params, $types); - self::assertEquals(array(array('id' => 1), array('id' => 2)), $result); + self::assertEquals([['id' => 1], ['id' => 2]], $result); } } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php index ced8f6615e6..2e67d0a023f 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php @@ -2,48 +2,46 @@ namespace Doctrine\Tests\DBAL\Sharding\SQLAzure; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager; +use PHPUnit\Framework\TestCase; use function strpos; -abstract class AbstractTestCase extends \PHPUnit\Framework\TestCase +abstract class AbstractTestCase extends TestCase { - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ protected $conn; - /** - * @var SQLAzureShardManager - */ + /** @var SQLAzureShardManager */ protected $sm; protected function setUp() { - if (!isset($GLOBALS['db_type']) || strpos($GLOBALS['db_type'], "sqlsrv") === false) { + if (! isset($GLOBALS['db_type']) || strpos($GLOBALS['db_type'], 'sqlsrv') === false) { $this->markTestSkipped('No driver or sqlserver driver specified.'); } - $params = array( + $params = [ 'driver' => $GLOBALS['db_type'], 'dbname' => $GLOBALS['db_name'], 'user' => $GLOBALS['db_username'], 'password' => $GLOBALS['db_password'], 'host' => $GLOBALS['db_host'], - 'sharding' => array( + 'sharding' => [ 'federationName' => 'Orders_Federation', 'distributionKey' => 'CustID', 'distributionType' => 'integer', 'filteringEnabled' => false, - ), - 'driverOptions' => array('MultipleActiveResultSets' => false) - ); + ], + 'driverOptions' => ['MultipleActiveResultSets' => false], + ]; $this->conn = DriverManager::getConnection($params); $serverEdition = $this->conn->fetchColumn("SELECT CONVERT(NVARCHAR(128), SERVERPROPERTY('Edition'))"); - if (0 !== strpos($serverEdition, 'SQL Azure')) { + if (strpos($serverEdition, 'SQL Azure') !== 0) { $this->markTestSkipped('SQL Azure only test.'); } @@ -62,8 +60,8 @@ public function createShopSchema() $products->addColumn('ProductID', 'integer'); $products->addColumn('SupplierID', 'integer'); $products->addColumn('ProductName', 'string'); - $products->addColumn('Price', 'decimal', array('scale' => 2, 'precision' => 12)); - $products->setPrimaryKey(array('ProductID')); + $products->addColumn('Price', 'decimal', ['scale' => 2, 'precision' => 12]); + $products->setPrimaryKey(['ProductID']); $products->addOption('azure.federated', true); $customers = $schema->createTable('Customers'); @@ -71,7 +69,7 @@ public function createShopSchema() $customers->addColumn('CompanyName', 'string'); $customers->addColumn('FirstName', 'string'); $customers->addColumn('LastName', 'string'); - $customers->setPrimaryKey(array('CustomerID')); + $customers->setPrimaryKey(['CustomerID']); $customers->addOption('azure.federated', true); $customers->addOption('azure.federatedOnColumnName', 'CustomerID'); @@ -79,7 +77,7 @@ public function createShopSchema() $orders->addColumn('CustomerID', 'integer'); $orders->addColumn('OrderID', 'integer'); $orders->addColumn('OrderDate', 'datetime'); - $orders->setPrimaryKey(array('CustomerID', 'OrderID')); + $orders->setPrimaryKey(['CustomerID', 'OrderID']); $orders->addOption('azure.federated', true); $orders->addOption('azure.federatedOnColumnName', 'CustomerID'); @@ -88,7 +86,7 @@ public function createShopSchema() $orderItems->addColumn('OrderID', 'integer'); $orderItems->addColumn('ProductID', 'integer'); $orderItems->addColumn('Quantity', 'integer'); - $orderItems->setPrimaryKey(array('CustomerID', 'OrderID', 'ProductID')); + $orderItems->setPrimaryKey(['CustomerID', 'OrderID', 'ProductID']); $orderItems->addOption('azure.federated', true); $orderItems->addOption('azure.federatedOnColumnName', 'CustomerID'); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php index b65c99a6ebe..8a99ea70879 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php @@ -1,4 +1,5 @@ sm->selectShard(0); - $this->conn->insert("Products", array( - "ProductID" => 1, - "SupplierID" => 2, - "ProductName" => "Test", - "Price" => 10.45 - )); - - $this->conn->insert("Customers", array( - "CustomerID" => 1, - "CompanyName" => "Foo", - "FirstName" => "Benjamin", - "LastName" => "E.", - )); - - $query = "SELECT * FROM Products"; - $data = $this->conn->fetchAll($query); + $this->conn->insert('Products', [ + 'ProductID' => 1, + 'SupplierID' => 2, + 'ProductName' => 'Test', + 'Price' => 10.45, + ]); + + $this->conn->insert('Customers', [ + 'CustomerID' => 1, + 'CompanyName' => 'Foo', + 'FirstName' => 'Benjamin', + 'LastName' => 'E.', + ]); + + $query = 'SELECT * FROM Products'; + $data = $this->conn->fetchAll($query); self::assertGreaterThan(0, count($data)); - $query = "SELECT * FROM Customers"; - $data = $this->conn->fetchAll($query); + $query = 'SELECT * FROM Customers'; + $data = $this->conn->fetchAll($query); self::assertGreaterThan(0, count($data)); - $data = $this->sm->queryAll("SELECT * FROM Customers"); + $data = $this->sm->queryAll('SELECT * FROM Customers'); self::assertGreaterThan(0, count($data)); } } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php index 99be4eff108..d49831e907d 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php @@ -22,44 +22,44 @@ use Doctrine\DBAL\Platforms\SQLAzurePlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Sharding\SQLAzure\Schema\MultiTenantVisitor; +use PHPUnit\Framework\TestCase; -class MultiTenantVisitorTest extends \PHPUnit\Framework\TestCase +class MultiTenantVisitorTest extends TestCase { public function testMultiTenantPrimaryKey() { $platform = new SQLAzurePlatform(); - $visitor = new MultiTenantVisitor(); + $visitor = new MultiTenantVisitor(); $schema = new Schema(); - $foo = $schema->createTable('foo'); + $foo = $schema->createTable('foo'); $foo->addColumn('id', 'string'); - $foo->setPrimaryKey(array('id')); + $foo->setPrimaryKey(['id']); $schema->visit($visitor); - self::assertEquals(array('id', 'tenant_id'), $foo->getPrimaryKey()->getColumns()); + self::assertEquals(['id', 'tenant_id'], $foo->getPrimaryKey()->getColumns()); self::assertTrue($foo->hasColumn('tenant_id')); } public function testMultiTenantNonPrimaryKey() { $platform = new SQLAzurePlatform(); - $visitor = new MultiTenantVisitor(); + $visitor = new MultiTenantVisitor(); $schema = new Schema(); - $foo = $schema->createTable('foo'); + $foo = $schema->createTable('foo'); $foo->addColumn('id', 'string'); $foo->addColumn('created', 'datetime'); - $foo->setPrimaryKey(array('id')); - $foo->addIndex(array('created'), 'idx'); + $foo->setPrimaryKey(['id']); + $foo->addIndex(['created'], 'idx'); $foo->getPrimaryKey()->addFlag('nonclustered'); $foo->getIndex('idx')->addFlag('clustered'); $schema->visit($visitor); - self::assertEquals(array('id'), $foo->getPrimaryKey()->getColumns()); + self::assertEquals(['id'], $foo->getPrimaryKey()->getColumns()); self::assertTrue($foo->hasColumn('tenant_id')); - self::assertEquals(array('created', 'tenant_id'), $foo->getIndex('idx')->getColumns()); + self::assertEquals(['created', 'tenant_id'], $foo->getIndex('idx')->getColumns()); } } - diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php index 7561b12b3ec..20e479a3e00 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php @@ -1,4 +1,5 @@ createShopSchema(); $synchronizer = new SQLAzureFederationsSynchronizer($this->conn, $this->sm); - $sql = $synchronizer->getCreateSchema($schema); + $sql = $synchronizer->getCreateSchema($schema); - self::assertEquals(array ( + self::assertEquals([ "--Create Federation\nCREATE FEDERATION Orders_Federation (CustID INT RANGE)", - "USE FEDERATION Orders_Federation (CustID = 0) WITH RESET, FILTERING = OFF;", - "CREATE TABLE Products (ProductID INT NOT NULL, SupplierID INT NOT NULL, ProductName NVARCHAR(255) NOT NULL, Price NUMERIC(12, 2) NOT NULL, PRIMARY KEY (ProductID))", - "CREATE TABLE Customers (CustomerID INT NOT NULL, CompanyName NVARCHAR(255) NOT NULL, FirstName NVARCHAR(255) NOT NULL, LastName NVARCHAR(255) NOT NULL, PRIMARY KEY (CustomerID))", - "CREATE TABLE Orders (CustomerID INT NOT NULL, OrderID INT NOT NULL, OrderDate DATETIME2(6) NOT NULL, PRIMARY KEY (CustomerID, OrderID))", - "CREATE TABLE OrderItems (CustomerID INT NOT NULL, OrderID INT NOT NULL, ProductID INT NOT NULL, Quantity INT NOT NULL, PRIMARY KEY (CustomerID, OrderID, ProductID))", - ), $sql); + 'USE FEDERATION Orders_Federation (CustID = 0) WITH RESET, FILTERING = OFF;', + 'CREATE TABLE Products (ProductID INT NOT NULL, SupplierID INT NOT NULL, ProductName NVARCHAR(255) NOT NULL, Price NUMERIC(12, 2) NOT NULL, PRIMARY KEY (ProductID))', + 'CREATE TABLE Customers (CustomerID INT NOT NULL, CompanyName NVARCHAR(255) NOT NULL, FirstName NVARCHAR(255) NOT NULL, LastName NVARCHAR(255) NOT NULL, PRIMARY KEY (CustomerID))', + 'CREATE TABLE Orders (CustomerID INT NOT NULL, OrderID INT NOT NULL, OrderDate DATETIME2(6) NOT NULL, PRIMARY KEY (CustomerID, OrderID))', + 'CREATE TABLE OrderItems (CustomerID INT NOT NULL, OrderID INT NOT NULL, ProductID INT NOT NULL, Quantity INT NOT NULL, PRIMARY KEY (CustomerID, OrderID, ProductID))', + ], $sql); } public function testUpdateSchema() @@ -31,7 +32,7 @@ public function testUpdateSchema() $sql = $synchronizer->getUpdateSchema($schema); - self::assertEquals(array(), $sql); + self::assertEquals([], $sql); } public function testDropSchema() diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php index 80d510f7d12..04dc31723ef 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php @@ -3,16 +3,17 @@ namespace Doctrine\Tests\DBAL\Sharding\SQLAzure; use Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager; +use PHPUnit\Framework\TestCase; -class SQLAzureShardManagerTest extends \PHPUnit\Framework\TestCase +class SQLAzureShardManagerTest extends TestCase { public function testNoFederationName() { $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); $this->expectExceptionMessage('SQLAzure requires a federation name to be set during sharding configuration.'); - $conn = $this->createConnection(array('sharding' => array('distributionKey' => 'abc', 'distributionType' => 'integer'))); - $sm = new SQLAzureShardManager($conn); + $conn = $this->createConnection(['sharding' => ['distributionKey' => 'abc', 'distributionType' => 'integer']]); + $sm = new SQLAzureShardManager($conn); } public function testNoDistributionKey() @@ -20,21 +21,21 @@ public function testNoDistributionKey() $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); $this->expectExceptionMessage('SQLAzure requires a distribution key to be set during sharding configuration.'); - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionType' => 'integer'))); - $sm = new SQLAzureShardManager($conn); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionType' => 'integer']]); + $sm = new SQLAzureShardManager($conn); } public function testNoDistributionType() { $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo'))); - $sm = new SQLAzureShardManager($conn); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo']]); + $sm = new SQLAzureShardManager($conn); } public function testGetDefaultDistributionValue() { - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $sm = new SQLAzureShardManager($conn); self::assertNull($sm->getCurrentDistributionValue()); @@ -42,7 +43,7 @@ public function testGetDefaultDistributionValue() public function testSelectGlobalTransactionActive() { - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); @@ -54,7 +55,7 @@ public function testSelectGlobalTransactionActive() public function testSelectGlobal() { - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false)); $conn->expects($this->at(2))->method('exec')->with($this->equalTo('USE FEDERATION ROOT WITH RESET')); @@ -64,7 +65,7 @@ public function testSelectGlobal() public function testSelectShard() { - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); @@ -78,7 +79,7 @@ public function testSelectShard() public function testSelectShardNoDistributionValue() { - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false)); $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); @@ -91,7 +92,7 @@ public function testSelectShardNoDistributionValue() private function createConnection(array $params) { $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('getParams', 'exec', 'isTransactionActive')) + ->setMethods(['getParams', 'exec', 'isTransactionActive']) ->disableOriginalConstructor() ->getMock(); $conn->expects($this->at(0))->method('getParams')->will($this->returnValue($params)); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php b/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php index cf4da5b317d..d3eaf32ccfa 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php @@ -20,13 +20,14 @@ namespace Doctrine\Tests\DBAL\Sharding\ShardChoser; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; +use PHPUnit\Framework\TestCase; -class MultiTenantShardChoserTest extends \PHPUnit\Framework\TestCase +class MultiTenantShardChoserTest extends TestCase { public function testPickShard() { $choser = new MultiTenantShardChoser(); - $conn = $this->createConnectionMock(); + $conn = $this->createConnectionMock(); self::assertEquals(1, $choser->pickShard(1, $conn)); self::assertEquals(2, $choser->pickShard(2, $conn)); @@ -35,9 +36,8 @@ public function testPickShard() private function createConnectionMock() { return $this->getMockBuilder('Doctrine\DBAL\Sharding\PoolingShardConnection') - ->setMethods(array('connect', 'getParams', 'fetchAll')) + ->setMethods(['connect', 'getParams', 'fetchAll']) ->disableOriginalConstructor() ->getMock(); } } - diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index fa22536f2d4..88559c07ceb 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -2,48 +2,44 @@ namespace Doctrine\Tests\DBAL; +use Doctrine\DBAL\Configuration; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Statement; -use Doctrine\DBAL\Logging\SQLLogger; +use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; +use Exception; +use PDOStatement; -class StatementTest extends \Doctrine\Tests\DbalTestCase +class StatementTest extends DbalTestCase { - /** - * - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ private $conn; - /** - * - * @var \Doctrine\DBAL\Configuration - */ + /** @var Configuration */ private $configuration; - /** - * @var \PDOStatement - */ + /** @var PDOStatement */ private $pdoStatement; protected function setUp() { $this->pdoStatement = $this->getMockBuilder('\PDOStatement') - ->setMethods(array('execute', 'bindParam', 'bindValue')) + ->setMethods(['execute', 'bindParam', 'bindValue']) ->getMock(); - $platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform(); - $driverConnection = $this->createMock('\Doctrine\DBAL\Driver\Connection'); + $platform = new MockPlatform(); + $driverConnection = $this->createMock('\Doctrine\DBAL\Driver\Connection'); $driverConnection->expects($this->any()) ->method('prepare') ->will($this->returnValue($this->pdoStatement)); - $driver = $this->createMock('\Doctrine\DBAL\Driver'); - $constructorArgs = array( - array( - 'platform' => $platform - ), - $driver - ); - $this->conn = $this->getMockBuilder('\Doctrine\DBAL\Connection') + $driver = $this->createMock('\Doctrine\DBAL\Driver'); + $constructorArgs = [ + ['platform' => $platform], + $driver, + ]; + $this->conn = $this->getMockBuilder('\Doctrine\DBAL\Connection') ->setConstructorArgs($constructorArgs) ->getMock(); $this->conn->expects($this->atLeastOnce()) @@ -58,7 +54,6 @@ protected function setUp() $this->conn->expects($this->any()) ->method('getDriver') ->will($this->returnValue($driver)); - } public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() @@ -86,11 +81,11 @@ public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedToExecute() { - $name = 'foo'; - $var = 'bar'; - $values = array($name => $var); - $types = array(); - $sql = ''; + $name = 'foo'; + $var = 'bar'; + $values = [$name => $var]; + $types = []; + $sql = ''; $logger = $this->createMock('\Doctrine\DBAL\Logging\SQLLogger'); $logger->expects($this->once()) @@ -141,7 +136,7 @@ public function testExecuteCallsLoggerStopQueryOnException() // Needed to satisfy construction of DBALException $this->conn->expects($this->any()) ->method('resolveParams') - ->will($this->returnValue(array())); + ->will($this->returnValue([])); $logger->expects($this->once()) ->method('startQuery'); @@ -151,9 +146,9 @@ public function testExecuteCallsLoggerStopQueryOnException() $this->pdoStatement->expects($this->once()) ->method('execute') - ->will($this->throwException(new \Exception("Mock test exception"))); + ->will($this->throwException(new Exception('Mock test exception'))); - $statement = new Statement("", $this->conn); + $statement = new Statement('', $this->conn); $statement->execute(); } } diff --git a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php index 164a609198a..84907e09316 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php @@ -2,21 +2,23 @@ namespace Doctrine\Tests\DBAL\Tools\Console; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; use Doctrine\DBAL\Tools\Console\ConsoleRunner; +use LogicException; +use PHPUnit\Framework\TestCase; +use RuntimeException; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -class RunSqlCommandTest extends \PHPUnit\Framework\TestCase +class RunSqlCommandTest extends TestCase { /** @var CommandTester */ private $commandTester; /** @var RunSqlCommand */ private $command; - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ private $connectionMock; protected function setUp() @@ -24,12 +26,12 @@ protected function setUp() $application = new Application(); $application->add(new RunSqlCommand()); - $this->command = $application->find('dbal:run-sql'); + $this->command = $application->find('dbal:run-sql'); $this->commandTester = new CommandTester($this->command); $this->connectionMock = $this->createMock('\Doctrine\DBAL\Connection'); $this->connectionMock->method('fetchAll') - ->willReturn(array(array(1))); + ->willReturn([[1]]); $this->connectionMock->method('executeUpdate') ->willReturn(42); @@ -40,12 +42,12 @@ protected function setUp() public function testMissingSqlArgument() { try { - $this->commandTester->execute(array( + $this->commandTester->execute([ 'command' => $this->command->getName(), 'sql' => null, - )); + ]); $this->fail('Expected a runtime exception when omitting sql argument'); - } catch (\RuntimeException $e) { + } catch (RuntimeException $e) { self::assertContains("Argument 'SQL", $e->getMessage()); } } @@ -53,13 +55,13 @@ public function testMissingSqlArgument() public function testIncorrectDepthOption() { try { - $this->commandTester->execute(array( + $this->commandTester->execute([ 'command' => $this->command->getName(), 'sql' => 'SELECT 1', '--depth' => 'string', - )); + ]); $this->fail('Expected a logic exception when executing with a stringy depth'); - } catch (\LogicException $e) { + } catch (LogicException $e) { self::assertContains("Option 'depth'", $e->getMessage()); } } @@ -68,10 +70,10 @@ public function testSelectStatementsPrintsResult() { $this->expectConnectionFetchAll(); - $this->commandTester->execute(array( + $this->commandTester->execute([ 'command' => $this->command->getName(), 'sql' => 'SELECT 1', - )); + ]); self::assertRegExp('@int.*1.*@', $this->commandTester->getDisplay()); self::assertRegExp('@array.*1.*@', $this->commandTester->getDisplay()); @@ -81,10 +83,10 @@ public function testUpdateStatementsPrintsAffectedLines() { $this->expectConnectionExecuteUpdate(); - $this->commandTester->execute(array( + $this->commandTester->execute([ 'command' => $this->command->getName(), 'sql' => 'UPDATE foo SET bar = 42', - )); + ]); self::assertRegExp('@int.*42.*@', $this->commandTester->getDisplay()); self::assertNotRegExp('@array.*1.*@', $this->commandTester->getDisplay()); @@ -114,11 +116,11 @@ public function testStatementsWithFetchResultPrintsResult() { $this->expectConnectionFetchAll(); - $this->commandTester->execute(array( + $this->commandTester->execute([ 'command' => $this->command->getName(), 'sql' => '"WITH bar as (SELECT 1) SELECT * FROM bar', '--force-fetch' => true, - )); + ]); self::assertRegExp('@int.*1.*@', $this->commandTester->getDisplay()); self::assertRegExp('@array.*1.*@', $this->commandTester->getDisplay()); diff --git a/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php b/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php index cf4fe4d560a..2aae261561f 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php @@ -9,6 +9,7 @@ use DateTimeZone; use Doctrine\DBAL\Tools\Dumper; use Doctrine\Tests\DbalTestCase; +use stdClass; use function print_r; use function strpos; use function substr; @@ -17,7 +18,7 @@ class DumperTest extends DbalTestCase { public function testExportObject() { - $obj = new \stdClass(); + $obj = new stdClass(); $obj->foo = 'bar'; $obj->bar = 1234; diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index c6599e66d65..b536c0c1d21 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -5,31 +5,28 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; use function serialize; -class ArrayTest extends \Doctrine\Tests\DbalTestCase +class ArrayTest extends DbalTestCase { - /** - * @var AbstractPlatform - */ + /** @var AbstractPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('array'); + $this->_type = Type::getType('array'); } public function testArrayConvertsToDatabaseValue() { self::assertInternalType( 'string', - $this->_type->convertToDatabaseValue(array(), $this->_platform) + $this->_type->convertToDatabaseValue([], $this->_platform) ); } @@ -37,7 +34,7 @@ public function testArrayConvertsToPHPValue() { self::assertInternalType( 'array', - $this->_type->convertToPHPValue(serialize(array()), $this->_platform) + $this->_type->convertToPHPValue(serialize([]), $this->_platform) ); } diff --git a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php index a86b530c247..985c06605c5 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php @@ -2,25 +2,24 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; +use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use PHPUnit\Framework\TestCase; +use stdClass; use function date_default_timezone_get; use function date_default_timezone_set; -abstract class BaseDateTypeTestCase extends \PHPUnit\Framework\TestCase +abstract class BaseDateTypeTestCase extends TestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $platform; - /** - * @var \Doctrine\DBAL\Types\Type - */ + /** @var Type */ protected $type; - /** - * @var string - */ + /** @var string */ private $currentTimezone; /** @@ -44,13 +43,13 @@ protected function tearDown() public function testDateConvertsToDatabaseValue() { - self::assertInternalType('string', $this->type->convertToDatabaseValue(new \DateTime(), $this->platform)); + self::assertInternalType('string', $this->type->convertToDatabaseValue(new DateTime(), $this->platform)); } /** - * @dataProvider invalidPHPValuesProvider - * * @param mixed $value + * + * @dataProvider invalidPHPValuesProvider */ public function testInvalidTypeConversionToDatabaseValue($value) { @@ -66,7 +65,7 @@ public function testNullConversion() public function testConvertDateTimeToPHPValue() { - $date = new \DateTime('now'); + $date = new DateTime('now'); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } @@ -80,7 +79,7 @@ public function testConvertDateTimeToPHPValue() */ public function testConvertDateTimeImmutableToPHPValue() { - $date = new \DateTimeImmutable('now'); + $date = new DateTimeImmutable('now'); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } @@ -96,7 +95,7 @@ public function testDateTimeImmutableConvertsToDatabaseValue() { self::assertInternalType( 'string', - $this->type->convertToDatabaseValue(new \DateTimeImmutable(), $this->platform) + $this->type->convertToDatabaseValue(new DateTimeImmutable(), $this->platform) ); } @@ -112,7 +111,7 @@ public function invalidPHPValuesProvider() ['10:11:12'], ['2015-01-31'], ['2015-01-31 10:11:12'], - [new \stdClass()], + [new stdClass()], [$this], [27], [-1], diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index 9881c897960..fbcf5fb9357 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -3,22 +3,20 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; use function base64_encode; use function fopen; use function stream_get_contents; -class BinaryTest extends \Doctrine\Tests\DbalTestCase +class BinaryTest extends DbalTestCase { - /** - * @var \Doctrine\Tests\DBAL\Mocks\MockPlatform - */ + /** @var MockPlatform */ protected $platform; - /** - * @var \Doctrine\DBAL\Types\BinaryType - */ + /** @var BinaryType */ protected $type; /** @@ -42,7 +40,7 @@ public function testReturnsName() public function testReturnsSQLDeclaration() { - self::assertSame('DUMMYBINARY', $this->type->getSQLDeclaration(array(), $this->platform)); + self::assertSame('DUMMYBINARY', $this->type->getSQLDeclaration([], $this->platform)); } public function testBinaryNullConvertsToPHPValue() @@ -78,15 +76,15 @@ public function testThrowsConversionExceptionOnInvalidDatabaseValue($value) public function getInvalidDatabaseValues() { - return array( - array(false), - array(true), - array(0), - array(1), - array(-1), - array(0.0), - array(1.1), - array(-1.1), - ); + return [ + [false], + [true], + [0], + [1], + [-1], + [0.0], + [1.1], + [-1.1], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php index 1ee3fefc43c..5500836cfdb 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php @@ -2,23 +2,21 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; use function base64_encode; use function chr; use function fopen; use function stream_get_contents; -class BlobTest extends \Doctrine\Tests\DbalTestCase +class BlobTest extends DbalTestCase { - /** - * @var \Doctrine\Tests\DBAL\Mocks\MockPlatform - */ + /** @var MockPlatform */ protected $platform; - /** - * @var \Doctrine\DBAL\Types\BlobType - */ + /** @var BlobType */ protected $type; /** @@ -27,7 +25,7 @@ class BlobTest extends \Doctrine\Tests\DbalTestCase protected function setUp() { $this->platform = new MockPlatform(); - $this->type = Type::getType('blob'); + $this->type = Type::getType('blob'); } public function testBlobNullConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php index 0c5cb3ccecd..21b043d1c70 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php @@ -4,23 +4,20 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class BooleanTest extends \Doctrine\Tests\DbalTestCase +class BooleanTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('boolean'); + $this->_type = Type::getType('boolean'); } public function testBooleanConvertsToDatabaseValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php index a8847030c29..2740e708e10 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php @@ -3,14 +3,17 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\Types\ConversionException; +use Exception; +use PHPUnit\Framework\TestCase; +use stdClass; use function tmpfile; -class ConversionExceptionTest extends \PHPUnit\Framework\TestCase +class ConversionExceptionTest extends TestCase { /** - * @dataProvider scalarsProvider - * * @param mixed $scalarValue + * + * @dataProvider scalarsProvider */ public function testConversionFailedInvalidTypeWithScalar($scalarValue) { @@ -24,9 +27,9 @@ public function testConversionFailedInvalidTypeWithScalar($scalarValue) ); } /** - * @dataProvider nonScalarsProvider - * * @param mixed $nonScalar + * + * @dataProvider nonScalarsProvider */ public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) { @@ -42,7 +45,7 @@ public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) public function testConversionFailedFormatPreservesPreviousException() { - $previous = new \Exception(); + $previous = new Exception(); $exception = ConversionException::conversionFailedFormat('foo', 'bar', 'baz', $previous); @@ -60,7 +63,7 @@ public function nonScalarsProvider() [['foo']], [null], [$this], - [new \stdClass()], + [new stdClass()], [tmpfile()], ]; } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php index 7c60986240e..5fd15d812d3 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php @@ -2,28 +2,28 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; +use Prophecy\Prophecy\ObjectProphecy; use function get_class; -class DateImmutableTypeTest extends \PHPUnit\Framework\TestCase +class DateImmutableTypeTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy - */ + /** @var AbstractPlatform|ObjectProphecy */ private $platform; - /** - * @var DateImmutableType - */ + /** @var DateImmutableType */ private $type; protected function setUp() { - $this->type = Type::getType('date_immutable'); + $this->type = Type::getType('date_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); } @@ -44,7 +44,7 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->prophesize(DateTimeImmutable::class); $this->platform->getDateFormatString()->willReturn('Y-m-d')->shouldBeCalled(); $date->format('Y-m-d')->willReturn('2016-01-01')->shouldBeCalled(); @@ -64,12 +64,12 @@ public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { - $date = new \DateTimeImmutable(); + $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } @@ -85,7 +85,7 @@ public function testConvertsDateStringToPHPValue() $date = $this->type->convertToPHPValue('2016-01-01', $this->platform->reveal()); - self::assertInstanceOf(\DateTimeImmutable::class, $date); + self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('2016-01-01', $date->format('Y-m-d')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index 61919ec6c87..27d83ae7df7 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -2,22 +2,21 @@ namespace Doctrine\Tests\DBAL\Types; +use DateInterval; +use DateTime; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateIntervalType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; +use stdClass; final class DateIntervalTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ private $platform; - /** - * @var \Doctrine\DBAL\Types\DateIntervalType - */ + /** @var DateIntervalType */ private $type; /** @@ -33,10 +32,10 @@ protected function setUp() : void public function testDateIntervalConvertsToDatabaseValue() : void { - $interval = new \DateInterval('P2Y1DT1H2M3S'); + $interval = new DateInterval('P2Y1DT1H2M3S'); $expected = '+P02Y00M01DT01H02M03S'; - $actual = $this->type->convertToDatabaseValue($interval, $this->platform); + $actual = $this->type->convertToDatabaseValue($interval, $this->platform); self::assertEquals($expected, $actual); } @@ -45,13 +44,13 @@ public function testDateIntervalConvertsToPHPValue() : void { $interval = $this->type->convertToPHPValue('+P02Y00M01DT01H02M03S', $this->platform); - self::assertInstanceOf(\DateInterval::class, $interval); + self::assertInstanceOf(DateInterval::class, $interval); self::assertEquals('+P02Y00M01DT01H02M03S', $interval->format(DateIntervalType::FORMAT)); } public function testNegativeDateIntervalConvertsToDatabaseValue() : void { - $interval = new \DateInterval('P2Y1DT1H2M3S'); + $interval = new DateInterval('P2Y1DT1H2M3S'); $interval->invert = 1; $actual = $this->type->convertToDatabaseValue($interval, $this->platform); @@ -63,7 +62,7 @@ public function testNegativeDateIntervalConvertsToPHPValue() : void { $interval = $this->type->convertToPHPValue('-P02Y00M01DT01H02M03S', $this->platform); - self::assertInstanceOf(\DateInterval::class, $interval); + self::assertInstanceOf(DateInterval::class, $interval); self::assertEquals('-P02Y00M01DT01H02M03S', $interval->format(DateIntervalType::FORMAT)); } @@ -71,7 +70,7 @@ public function testDateIntervalFormatWithoutSignConvertsToPHPValue() : void { $interval = $this->type->convertToPHPValue('P02Y00M01DT01H02M03S', $this->platform); - self::assertInstanceOf(\DateInterval::class, $interval); + self::assertInstanceOf(DateInterval::class, $interval); self::assertEquals('+P02Y00M01DT01H02M03S', $interval->format(DateIntervalType::FORMAT)); } @@ -124,14 +123,14 @@ public function invalidPHPValuesProvider() : array ['10:11:12'], ['2015-01-31'], ['2015-01-31 10:11:12'], - [new \stdClass()], + [new stdClass()], [$this], [27], [-1], [1.2], [[]], [['an array']], - [new \DateTime()], + [new DateTime()], ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index c68ebc7f471..6b41eab3c50 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; use Doctrine\DBAL\Types\Type; use function date_default_timezone_set; @@ -21,7 +22,7 @@ public function testDateConvertsToPHPValue() { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) self::assertInstanceOf( - \DateTime::class, + DateTime::class, $this->type->convertToPHPValue('1985-09-01', $this->platform) ); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php index 9cb1f9c6b72..dfedcca32b1 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php @@ -2,28 +2,28 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; +use Prophecy\Prophecy\ObjectProphecy; use function get_class; -class DateTimeImmutableTypeTest extends \PHPUnit\Framework\TestCase +class DateTimeImmutableTypeTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy - */ + /** @var AbstractPlatform|ObjectProphecy */ private $platform; - /** - * @var DateTimeImmutableType - */ + /** @var DateTimeImmutableType */ private $type; protected function setUp() { - $this->type = Type::getType('datetime_immutable'); + $this->type = Type::getType('datetime_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); } @@ -44,7 +44,7 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->prophesize(DateTimeImmutable::class); $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s')->shouldBeCalled(); $date->format('Y-m-d H:i:s')->willReturn('2016-01-01 15:58:59')->shouldBeCalled(); @@ -64,12 +64,12 @@ public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { - $date = new \DateTimeImmutable(); + $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } @@ -85,7 +85,7 @@ public function testConvertsDateTimeStringToPHPValue() $date = $this->type->convertToPHPValue('2016-01-01 15:58:59', $this->platform->reveal()); - self::assertInstanceOf(\DateTimeImmutable::class, $date); + self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('2016-01-01 15:58:59', $date->format('Y-m-d H:i:s')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index 3b66c260c8d..d104f83a835 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; use Doctrine\DBAL\Types\Type; class DateTimeTest extends BaseDateTypeTestCase @@ -18,10 +19,10 @@ protected function setUp() public function testDateTimeConvertsToDatabaseValue() { - $date = new \DateTime('1985-09-01 10:10:10'); + $date = new DateTime('1985-09-01 10:10:10'); $expected = $date->format($this->platform->getDateTimeTzFormatString()); - $actual = $this->type->convertToDatabaseValue($date, $this->platform); + $actual = $this->type->convertToDatabaseValue($date, $this->platform); self::assertEquals($expected, $actual); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php index 9563d968082..df47f7b3991 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php @@ -2,28 +2,28 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeTzImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; +use Prophecy\Prophecy\ObjectProphecy; use function get_class; -class DateTimeTzImmutableTypeTest extends \PHPUnit\Framework\TestCase +class DateTimeTzImmutableTypeTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy - */ + /** @var AbstractPlatform|ObjectProphecy */ private $platform; - /** - * @var DateTimeTzImmutableType - */ + /** @var DateTimeTzImmutableType */ private $type; protected function setUp() { - $this->type = Type::getType('datetimetz_immutable'); + $this->type = Type::getType('datetimetz_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); } @@ -44,7 +44,7 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->prophesize(DateTimeImmutable::class); $this->platform->getDateTimeTzFormatString()->willReturn('Y-m-d H:i:s T')->shouldBeCalled(); $date->format('Y-m-d H:i:s T')->willReturn('2016-01-01 15:58:59 UTC')->shouldBeCalled(); @@ -64,12 +64,12 @@ public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { - $date = new \DateTimeImmutable(); + $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } @@ -85,7 +85,7 @@ public function testConvertsDateTimeWithTimezoneStringToPHPValue() $date = $this->type->convertToPHPValue('2016-01-01 15:58:59 UTC', $this->platform->reveal()); - self::assertInstanceOf(\DateTimeImmutable::class, $date); + self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('2016-01-01 15:58:59 UTC', $date->format('Y-m-d H:i:s T')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index bcc77b4c989..8f97ff83167 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; use Doctrine\DBAL\Types\Type; class DateTimeTzTest extends BaseDateTypeTestCase @@ -18,10 +19,10 @@ protected function setUp() public function testDateTimeConvertsToDatabaseValue() { - $date = new \DateTime('1985-09-01 10:10:10'); + $date = new DateTime('1985-09-01 10:10:10'); $expected = $date->format($this->platform->getDateTimeTzFormatString()); - $actual = $this->type->convertToDatabaseValue($date, $this->platform); + $actual = $this->type->convertToDatabaseValue($date, $this->platform); self::assertEquals($expected, $actual); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php index 9571629af25..aedb6c98bb6 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php @@ -4,23 +4,20 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class DecimalTest extends \Doctrine\Tests\DbalTestCase +class DecimalTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('decimal'); + $this->_type = Type::getType('decimal'); } public function testDecimalConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php index 036481ce10e..e3fc70a8be9 100644 --- a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php @@ -4,23 +4,20 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class FloatTest extends \Doctrine\Tests\DbalTestCase +class FloatTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('float'); + $this->_type = Type::getType('float'); } public function testFloatConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php index cfc40999ef1..439e9de7168 100644 --- a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php @@ -9,26 +9,22 @@ class GuidTypeTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('guid'); + $this->_type = Type::getType('guid'); } public function testConvertToPHPValue() { - self::assertInternalType("string", $this->_type->convertToPHPValue("foo", $this->_platform)); - self::assertInternalType("string", $this->_type->convertToPHPValue("", $this->_platform)); + self::assertInternalType('string', $this->_type->convertToPHPValue('foo', $this->_platform)); + self::assertInternalType('string', $this->_type->convertToPHPValue('', $this->_platform)); } public function testNullConversion() diff --git a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php index 51d57d5c98e..07fda0d8165 100644 --- a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php @@ -4,23 +4,20 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class IntegerTest extends \Doctrine\Tests\DbalTestCase +class IntegerTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('integer'); + $this->_type = Type::getType('integer'); } public function testIntegerConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index 3972002caf8..564371a30b3 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -3,22 +3,20 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Types\JsonArrayType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; use function base64_encode; use function fopen; use function json_encode; -class JsonArrayTest extends \Doctrine\Tests\DbalTestCase +class JsonArrayTest extends DbalTestCase { - /** - * @var \Doctrine\Tests\DBAL\Mocks\MockPlatform - */ + /** @var MockPlatform */ protected $platform; - /** - * @var \Doctrine\DBAL\Types\JsonArrayType - */ + /** @var JsonArrayType */ protected $type; /** @@ -42,22 +40,22 @@ public function testReturnsName() public function testReturnsSQLDeclaration() { - self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration(array(), $this->platform)); + self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration([], $this->platform)); } public function testJsonNullConvertsToPHPValue() { - self::assertSame(array(), $this->type->convertToPHPValue(null, $this->platform)); + self::assertSame([], $this->type->convertToPHPValue(null, $this->platform)); } public function testJsonEmptyStringConvertsToPHPValue() { - self::assertSame(array(), $this->type->convertToPHPValue('', $this->platform)); + self::assertSame([], $this->type->convertToPHPValue('', $this->platform)); } public function testJsonStringConvertsToPHPValue() { - $value = array('foo' => 'bar', 'bar' => 'foo'); + $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = json_encode($value); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); @@ -66,7 +64,7 @@ public function testJsonStringConvertsToPHPValue() public function testJsonResourceConvertsToPHPValue() { - $value = array('foo' => 'bar', 'bar' => 'foo'); + $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = fopen('data://text/plain;base64,' . base64_encode(json_encode($value)), 'r'); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index ddf72b22d79..18ef77a6394 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -3,22 +3,20 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Types\JsonType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; use function base64_encode; use function fopen; use function json_encode; -class JsonTest extends \Doctrine\Tests\DbalTestCase +class JsonTest extends DbalTestCase { - /** - * @var \Doctrine\Tests\DBAL\Mocks\MockPlatform - */ + /** @var MockPlatform */ protected $platform; - /** - * @var \Doctrine\DBAL\Types\JsonType - */ + /** @var JsonType */ protected $type; /** @@ -42,7 +40,7 @@ public function testReturnsName() public function testReturnsSQLDeclaration() { - self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration(array(), $this->platform)); + self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration([], $this->platform)); } public function testJsonNullConvertsToPHPValue() @@ -57,7 +55,7 @@ public function testJsonEmptyStringConvertsToPHPValue() public function testJsonStringConvertsToPHPValue() { - $value = array('foo' => 'bar', 'bar' => 'foo'); + $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = json_encode($value); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); @@ -73,12 +71,12 @@ public function testConversionFailure($data) public function providerFailure() { - return array(array('a'), array('{')); + return [['a'], ['{']]; } public function testJsonResourceConvertsToPHPValue() { - $value = array('foo' => 'bar', 'bar' => 'foo'); + $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = fopen('data://text/plain;base64,' . base64_encode(json_encode($value)), 'r'); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index bd4fcd8057d..7f1794e0d0c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -4,34 +4,32 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; +use stdClass; use function serialize; -class ObjectTest extends \Doctrine\Tests\DbalTestCase +class ObjectTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('object'); + $this->_type = Type::getType('object'); } public function testObjectConvertsToDatabaseValue() { - self::assertInternalType('string', $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform)); + self::assertInternalType('string', $this->_type->convertToDatabaseValue(new stdClass(), $this->_platform)); } public function testObjectConvertsToPHPValue() { - self::assertInternalType('object', $this->_type->convertToPHPValue(serialize(new \stdClass), $this->_platform)); + self::assertInternalType('object', $this->_type->convertToPHPValue(serialize(new stdClass()), $this->_platform)); } public function testConversionFailure() diff --git a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php index 89a50117e15..3d4770a9c43 100644 --- a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php @@ -4,23 +4,20 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class SmallIntTest extends \Doctrine\Tests\DbalTestCase +class SmallIntTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('smallint'); + $this->_type = Type::getType('smallint'); } public function testSmallIntConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/StringTest.php b/tests/Doctrine/Tests/DBAL/Types/StringTest.php index e968b9f0d99..b19dff22683 100644 --- a/tests/Doctrine/Tests/DBAL/Types/StringTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -4,28 +4,25 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class StringTest extends \Doctrine\Tests\DbalTestCase +class StringTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('string'); + $this->_type = Type::getType('string'); } public function testReturnsSqlDeclarationFromPlatformVarchar() { - self::assertEquals("DUMMYVARCHAR()", $this->_type->getSqlDeclaration(array(), $this->_platform)); + self::assertEquals('DUMMYVARCHAR()', $this->_type->getSqlDeclaration([], $this->_platform)); } public function testReturnsDefaultLengthFromPlatformVarchar() @@ -35,8 +32,8 @@ public function testReturnsDefaultLengthFromPlatformVarchar() public function testConvertToPHPValue() { - self::assertInternalType("string", $this->_type->convertToPHPValue("foo", $this->_platform)); - self::assertInternalType("string", $this->_type->convertToPHPValue("", $this->_platform)); + self::assertInternalType('string', $this->_type->convertToPHPValue('foo', $this->_platform)); + self::assertInternalType('string', $this->_type->convertToPHPValue('', $this->_platform)); } public function testNullConversion() @@ -46,7 +43,7 @@ public function testNullConversion() public function testSQLConversion() { - self::assertFalse($this->_type->canRequireSQLConversion(), "String type can never require SQL conversion to work."); + self::assertFalse($this->_type->canRequireSQLConversion(), 'String type can never require SQL conversion to work.'); self::assertEquals('t.foo', $this->_type->convertToDatabaseValueSQL('t.foo', $this->_platform)); self::assertEquals('t.foo', $this->_type->convertToPHPValueSQL('t.foo', $this->_platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php index 78ae5917f77..0f7427df3ed 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php @@ -2,28 +2,28 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\TimeImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; +use Prophecy\Prophecy\ObjectProphecy; use function get_class; -class TimeImmutableTypeTest extends \PHPUnit\Framework\TestCase +class TimeImmutableTypeTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy - */ + /** @var AbstractPlatform|ObjectProphecy */ private $platform; - /** - * @var TimeImmutableType - */ + /** @var TimeImmutableType */ private $type; protected function setUp() { - $this->type = Type::getType('time_immutable'); + $this->type = Type::getType('time_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); } @@ -44,7 +44,7 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->prophesize(DateTimeImmutable::class); $this->platform->getTimeFormatString()->willReturn('H:i:s')->shouldBeCalled(); $date->format('H:i:s')->willReturn('15:58:59')->shouldBeCalled(); @@ -64,12 +64,12 @@ public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { - $date = new \DateTimeImmutable(); + $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } @@ -85,7 +85,7 @@ public function testConvertsTimeStringToPHPValue() $date = $this->type->convertToPHPValue('15:58:59', $this->platform->reveal()); - self::assertInstanceOf(\DateTimeImmutable::class, $date); + self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('15:58:59', $date->format('H:i:s')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php index ebf21284651..870bb23cc98 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php @@ -2,22 +2,22 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\VarDateTimeImmutableType; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\VarDateTimeImmutableType; +use PHPUnit\Framework\TestCase; +use Prophecy\Prophecy\ObjectProphecy; -class VarDateTimeImmutableTypeTest extends \PHPUnit\Framework\TestCase +class VarDateTimeImmutableTypeTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy - */ + /** @var AbstractPlatform|ObjectProphecy */ private $platform; - /** - * @var VarDateTimeImmutableType - */ + /** @var VarDateTimeImmutableType */ private $type; protected function setUp() @@ -26,7 +26,7 @@ protected function setUp() Type::addType('vardatetime_immutable', VarDateTimeImmutableType::class); } - $this->type = Type::getType('vardatetime_immutable'); + $this->type = Type::getType('vardatetime_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); } @@ -42,7 +42,7 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->prophesize(DateTimeImmutable::class); $this->platform->getDateTimeFormatString()->willReturn('Y-m-d H:i:s')->shouldBeCalled(); $date->format('Y-m-d H:i:s')->willReturn('2016-01-01 15:58:59')->shouldBeCalled(); @@ -62,12 +62,12 @@ public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { - $date = new \DateTimeImmutable(); + $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } @@ -83,7 +83,7 @@ public function testConvertsDateishStringToPHPValue() $date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456 UTC', $this->platform->reveal()); - self::assertInstanceOf(\DateTimeImmutable::class, $date); + self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('2016-01-01 15:58:59.123456 UTC', $date->format('Y-m-d H:i:s.u T')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index 4af76968cf1..a4e5139d266 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -2,25 +2,23 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class VarDateTimeTest extends \Doctrine\Tests\DbalTestCase +class VarDateTimeTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - if (!Type::hasType('vardatetime')) { + if (! Type::hasType('vardatetime')) { Type::addType('vardatetime', 'Doctrine\DBAL\Types\VarDateTimeType'); } $this->_type = Type::getType('vardatetime'); @@ -28,10 +26,10 @@ protected function setUp() public function testDateTimeConvertsToDatabaseValue() { - $date = new \DateTime('1985-09-01 10:10:10'); + $date = new DateTime('1985-09-01 10:10:10'); $expected = $date->format($this->_platform->getDateTimeTzFormatString()); - $actual = $this->_type->convertToDatabaseValue($date, $this->_platform); + $actual = $this->_type->convertToDatabaseValue($date, $this->_platform); self::assertEquals($expected, $actual); } @@ -66,7 +64,7 @@ public function testNullConversion() public function testConvertDateTimeToPHPValue() { - $date = new \DateTime("now"); + $date = new DateTime('now'); self::assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/UtilTest.php b/tests/Doctrine/Tests/DBAL/UtilTest.php index ac26d8aa1dd..2c94e29555d 100644 --- a/tests/Doctrine/Tests/DBAL/UtilTest.php +++ b/tests/Doctrine/Tests/DBAL/UtilTest.php @@ -2,73 +2,77 @@ namespace Doctrine\Tests\DBAL; -class UtilTest extends \Doctrine\Tests\DbalTestCase +use Doctrine\DBAL\Driver\OCI8\OCI8Statement; +use Doctrine\Tests\DbalTestCase; + +class UtilTest extends DbalTestCase { public static function dataConvertPositionalToNamedParameters() { - return array( - array( + return [ + [ 'SELECT name FROM users WHERE id = ?', 'SELECT name FROM users WHERE id = :param1', - array(1 => ':param1') - ), - array( + [1 => ':param1'], + ], + [ 'SELECT name FROM users WHERE id = ? AND status = ?', 'SELECT name FROM users WHERE id = :param1 AND status = :param2', - array(1 => ':param1', 2 => ':param2'), - ), - array( + [1 => ':param1', 2 => ':param2'], + ], + [ "UPDATE users SET name = '???', status = ?", "UPDATE users SET name = '???', status = :param1", - array(1 => ':param1'), - ), - array( + [1 => ':param1'], + ], + [ "UPDATE users SET status = ?, name = '???'", "UPDATE users SET status = :param1, name = '???'", - array(1 => ':param1'), - ), - array( + [1 => ':param1'], + ], + [ "UPDATE users SET foo = ?, name = '???', status = ?", "UPDATE users SET foo = :param1, name = '???', status = :param2", - array(1 => ':param1', 2 => ':param2'), - ), - array( + [1 => ':param1', 2 => ':param2'], + ], + [ 'UPDATE users SET name = "???", status = ?', 'UPDATE users SET name = "???", status = :param1', - array(1 => ':param1'), - ), - array( + [1 => ':param1'], + ], + [ 'UPDATE users SET status = ?, name = "???"', 'UPDATE users SET status = :param1, name = "???"', - array(1 => ':param1'), - ), - array( + [1 => ':param1'], + ], + [ 'UPDATE users SET foo = ?, name = "???", status = ?', 'UPDATE users SET foo = :param1, name = "???", status = :param2', - array(1 => ':param1', 2 => ':param2'), - ), - array( + [1 => ':param1', 2 => ':param2'], + ], + [ 'SELECT * FROM users WHERE id = ? AND name = "" AND status = ?', 'SELECT * FROM users WHERE id = :param1 AND name = "" AND status = :param2', - array(1 => ':param1', 2 => ':param2'), - ), - array( + [1 => ':param1', 2 => ':param2'], + ], + [ "SELECT * FROM users WHERE id = ? AND name = '' AND status = ?", "SELECT * FROM users WHERE id = :param1 AND name = '' AND status = :param2", - array(1 => ':param1', 2 => ':param2'), - ) - ); + [1 => ':param1', 2 => ':param2'], + ], + ]; } /** - * @dataProvider dataConvertPositionalToNamedParameters * @param string $inputSQL * @param string $expectedOutputSQL * @param array $expectedOutputParamsMap + * + * @dataProvider dataConvertPositionalToNamedParameters */ public function testConvertPositionalToNamedParameters($inputSQL, $expectedOutputSQL, $expectedOutputParamsMap) { - list($statement, $params) = \Doctrine\DBAL\Driver\OCI8\OCI8Statement::convertPositionalToNamedPlaceholders($inputSQL); + [$statement, $params] = OCI8Statement::convertPositionalToNamedPlaceholders($inputSQL); self::assertEquals($expectedOutputSQL, $statement); self::assertEquals($expectedOutputParamsMap, $params); diff --git a/tests/Doctrine/Tests/DbalFunctionalTestCase.php b/tests/Doctrine/Tests/DbalFunctionalTestCase.php index 17154eac9f6..9fabe2d8101 100644 --- a/tests/Doctrine/Tests/DbalFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DbalFunctionalTestCase.php @@ -1,6 +1,12 @@ close(); - self::$_sharedConn = null; + if (! self::$_sharedConn) { + return; } + + self::$_sharedConn->close(); + self::$_sharedConn = null; } protected function setUp() { - if ( ! isset(self::$_sharedConn)) { + if (! isset(self::$_sharedConn)) { self::$_sharedConn = TestUtil::getConnection(); } $this->_conn = self::$_sharedConn; - $this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack(); + $this->_sqlLoggerStack = new DebugStack(); $this->_conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); } @@ -57,45 +61,47 @@ protected function tearDown() } } - protected function onNotSuccessfulTest(\Throwable $t) + protected function onNotSuccessfulTest(Throwable $t) { - if ($t instanceof \PHPUnit\Framework\AssertionFailedError) { + if ($t instanceof AssertionFailedError) { throw $t; } - if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) { - $queries = ""; - $i = count($this->_sqlLoggerStack->queries); + if (isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) { + $queries = ''; + $i = count($this->_sqlLoggerStack->queries); foreach (array_reverse($this->_sqlLoggerStack->queries) as $query) { - $params = array_map(function($p) { + $params = array_map(static function ($p) { if (is_object($p)) { return get_class($p); } elseif (is_scalar($p)) { - return "'".$p."'"; + return "'" . $p . "'"; } return var_export($p, true); - }, $query['params'] ?: array()); - $queries .= $i.". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; + }, $query['params'] ?: []); + $queries .= $i . ". SQL: '" . $query['sql'] . "' Params: " . implode(', ', $params) . PHP_EOL; $i--; } - $trace = $t->getTrace(); - $traceMsg = ""; - foreach($trace as $part) { - if(isset($part['file'])) { - if(strpos($part['file'], "PHPUnit/") !== false) { - // Beginning with PHPUnit files we don't print the trace anymore. - break; - } + $trace = $t->getTrace(); + $traceMsg = ''; + foreach ($trace as $part) { + if (! isset($part['file'])) { + continue; + } - $traceMsg .= $part['file'].":".$part['line'].PHP_EOL; + if (strpos($part['file'], 'PHPUnit/') !== false) { + // Beginning with PHPUnit files we don't print the trace anymore. + break; } + + $traceMsg .= $part['file'] . ':' . $part['line'] . PHP_EOL; } - $message = "[".get_class($t)."] ".$t->getMessage().PHP_EOL.PHP_EOL."With queries:".PHP_EOL.$queries.PHP_EOL."Trace:".PHP_EOL.$traceMsg; + $message = '[' . get_class($t) . '] ' . $t->getMessage() . PHP_EOL . PHP_EOL . 'With queries:' . PHP_EOL . $queries . PHP_EOL . 'Trace:' . PHP_EOL . $traceMsg; - throw new \Exception($message, (int) $t->getCode(), $t); + throw new Exception($message, (int) $t->getCode(), $t); } throw $t; } diff --git a/tests/Doctrine/Tests/DbalPerformanceTestCase.php b/tests/Doctrine/Tests/DbalPerformanceTestCase.php index 0422e5aa987..bfc60201bef 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestCase.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestCase.php @@ -1,17 +1,15 @@ startTime, "Test timing was started"); - self::assertNotNull($this->runTime, "Test timing was stopped"); + self::assertNotNull($this->startTime, 'Test timing was started'); + self::assertNotNull($this->runTime, 'Test timing was stopped'); } /** diff --git a/tests/Doctrine/Tests/DbalPerformanceTestListener.php b/tests/Doctrine/Tests/DbalPerformanceTestListener.php index 46085829434..06e8ce77e96 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestListener.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestListener.php @@ -11,15 +11,12 @@ /** * Listener for collecting and reporting results of performance tests - * - * @author Bill Schaller */ class DbalPerformanceTestListener implements TestListener { use TestListenerDefaultImplementation; - /** - * @var string[][] - */ + + /** @var string[][] */ private $timings = []; /** @@ -28,18 +25,19 @@ class DbalPerformanceTestListener implements TestListener public function endTest(Test $test, float $time) : void { // This listener only applies to performance tests. - if ($test instanceof \Doctrine\Tests\DbalPerformanceTestCase) - { - // we identify perf tests by class, method, and dataset - $class = str_replace('Doctrine\Tests\DBAL\Performance\\', '', get_class($test)); + if (! ($test instanceof DbalPerformanceTestCase)) { + return; + } - if (!isset($this->timings[$class])) { - $this->timings[$class] = []; - } + // we identify perf tests by class, method, and dataset + $class = str_replace('Doctrine\Tests\DBAL\Performance\\', '', get_class($test)); - // Store timing data for each test in the order they were run. - $this->timings[$class][$test->getName(true)] = $test->getTime(); + if (! isset($this->timings[$class])) { + $this->timings[$class] = []; } + + // Store timing data for each test in the order they were run. + $this->timings[$class][$test->getName(true)] = $test->getTime(); } /** @@ -50,15 +48,17 @@ public function endTest(Test $test, float $time) : void */ public function __destruct() { - if (!empty($this->timings)) { - // Report timings. - print("\nPerformance test results:\n\n"); + if (empty($this->timings)) { + return; + } + + // Report timings. + print "\nPerformance test results:\n\n"; - foreach($this->timings as $class => $tests) { - printf("%s:\n", $class); - foreach($tests as $test => $time) { - printf("\t%s: %.3f seconds\n", $test, $time); - } + foreach ($this->timings as $class => $tests) { + printf("%s:\n", $class); + foreach ($tests as $test => $time) { + printf("\t%s: %.3f seconds\n", $test, $time); } } } diff --git a/tests/Doctrine/Tests/DbalTestCase.php b/tests/Doctrine/Tests/DbalTestCase.php index b577893e6f1..8664141c03e 100644 --- a/tests/Doctrine/Tests/DbalTestCase.php +++ b/tests/Doctrine/Tests/DbalTestCase.php @@ -2,9 +2,11 @@ namespace Doctrine\Tests; +use PHPUnit\Framework\TestCase; + /** * Base testcase class for all dbal testcases. */ -abstract class DbalTestCase extends \PHPUnit\Framework\TestCase +abstract class DbalTestCase extends TestCase { } diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index fb5dcc47b4d..989b063adc6 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -1,23 +1,19 @@ _platformMock; } - /** - * @override - */ - public function insert($tableName, array $data, array $types = array()) + public function insert($tableName, array $data, array $types = []) { $this->_inserts[$tableName][] = $data; } - /** - * @override - */ public function lastInsertId($seqName = null) { return $this->_lastInsertId; } - /** - * @override - */ public function quote($input, $type = null) { if (is_string($input)) { @@ -74,7 +58,7 @@ public function getInserts() public function reset() { - $this->_inserts = array(); + $this->_inserts = []; $this->_lastInsertId = 0; } } diff --git a/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php b/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php index 021746831af..231d6dbc5dc 100644 --- a/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php +++ b/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php @@ -3,66 +3,61 @@ namespace Doctrine\Tests\Mocks; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\AbstractPlatform; -class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform +class DatabasePlatformMock extends AbstractPlatform { - /** - * @var string - */ - private $_sequenceNextValSql = ""; + /** @var string */ + private $_sequenceNextValSql = ''; - /** - * @var bool - */ + /** @var bool */ private $_prefersIdentityColumns = true; - /** - * @var bool - */ + /** @var bool */ private $_prefersSequences = false; - /** - * @override - */ public function prefersIdentityColumns() { return $this->_prefersIdentityColumns; } - /** - * @override - */ public function prefersSequences() { return $this->_prefersSequences; } - /** @override */ public function getSequenceNextValSQL($sequenceName) { return $this->_sequenceNextValSql; } - /** @override */ - public function getBooleanTypeDeclarationSQL(array $field) {} + public function getBooleanTypeDeclarationSQL(array $field) + { + } - /** @override */ - public function getIntegerTypeDeclarationSQL(array $field) {} + public function getIntegerTypeDeclarationSQL(array $field) + { + } - /** @override */ - public function getBigIntTypeDeclarationSQL(array $field) {} + public function getBigIntTypeDeclarationSQL(array $field) + { + } - /** @override */ - public function getSmallIntTypeDeclarationSQL(array $field) {} + public function getSmallIntTypeDeclarationSQL(array $field) + { + } - /** @override */ - protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) {} + protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) + { + } - /** @override */ - public function getVarcharTypeDeclarationSQL(array $field) {} + public function getVarcharTypeDeclarationSQL(array $field) + { + } - /** @override */ - public function getClobTypeDeclarationSQL(array $field) {} + public function getClobTypeDeclarationSQL(array $field) + { + } /* MOCK API */ @@ -85,11 +80,11 @@ public function getName() { return 'mock'; } - protected function initializeDoctrineTypeMappings() { + protected function initializeDoctrineTypeMappings() + { } protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { - } /** * Gets the SQL Snippet used to declare a BLOB column type. diff --git a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php index 760dbff40cf..7b8872f2ea8 100644 --- a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php @@ -2,22 +2,41 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\ParameterType; -class DriverConnectionMock implements \Doctrine\DBAL\Driver\Connection +class DriverConnectionMock implements Connection { - public function prepare($prepareString) {} - public function query() {} + public function prepare($prepareString) + { + } + public function query() + { + } public function quote($input, $type = ParameterType::STRING) { } - public function exec($statement) {} - public function lastInsertId($name = null) {} - public function beginTransaction() {} - public function commit() {} - public function rollBack() {} - public function errorCode() {} - public function errorInfo() {} + public function exec($statement) + { + } + public function lastInsertId($name = null) + { + } + public function beginTransaction() + { + } + public function commit() + { + } + public function rollBack() + { + } + public function errorCode() + { + } + public function errorInfo() + { + } } diff --git a/tests/Doctrine/Tests/Mocks/DriverMock.php b/tests/Doctrine/Tests/Mocks/DriverMock.php index 61b2d992aff..432bb9135ac 100644 --- a/tests/Doctrine/Tests/Mocks/DriverMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverMock.php @@ -2,53 +2,36 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Throwable; -class DriverMock implements \Doctrine\DBAL\Driver +class DriverMock implements Driver { - /** - * @var DatabasePlatformMock - */ + /** @var DatabasePlatformMock */ private $_platformMock; - /** - * @var AbstractSchemaManager - */ + /** @var AbstractSchemaManager */ private $_schemaManagerMock; - public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) + public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { return new DriverConnectionMock(); } - /** - * Constructs the Sqlite PDO DSN. - * - * @return string The DSN. - * @override - */ - protected function _constructPdoDsn(array $params) - { - return ""; - } - - /** - * @override - */ public function getDatabasePlatform() { - if ( ! $this->_platformMock) { - $this->_platformMock = new DatabasePlatformMock; + if (! $this->_platformMock) { + $this->_platformMock = new DatabasePlatformMock(); } return $this->_platformMock; } - /** - * @override - */ - public function getSchemaManager(\Doctrine\DBAL\Connection $conn) + public function getSchemaManager(Connection $conn) { - if($this->_schemaManagerMock == null) { + if ($this->_schemaManagerMock === null) { return new SchemaManagerMock($conn); } @@ -57,7 +40,7 @@ public function getSchemaManager(\Doctrine\DBAL\Connection $conn) /* MOCK API */ - public function setDatabasePlatform(\Doctrine\DBAL\Platforms\AbstractPlatform $platform) + public function setDatabasePlatform(AbstractPlatform $platform) { $this->_platformMock = $platform; } @@ -72,12 +55,12 @@ public function getName() return 'mock'; } - public function getDatabase(\Doctrine\DBAL\Connection $conn) + public function getDatabase(Connection $conn) { return; } - public function convertExceptionCode(\Exception $exception) + public function convertExceptionCode(Throwable $exception) { return 0; } diff --git a/tests/Doctrine/Tests/Mocks/DriverResultStatementMock.php b/tests/Doctrine/Tests/Mocks/DriverResultStatementMock.php index 04c085c7459..46573c39494 100644 --- a/tests/Doctrine/Tests/Mocks/DriverResultStatementMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverResultStatementMock.php @@ -3,7 +3,8 @@ namespace Doctrine\Tests\Mocks; use Doctrine\DBAL\Driver\ResultStatement; +use IteratorAggregate; -interface DriverResultStatementMock extends ResultStatement, \IteratorAggregate +interface DriverResultStatementMock extends ResultStatement, IteratorAggregate { } diff --git a/tests/Doctrine/Tests/Mocks/DriverStatementMock.php b/tests/Doctrine/Tests/Mocks/DriverStatementMock.php index 62f09464c0f..5c14d6962e2 100644 --- a/tests/Doctrine/Tests/Mocks/DriverStatementMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverStatementMock.php @@ -3,7 +3,8 @@ namespace Doctrine\Tests\Mocks; use Doctrine\DBAL\Driver\Statement; +use IteratorAggregate; -interface DriverStatementMock extends Statement, \IteratorAggregate +interface DriverStatementMock extends Statement, IteratorAggregate { } diff --git a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php b/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php index d4c3c28c004..6eccd68609e 100644 --- a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php @@ -2,12 +2,17 @@ namespace Doctrine\Tests\Mocks; -class SchemaManagerMock extends \Doctrine\DBAL\Schema\AbstractSchemaManager +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Schema\AbstractSchemaManager; + +class SchemaManagerMock extends AbstractSchemaManager { - public function __construct(\Doctrine\DBAL\Connection $conn) + public function __construct(Connection $conn) { parent::__construct($conn); } - protected function _getPortableTableColumnDefinition($tableColumn) {} -} \ No newline at end of file + protected function _getPortableTableColumnDefinition($tableColumn) + { + } +} diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index be90e6c8ae8..37553595490 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -11,14 +11,10 @@ /** * TestUtil is a class with static utility methods used during tests. - * - * @author robo */ class TestUtil { - /** - * @var bool Whether the database schema is initialized. - */ + /** @var bool Whether the database schema is initialized. */ private static $initialized = false; /** @@ -51,7 +47,8 @@ public static function getConnection() return $conn; } - private static function getConnectionParams() { + private static function getConnectionParams() + { if (self::hasRequiredConnectionParams()) { return self::getSpecifiedConnectionParams(); } @@ -78,16 +75,17 @@ private static function hasRequiredConnectionParams() ); } - private static function getSpecifiedConnectionParams() { + private static function getSpecifiedConnectionParams() + { $realDbParams = self::getParamsForMainConnection(); - $tmpDbParams = self::getParamsForTemporaryConnection(); + $tmpDbParams = self::getParamsForTemporaryConnection(); $realConn = DriverManager::getConnection($realDbParams); // Connect to tmpdb in order to drop and create the real test db. $tmpConn = DriverManager::getConnection($tmpDbParams); - $platform = $tmpConn->getDatabasePlatform(); + $platform = $tmpConn->getDatabasePlatform(); if (! self::$initialized) { if ($platform->supportsCreateDropDatabase()) { @@ -101,7 +99,7 @@ private static function getSpecifiedConnectionParams() { $sm = $realConn->getSchemaManager(); $schema = $sm->createSchema(); - $stmts = $schema->toDropSql($realConn->getDatabasePlatform()); + $stmts = $schema->toDropSql($realConn->getDatabasePlatform()); foreach ($stmts as $stmt) { $realConn->exec($stmt); @@ -120,10 +118,10 @@ private static function getFallbackConnectionParams() Assert::markTestSkipped('PDO SQLite extension is not loaded'); } - $params = array( + $params = [ 'driver' => 'pdo_sqlite', - 'memory' => true - ); + 'memory' => true, + ]; if (isset($GLOBALS['db_path'])) { $params['path'] = $GLOBALS['db_path']; @@ -133,26 +131,29 @@ private static function getFallbackConnectionParams() return $params; } - private static function addDbEventSubscribers(Connection $conn) { - if (isset($GLOBALS['db_event_subscribers'])) { - $evm = $conn->getEventManager(); - foreach (explode(",", $GLOBALS['db_event_subscribers']) as $subscriberClass) { - $subscriberInstance = new $subscriberClass(); - $evm->addEventSubscriber($subscriberInstance); - } + private static function addDbEventSubscribers(Connection $conn) + { + if (! isset($GLOBALS['db_event_subscribers'])) { + return; + } + + $evm = $conn->getEventManager(); + foreach (explode(',', $GLOBALS['db_event_subscribers']) as $subscriberClass) { + $subscriberInstance = new $subscriberClass(); + $evm->addEventSubscriber($subscriberInstance); } } private static function getParamsForTemporaryConnection() { - $connectionParams = array( + $connectionParams = [ 'driver' => $GLOBALS['tmpdb_type'], 'user' => $GLOBALS['tmpdb_username'], 'password' => $GLOBALS['tmpdb_password'], 'host' => $GLOBALS['tmpdb_host'], 'dbname' => null, - 'port' => $GLOBALS['tmpdb_port'] - ); + 'port' => $GLOBALS['tmpdb_port'], + ]; if (isset($GLOBALS['tmpdb_name'])) { $connectionParams['dbname'] = $GLOBALS['tmpdb_name']; @@ -171,14 +172,14 @@ private static function getParamsForTemporaryConnection() private static function getParamsForMainConnection() { - $connectionParams = array( + $connectionParams = [ 'driver' => $GLOBALS['db_type'], 'user' => $GLOBALS['db_username'], 'password' => $GLOBALS['db_password'], 'host' => $GLOBALS['db_host'], 'dbname' => $GLOBALS['db_name'], - 'port' => $GLOBALS['db_port'] - ); + 'port' => $GLOBALS['db_port'], + ]; if (isset($GLOBALS['db_server'])) { $connectionParams['server'] = $GLOBALS['db_server']; diff --git a/tests/Doctrine/Tests/Types/MySqlPointType.php b/tests/Doctrine/Tests/Types/MySqlPointType.php index d325cb272d6..7e95418bc18 100644 --- a/tests/Doctrine/Tests/Types/MySqlPointType.php +++ b/tests/Doctrine/Tests/Types/MySqlPointType.php @@ -20,6 +20,6 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla public function getMappedDatabaseTypes(AbstractPlatform $platform) { - return array('point'); + return ['point']; } } diff --git a/tests/continuousphp/bootstrap.php b/tests/continuousphp/bootstrap.php index feaa1887e6a..cfdfb40eb1a 100644 --- a/tests/continuousphp/bootstrap.php +++ b/tests/continuousphp/bootstrap.php @@ -2,7 +2,7 @@ declare(strict_types=1); -(function () : void { +(static function () : void { $pos = array_search('--coverage-clover', $_SERVER['argv'], true); if ($pos === false) { @@ -11,7 +11,7 @@ $file = $_SERVER['argv'][$pos + 1]; - register_shutdown_function(function () use ($file) : void { + register_shutdown_function(static function () use ($file) : void { $cmd = 'wget https://github.com/scrutinizer-ci/ocular/releases/download/1.5.2/ocular.phar' . ' && php ocular.phar code-coverage:upload --format=php-clover ' . escapeshellarg($file); diff --git a/tests/phpstan-polyfill.php b/tests/phpstan-polyfill.php index 13b5aa1e185..f27e09de3a0 100644 --- a/tests/phpstan-polyfill.php +++ b/tests/phpstan-polyfill.php @@ -2,7 +2,7 @@ declare(strict_types=1); -(function () : void { +(static function () : void { foreach (['ibm_db2', 'mysqli', 'oci8', 'sqlsrv', 'pgsql'] as $extension) { if (extension_loaded($extension)) { continue;