Reworked Type tests

parent 8f25277f
......@@ -33,9 +33,6 @@ parameters:
# weird class name, represented in stubs as OCI_(Lob|Collection)
- '~unknown class OCI-(Lob|Collection)~'
# impossible inference for covariance
- '~^Property Doctrine\\Tests\\DBAL\\Types\\\S+Test::\$type \(Doctrine\\DBAL\\Types\\\S+Type\) does not accept Doctrine\\DBAL\\Types\\Type\.\z~'
# https://github.com/doctrine/dbal/pull/3582/files#r290847062
-
message: '~Parameter #3 \$type of method Doctrine\\DBAL\\Driver\\Statement::bindValue\(\) expects int, string given\.~'
......
......@@ -7,7 +7,6 @@ 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\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use function serialize;
......@@ -23,7 +22,7 @@ class ArrayTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('array');
$this->type = new ArrayType();
}
public function testArrayConvertsToDatabaseValue() : void
......
......@@ -8,7 +8,6 @@ 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\DBAL\Types\Types;
use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
......@@ -32,7 +31,7 @@ class BinaryTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('binary');
$this->type = new BinaryType();
}
public function testReturnsBindingType() : void
......
......@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
......@@ -24,7 +23,7 @@ class BlobTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('blob');
$this->type = new BlobType();
}
public function testBlobNullConvertsToPHPValue() : void
......
......@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\BooleanType;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
......@@ -20,18 +19,28 @@ class BooleanTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->getMockForAbstractClass(AbstractPlatform::class);
$this->type = Type::getType('boolean');
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = new BooleanType();
}
public function testBooleanConvertsToDatabaseValue() : void
{
self::assertIsInt($this->type->convertToDatabaseValue(1, $this->platform));
$this->platform->expects($this->once())
->method('convertBooleansToDatabaseValue')
->with(true)
->willReturn(1);
self::assertSame(1, $this->type->convertToDatabaseValue(true, $this->platform));
}
public function testBooleanConvertsToPHPValue() : void
{
self::assertIsBool($this->type->convertToPHPValue(0, $this->platform));
$this->platform->expects($this->once())
->method('convertFromBoolean')
->with(0)
->willReturn(false);
self::assertFalse($this->type->convertToPHPValue(0, $this->platform));
}
public function testBooleanNullConvertsToPHPValue() : void
......
......@@ -10,7 +10,6 @@ use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\DateImmutableType;
use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function get_class;
......@@ -25,8 +24,8 @@ class DateImmutableTypeTest extends TestCase
protected function setUp() : void
{
$this->type = Type::getType('date_immutable');
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = new DateImmutableType();
}
public function testFactoryCreatesCorrectType() : void
......
......@@ -9,7 +9,6 @@ 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\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use stdClass;
......@@ -28,9 +27,7 @@ final class DateIntervalTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('dateinterval');
self::assertInstanceOf(DateIntervalType::class, $this->type);
$this->type = new DateIntervalType();
}
public function testDateIntervalConvertsToDatabaseValue() : void
......
......@@ -6,7 +6,7 @@ namespace Doctrine\Tests\DBAL\Types;
use DateTime;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\DateType;
use function date_default_timezone_set;
class DateTest extends BaseDateTypeTestCase
......@@ -16,7 +16,7 @@ class DateTest extends BaseDateTypeTestCase
*/
protected function setUp() : void
{
$this->type = Type::getType('date');
$this->type = new DateType();
parent::setUp();
}
......
......@@ -10,7 +10,6 @@ use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\DateTimeImmutableType;
use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function get_class;
......@@ -25,8 +24,8 @@ class DateTimeImmutableTypeTest extends TestCase
protected function setUp() : void
{
$this->type = Type::getType('datetime_immutable');
$this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock();
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = new DateTimeImmutableType();
}
public function testFactoryCreatesCorrectType() : void
......@@ -46,7 +45,7 @@ class DateTimeImmutableTypeTest extends TestCase
public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void
{
$date = $this->getMockBuilder(DateTimeImmutable::class)->getMock();
$date = $this->createMock(DateTimeImmutable::class);
$this->platform->expects($this->once())
->method('getDateTimeFormatString')
......
......@@ -6,7 +6,7 @@ namespace Doctrine\Tests\DBAL\Types;
use DateTime;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\DateTimeType;
class DateTimeTest extends BaseDateTypeTestCase
{
......@@ -15,7 +15,7 @@ class DateTimeTest extends BaseDateTypeTestCase
*/
protected function setUp() : void
{
$this->type = Type::getType('datetime');
$this->type = new DateTimeType();
parent::setUp();
}
......
......@@ -10,7 +10,6 @@ use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\DateTimeTzImmutableType;
use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function get_class;
......@@ -25,8 +24,8 @@ class DateTimeTzImmutableTypeTest extends TestCase
protected function setUp() : void
{
$this->type = Type::getType('datetimetz_immutable');
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = new DateTimeTzImmutableType();
}
public function testFactoryCreatesCorrectType() : void
......
......@@ -6,7 +6,7 @@ namespace Doctrine\Tests\DBAL\Types;
use DateTime;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\DateTimeTzType;
class DateTimeTzTest extends BaseDateTypeTestCase
{
......@@ -15,7 +15,7 @@ class DateTimeTzTest extends BaseDateTypeTestCase
*/
protected function setUp() : void
{
$this->type = Type::getType('datetimetz');
$this->type = new DateTimeTzType();
parent::setUp();
}
......
......@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\DecimalType;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
......@@ -21,7 +20,7 @@ class DecimalTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('decimal');
$this->type = new DecimalType();
}
public function testDecimalConvertsToPHPValue() : void
......
......@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\FloatType;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
......@@ -21,7 +20,7 @@ class FloatTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('float');
$this->type = new FloatType();
}
public function testFloatConvertsToPHPValue() : void
......
......@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\GuidType;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
......@@ -21,7 +20,7 @@ class GuidTypeTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('guid');
$this->type = new GuidType();
}
public function testConvertToPHPValue() : void
......
......@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
......@@ -21,7 +20,7 @@ class IntegerTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('integer');
$this->type = new IntegerType();
}
public function testIntegerConvertsToPHPValue() : void
......
......@@ -8,7 +8,6 @@ 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\DBAL\Types\Types;
use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
......@@ -29,7 +28,7 @@ class JsonTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('json');
$this->type = new JsonType();
}
public function testReturnsBindingType() : void
......
......@@ -7,7 +7,6 @@ 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\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use stdClass;
......@@ -24,7 +23,7 @@ class ObjectTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('object');
$this->type = new ObjectType();
}
public function testObjectConvertsToDatabaseValue() : void
......
......@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\SmallIntType;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
......@@ -21,7 +20,7 @@ class SmallIntTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('smallint');
$this->type = new SmallIntType();
}
public function testSmallIntConvertsToPHPValue() : void
......
......@@ -6,7 +6,6 @@ namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
......@@ -21,7 +20,7 @@ class StringTest extends DbalTestCase
protected function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('string');
$this->type = new StringType();
}
public function testReturnsSQLDeclaration() : void
......
......@@ -10,7 +10,6 @@ use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\TimeImmutableType;
use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function get_class;
......@@ -25,8 +24,8 @@ class TimeImmutableTypeTest extends TestCase
protected function setUp() : void
{
$this->type = Type::getType('time_immutable');
$this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock();
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = new TimeImmutableType();
}
public function testFactoryCreatesCorrectType() : void
......@@ -46,7 +45,7 @@ class TimeImmutableTypeTest extends TestCase
public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void
{
$date = $this->getMockBuilder(DateTimeImmutable::class)->getMock();
$date = $this->createMock(DateTimeImmutable::class);
$this->platform->expects($this->once())
->method('getTimeFormatString')
......
......@@ -5,7 +5,7 @@ declare(strict_types=1);
namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\TimeType;
class TimeTest extends BaseDateTypeTestCase
{
......@@ -14,7 +14,7 @@ class TimeTest extends BaseDateTypeTestCase
*/
protected function setUp() : void
{
$this->type = Type::getType('time');
$this->type = new TimeType();
parent::setUp();
}
......
......@@ -9,7 +9,6 @@ use DateTimeImmutable;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\VarDateTimeImmutableType;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
......@@ -24,12 +23,8 @@ class VarDateTimeImmutableTypeTest extends TestCase
protected function setUp() : void
{
if (! Type::hasType('vardatetime_immutable')) {
Type::addType('vardatetime_immutable', VarDateTimeImmutableType::class);
}
$this->type = Type::getType('vardatetime_immutable');
$this->platform = $this->getMockForAbstractClass(AbstractPlatform::class);
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = new VarDateTimeImmutableType();
}
public function testReturnsName() : void
......@@ -44,7 +39,11 @@ class VarDateTimeImmutableTypeTest extends TestCase
public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void
{
$date = $this->getMockBuilder(DateTimeImmutable::class)->getMock();
$this->platform->expects($this->any())
->method('getDateTimeFormatString')
->will($this->returnValue('Y-m-d H:i:s'));
$date = $this->createMock(DateTimeImmutable::class);
$date->expects($this->once())
->method('format')
......
......@@ -7,7 +7,6 @@ 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\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
......@@ -27,10 +26,7 @@ class VarDateTimeTest extends DbalTestCase
->method('getDateTimeFormatString')
->will($this->returnValue('U'));
if (! Type::hasType('vardatetime')) {
Type::addType('vardatetime', VarDateTimeType::class);
}
$this->type = Type::getType('vardatetime');
$this->type = new VarDateTimeType();
}
public function testDateTimeConvertsToDatabaseValue() : void
......
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