Unverified Commit d3d09e29 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3470 from morozov/remove-mock-platform

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