diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index a2a72bdf207..d04fdac16f1 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -53,7 +53,7 @@ protected function setUp() : void $this->connection = DriverManager::getConnection($this->params); } - public function getExecuteUpdateMockConnection() + private function getExecuteUpdateMockConnection() : Connection { $driverMock = $this->createMock(Driver::class); @@ -63,10 +63,15 @@ public function getExecuteUpdateMockConnection() $this->createMock(DriverConnection::class) )); - return $this->getMockBuilder(Connection::class) + $platform = $this->getMockForAbstractClass(AbstractPlatform::class); + + /** @var Connection|MockObject $connection */ + $connection = $this->getMockBuilder(Connection::class) ->setMethods(['executeUpdate']) - ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) + ->setConstructorArgs([['platform' => $platform], $driverMock]) ->getMock(); + + return $connection; } public function testIsConnected() @@ -153,9 +158,8 @@ public function testConnectDispatchEvent() $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 @@ public function testConnectStartsTransactionInNoAutoCommitMode() ->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 @@ public function testCommitStartsTransactionInNoAutoCommitMode() ->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 @@ public function testRollBackStartsTransactionInNoAutoCommitMode() ->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 @@ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() ->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 @@ public function testFetchAssoc() /** @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 @@ public function testFetchArray() /** @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 @@ public function testFetchColumn() /** @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 @@ public function testFetchAll() /** @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 @@ public function dataCallConnectOnce() 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()) diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index 828e4fc1a3a..0fe228aa45a 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -9,9 +9,9 @@ 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 @@ public function testInvalidDriver() */ 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()); } /** diff --git a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php b/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php deleted file mode 100644 index 6a3f3d8e376..00000000000 --- a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php +++ /dev/null @@ -1,100 +0,0 @@ -createMock(MockPlatform::class); + /** @var AbstractPlatform|MockObject $platform */ + $platform = $this->createMock(AbstractPlatform::class); $platform->expects($this->exactly(1)) ->method('getCreateSchemaSQL') ->with('foo_ns') @@ -93,6 +95,7 @@ public function createPlatform($unsafe = false) $platform->expects($this->exactly(2)) ->method('supportsForeignKeyConstraints') ->will($this->returnValue(true)); + return $platform; } diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php index 80b9ef7b2c2..ae1682739c6 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php @@ -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 @@ public function testReturnsName() { $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 @@ public function testReturnsName() */ public function testPrefersNameFromTableObject() { - $platformMock = new MockPlatform(); - $tableMock = $this->getMockBuilder(Table::class) + $tableMock = $this->getMockBuilder(Table::class) ->disableOriginalConstructor() ->getMock(); @@ -35,10 +43,10 @@ public function testPrefersNameFromTableObject() $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)); } /** diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index f7ff02d2ac6..1dae44d253d 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -10,7 +10,6 @@ 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 @@ protected function setUp() : void $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') diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index 66181f7e0c8..6f09cbf2bc0 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -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'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php index 2b447d95cfd..3e73c96e7c9 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php @@ -4,9 +4,10 @@ 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 @@ 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); diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index e5bd3c201dc..b26a35cab42 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -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 @@ public function testReturnsName() 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() diff --git a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php index 57f26004140..70bbcf55967 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php @@ -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 @@ 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'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php index ad9dcc673bf..af84fbf00d2 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php @@ -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'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index 27d83ae7df7..710474257af 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -4,16 +4,17 @@ 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); diff --git a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php index e702f7718ff..7087d2a6a49 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php @@ -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'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php index b3da2257c72..6daffd7d29b 100644 --- a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php @@ -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'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php index b35670405d4..bbd309bea6d 100644 --- a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php @@ -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 @@ public function testNativeGuidSupport() { 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)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php index 11e0f91c5fe..789de21e208 100644 --- a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php @@ -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'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index 8bc0ed1d8f8..730234dc85f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -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 @@ public function testReturnsName() 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() diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index e36c84a33d4..123291f53b6 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -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 @@ public function testReturnsName() 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() diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index 0176f35a295..f8852ff1640 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -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'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php index d7c98caad4a..8aecc6649fa 100644 --- a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php @@ -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'); } diff --git a/tests/Doctrine/Tests/DBAL/Types/StringTest.php b/tests/Doctrine/Tests/DBAL/Types/StringTest.php index 651058811f2..4ffb9af7d96 100644 --- a/tests/Doctrine/Tests/DBAL/Types/StringTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -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)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index 516f42836b4..0807b25f022 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -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); }