Replaced MockPlatform with the ones generated by PHPUnit

parent f5ddd097
...@@ -53,7 +53,10 @@ class ConnectionTest extends DbalTestCase ...@@ -53,7 +53,10 @@ class ConnectionTest extends DbalTestCase
$this->connection = DriverManager::getConnection($this->params); $this->connection = DriverManager::getConnection($this->params);
} }
public function getExecuteUpdateMockConnection() /**
* @return Connection|MockObject
*/
private function getExecuteUpdateMockConnection()
{ {
$driverMock = $this->createMock(Driver::class); $driverMock = $this->createMock(Driver::class);
...@@ -63,9 +66,11 @@ class ConnectionTest extends DbalTestCase ...@@ -63,9 +66,11 @@ class ConnectionTest extends DbalTestCase
$this->createMock(DriverConnection::class) $this->createMock(DriverConnection::class)
)); ));
$platform = $this->getMockForAbstractClass(AbstractPlatform::class);
return $this->getMockBuilder(Connection::class) return $this->getMockBuilder(Connection::class)
->setMethods(['executeUpdate']) ->setMethods(['executeUpdate'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->setConstructorArgs([['platform' => $platform], $driverMock])
->getMock(); ->getMock();
} }
...@@ -153,9 +158,8 @@ class ConnectionTest extends DbalTestCase ...@@ -153,9 +158,8 @@ class ConnectionTest extends DbalTestCase
$driverMock = $this->createMock(Driver::class); $driverMock = $this->createMock(Driver::class);
$driverMock->expects($this->at(0)) $driverMock->expects($this->at(0))
->method('connect'); ->method('connect');
$platform = new Mocks\MockPlatform();
$conn = new Connection(['platform' => $platform], $driverMock, new Configuration(), $eventManager); $conn = new Connection([], $driverMock, new Configuration(), $eventManager);
$conn->connect(); $conn->connect();
} }
...@@ -249,7 +253,7 @@ class ConnectionTest extends DbalTestCase ...@@ -249,7 +253,7 @@ class ConnectionTest extends DbalTestCase
->will($this->returnValue( ->will($this->returnValue(
$this->createMock(DriverConnection::class) $this->createMock(DriverConnection::class)
)); ));
$conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn = new Connection([], $driverMock);
$conn->setAutoCommit(false); $conn->setAutoCommit(false);
...@@ -271,7 +275,7 @@ class ConnectionTest extends DbalTestCase ...@@ -271,7 +275,7 @@ class ConnectionTest extends DbalTestCase
->will($this->returnValue( ->will($this->returnValue(
$this->createMock(DriverConnection::class) $this->createMock(DriverConnection::class)
)); ));
$conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn = new Connection([], $driverMock);
$conn->setAutoCommit(false); $conn->setAutoCommit(false);
$conn->connect(); $conn->connect();
...@@ -291,7 +295,7 @@ class ConnectionTest extends DbalTestCase ...@@ -291,7 +295,7 @@ class ConnectionTest extends DbalTestCase
->will($this->returnValue( ->will($this->returnValue(
$this->createMock(DriverConnection::class) $this->createMock(DriverConnection::class)
)); ));
$conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn = new Connection([], $driverMock);
$conn->setAutoCommit(false); $conn->setAutoCommit(false);
$conn->connect(); $conn->connect();
...@@ -311,7 +315,7 @@ class ConnectionTest extends DbalTestCase ...@@ -311,7 +315,7 @@ class ConnectionTest extends DbalTestCase
->will($this->returnValue( ->will($this->returnValue(
$this->createMock(DriverConnection::class) $this->createMock(DriverConnection::class)
)); ));
$conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn = new Connection([], $driverMock);
$conn->connect(); $conn->connect();
$conn->beginTransaction(); $conn->beginTransaction();
...@@ -520,7 +524,7 @@ class ConnectionTest extends DbalTestCase ...@@ -520,7 +524,7 @@ class ConnectionTest extends DbalTestCase
/** @var Connection|MockObject $conn */ /** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class) $conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery']) ->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->setConstructorArgs([[], $driverMock])
->getMock(); ->getMock();
$conn->expects($this->once()) $conn->expects($this->once())
...@@ -556,7 +560,7 @@ class ConnectionTest extends DbalTestCase ...@@ -556,7 +560,7 @@ class ConnectionTest extends DbalTestCase
/** @var Connection|MockObject $conn */ /** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class) $conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery']) ->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->setConstructorArgs([[], $driverMock])
->getMock(); ->getMock();
$conn->expects($this->once()) $conn->expects($this->once())
...@@ -593,7 +597,7 @@ class ConnectionTest extends DbalTestCase ...@@ -593,7 +597,7 @@ class ConnectionTest extends DbalTestCase
/** @var Connection|MockObject $conn */ /** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class) $conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery']) ->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->setConstructorArgs([[], $driverMock])
->getMock(); ->getMock();
$conn->expects($this->once()) $conn->expects($this->once())
...@@ -628,7 +632,7 @@ class ConnectionTest extends DbalTestCase ...@@ -628,7 +632,7 @@ class ConnectionTest extends DbalTestCase
/** @var Connection|MockObject $conn */ /** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class) $conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery']) ->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->setConstructorArgs([[], $driverMock])
->getMock(); ->getMock();
$conn->expects($this->once()) $conn->expects($this->once())
...@@ -694,8 +698,8 @@ class ConnectionTest extends DbalTestCase ...@@ -694,8 +698,8 @@ class ConnectionTest extends DbalTestCase
public function testCallConnectOnce($method, $params) public function testCallConnectOnce($method, $params)
{ {
$driverMock = $this->createMock(Driver::class); $driverMock = $this->createMock(Driver::class);
$pdoMock = $this->createMock(\Doctrine\DBAL\Driver\Connection::class); $pdoMock = $this->createMock(Connection::class);
$platformMock = new Mocks\MockPlatform(); $platformMock = $this->createMock(AbstractPlatform::class);
$stmtMock = $this->createMock(Statement::class); $stmtMock = $this->createMock(Statement::class);
$pdoMock->expects($this->any()) $pdoMock->expects($this->any())
......
...@@ -9,9 +9,9 @@ use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySQLDriver; ...@@ -9,9 +9,9 @@ use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySQLDriver;
use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSqliteDriver; use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSqliteDriver;
use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Sharding\PoolingShardConnection; use Doctrine\DBAL\Sharding\PoolingShardConnection;
use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\DriverMock;
...@@ -77,14 +77,14 @@ class DriverManagerTest extends DbalTestCase ...@@ -77,14 +77,14 @@ class DriverManagerTest extends DbalTestCase
*/ */
public function testCustomPlatform() public function testCustomPlatform()
{ {
$mockPlatform = new MockPlatform(); $platform = $this->createMock(AbstractPlatform::class);
$options = [ $options = [
'pdo' => new PDO('sqlite::memory:'), 'pdo' => new PDO('sqlite::memory:'),
'platform' => $mockPlatform, 'platform' => $platform,
]; ];
$conn = DriverManager::getConnection($options); $conn = DriverManager::getConnection($options);
self::assertSame($mockPlatform, $conn->getDatabasePlatform()); self::assertSame($platform, $conn->getDatabasePlatform());
} }
/** /**
......
<?php
namespace Doctrine\Tests\DBAL\Mocks;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class MockPlatform extends AbstractPlatform
{
/**
* {@inheritDoc}
*/
public function getBlobTypeDeclarationSQL(array $field)
{
throw DBALException::notSupported(__METHOD__);
}
/**
* {@inheritDoc}
*/
public function getBooleanTypeDeclarationSQL(array $columnDef)
{
}
/**
* {@inheritDoc}
*/
public function getIntegerTypeDeclarationSQL(array $columnDef)
{
}
/**
* {@inheritDoc}
*/
public function getBigIntTypeDeclarationSQL(array $columnDef)
{
}
/**
* {@inheritDoc}
*/
public function getSmallIntTypeDeclarationSQL(array $columnDef)
{
}
/**
* {@inheritDoc}
*/
public function _getCommonIntegerTypeDeclarationSQL(array $columnDef)
{
}
/**
* {@inheritDoc}
*/
public function getVarcharTypeDeclarationSQL(array $field)
{
return 'DUMMYVARCHAR()';
}
/**
* {@inheritDoc}
*/
public function getClobTypeDeclarationSQL(array $field)
{
return 'DUMMYCLOB';
}
/**
* {@inheritdoc}
*/
public function getJsonTypeDeclarationSQL(array $field)
{
return 'DUMMYJSON';
}
/**
* {@inheritdoc}
*/
public function getBinaryTypeDeclarationSQL(array $field)
{
return 'DUMMYBINARY';
}
public function getVarcharDefaultLength()
{
return 255;
}
public function getName()
{
return 'mock';
}
protected function initializeDoctrineTypeMappings()
{
}
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
}
}
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
namespace Doctrine\Tests\DBAL\Schema; namespace Doctrine\Tests\DBAL\Schema;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\SchemaDiff; use Doctrine\DBAL\Schema\SchemaDiff;
use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\Tests\DBAL\Mocks\MockPlatform; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class SchemaDiffTest extends TestCase class SchemaDiffTest extends TestCase
...@@ -36,9 +37,13 @@ class SchemaDiffTest extends TestCase ...@@ -36,9 +37,13 @@ class SchemaDiffTest extends TestCase
self::assertEquals($expected, $sql); self::assertEquals($expected, $sql);
} }
public function createPlatform($unsafe = false) /**
* @return AbstractPlatform|MockObject
*/
private function createPlatform(bool $unsafe)
{ {
$platform = $this->createMock(MockPlatform::class); /** @var AbstractPlatform|MockObject $platform */
$platform = $this->createMock(AbstractPlatform::class);
$platform->expects($this->exactly(1)) $platform->expects($this->exactly(1))
->method('getCreateSchemaSQL') ->method('getCreateSchemaSQL')
->with('foo_ns') ->with('foo_ns')
...@@ -93,6 +98,7 @@ class SchemaDiffTest extends TestCase ...@@ -93,6 +98,7 @@ class SchemaDiffTest extends TestCase
$platform->expects($this->exactly(2)) $platform->expects($this->exactly(2))
->method('supportsForeignKeyConstraints') ->method('supportsForeignKeyConstraints')
->will($this->returnValue(true)); ->will($this->returnValue(true));
return $platform; return $platform;
} }
......
...@@ -2,14 +2,23 @@ ...@@ -2,14 +2,23 @@
namespace Doctrine\Tests\DBAL\Schema; namespace Doctrine\Tests\DBAL\Schema;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Identifier;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\Tests\DBAL\Mocks\MockPlatform; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class TableDiffTest extends TestCase class TableDiffTest extends TestCase
{ {
/** @var AbstractPlatform|MockObject */
private $platform;
public function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
}
/** /**
* @group DBAL-1013 * @group DBAL-1013
*/ */
...@@ -17,7 +26,7 @@ class TableDiffTest extends TestCase ...@@ -17,7 +26,7 @@ class TableDiffTest extends TestCase
{ {
$tableDiff = new TableDiff('foo'); $tableDiff = new TableDiff('foo');
self::assertEquals(new Identifier('foo'), $tableDiff->getName(new MockPlatform())); self::assertEquals(new Identifier('foo'), $tableDiff->getName($this->platform));
} }
/** /**
...@@ -25,7 +34,6 @@ class TableDiffTest extends TestCase ...@@ -25,7 +34,6 @@ class TableDiffTest extends TestCase
*/ */
public function testPrefersNameFromTableObject() public function testPrefersNameFromTableObject()
{ {
$platformMock = new MockPlatform();
$tableMock = $this->getMockBuilder(Table::class) $tableMock = $this->getMockBuilder(Table::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
...@@ -35,10 +43,10 @@ class TableDiffTest extends TestCase ...@@ -35,10 +43,10 @@ class TableDiffTest extends TestCase
$tableMock->expects($this->once()) $tableMock->expects($this->once())
->method('getQuotedName') ->method('getQuotedName')
->with($platformMock) ->with($this->platform)
->will($this->returnValue('foo')); ->will($this->returnValue('foo'));
self::assertEquals(new Identifier('foo'), $tableDiff->getName($platformMock)); self::assertEquals(new Identifier('foo'), $tableDiff->getName($this->platform));
} }
/** /**
......
...@@ -10,7 +10,6 @@ use Doctrine\DBAL\Driver\Connection as DriverConnection; ...@@ -10,7 +10,6 @@ use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Statement; use Doctrine\DBAL\Statement;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use Exception; use Exception;
use PDOStatement; use PDOStatement;
...@@ -31,19 +30,16 @@ class StatementTest extends DbalTestCase ...@@ -31,19 +30,16 @@ class StatementTest extends DbalTestCase
$this->pdoStatement = $this->getMockBuilder(PDOStatement::class) $this->pdoStatement = $this->getMockBuilder(PDOStatement::class)
->setMethods(['execute', 'bindParam', 'bindValue']) ->setMethods(['execute', 'bindParam', 'bindValue'])
->getMock(); ->getMock();
$platform = new MockPlatform();
$driverConnection = $this->createMock(DriverConnection::class); $driverConnection = $this->createMock(DriverConnection::class);
$driverConnection->expects($this->any()) $driverConnection->expects($this->any())
->method('prepare') ->method('prepare')
->will($this->returnValue($this->pdoStatement)); ->will($this->returnValue($this->pdoStatement));
$driver = $this->createMock(Driver::class); $driver = $this->createMock(Driver::class);
$constructorArgs = [
['platform' => $platform],
$driver,
];
$this->conn = $this->getMockBuilder(Connection::class) $this->conn = $this->getMockBuilder(Connection::class)
->setConstructorArgs($constructorArgs) ->setConstructorArgs([[], $driver])
->getMock(); ->getMock();
$this->conn->expects($this->atLeastOnce()) $this->conn->expects($this->atLeastOnce())
->method('getWrappedConnection') ->method('getWrappedConnection')
......
...@@ -3,23 +3,24 @@ ...@@ -3,23 +3,24 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ArrayType;
use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use function serialize; use function serialize;
class ArrayTest extends DbalTestCase class ArrayTest extends DbalTestCase
{ {
/** @var AbstractPlatform */ /** @var AbstractPlatform|MockObject */
private $platform; private $platform;
/** @var Type */ /** @var ArrayType */
private $type; private $type;
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('array'); $this->type = Type::getType('array');
} }
......
...@@ -4,9 +4,10 @@ namespace Doctrine\Tests\DBAL\Types; ...@@ -4,9 +4,10 @@ namespace Doctrine\Tests\DBAL\Types;
use DateTime; use DateTime;
use DateTimeImmutable; use DateTimeImmutable;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use stdClass; use stdClass;
use function date_default_timezone_get; use function date_default_timezone_get;
...@@ -14,7 +15,7 @@ use function date_default_timezone_set; ...@@ -14,7 +15,7 @@ use function date_default_timezone_set;
abstract class BaseDateTypeTestCase extends TestCase abstract class BaseDateTypeTestCase extends TestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
protected $platform; protected $platform;
/** @var Type */ /** @var Type */
...@@ -28,7 +29,7 @@ abstract class BaseDateTypeTestCase extends TestCase ...@@ -28,7 +29,7 @@ abstract class BaseDateTypeTestCase extends TestCase
*/ */
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class);
$this->currentTimezone = date_default_timezone_get(); $this->currentTimezone = date_default_timezone_get();
self::assertInstanceOf(Type::class, $this->type); self::assertInstanceOf(Type::class, $this->type);
......
...@@ -3,18 +3,19 @@ ...@@ -3,18 +3,19 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\BinaryType;
use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use function base64_encode; use function base64_encode;
use function fopen; use function fopen;
use function stream_get_contents; use function stream_get_contents;
class BinaryTest extends DbalTestCase class BinaryTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
protected $platform; protected $platform;
/** @var BinaryType */ /** @var BinaryType */
...@@ -25,7 +26,7 @@ class BinaryTest extends DbalTestCase ...@@ -25,7 +26,7 @@ class BinaryTest extends DbalTestCase
*/ */
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('binary'); $this->type = Type::getType('binary');
} }
...@@ -41,7 +42,11 @@ class BinaryTest extends DbalTestCase ...@@ -41,7 +42,11 @@ class BinaryTest extends DbalTestCase
public function testReturnsSQLDeclaration() public function testReturnsSQLDeclaration()
{ {
self::assertSame('DUMMYBINARY', $this->type->getSQLDeclaration([], $this->platform)); $this->platform->expects($this->once())
->method('getBinaryTypeDeclarationSQL')
->willReturn('TEST_BINARY');
self::assertSame('TEST_BINARY', $this->type->getSQLDeclaration([], $this->platform));
} }
public function testBinaryNullConvertsToPHPValue() public function testBinaryNullConvertsToPHPValue()
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use function base64_encode; use function base64_encode;
use function chr; use function chr;
use function fopen; use function fopen;
...@@ -13,7 +14,7 @@ use function stream_get_contents; ...@@ -13,7 +14,7 @@ use function stream_get_contents;
class BlobTest extends DbalTestCase class BlobTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
protected $platform; protected $platform;
/** @var BlobType */ /** @var BlobType */
...@@ -24,7 +25,7 @@ class BlobTest extends DbalTestCase ...@@ -24,7 +25,7 @@ class BlobTest extends DbalTestCase
*/ */
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('blob'); $this->type = Type::getType('blob');
} }
......
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\BooleanType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
class BooleanTest extends DbalTestCase class BooleanTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
private $platform; private $platform;
/** @var Type */ /** @var BooleanType */
private $type; private $type;
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class);
$this->type = Type::getType('boolean'); $this->type = Type::getType('boolean');
} }
......
...@@ -4,16 +4,17 @@ namespace Doctrine\Tests\DBAL\Types; ...@@ -4,16 +4,17 @@ namespace Doctrine\Tests\DBAL\Types;
use DateInterval; use DateInterval;
use DateTime; use DateTime;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\DateIntervalType; use Doctrine\DBAL\Types\DateIntervalType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use stdClass; use stdClass;
final class DateIntervalTest extends DbalTestCase final class DateIntervalTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
private $platform; private $platform;
/** @var DateIntervalType */ /** @var DateIntervalType */
...@@ -24,7 +25,7 @@ final class DateIntervalTest extends DbalTestCase ...@@ -24,7 +25,7 @@ final class DateIntervalTest extends DbalTestCase
*/ */
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('dateinterval'); $this->type = Type::getType('dateinterval');
self::assertInstanceOf(DateIntervalType::class, $this->type); self::assertInstanceOf(DateIntervalType::class, $this->type);
......
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\DecimalType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
class DecimalTest extends DbalTestCase class DecimalTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
private $platform; private $platform;
/** @var Type */ /** @var DecimalType */
private $type; private $type;
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('decimal'); $this->type = Type::getType('decimal');
} }
......
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\FloatType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
class FloatTest extends DbalTestCase class FloatTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
private $platform; private $platform;
/** @var Type */ /** @var FloatType */
private $type; private $type;
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('float'); $this->type = Type::getType('float');
} }
......
...@@ -2,22 +2,23 @@ ...@@ -2,22 +2,23 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\GuidType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use function get_class; use PHPUnit\Framework\MockObject\MockObject;
class GuidTypeTest extends DbalTestCase class GuidTypeTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
private $platform; private $platform;
/** @var Type */ /** @var GuidType */
private $type; private $type;
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('guid'); $this->type = Type::getType('guid');
} }
...@@ -36,11 +37,10 @@ class GuidTypeTest extends DbalTestCase ...@@ -36,11 +37,10 @@ class GuidTypeTest extends DbalTestCase
{ {
self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); self::assertTrue($this->type->requiresSQLCommentHint($this->platform));
$mock = $this->createMock(get_class($this->platform)); $this->platform->expects($this->any())
$mock->expects($this->any())
->method('hasNativeGuidType') ->method('hasNativeGuidType')
->will($this->returnValue(true)); ->will($this->returnValue(true));
self::assertFalse($this->type->requiresSQLCommentHint($mock)); self::assertFalse($this->type->requiresSQLCommentHint($this->platform));
} }
} }
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
class IntegerTest extends DbalTestCase class IntegerTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
private $platform; private $platform;
/** @var Type */ /** @var IntegerType */
private $type; private $type;
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('integer'); $this->type = Type::getType('integer');
} }
......
...@@ -3,17 +3,18 @@ ...@@ -3,17 +3,18 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\JsonArrayType; use Doctrine\DBAL\Types\JsonArrayType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use function base64_encode; use function base64_encode;
use function fopen; use function fopen;
use function json_encode; use function json_encode;
class JsonArrayTest extends DbalTestCase class JsonArrayTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
protected $platform; protected $platform;
/** @var JsonArrayType */ /** @var JsonArrayType */
...@@ -24,7 +25,7 @@ class JsonArrayTest extends DbalTestCase ...@@ -24,7 +25,7 @@ class JsonArrayTest extends DbalTestCase
*/ */
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('json_array'); $this->type = Type::getType('json_array');
} }
...@@ -40,7 +41,11 @@ class JsonArrayTest extends DbalTestCase ...@@ -40,7 +41,11 @@ class JsonArrayTest extends DbalTestCase
public function testReturnsSQLDeclaration() public function testReturnsSQLDeclaration()
{ {
self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration([], $this->platform)); $this->platform->expects($this->once())
->method('getJsonTypeDeclarationSQL')
->willReturn('TEST_JSON');
self::assertSame('TEST_JSON', $this->type->getSQLDeclaration([], $this->platform));
} }
public function testJsonNullConvertsToPHPValue() public function testJsonNullConvertsToPHPValue()
......
...@@ -3,18 +3,19 @@ ...@@ -3,18 +3,19 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\JsonType; use Doctrine\DBAL\Types\JsonType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use function base64_encode; use function base64_encode;
use function fopen; use function fopen;
use function json_encode; use function json_encode;
class JsonTest extends DbalTestCase class JsonTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
protected $platform; protected $platform;
/** @var JsonType */ /** @var JsonType */
...@@ -25,7 +26,7 @@ class JsonTest extends DbalTestCase ...@@ -25,7 +26,7 @@ class JsonTest extends DbalTestCase
*/ */
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('json'); $this->type = Type::getType('json');
} }
...@@ -41,7 +42,11 @@ class JsonTest extends DbalTestCase ...@@ -41,7 +42,11 @@ class JsonTest extends DbalTestCase
public function testReturnsSQLDeclaration() public function testReturnsSQLDeclaration()
{ {
self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration([], $this->platform)); $this->platform->expects($this->once())
->method('getJsonTypeDeclarationSQL')
->willReturn('TEST_JSON');
self::assertSame('TEST_JSON', $this->type->getSQLDeclaration([], $this->platform));
} }
public function testJsonNullConvertsToPHPValue() public function testJsonNullConvertsToPHPValue()
......
...@@ -2,24 +2,26 @@ ...@@ -2,24 +2,26 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\ObjectType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use stdClass; use stdClass;
use function serialize; use function serialize;
class ObjectTest extends DbalTestCase class ObjectTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
private $platform; private $platform;
/** @var Type */ /** @var ObjectType */
private $type; private $type;
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('object'); $this->type = Type::getType('object');
} }
......
...@@ -2,21 +2,23 @@ ...@@ -2,21 +2,23 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\SmallIntType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
class SmallIntTest extends DbalTestCase class SmallIntTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
private $platform; private $platform;
/** @var Type */ /** @var SmallIntType */
private $type; private $type;
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('smallint'); $this->type = Type::getType('smallint');
} }
......
...@@ -2,31 +2,41 @@ ...@@ -2,31 +2,41 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
class StringTest extends DbalTestCase class StringTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
private $platform; private $platform;
/** @var Type */ /** @var StringType */
private $type; private $type;
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('string'); $this->type = Type::getType('string');
} }
public function testReturnsSqlDeclarationFromPlatformVarchar() public function testReturnsSqlDeclarationFromPlatformVarchar()
{ {
self::assertEquals('DUMMYVARCHAR()', $this->type->getSqlDeclaration([], $this->platform)); $this->platform->expects($this->once())
->method('getVarcharTypeDeclarationSQL')
->willReturn('TEST_VARCHAR');
self::assertEquals('TEST_VARCHAR', $this->type->getSqlDeclaration([], $this->platform));
} }
public function testReturnsDefaultLengthFromPlatformVarchar() public function testReturnsDefaultLengthFromPlatformVarchar()
{ {
$this->platform->expects($this->once())
->method('getVarcharDefaultLength')
->willReturn(255);
self::assertEquals(255, $this->type->getDefaultLength($this->platform)); self::assertEquals(255, $this->type->getDefaultLength($this->platform));
} }
......
...@@ -3,23 +3,24 @@ ...@@ -3,23 +3,24 @@
namespace Doctrine\Tests\DBAL\Types; namespace Doctrine\Tests\DBAL\Types;
use DateTime; use DateTime;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\VarDateTimeType; use Doctrine\DBAL\Types\VarDateTimeType;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
class VarDateTimeTest extends DbalTestCase class VarDateTimeTest extends DbalTestCase
{ {
/** @var MockPlatform */ /** @var AbstractPlatform|MockObject */
private $platform; private $platform;
/** @var Type */ /** @var VarDateTimeType */
private $type; private $type;
protected function setUp() : void protected function setUp() : void
{ {
$this->platform = new MockPlatform(); $this->platform = $this->createMock(AbstractPlatform::class);
if (! Type::hasType('vardatetime')) { if (! Type::hasType('vardatetime')) {
Type::addType('vardatetime', VarDateTimeType::class); Type::addType('vardatetime', VarDateTimeType::class);
} }
......
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