Unverified Commit 30b9231c authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3446 from morozov/phpunit-8.0

Upgraded PHPUnit to 8.0
parents 1c75231d 53912cc0
/.phpunit.result.cache
build/
logs/
reports/
......
This diff is collapsed.
......@@ -33,7 +33,7 @@ class QueryCacheProfileTest extends DbalTestCase
'driver' => 'database_driver',
];
protected function setUp()
protected function setUp() : void
{
$this->queryCacheProfile = new QueryCacheProfile(self::LIFETIME, self::CACHE_KEY);
}
......@@ -110,7 +110,7 @@ class QueryCacheProfileTest extends DbalTestCase
self::assertArrayHasKey('connectionParams', $params);
foreach ($this->connectionParams as $param) {
self::assertNotContains($param, $params['connectionParams']);
self::assertStringNotContainsString($param, $params['connectionParams']);
}
}
......
......@@ -20,7 +20,7 @@ class ConfigurationTest extends DbalTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp() : void
{
$this->config = new Configuration();
}
......
......@@ -27,7 +27,7 @@ use Doctrine\Tests\Mocks\DriverStatementMock;
use Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock;
use Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock;
use Exception;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionObject;
use stdClass;
use function call_user_func_array;
......@@ -49,7 +49,7 @@ class ConnectionTest extends DbalTestCase
'port' => '1234',
];
protected function setUp()
protected function setUp() : void
{
$this->connection = DriverManager::getConnection($this->params);
}
......@@ -170,7 +170,6 @@ class ConnectionTest extends DbalTestCase
/**
* @requires extension pdo_sqlite
* @expectedException \Doctrine\DBAL\DBALException
* @dataProvider getQueryMethods
*/
public function testDriverExceptionIsWrapped($method)
......@@ -519,7 +518,7 @@ class ConnectionTest extends DbalTestCase
->with(FetchMode::ASSOCIATIVE)
->will($this->returnValue($result));
/** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock])
......@@ -555,7 +554,7 @@ class ConnectionTest extends DbalTestCase
->with(FetchMode::NUMERIC)
->will($this->returnValue($result));
/** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock])
......@@ -592,7 +591,7 @@ class ConnectionTest extends DbalTestCase
->with($column)
->will($this->returnValue($result));
/** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock])
......@@ -650,7 +649,7 @@ class ConnectionTest extends DbalTestCase
->method('fetchAll')
->will($this->returnValue($result));
/** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock])
......@@ -742,13 +741,13 @@ class ConnectionTest extends DbalTestCase
*/
public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform()
{
/** @var VersionAwarePlatformDriverMock|PHPUnit_Framework_MockObject_MockObject $driverMock */
/** @var VersionAwarePlatformDriverMock|MockObject $driverMock */
$driverMock = $this->createMock(VersionAwarePlatformDriverMock::class);
/** @var ServerInfoAwareConnectionMock|PHPUnit_Framework_MockObject_MockObject $driverConnectionMock */
/** @var ServerInfoAwareConnectionMock|MockObject $driverConnectionMock */
$driverConnectionMock = $this->createMock(ServerInfoAwareConnectionMock::class);
/** @var AbstractPlatform|PHPUnit_Framework_MockObject_MockObject $platformMock */
/** @var AbstractPlatform|MockObject $platformMock */
$platformMock = $this->getMockForAbstractClass(AbstractPlatform::class);
$connection = new Connection([], $driverMock);
......@@ -787,7 +786,7 @@ class ConnectionTest extends DbalTestCase
$params = [666];
$types = [ParameterType::INTEGER];
/** @var QueryCacheProfile|PHPUnit_Framework_MockObject_MockObject $queryCacheProfileMock */
/** @var QueryCacheProfile|MockObject $queryCacheProfileMock */
$queryCacheProfileMock = $this->createMock(QueryCacheProfile::class);
$queryCacheProfileMock
......@@ -824,7 +823,7 @@ class ConnectionTest extends DbalTestCase
->with('cacheKey')
->will($this->returnValue(['realKey' => []]));
/** @var QueryCacheProfile|PHPUnit_Framework_MockObject_MockObject $queryCacheProfileMock */
/** @var QueryCacheProfile|MockObject $queryCacheProfileMock */
$queryCacheProfileMock = $this->createMock(QueryCacheProfile::class);
$queryCacheProfileMock
......@@ -871,7 +870,7 @@ class ConnectionTest extends DbalTestCase
*/
public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase()
{
/** @var VersionAwarePlatformDriverMock|PHPUnit_Framework_MockObject_MockObject $driverMock */
/** @var VersionAwarePlatformDriverMock|MockObject $driverMock */
$driverMock = $this->createMock(VersionAwarePlatformDriverMock::class);
$connection = new Connection(['dbname' => 'foo'], $driverMock);
......
......@@ -20,7 +20,7 @@ class DBALExceptionTest extends DbalTestCase
/** @var Driver $driver */
$driver = $this->createMock(Driver::class);
$e = DBALException::driverExceptionDuringQuery($driver, new Exception(), '', ['ABC', chr(128)]);
self::assertContains('with params ["ABC", "\x80"]', $e->getMessage());
self::assertStringContainsString('with params ["ABC", "\x80"]', $e->getMessage());
}
public function testDriverExceptionDuringQueryAcceptsResource()
......@@ -28,7 +28,7 @@ class DBALExceptionTest extends DbalTestCase
/** @var Driver $driver */
$driver = $this->createMock(Driver::class);
$e = DBALException::driverExceptionDuringQuery($driver, new Exception(), 'INSERT INTO file (`content`) VALUES (?)', [1 => fopen(__FILE__, 'r')]);
self::assertContains('Resource', $e->getMessage());
self::assertStringContainsString('Resource', $e->getMessage());
}
public function testAvoidOverWrappingOnDriverException()
......
......@@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
......@@ -28,6 +29,7 @@ use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver;
use Doctrine\Tests\DbalTestCase;
use Exception;
use ReflectionProperty;
use function get_class;
use function sprintf;
......@@ -58,7 +60,7 @@ abstract class AbstractDriverTest extends DbalTestCase
*/
protected $driver;
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......@@ -158,15 +160,13 @@ abstract class AbstractDriverTest extends DbalTestCase
}
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion()
{
if (! $this->driver instanceof VersionAwarePlatformDriver) {
$this->markTestSkipped('This test is only intended for version aware platform drivers.');
}
$this->expectException(DBALException::class);
$this->driver->createDatabasePlatformForVersion('foo');
}
......@@ -198,7 +198,11 @@ abstract class AbstractDriverTest extends DbalTestCase
$schemaManager = $this->driver->getSchemaManager($connection);
self::assertEquals($this->createSchemaManager($connection), $schemaManager);
self::assertAttributeSame($connection, '_conn', $schemaManager);
$re = new ReflectionProperty($schemaManager, '_conn');
$re->setAccessible(true);
self::assertSame($connection, $re->getValue($schemaManager));
}
/**
......
......@@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver\IBMDB2\DB2Connection;
use Doctrine\Tests\DbalTestCase;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use function extension_loaded;
class DB2ConnectionTest extends DbalTestCase
......@@ -12,11 +12,11 @@ class DB2ConnectionTest extends DbalTestCase
/**
* The ibm_db2 driver connection mock under test.
*
* @var DB2Connection|PHPUnit_Framework_MockObject_MockObject
* @var DB2Connection|MockObject
*/
private $connectionMock;
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('ibm_db2')) {
$this->markTestSkipped('ibm_db2 is not installed.');
......
......@@ -6,7 +6,7 @@ use Doctrine\DBAL\Driver\Mysqli\MysqliConnection;
use Doctrine\DBAL\Driver\Mysqli\MysqliException;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\Tests\DbalFunctionalTestCase;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use function extension_loaded;
use function restore_error_handler;
use function set_error_handler;
......@@ -16,11 +16,11 @@ class MysqliConnectionTest extends DbalFunctionalTestCase
/**
* The mysqli driver connection mock under test.
*
* @var MysqliConnection|PHPUnit_Framework_MockObject_MockObject
* @var MysqliConnection|MockObject
*/
private $connectionMock;
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('mysqli')) {
$this->markTestSkipped('mysqli is not installed.');
......
......@@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\OCI8\OCI8Connection;
use Doctrine\Tests\DbalTestCase;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use function extension_loaded;
class OCI8ConnectionTest extends DbalTestCase
......@@ -12,11 +12,11 @@ class OCI8ConnectionTest extends DbalTestCase
/**
* The oci8 driver connection mock under test.
*
* @var OCI8Connection|PHPUnit_Framework_MockObject_MockObject
* @var OCI8Connection|MockObject
*/
private $connectionMock;
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('oci8')) {
$this->markTestSkipped('oci8 is not installed.');
......
......@@ -11,7 +11,7 @@ use function extension_loaded;
class OCI8StatementTest extends DbalTestCase
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('oci8')) {
$this->markTestSkipped('oci8 is not installed.');
......@@ -32,7 +32,6 @@ class OCI8StatementTest extends DbalTestCase
* @param mixed[] $params
*
* @dataProvider executeDataProvider
* @expectedException \Doctrine\DBAL\Driver\OCI8\OCI8Exception
*/
public function testExecute(array $params)
{
......@@ -73,6 +72,7 @@ class OCI8StatementTest extends DbalTestCase
$reflProperty->setAccessible(true);
$reflProperty->setValue($statement, $conn);
$this->expectException(OCI8Exception::class);
$statement->execute($params);
}
......
......@@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Driver;
use Doctrine\DBAL\Driver\PDOException;
use Doctrine\Tests\DbalTestCase;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use function extension_loaded;
class PDOExceptionTest extends DbalTestCase
......@@ -25,11 +25,11 @@ class PDOExceptionTest extends DbalTestCase
/**
* The wrapped PDO exception mock.
*
* @var \PDOException|PHPUnit_Framework_MockObject_MockObject
* @var \PDOException|MockObject
*/
private $wrappedException;
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('PDO')) {
$this->markTestSkipped('PDO is not installed.');
......
......@@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Driver\SQLAnywhere;
use Doctrine\DBAL\Driver\SQLAnywhere\SQLAnywhereConnection;
use Doctrine\Tests\DbalTestCase;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use function extension_loaded;
class SQLAnywhereConnectionTest extends DbalTestCase
......@@ -12,11 +12,11 @@ class SQLAnywhereConnectionTest extends DbalTestCase
/**
* The sqlanywhere driver connection mock under test.
*
* @var SQLAnywhereConnection|PHPUnit_Framework_MockObject_MockObject
* @var SQLAnywhereConnection|MockObject
*/
private $connectionMock;
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('sqlanywhere')) {
$this->markTestSkipped('sqlanywhere is not installed.');
......
......@@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Driver\SQLSrv\SQLSrvConnection;
use Doctrine\Tests\DbalTestCase;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use function extension_loaded;
class SQLSrvConnectionTest extends DbalTestCase
......@@ -12,11 +12,11 @@ class SQLSrvConnectionTest extends DbalTestCase
/**
* The sqlsrv driver connection mock under test.
*
* @var SQLSrvConnection|PHPUnit_Framework_MockObject_MockObject
* @var SQLSrvConnection|MockObject
*/
private $connectionMock;
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('sqlsrv')) {
$this->markTestSkipped('sqlsrv is not installed.');
......
......@@ -25,10 +25,10 @@ class DriverManagerTest extends DbalTestCase
{
/**
* @requires extension pdo_sqlite
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testInvalidPdoInstance()
{
$this->expectException(DBALException::class);
DriverManager::getConnection(['pdo' => 'test']);
}
......@@ -58,19 +58,17 @@ class DriverManagerTest extends DbalTestCase
self::assertEquals(PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(PDO::ATTR_ERRMODE));
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testCheckParams()
{
$this->expectException(DBALException::class);
DriverManager::getConnection([]);
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testInvalidDriver()
{
$this->expectException(DBALException::class);
DriverManager::getConnection(['driver' => 'invalid_driver']);
}
......
......@@ -18,7 +18,7 @@ use function stream_get_contents;
*/
class BlobTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......@@ -164,7 +164,7 @@ class BlobTest extends DbalFunctionalTestCase
$blobValue = Type::getType('blob')->convertToPHPValue($rows[0], $this->connection->getDatabasePlatform());
self::assertInternalType('resource', $blobValue);
self::assertIsResource($blobValue);
self::assertEquals($text, stream_get_contents($blobValue));
}
}
......@@ -18,13 +18,13 @@ use function in_array;
class ConnectionTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
$this->resetSharedConn();
parent::setUp();
}
protected function tearDown()
protected function tearDown() : void
{
parent::tearDown();
$this->resetSharedConn();
......
......@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Functional;
use DateTime;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Mysqli\Driver as MySQLiDriver;
use Doctrine\DBAL\Driver\OCI8\Driver as Oci8Driver;
use Doctrine\DBAL\Driver\PDOConnection;
......@@ -37,7 +38,7 @@ class DataAccessTest extends DbalFunctionalTestCase
/** @var bool */
static private $generated = false;
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......@@ -238,7 +239,6 @@ class DataAccessTest extends DbalFunctionalTestCase
/**
* @group DBAL-209
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testFetchAllWithMissingTypes()
{
......@@ -250,6 +250,9 @@ class DataAccessTest extends DbalFunctionalTestCase
$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 = ?';
$this->expectException(DBALException::class);
$this->connection->fetchAll($sql, [1, $datetime]);
}
......@@ -304,9 +307,6 @@ class DataAccessTest extends DbalFunctionalTestCase
self::assertStringStartsWith($datetimeString, $row['test_datetime']);
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testFetchAssocWithMissingTypes()
{
if ($this->connection->getDriver() instanceof MySQLiDriver ||
......@@ -317,6 +317,9 @@ class DataAccessTest extends DbalFunctionalTestCase
$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 = ?';
$this->expectException(DBALException::class);
$this->connection->fetchAssoc($sql, [1, $datetime]);
}
......@@ -345,9 +348,6 @@ class DataAccessTest extends DbalFunctionalTestCase
self::assertStringStartsWith($datetimeString, $row[1]);
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testFetchArrayWithMissingTypes()
{
if ($this->connection->getDriver() instanceof MySQLiDriver ||
......@@ -358,7 +358,10 @@ class DataAccessTest extends DbalFunctionalTestCase
$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->connection->fetchArray($sql, [1, $datetime]);
$this->expectException(DBALException::class);
$this->connection->fetchArray($sql, [1, $datetime]);
}
public function testFetchColumn()
......@@ -387,9 +390,6 @@ class DataAccessTest extends DbalFunctionalTestCase
self::assertStringStartsWith($datetimeString, $column);
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testFetchColumnWithMissingTypes()
{
if ($this->connection->getDriver() instanceof MySQLiDriver ||
......@@ -400,7 +400,10 @@ class DataAccessTest extends DbalFunctionalTestCase
$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->connection->fetchColumn($sql, [1, $datetime], 1);
$this->expectException(DBALException::class);
$this->connection->fetchColumn($sql, [1, $datetime], 1);
}
/**
......
......@@ -16,7 +16,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase
*/
protected $driver;
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -8,7 +8,7 @@ use function extension_loaded;
class DB2DriverTest extends AbstractDriverTest
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('ibm_db2')) {
$this->markTestSkipped('ibm_db2 is not installed.');
......
......@@ -11,7 +11,7 @@ use function extension_loaded;
class DB2StatementTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('ibm_db2')) {
$this->markTestSkipped('ibm_db2 is not installed.');
......
......@@ -4,13 +4,14 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\Mysqli;
use Doctrine\DBAL\Driver\Mysqli\Driver;
use Doctrine\DBAL\Driver\Mysqli\MysqliConnection;
use Doctrine\DBAL\Driver\Mysqli\MysqliException;
use Doctrine\Tests\DbalFunctionalTestCase;
use const MYSQLI_OPT_CONNECT_TIMEOUT;
use function extension_loaded;
class ConnectionTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('mysqli')) {
$this->markTestSkipped('mysqli is not installed.');
......@@ -25,7 +26,7 @@ class ConnectionTest extends DbalFunctionalTestCase
$this->markTestSkipped('MySQLi only test.');
}
protected function tearDown()
protected function tearDown() : void
{
parent::tearDown();
}
......@@ -38,11 +39,10 @@ class ConnectionTest extends DbalFunctionalTestCase
self::assertInstanceOf(MysqliConnection::class, $connection);
}
/**
* @expectedException \Doctrine\DBAL\Driver\Mysqli\MysqliException
*/
public function testUnsupportedDriverOption()
{
$this->expectException(MysqliException::class);
$this->getConnection(['hello' => 'world']); // use local infile
}
......
......@@ -8,7 +8,7 @@ use function extension_loaded;
class DriverTest extends AbstractDriverTest
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('mysqli')) {
$this->markTestSkipped('mysqli is not installed.');
......
......@@ -8,7 +8,7 @@ use function extension_loaded;
class DriverTest extends AbstractDriverTest
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('oci8')) {
$this->markTestSkipped('oci8 is not installed.');
......
......@@ -13,7 +13,7 @@ class OCI8ConnectionTest extends DbalFunctionalTestCase
/** @var OCI8Connection */
protected $driverConnection;
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('oci8')) {
$this->markTestSkipped('oci8 is not installed.');
......
......@@ -8,7 +8,7 @@ use function extension_loaded;
class StatementTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('oci8')) {
$this->markTestSkipped('oci8 is not installed.');
......
......@@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Functional\Driver;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\PDOException;
use Doctrine\Tests\DbalFunctionalTestCase;
use PDO;
use function extension_loaded;
......@@ -17,7 +18,7 @@ class PDOConnectionTest extends DbalFunctionalTestCase
*/
protected $driverConnection;
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('PDO')) {
$this->markTestSkipped('PDO is not installed.');
......@@ -34,7 +35,7 @@ class PDOConnectionTest extends DbalFunctionalTestCase
$this->markTestSkipped('PDO connection only test.');
}
protected function tearDown()
protected function tearDown() : void
{
$this->resetSharedConn();
......@@ -46,26 +47,23 @@ class PDOConnectionTest extends DbalFunctionalTestCase
self::assertFalse($this->driverConnection->requiresQueryForServerVersion());
}
/**
* @expectedException \Doctrine\DBAL\Driver\PDOException
*/
public function testThrowsWrappedExceptionOnConstruct()
{
$this->expectException(PDOException::class);
new PDOConnection('foo');
}
/**
* @group DBAL-1022
* @expectedException \Doctrine\DBAL\Driver\PDOException
*/
public function testThrowsWrappedExceptionOnExec()
{
$this->expectException(PDOException::class);
$this->driverConnection->exec('foo');
}
/**
* @expectedException \Doctrine\DBAL\Driver\PDOException
*/
public function testThrowsWrappedExceptionOnPrepare()
{
if ($this->connection->getDriver()->getName() === 'pdo_sqlsrv') {
......@@ -76,6 +74,8 @@ class PDOConnectionTest extends DbalFunctionalTestCase
// so that PDO actually communicates with the database server to check the query.
$this->driverConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$this->expectException(PDOException::class);
$this->driverConnection->prepare('foo');
// Some PDO adapters like PostgreSQL do not check the query server-side
......@@ -91,11 +91,10 @@ class PDOConnectionTest extends DbalFunctionalTestCase
);
}
/**
* @expectedException \Doctrine\DBAL\Driver\PDOException
*/
public function testThrowsWrappedExceptionOnQuery()
{
$this->expectException(PDOException::class);
$this->driverConnection->query('foo');
}
}
......@@ -8,7 +8,7 @@ use function extension_loaded;
class DriverTest extends AbstractDriverTest
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('pdo_mysql')) {
$this->markTestSkipped('pdo_mysql is not installed.');
......
......@@ -8,7 +8,7 @@ use function extension_loaded;
class DriverTest extends AbstractDriverTest
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('PDO_OCI')) {
$this->markTestSkipped('PDO_OCI is not installed.');
......
......@@ -13,7 +13,7 @@ use function sprintf;
class DriverTest extends AbstractDriverTest
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('pdo_pgsql')) {
$this->markTestSkipped('pdo_pgsql is not installed.');
......
......@@ -10,7 +10,7 @@ use function extension_loaded;
class PDOPgsqlConnectionTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('pdo_pgsql')) {
$this->markTestSkipped('pdo_pgsql is not loaded.');
......
......@@ -8,7 +8,7 @@ use function extension_loaded;
class DriverTest extends AbstractDriverTest
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('pdo_sqlite')) {
$this->markTestSkipped('pdo_sqlite is not installed.');
......
......@@ -10,7 +10,7 @@ use function extension_loaded;
class DriverTest extends AbstractDriverTest
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('pdo_sqlsrv')) {
$this->markTestSkipped('pdo_sqlsrv is not installed.');
......
......@@ -9,7 +9,7 @@ use function extension_loaded;
class ConnectionTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('sqlanywhere')) {
$this->markTestSkipped('sqlanywhere is not installed.');
......
......@@ -9,7 +9,7 @@ use function extension_loaded;
class DriverTest extends AbstractDriverTest
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('sqlanywhere')) {
$this->markTestSkipped('sqlanywhere is not installed.');
......@@ -38,7 +38,7 @@ class DriverTest extends AbstractDriverTest
// SQL Anywhere has no "default" database. The name of the default database
// is defined on server startup and therefore can be arbitrary.
self::assertInternalType('string', $this->driver->getDatabase($connection));
self::assertIsString($this->driver->getDatabase($connection));
}
/**
......
......@@ -9,7 +9,7 @@ use function extension_loaded;
class StatementTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('sqlanywhere')) {
$this->markTestSkipped('sqlanywhere is not installed.');
......
......@@ -8,7 +8,7 @@ use function extension_loaded;
class DriverTest extends AbstractDriverTest
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('sqlsrv')) {
$this->markTestSkipped('sqlsrv is not installed.');
......
......@@ -9,7 +9,7 @@ use function extension_loaded;
class StatementTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('sqlsrv')) {
self::markTestSkipped('sqlsrv is not installed.');
......
......@@ -20,7 +20,7 @@ use function unlink;
class ExceptionTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -20,7 +20,7 @@ use function substr;
*/
class MasterSlaveConnectionTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -13,7 +13,7 @@ class ModifyLimitQueryTest extends DbalFunctionalTestCase
/** @var bool */
private static $tableCreated = false;
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -147,7 +147,7 @@ class NamedParametersTest extends DbalFunctionalTestCase
];
}
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -10,7 +10,7 @@ use function extension_loaded;
class PDOStatementTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
if (! extension_loaded('pdo')) {
$this->markTestSkipped('PDO is not installed');
......
......@@ -11,7 +11,7 @@ final class NewPrimaryKeyWithNewAutoIncrementColumnTest extends DbalFunctionalTe
/**
* {@inheritDoc}
*/
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -21,7 +21,7 @@ class PortabilityTest extends DbalFunctionalTestCase
/** @var Connection */
private $portableConnection;
protected function tearDown()
protected function tearDown() : void
{
if ($this->portableConnection) {
$this->portableConnection->close();
......
......@@ -26,7 +26,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
/** @var DebugStack */
private $sqlLogger;
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......@@ -49,7 +49,7 @@ class ResultCacheTest extends DbalFunctionalTestCase
$config->setResultCacheImpl($cache);
}
protected function tearDown()
protected function tearDown() : void
{
$this->connection->getSchemaManager()->dropTable('caching');
......
......@@ -17,7 +17,7 @@ class ComparatorTest extends DbalFunctionalTestCase
/** @var Comparator */
private $comparator;
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -15,7 +15,7 @@ use function sprintf;
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -14,7 +14,7 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
/** @var bool */
private static $privilegesGranted = false;
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -19,7 +19,7 @@ use function strtolower;
class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
protected function tearDown()
protected function tearDown() : void
{
parent::tearDown();
......@@ -48,7 +48,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
$names = $this->schemaManager->getSchemaNames();
self::assertInternalType('array', $names);
self::assertIsArray($names);
self::assertNotEmpty($names);
self::assertContains('public', $names, 'The public schema should be found.');
}
......
......@@ -37,7 +37,7 @@ class SQLAnywhereSchemaManagerTest extends SchemaManagerFunctionalTestCase
);
$tableIndexes = $this->schemaManager->listTableIndexes('test_create_advanced_index');
self::assertInternalType('array', $tableIndexes);
self::assertIsArray($tableIndexes);
self::assertEquals('test', $tableIndexes['test']->getName());
self::assertEquals(['test'], $tableIndexes['test']->getColumns());
self::assertTrue($tableIndexes['test']->isUnique());
......
......@@ -59,7 +59,7 @@ class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
return strtolower(str_replace('SchemaManagerTest', null, $testClass));
}
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......@@ -73,7 +73,7 @@ class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
}
protected function tearDown()
protected function tearDown() : void
{
parent::tearDown();
......@@ -168,7 +168,7 @@ class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$sequences = $this->schemaManager->listSequences();
self::assertInternalType('array', $sequences, 'listSequences() should return an array.');
self::assertIsArray($sequences, 'listSequences() should return an array.');
$foundSequence = null;
foreach ($sequences as $sequence) {
......@@ -227,7 +227,7 @@ class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$this->createTestTable('list_tables_test');
$tables = $this->schemaManager->listTables();
self::assertInternalType('array', $tables);
self::assertIsArray($tables);
self::assertTrue(count($tables) > 0, "List Tables has to find at least one table named 'list_tables_test'.");
$foundTable = false;
......@@ -278,7 +278,7 @@ class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
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::assertIsArray($columns['id']->getPlatformOptions());
self::assertArrayHasKey('test', $columns);
self::assertEquals(1, array_search('test', $columnsKeys));
......@@ -288,7 +288,7 @@ class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
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::assertIsArray($columns['test']->getPlatformOptions());
self::assertEquals('foo', strtolower($columns['foo']->getname()));
self::assertEquals(2, array_search('foo', $columnsKeys));
......@@ -297,7 +297,7 @@ class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
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::assertIsArray($columns['foo']->getPlatformOptions());
self::assertEquals('bar', strtolower($columns['bar']->getname()));
self::assertEquals(3, array_search('bar', $columnsKeys));
......@@ -309,28 +309,28 @@ class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
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::assertIsArray($columns['bar']->getPlatformOptions());
self::assertEquals('baz1', strtolower($columns['baz1']->getname()));
self::assertEquals(4, array_search('baz1', $columnsKeys));
self::assertInstanceOf(DateTimeType::class, $columns['baz1']->gettype());
self::assertEquals(true, $columns['baz1']->getnotnull());
self::assertEquals(null, $columns['baz1']->getdefault());
self::assertInternalType('array', $columns['baz1']->getPlatformOptions());
self::assertIsArray($columns['baz1']->getPlatformOptions());
self::assertEquals('baz2', strtolower($columns['baz2']->getname()));
self::assertEquals(5, array_search('baz2', $columnsKeys));
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::assertIsArray($columns['baz2']->getPlatformOptions());
self::assertEquals('baz3', strtolower($columns['baz3']->getname()));
self::assertEquals(6, array_search('baz3', $columnsKeys));
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());
self::assertIsArray($columns['baz3']->getPlatformOptions());
}
/**
......@@ -459,7 +459,7 @@ class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$this->schemaManager->dropAndCreateIndex($table->getIndex('test'), $table);
$tableIndexes = $this->schemaManager->listTableIndexes('test_create_index');
self::assertInternalType('array', $tableIndexes);
self::assertIsArray($tableIndexes);
self::assertEquals('test', strtolower($tableIndexes['test']->getName()));
self::assertEquals(['test'], array_map('strtolower', $tableIndexes['test']->getColumns()));
......@@ -1188,8 +1188,8 @@ class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$table->addColumn('id', 'integer', ['columnDefinition' => $columnDefinition, 'comment' => 'unexpected_column_comment']);
$sql = $this->connection->getDatabasePlatform()->getCreateTableSQL($table);
self::assertContains('expected+column+comment', $sql[0]);
self::assertNotContains('unexpected_column_comment', $sql[0]);
self::assertStringContainsString('expected+column+comment', $sql[0]);
self::assertStringNotContainsString('unexpected_column_comment', $sql[0]);
}
/**
......
......@@ -2,6 +2,7 @@
namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Table;
......@@ -17,11 +18,11 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
/**
* SQLITE does not support databases.
*
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testListDatabases()
{
$this->expectException(DBALException::class);
$this->schemaManager->listDatabases();
}
......
......@@ -14,7 +14,7 @@ use function stream_get_contents;
class StatementTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......@@ -69,7 +69,7 @@ class StatementTest extends DbalFunctionalTestCase
$stmt = $this->connection->prepare('SELECT param, val FROM stmt_longer_results ORDER BY param');
$stmt->execute();
self::assertArraySubset([
self::assertEquals([
['param1', 'X'],
], $stmt->fetchAll(FetchMode::NUMERIC));
......@@ -80,7 +80,7 @@ class StatementTest extends DbalFunctionalTestCase
$this->connection->insert('stmt_longer_results', $row2);
$stmt->execute();
self::assertArraySubset([
self::assertEquals([
['param1', 'X'],
['param2', 'A bit longer value'],
], $stmt->fetchAll(FetchMode::NUMERIC));
......
......@@ -16,7 +16,7 @@ class TableGeneratorTest extends DbalFunctionalTestCase
/** @var TableGenerator */
private $generator;
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -9,7 +9,7 @@ use Throwable;
class TemporaryTableTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
try {
......@@ -18,7 +18,7 @@ class TemporaryTableTest extends DbalFunctionalTestCase
}
}
protected function tearDown()
protected function tearDown() : void
{
if ($this->connection) {
try {
......
......@@ -10,7 +10,7 @@ use Doctrine\Tests\DbalFunctionalTestCase;
*/
class DBAL202Test extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -11,7 +11,7 @@ use function preg_match;
*/
class DBAL421Test extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -11,7 +11,7 @@ use Doctrine\Tests\DbalFunctionalTestCase;
*/
class DBAL510Test extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -16,7 +16,7 @@ class DBAL630Test extends DbalFunctionalTestCase
/** @var bool */
private $running = false;
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......@@ -34,7 +34,7 @@ class DBAL630Test extends DbalFunctionalTestCase
$this->running = true;
}
protected function tearDown()
protected function tearDown() : void
{
if ($this->running) {
$this->connection->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
......
......@@ -10,7 +10,7 @@ use function in_array;
*/
class DBAL752Test extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -8,7 +8,6 @@ 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 DbalFunctionalTestCase
......@@ -16,7 +15,7 @@ class TypeConversionTest extends DbalFunctionalTestCase
/** @var int */
static private $typeCounter = 0;
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......@@ -38,45 +37,79 @@ class TypeConversionTest extends DbalFunctionalTestCase
$table->addColumn('test_decimal', 'decimal', ['notnull' => false, 'scale' => 2, 'precision' => 10]);
$table->setPrimaryKey(['id']);
try {
$this->connection->getSchemaManager()->createTable($table);
} catch (Throwable $e) {
}
$this->connection
->getSchemaManager()
->dropAndCreateTable($table);
}
public static function dataIdempotentDataConversion()
/**
* @dataProvider booleanProvider
*/
public function testIdempotentConversionToBoolean(string $type, $originalValue) : void
{
$obj = new stdClass();
$obj->foo = 'bar';
$obj->bar = 'baz';
$dbValue = $this->processValue($type, $originalValue);
self::assertIsBool($dbValue);
self::assertEquals($originalValue, $dbValue);
}
/**
* @return mixed[][]
*/
public static function booleanProvider() : iterable
{
return [
'true' => ['boolean', true],
'false' => ['boolean', false],
];
}
/**
* @dataProvider integerProvider
*/
public function testIdempotentConversionToInteger(string $type, $originalValue) : void
{
$dbValue = $this->processValue($type, $originalValue);
self::assertIsInt($dbValue);
self::assertEquals($originalValue, $dbValue);
}
/**
* @return mixed[][]
*/
public static function integerProvider() : iterable
{
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'],
'smallint' => ['smallint', 123],
];
}
/**
* @param string $type
* @param mixed $originalValue
* @param string $expectedPhpType
*
* @dataProvider dataIdempotentDataConversion
* @dataProvider floatProvider
*/
public function testIdempotentDataConversion($type, $originalValue, $expectedPhpType)
public function testIdempotentConversionToFloat(string $type, $originalValue) : void
{
$dbValue = $this->processValue($type, $originalValue);
self::assertIsFloat($dbValue);
self::assertEquals($originalValue, $dbValue);
}
/**
* @return mixed[][]
*/
public static function floatProvider() : iterable
{
return [
'float' => ['float', 1.5],
];
}
/**
* @dataProvider toStringProvider
*/
public function testIdempotentConversionToString(string $type, $originalValue) : void
{
if ($type === 'text' && $this->connection->getDriver() instanceof PDOOracleDriver) {
// inserting BLOBs as streams on Oracle requires Oracle-specific SQL syntax which is currently not supported
......@@ -84,31 +117,121 @@ class TypeConversionTest extends DbalFunctionalTestCase
$this->markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI');
}
$columnName = 'test_' . $type;
$typeInstance = Type::getType($type);
$insertionValue = $typeInstance->convertToDatabaseValue($originalValue, $this->connection->getDatabasePlatform());
$dbValue = $this->processValue($type, $originalValue);
$this->connection->insert('type_conversion', ['id' => ++self::$typeCounter, $columnName => $insertionValue]);
self::assertIsString($dbValue);
self::assertEquals($originalValue, $dbValue);
}
$sql = 'SELECT ' . $columnName . ' FROM type_conversion WHERE id = ' . self::$typeCounter;
$actualDbValue = $typeInstance->convertToPHPValue($this->connection->fetchColumn($sql), $this->connection->getDatabasePlatform());
/**
* @return mixed[][]
*/
public static function toStringProvider() : iterable
{
return [
'string' => ['string', 'ABCDEFGabcdefg'],
'bigint' => ['bigint', 12345678],
'text' => ['text', str_repeat('foo ', 1000)],
'decimal' => ['decimal', 1.55],
];
}
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);
}
/**
* @dataProvider toArrayProvider
*/
public function testIdempotentConversionToArray(string $type, $originalValue) : void
{
$dbValue = $this->processValue($type, $originalValue);
self::assertIsArray($dbValue);
self::assertEquals($originalValue, $dbValue);
}
/**
* @return mixed[][]
*/
public static function toArrayProvider() : iterable
{
return [
'array' => ['array', ['foo' => 'bar']],
'json_array' => ['json_array', ['foo' => 'bar']],
];
}
/**
* @dataProvider toObjectProvider
*/
public function testIdempotentConversionToObject(string $type, $originalValue) : void
{
$dbValue = $this->processValue($type, $originalValue);
self::assertIsObject($dbValue);
self::assertEquals($originalValue, $dbValue);
}
/**
* @return mixed[][]
*/
public static function toObjectProvider() : iterable
{
$obj = new stdClass();
$obj->foo = 'bar';
$obj->bar = 'baz';
return [
'object' => ['object', $obj],
];
}
/**
* @dataProvider toDateTimeProvider
*/
public function testIdempotentConversionToDateTime(string $type, DateTime $originalValue) : void
{
$dbValue = $this->processValue($type, $originalValue);
self::assertInstanceOf(DateTime::class, $dbValue);
if ($type === 'datetimetz') {
return;
}
self::assertEquals($originalValue, $actualDbValue, 'Conversion between values should produce the same out as in value, but doesnt!');
self::assertEquals($originalValue, $dbValue);
self::assertEquals(
$originalValue->getTimezone(),
$dbValue->getTimezone()
);
}
if (! ($originalValue instanceof DateTime)) {
return;
}
/**
* @return mixed[][]
*/
public static function toDateTimeProvider() : iterable
{
return [
'datetime' => ['datetime', new DateTime('2010-04-05 10:10:10')],
'datetimetz' => ['datetimetz', new DateTime('2010-04-05 10:10:10')],
'date' => ['date', new DateTime('2010-04-05')],
'time' => ['time', new DateTime('1970-01-01 10:10:10')],
];
}
/**
* @param mixed $originalValue
*/
private function processValue(string $type, $originalValue)
{
$columnName = 'test_' . $type;
$typeInstance = Type::getType($type);
$insertionValue = $typeInstance->convertToDatabaseValue($originalValue, $this->connection->getDatabasePlatform());
$this->connection->insert('type_conversion', ['id' => ++self::$typeCounter, $columnName => $insertionValue]);
$sql = 'SELECT ' . $columnName . ' FROM type_conversion WHERE id = ' . self::$typeCounter;
self::assertEquals($originalValue->getTimezone()->getName(), $actualDbValue->getTimezone()->getName(), 'Timezones should be the same.');
return $typeInstance->convertToPHPValue(
$this->connection->fetchColumn($sql),
$this->connection->getDatabasePlatform()
);
}
}
......@@ -16,7 +16,7 @@ use function stream_get_contents;
class BinaryTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -15,7 +15,7 @@ use function strtolower;
class WriteTest extends DbalFunctionalTestCase
{
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......
......@@ -10,12 +10,12 @@ class DebugStackTest extends DbalTestCase
/** @var DebugStack */
private $logger;
protected function setUp()
protected function setUp() : void
{
$this->logger = new DebugStack();
}
protected function tearDown()
protected function tearDown() : void
{
unset($this->logger);
}
......
......@@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
......@@ -13,6 +14,9 @@ use function array_shift;
abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
{
/** @var MySqlPlatform */
protected $platform;
public function testModifyLimitQueryWitoutLimit()
{
$sql = $this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10);
......@@ -842,7 +846,10 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableIndexesSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\", 'foo_db'), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\", 'foo_db')
);
}
/**
......@@ -850,7 +857,10 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
*/
public function testQuotesDatabaseNameInListTableIndexesSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL('foo_table', "Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\\\'",
$this->platform->getListTableIndexesSQL('foo_table', "Foo'Bar\\")
);
}
/**
......@@ -858,7 +868,10 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
*/
public function testQuotesDatabaseNameInListViewsSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListViewsSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\\\'",
$this->platform->getListViewsSQL("Foo'Bar\\")
);
}
/**
......@@ -866,7 +879,10 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableForeignKeysSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\")
);
}
/**
......@@ -874,7 +890,10 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
*/
public function testQuotesDatabaseNameInListTableForeignKeysSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL('foo_table', "Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\\\'",
$this->platform->getListTableForeignKeysSQL('foo_table', "Foo'Bar\\")
);
}
/**
......@@ -882,7 +901,10 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\\\'",
$this->platform->getListTableColumnsSQL("Foo'Bar\\")
);
}
/**
......@@ -890,19 +912,22 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
*/
public function testQuotesDatabaseNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\\\'",
$this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\")
);
}
public function testListTableForeignKeysSQLEvaluatesDatabase()
{
$sql = $this->platform->getListTableForeignKeysSQL('foo');
self::assertContains('DATABASE()', $sql);
self::assertStringContainsString('DATABASE()', $sql);
$sql = $this->platform->getListTableForeignKeysSQL('foo', 'bar');
self::assertContains('bar', $sql);
self::assertNotContains('DATABASE()', $sql);
self::assertStringContainsString('bar', $sql);
self::assertStringNotContainsString('DATABASE()', $sql);
}
public function testColumnCharsetDeclarationSQL() : void
......
......@@ -29,7 +29,7 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
abstract public function createPlatform();
protected function setUp()
protected function setUp() : void
{
$this->platform = $this->createPlatform();
}
......@@ -266,10 +266,7 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
$fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk');
if ($this->platform->supportsForeignKeyConstraints()) {
self::assertInternalType(
'string',
$this->platform->getCreateForeignKeySQL($fk, 'test')
);
self::assertIsString($this->platform->getCreateForeignKeySQL($fk, 'test'));
} else {
$this->expectException(DBALException::class);
$this->platform->getCreateForeignKeySQL($fk, 'test');
......@@ -773,11 +770,10 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
return false;
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testGetCreateSchemaSQL()
{
$this->expectException(DBALException::class);
$this->platform->getCreateSchemaSQL('schema');
}
......@@ -797,7 +793,7 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
['type']
);
self::assertContains(
self::assertStringContainsString(
$this->platform->quoteIdentifier('select'),
implode(';', $this->platform->getAlterTableSQL($tableDiff))
);
......@@ -813,10 +809,11 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
/**
* @group DBAL-563
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testReturnsIdentitySequenceName()
{
$this->expectException(DBALException::class);
$this->platform->getIdentitySequenceName('mytable', 'mycolumn');
}
......@@ -840,11 +837,10 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
return 4000;
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testReturnsBinaryTypeDeclarationSQL()
{
$this->expectException(DBALException::class);
$this->platform->getBinaryTypeDeclarationSQL([]);
}
......@@ -1301,10 +1297,11 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
/**
* @group DBAL-423
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testReturnsGuidTypeDeclarationSQL()
{
$this->expectException(DBALException::class);
$this->platform->getGuidTypeDeclarationSQL([]);
}
......
......@@ -11,6 +11,7 @@ use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Type;
use UnexpectedValueException;
use function sprintf;
abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCase
......@@ -477,13 +478,14 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
self::assertSame($booleanValue, $platform->convertFromBoolean($databaseValue));
}
/**
* @expectedException UnexpectedValueException
* @expectedExceptionMessage Unrecognized boolean literal 'my-bool'
*/
public function testThrowsExceptionWithInvalidBooleanLiteral()
{
$platform = $this->createPlatform()->convertBooleansToDatabaseValue('my-bool');
$platform = $this->createPlatform();
$this->expectException(UnexpectedValueException::class);
$this->expectExceptionMessage("Unrecognized boolean literal 'my-bool'");
$platform->convertBooleansToDatabaseValue('my-bool');
}
public function testGetCreateSchemaSQL()
......@@ -602,7 +604,7 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
public function testCreateSequenceWithCache($cacheSize, $expectedSql)
{
$sequence = new Sequence('foo', 1, 1, $cacheSize);
self::assertContains($expectedSql, $this->platform->getCreateSequenceSQL($sequence));
self::assertStringContainsString($expectedSql, $this->platform->getCreateSequenceSQL($sequence));
}
public function dataCreateSequenceWithCache()
......@@ -952,7 +954,10 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
public function testQuotesTableNameInListTableForeignKeysSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\")
);
}
/**
......@@ -960,11 +965,9 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
public function testQuotesSchemaNameInListTableForeignKeysSQL()
{
self::assertContains(
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"),
'',
true
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table")
);
}
......@@ -973,7 +976,10 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
public function testQuotesTableNameInListTableConstraintsSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableConstraintsSQL("Foo'Bar\\")
);
}
/**
......@@ -981,7 +987,10 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
public function testQuotesTableNameInListTableIndexesSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\")
);
}
/**
......@@ -989,11 +998,9 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
public function testQuotesSchemaNameInListTableIndexesSQL()
{
self::assertContains(
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"),
'',
true
$this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table")
);
}
......@@ -1002,7 +1009,10 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
public function testQuotesTableNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableColumnsSQL("Foo'Bar\\")
);
}
/**
......@@ -1010,11 +1020,9 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
public function testQuotesSchemaNameInListTableColumnsSQL()
{
self::assertContains(
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"),
'',
true
$this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table")
);
}
......@@ -1023,11 +1031,9 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
*/
public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL()
{
self::assertContains(
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\"),
'',
true
$this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\")
);
}
}
......@@ -47,11 +47,10 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
];
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testDoesNotSupportRegexp()
{
$this->expectException(DBALException::class);
$this->platform->getRegexpExpression();
}
......@@ -1423,7 +1422,10 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
*/
public function testQuotesTableNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableColumnsSQL("Foo'Bar\\")
);
}
/**
......@@ -1431,11 +1433,9 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
*/
public function testQuotesSchemaNameInListTableColumnsSQL()
{
self::assertContains(
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"),
'',
true
$this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table")
);
}
......@@ -1444,7 +1444,10 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
*/
public function testQuotesTableNameInListTableForeignKeysSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\")
);
}
/**
......@@ -1452,11 +1455,9 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
*/
public function testQuotesSchemaNameInListTableForeignKeysSQL()
{
self::assertContains(
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"),
'',
true
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table")
);
}
......@@ -1465,7 +1466,10 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
*/
public function testQuotesTableNameInListTableIndexesSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\")
);
}
/**
......@@ -1473,11 +1477,9 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
*/
public function testQuotesSchemaNameInListTableIndexesSQL()
{
self::assertContains(
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"),
'',
true
$this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table")
);
}
......
......@@ -686,7 +686,10 @@ class DB2PlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableColumnsSQL("Foo'Bar\\")
);
}
/**
......@@ -694,7 +697,10 @@ class DB2PlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableIndexesSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\")
);
}
/**
......@@ -702,6 +708,9 @@ class DB2PlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableForeignKeysSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\")
);
}
}
......@@ -97,11 +97,10 @@ class OraclePlatformTest extends AbstractPlatformTestCase
];
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testRLike()
{
$this->expectException(DBALException::class);
self::assertEquals('RLIKE', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct');
}
......@@ -131,11 +130,10 @@ class OraclePlatformTest extends AbstractPlatformTestCase
);
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testCreateDatabaseThrowsException()
{
$this->expectException(DBALException::class);
self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar'));
}
......@@ -539,7 +537,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase
public function testCreateSequenceWithCache($cacheSize, $expectedSql)
{
$sequence = new Sequence('foo', 1, 1, $cacheSize);
self::assertContains($expectedSql, $this->platform->getCreateSequenceSQL($sequence));
self::assertStringContainsString($expectedSql, $this->platform->getCreateSequenceSQL($sequence));
}
public function dataCreateSequenceWithCache()
......@@ -875,7 +873,10 @@ SQL
*/
public function testQuotesDatabaseNameInListSequencesSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListSequencesSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListSequencesSQL("Foo'Bar\\")
);
}
/**
......@@ -883,7 +884,10 @@ SQL
*/
public function testQuotesTableNameInListTableIndexesSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\")
);
}
/**
......@@ -891,7 +895,10 @@ SQL
*/
public function testQuotesTableNameInListTableForeignKeysSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\")
);
}
/**
......@@ -899,7 +906,10 @@ SQL
*/
public function testQuotesTableNameInListTableConstraintsSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableConstraintsSQL("Foo'Bar\\")
);
}
/**
......@@ -907,7 +917,10 @@ SQL
*/
public function testQuotesTableNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableColumnsSQL("Foo'Bar\\")
);
}
/**
......@@ -915,6 +928,9 @@ SQL
*/
public function testQuotesDatabaseNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\")
);
}
}
......@@ -12,7 +12,7 @@ class ReservedKeywordsValidatorTest extends DbalTestCase
/** @var ReservedKeywordsValidator */
private $validator;
protected function setUp()
protected function setUp() : void
{
$this->validator = new ReservedKeywordsValidator([new MySQLKeywords()]);
}
......
......@@ -995,11 +995,9 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesSchemaNameInListTableColumnsSQL()
{
self::assertContains(
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"),
'',
true
$this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table")
);
}
......@@ -1008,7 +1006,7 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableConstraintsSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
}
/**
......@@ -1016,11 +1014,9 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesSchemaNameInListTableConstraintsSQL()
{
self::assertContains(
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableConstraintsSQL("Foo'Bar\\.baz_table"),
'',
true
$this->platform->getListTableConstraintsSQL("Foo'Bar\\.baz_table")
);
}
......@@ -1029,7 +1025,10 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableForeignKeysSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\")
);
}
/**
......@@ -1037,11 +1036,9 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesSchemaNameInListTableForeignKeysSQL()
{
self::assertContains(
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"),
'',
true
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table")
);
}
......@@ -1050,7 +1047,10 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableIndexesSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\")
);
}
/**
......@@ -1058,11 +1058,9 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesSchemaNameInListTableIndexesSQL()
{
self::assertContains(
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"),
'',
true
$this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table")
);
}
}
......@@ -14,7 +14,7 @@ class SQLAzurePlatformTest extends DbalTestCase
/** @var SQLAzurePlatform */
private $platform;
protected function setUp()
protected function setUp() : void
{
$this->platform = new SQLAzurePlatform();
}
......
......@@ -262,19 +262,17 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testGeneratesForeignKeyCreationSql()
{
$this->expectException(DBALException::class);
parent::testGeneratesForeignKeyCreationSql();
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testGeneratesConstraintCreationSql()
{
$this->expectException(DBALException::class);
parent::testGeneratesConstraintCreationSql();
}
......@@ -727,7 +725,10 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableConstraintsSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableConstraintsSQL("Foo'Bar\\")
);
}
/**
......@@ -735,7 +736,10 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableColumnsSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableColumnsSQL("Foo'Bar\\")
);
}
/**
......@@ -743,7 +747,10 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableIndexesSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableIndexesSQL("Foo'Bar\\")
);
}
/**
......@@ -751,7 +758,10 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
*/
public function testQuotesTableNameInListTableForeignKeysSQL()
{
self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
self::assertStringContainsStringIgnoringCase(
"'Foo''Bar\\'",
$this->platform->getListTableForeignKeysSQL("Foo'Bar\\")
);
}
public function testDateAddStaticNumberOfDays()
......
......@@ -9,24 +9,25 @@ use Doctrine\DBAL\Portability\Connection;
use Doctrine\DBAL\Portability\Statement;
use Doctrine\Tests\DbalTestCase;
use Doctrine\Tests\Mocks\DriverStatementMock;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionProperty;
use function iterator_to_array;
class StatementTest extends DbalTestCase
{
/** @var Connection|PHPUnit_Framework_MockObject_MockObject */
/** @var Connection|MockObject */
protected $conn;
/** @var Statement */
protected $stmt;
/** @var DriverStatement|PHPUnit_Framework_MockObject_MockObject */
/** @var DriverStatement|MockObject */
protected $wrappedStmt;
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp() : void
{
$this->wrappedStmt = $this->createWrappedStatement();
$this->conn = $this->createConnection();
......@@ -133,9 +134,12 @@ class StatementTest extends DbalTestCase
->with($fetchMode, $arg1, $arg2)
->will($this->returnValue(true));
self::assertAttributeSame(FetchMode::MIXED, 'defaultFetchMode', $this->stmt);
$re = new ReflectionProperty($this->stmt, 'defaultFetchMode');
$re->setAccessible(true);
self::assertSame(FetchMode::MIXED, $re->getValue($this->stmt));
self::assertTrue($this->stmt->setFetchMode($fetchMode, $arg1, $arg2));
self::assertAttributeSame($fetchMode, 'defaultFetchMode', $this->stmt);
self::assertSame($fetchMode, $re->getValue($this->stmt));
}
public function testGetIterator()
......@@ -159,7 +163,7 @@ class StatementTest extends DbalTestCase
}
/**
* @return Connection|PHPUnit_Framework_MockObject_MockObject
* @return Connection|MockObject
*/
protected function createConnection()
{
......@@ -177,7 +181,7 @@ class StatementTest extends DbalTestCase
}
/**
* @return DriverStatement|PHPUnit_Framework_MockObject_MockObject
* @return DriverStatement|MockObject
*/
protected function createWrappedStatement()
{
......
......@@ -15,7 +15,7 @@ class ExpressionBuilderTest extends DbalTestCase
/** @var ExpressionBuilder */
protected $expr;
protected function setUp()
protected function setUp() : void
{
$conn = $this->createMock(Connection::class);
......
......@@ -17,7 +17,7 @@ class QueryBuilderTest extends DbalTestCase
/** @var Connection */
protected $conn;
protected function setUp()
protected function setUp() : void
{
$this->conn = $this->createMock(Connection::class);
......
......@@ -8,8 +8,8 @@ use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject;
use function in_array;
/**
......@@ -17,13 +17,13 @@ use function in_array;
*/
final class DB2SchemaManagerTest extends TestCase
{
/** @var Connection|PHPUnit_Framework_MockObject_MockObject */
/** @var Connection|MockObject */
private $conn;
/** @var DB2SchemaManager */
private $manager;
protected function setUp()
protected function setUp() : void
{
$eventManager = new EventManager();
$driverMock = $this->createMock(Driver::class);
......@@ -87,7 +87,7 @@ final class DB2SchemaManagerTest extends TestCase
);
$callable = $this->conn->getConfiguration()->getSchemaAssetsFilter();
$this->assertInternalType('callable', $callable);
self::assertIsCallable($callable);
// BC check: Test that regexp expression is still preserved & accessible.
$this->assertEquals($filterExpression, $this->conn->getConfiguration()->getFilterSchemaAssetsExpression());
......
......@@ -21,7 +21,7 @@ class MySqlSchemaManagerTest extends TestCase
/** @var Connection */
private $conn;
protected function setUp()
protected function setUp() : void
{
$eventManager = new EventManager();
$driverMock = $this->createMock(Driver::class);
......
......@@ -16,7 +16,7 @@ class MySQLSchemaTest extends TestCase
/** @var AbstractPlatform */
private $platform;
protected function setUp()
protected function setUp() : void
{
$this->comparator = new Comparator();
$this->platform = new MySqlPlatform();
......
......@@ -10,6 +10,7 @@ use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Visitor\AbstractVisitor;
use Doctrine\DBAL\Schema\Visitor\Visitor;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use function current;
use function strlen;
......@@ -211,7 +212,11 @@ class SchemaTest extends TestCase
$fk = $schemaNew->getTable('bar')->getForeignKeys();
$fk = current($fk);
self::assertSame($schemaNew->getTable('bar'), $this->readAttribute($fk, '_localTable'));
$re = new ReflectionProperty($fk, '_localTable');
$re->setAccessible(true);
self::assertSame($schemaNew->getTable('bar'), $re->getValue($fk));
}
/**
......@@ -279,13 +284,15 @@ class SchemaTest extends TestCase
/**
* @group DBAL-669
* @expectedException \Doctrine\DBAL\Schema\SchemaException
*/
public function testThrowsExceptionOnCreatingNamespaceTwice()
{
$schema = new Schema();
$schema->createNamespace('foo');
$this->expectException(SchemaException::class);
$schema->createNamespace('foo');
}
......
......@@ -19,7 +19,7 @@ class SingleDatabaseSynchronizerTest extends TestCase
/** @var SingleDatabaseSynchronizer */
private $synchronizer;
protected function setUp()
protected function setUp() : void
{
$this->conn = DriverManager::getConnection([
'driver' => 'pdo_sqlite',
......
......@@ -783,7 +783,6 @@ class TableTest extends DbalTestCase
/**
* @group DBAL-234
* @expectedException \Doctrine\DBAL\Schema\SchemaException
*/
public function testThrowsExceptionOnRenamingNonExistingIndex()
{
......@@ -791,12 +790,13 @@ class TableTest extends DbalTestCase
$table->addColumn('id', 'integer');
$table->addIndex(['id'], 'idx');
$this->expectException(SchemaException::class);
$table->renameIndex('foo', 'bar');
}
/**
* @group DBAL-234
* @expectedException \Doctrine\DBAL\Schema\SchemaException
*/
public function testThrowsExceptionOnRenamingToAlreadyExistingIndex()
{
......@@ -806,6 +806,8 @@ class TableTest extends DbalTestCase
$table->addIndex(['id'], 'idx_id');
$table->addIndex(['foo'], 'idx_foo');
$this->expectException(SchemaException::class);
$table->renameIndex('idx_id', 'idx_foo');
}
......
......@@ -7,12 +7,12 @@ use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject;
class CreateSchemaSqlCollectorTest extends TestCase
{
/** @var AbstractPlatform|PHPUnit_Framework_MockObject_MockObject */
/** @var AbstractPlatform|MockObject */
private $platformMock;
/** @var CreateSchemaSqlCollector */
......@@ -21,7 +21,7 @@ class CreateSchemaSqlCollectorTest extends TestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp() : void
{
parent::setUp();
......@@ -130,7 +130,7 @@ class CreateSchemaSqlCollectorTest extends TestCase
}
/**
* @return ForeignKeyConstraint|PHPUnit_Framework_MockObject_MockObject
* @return ForeignKeyConstraint|MockObject
*/
private function createForeignKeyConstraintMock()
{
......@@ -140,7 +140,7 @@ class CreateSchemaSqlCollectorTest extends TestCase
}
/**
* @return Sequence|PHPUnit_Framework_MockObject_MockObject
* @return Sequence|MockObject
*/
private function createSequenceMock()
{
......@@ -150,7 +150,7 @@ class CreateSchemaSqlCollectorTest extends TestCase
}
/**
* @return Table|PHPUnit_Framework_MockObject_MockObject
* @return Table|MockObject
*/
private function createTableMock()
{
......
......@@ -17,7 +17,7 @@ abstract class AbstractTestCase extends TestCase
/** @var SQLAzureShardManager */
protected $sm;
protected function setUp()
protected function setUp() : void
{
if (! isset($GLOBALS['db_type']) || strpos($GLOBALS['db_type'], 'sqlsrv') === false) {
$this->markTestSkipped('No driver or sqlserver driver specified.');
......
......@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Logging\SQLLogger;
......@@ -25,7 +26,7 @@ class StatementTest extends DbalTestCase
/** @var PDOStatement */
private $pdoStatement;
protected function setUp()
protected function setUp() : void
{
$this->pdoStatement = $this->getMockBuilder(PDOStatement::class)
->setMethods(['execute', 'bindParam', 'bindValue'])
......@@ -124,9 +125,6 @@ class StatementTest extends DbalTestCase
$statement->execute();
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public function testExecuteCallsLoggerStopQueryOnException()
{
$logger = $this->createMock(SQLLogger::class);
......@@ -151,6 +149,9 @@ class StatementTest extends DbalTestCase
->will($this->throwException(new Exception('Mock test exception')));
$statement = new Statement('', $this->conn);
$this->expectException(DBALException::class);
$statement->execute();
}
}
......@@ -21,7 +21,7 @@ class RunSqlCommandTest extends TestCase
/** @var Connection */
private $connectionMock;
protected function setUp()
protected function setUp() : void
{
$application = new Application();
$application->add(new RunSqlCommand());
......@@ -48,7 +48,7 @@ class RunSqlCommandTest extends TestCase
]);
$this->fail('Expected a runtime exception when omitting sql argument');
} catch (RuntimeException $e) {
self::assertContains("Argument 'SQL", $e->getMessage());
self::assertStringContainsString("Argument 'SQL", $e->getMessage());
}
}
......@@ -62,7 +62,7 @@ class RunSqlCommandTest extends TestCase
]);
$this->fail('Expected a logic exception when executing with a stringy depth');
} catch (LogicException $e) {
self::assertContains("Option 'depth'", $e->getMessage());
self::assertStringContainsString("Option 'depth'", $e->getMessage());
}
}
......
......@@ -17,7 +17,7 @@ class ArrayTest extends DbalTestCase
/** @var Type */
private $type;
protected function setUp()
protected function setUp() : void
{
$this->platform = new MockPlatform();
$this->type = Type::getType('array');
......@@ -25,18 +25,12 @@ class ArrayTest extends DbalTestCase
public function testArrayConvertsToDatabaseValue()
{
self::assertInternalType(
'string',
$this->type->convertToDatabaseValue([], $this->platform)
);
self::assertIsString($this->type->convertToDatabaseValue([], $this->platform));
}
public function testArrayConvertsToPHPValue()
{
self::assertInternalType(
'array',
$this->type->convertToPHPValue(serialize([]), $this->platform)
);
self::assertIsArray($this->type->convertToPHPValue(serialize([]), $this->platform));
}
public function testConversionFailure()
......
......@@ -26,7 +26,7 @@ abstract class BaseDateTypeTestCase extends TestCase
/**
* {@inheritDoc}
*/
protected function setUp()
protected function setUp() : void
{
$this->platform = new MockPlatform();
$this->currentTimezone = date_default_timezone_get();
......@@ -37,14 +37,14 @@ abstract class BaseDateTypeTestCase extends TestCase
/**
* {@inheritDoc}
*/
protected function tearDown()
protected function tearDown() : void
{
date_default_timezone_set($this->currentTimezone);
}
public function testDateConvertsToDatabaseValue()
{
self::assertInternalType('string', $this->type->convertToDatabaseValue(new DateTime(), $this->platform));
self::assertIsString($this->type->convertToDatabaseValue(new DateTime(), $this->platform));
}
/**
......@@ -94,10 +94,7 @@ abstract class BaseDateTypeTestCase extends TestCase
*/
public function testDateTimeImmutableConvertsToDatabaseValue()
{
self::assertInternalType(
'string',
$this->type->convertToDatabaseValue(new DateTimeImmutable(), $this->platform)
);
self::assertIsString($this->type->convertToDatabaseValue(new DateTimeImmutable(), $this->platform));
}
/**
......
......@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Types\BinaryType;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase;
......@@ -22,7 +23,7 @@ class BinaryTest extends DbalTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp() : void
{
$this->platform = new MockPlatform();
$this->type = Type::getType('binary');
......@@ -53,7 +54,7 @@ class BinaryTest extends DbalTestCase
$databaseValue = 'binary string';
$phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform);
self::assertInternalType('resource', $phpValue);
self::assertIsResource($phpValue);
self::assertEquals($databaseValue, stream_get_contents($phpValue));
}
......@@ -67,10 +68,11 @@ class BinaryTest extends DbalTestCase
/**
* @dataProvider getInvalidDatabaseValues
* @expectedException \Doctrine\DBAL\Types\ConversionException
*/
public function testThrowsConversionExceptionOnInvalidDatabaseValue($value)
{
$this->expectException(ConversionException::class);
$this->type->convertToPHPValue($value, $this->platform);
}
......
......@@ -22,7 +22,7 @@ class BlobTest extends DbalTestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp() : void
{
$this->platform = new MockPlatform();
$this->type = Type::getType('blob');
......@@ -38,7 +38,7 @@ class BlobTest extends DbalTestCase
$databaseValue = $this->getBinaryString();
$phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform);
self::assertInternalType('resource', $phpValue);
self::assertIsResource($phpValue);
self::assertSame($databaseValue, stream_get_contents($phpValue));
}
......
......@@ -14,7 +14,7 @@ class BooleanTest extends DbalTestCase
/** @var Type */
private $type;
protected function setUp()
protected function setUp() : void
{
$this->platform = new MockPlatform();
$this->type = Type::getType('boolean');
......@@ -22,12 +22,12 @@ class BooleanTest extends DbalTestCase
public function testBooleanConvertsToDatabaseValue()
{
self::assertInternalType('integer', $this->type->convertToDatabaseValue(1, $this->platform));
self::assertIsInt($this->type->convertToDatabaseValue(1, $this->platform));
}
public function testBooleanConvertsToPHPValue()
{
self::assertInternalType('bool', $this->type->convertToPHPValue(0, $this->platform));
self::assertIsBool($this->type->convertToPHPValue(0, $this->platform));
}
public function testBooleanNullConvertsToPHPValue()
......
......@@ -21,7 +21,7 @@ class DateImmutableTypeTest extends TestCase
/** @var DateImmutableType */
private $type;
protected function setUp()
protected function setUp() : void
{
$this->type = Type::getType('date_immutable');
$this->platform = $this->prophesize(AbstractPlatform::class);
......
......@@ -12,7 +12,7 @@ class DateTest extends BaseDateTypeTestCase
/**
* {@inheritDoc}
*/
protected function setUp()
protected function setUp() : void
{
$this->type = Type::getType('date');
......
......@@ -21,7 +21,7 @@ class DateTimeImmutableTypeTest extends TestCase
/** @var DateTimeImmutableType */
private $type;
protected function setUp()
protected function setUp() : void
{
$this->type = Type::getType('datetime_immutable');
$this->platform = $this->prophesize(AbstractPlatform::class);
......
......@@ -11,7 +11,7 @@ class DateTimeTest extends BaseDateTypeTestCase
/**
* {@inheritDoc}
*/
protected function setUp()
protected function setUp() : void
{
$this->type = Type::getType('datetime');
......
......@@ -21,7 +21,7 @@ class DateTimeTzImmutableTypeTest extends TestCase
/** @var DateTimeTzImmutableType */
private $type;
protected function setUp()
protected function setUp() : void
{
$this->type = Type::getType('datetimetz_immutable');
$this->platform = $this->prophesize(AbstractPlatform::class);
......
......@@ -11,7 +11,7 @@ class DateTimeTzTest extends BaseDateTypeTestCase
/**
* {@inheritDoc}
*/
protected function setUp()
protected function setUp() : void
{
$this->type = Type::getType('datetimetz');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment