Remove assertions about createMock() return value

Upstream libs and tools have improvements that make them unnecessary.
parent 5cff2bb7
...@@ -1552,7 +1552,6 @@ abstract class AbstractPlatform ...@@ -1552,7 +1552,6 @@ abstract class AbstractPlatform
if (($createFlags&self::CREATE_INDEXES) > 0) { if (($createFlags&self::CREATE_INDEXES) > 0) {
foreach ($table->getIndexes() as $index) { foreach ($table->getIndexes() as $index) {
assert($index instanceof Index);
if ($index->isPrimary()) { if ($index->isPrimary()) {
$options['primary'] = $index->getQuotedColumns($this); $options['primary'] = $index->getQuotedColumns($this);
$options['primary_index'] = $index; $options['primary_index'] = $index;
......
...@@ -19,7 +19,6 @@ use function array_diff; ...@@ -19,7 +19,6 @@ use function array_diff;
use function array_merge; use function array_merge;
use function array_unique; use function array_unique;
use function array_values; use function array_values;
use function assert;
use function count; use function count;
use function explode; use function explode;
use function implode; use function implode;
...@@ -532,7 +531,6 @@ SQL ...@@ -532,7 +531,6 @@ SQL
} }
foreach ($diff->changedColumns as $columnDiff) { foreach ($diff->changedColumns as $columnDiff) {
assert($columnDiff instanceof ColumnDiff);
if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) { if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) {
continue; continue;
} }
......
...@@ -7,7 +7,6 @@ use Doctrine\DBAL\Schema\Visitor\Visitor; ...@@ -7,7 +7,6 @@ use Doctrine\DBAL\Schema\Visitor\Visitor;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use function array_filter; use function array_filter;
use function array_merge; use function array_merge;
use function assert;
use function in_array; use function in_array;
use function preg_match; use function preg_match;
use function strlen; use function strlen;
...@@ -242,7 +241,6 @@ class Table extends AbstractAsset ...@@ -242,7 +241,6 @@ class Table extends AbstractAsset
public function columnsAreIndexed(array $columnNames) public function columnsAreIndexed(array $columnNames)
{ {
foreach ($this->getIndexes() as $index) { foreach ($this->getIndexes() as $index) {
assert($index instanceof Index);
if ($index->spansColumns($columnNames)) { if ($index->spansColumns($columnNames)) {
return true; return true;
} }
......
...@@ -27,7 +27,6 @@ use Doctrine\Tests\DbalTestCase; ...@@ -27,7 +27,6 @@ use Doctrine\Tests\DbalTestCase;
use Exception; use Exception;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use stdClass; use stdClass;
use function assert;
use function call_user_func_array; use function call_user_func_array;
/** /**
...@@ -167,13 +166,11 @@ class ConnectionTest extends DbalTestCase ...@@ -167,13 +166,11 @@ class ConnectionTest extends DbalTestCase
$eventManager = new EventManager(); $eventManager = new EventManager();
$platform = $this->createMock(AbstractPlatform::class); $platform = $this->createMock(AbstractPlatform::class);
assert($platform instanceof AbstractPlatform && $platform instanceof MockObject);
$platform->expects($this->once()) $platform->expects($this->once())
->method('setEventManager') ->method('setEventManager')
->with($eventManager); ->with($eventManager);
$driver = $this->createMock(Driver::class); $driver = $this->createMock(Driver::class);
assert($driver instanceof Driver || $driver instanceof MockObject);
$driver->expects($this->any()) $driver->expects($this->any())
->method('getDatabasePlatform') ->method('getDatabasePlatform')
->willReturn($platform); ->willReturn($platform);
...@@ -569,7 +566,6 @@ class ConnectionTest extends DbalTestCase ...@@ -569,7 +566,6 @@ class ConnectionTest extends DbalTestCase
->onlyMethods(['executeQuery']) ->onlyMethods(['executeQuery'])
->setConstructorArgs([[], $driverMock]) ->setConstructorArgs([[], $driverMock])
->getMock(); ->getMock();
assert($conn instanceof Connection || $conn instanceof MockObject);
$conn->expects($this->once()) $conn->expects($this->once())
->method('executeQuery') ->method('executeQuery')
...@@ -605,7 +601,6 @@ class ConnectionTest extends DbalTestCase ...@@ -605,7 +601,6 @@ class ConnectionTest extends DbalTestCase
->onlyMethods(['executeQuery']) ->onlyMethods(['executeQuery'])
->setConstructorArgs([[], $driverMock]) ->setConstructorArgs([[], $driverMock])
->getMock(); ->getMock();
assert($conn instanceof Connection || $conn instanceof MockObject);
$conn->expects($this->once()) $conn->expects($this->once())
->method('executeQuery') ->method('executeQuery')
...@@ -642,7 +637,6 @@ class ConnectionTest extends DbalTestCase ...@@ -642,7 +637,6 @@ class ConnectionTest extends DbalTestCase
->onlyMethods(['executeQuery']) ->onlyMethods(['executeQuery'])
->setConstructorArgs([[], $driverMock]) ->setConstructorArgs([[], $driverMock])
->getMock(); ->getMock();
assert($conn instanceof Connection || $conn instanceof MockObject);
$conn->expects($this->once()) $conn->expects($this->once())
->method('executeQuery') ->method('executeQuery')
...@@ -677,7 +671,6 @@ class ConnectionTest extends DbalTestCase ...@@ -677,7 +671,6 @@ class ConnectionTest extends DbalTestCase
->onlyMethods(['executeQuery']) ->onlyMethods(['executeQuery'])
->setConstructorArgs([[], $driverMock]) ->setConstructorArgs([[], $driverMock])
->getMock(); ->getMock();
assert($conn instanceof Connection || $conn instanceof MockObject);
$conn->expects($this->once()) $conn->expects($this->once())
->method('executeQuery') ->method('executeQuery')
...@@ -711,8 +704,7 @@ class ConnectionTest extends DbalTestCase ...@@ -711,8 +704,7 @@ class ConnectionTest extends DbalTestCase
public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() : void public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() : void
{ {
$driver = $this->createMock(Driver::class); $driver = $this->createMock(Driver::class);
assert($driver instanceof Driver);
$pdoMock = $this->createMock(\Doctrine\DBAL\Driver\Connection::class); $pdoMock = $this->createMock(\Doctrine\DBAL\Driver\Connection::class);
// should never execute queries with invalid arguments // should never execute queries with invalid arguments
...@@ -771,13 +763,10 @@ class ConnectionTest extends DbalTestCase ...@@ -771,13 +763,10 @@ class ConnectionTest extends DbalTestCase
public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() : void public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() : void
{ {
$driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]); $driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]);
assert($driverMock instanceof Driver || $driverMock instanceof VersionAwarePlatformDriver || $driverMock instanceof MockObject);
$driverConnectionMock = $this->createMock(ServerInfoAwareConnection::class); $driverConnectionMock = $this->createMock(ServerInfoAwareConnection::class);
assert($driverConnectionMock instanceof ServerInfoAwareConnection || $driverConnectionMock instanceof MockObject);
$platformMock = $this->getMockForAbstractClass(AbstractPlatform::class); $platformMock = $this->getMockForAbstractClass(AbstractPlatform::class);
assert($platformMock instanceof AbstractPlatform || $platformMock instanceof MockObject);
$connection = new Connection([], $driverMock); $connection = new Connection([], $driverMock);
...@@ -816,7 +805,6 @@ class ConnectionTest extends DbalTestCase ...@@ -816,7 +805,6 @@ class ConnectionTest extends DbalTestCase
$types = [ParameterType::INTEGER]; $types = [ParameterType::INTEGER];
$queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class);
assert($queryCacheProfileMock instanceof QueryCacheProfile || $queryCacheProfileMock instanceof MockObject);
$queryCacheProfileMock $queryCacheProfileMock
->expects($this->any()) ->expects($this->any())
...@@ -831,7 +819,6 @@ class ConnectionTest extends DbalTestCase ...@@ -831,7 +819,6 @@ class ConnectionTest extends DbalTestCase
->will($this->returnValue(['cacheKey', 'realKey'])); ->will($this->returnValue(['cacheKey', 'realKey']));
$driver = $this->createMock(Driver::class); $driver = $this->createMock(Driver::class);
assert($driver instanceof Driver);
self::assertInstanceOf( self::assertInstanceOf(
ArrayStatement::class, ArrayStatement::class,
...@@ -853,7 +840,6 @@ class ConnectionTest extends DbalTestCase ...@@ -853,7 +840,6 @@ class ConnectionTest extends DbalTestCase
->will($this->returnValue(['realKey' => []])); ->will($this->returnValue(['realKey' => []]));
$queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class);
assert($queryCacheProfileMock instanceof QueryCacheProfile || $queryCacheProfileMock instanceof MockObject);
$queryCacheProfileMock $queryCacheProfileMock
->expects($this->any()) ->expects($this->any())
...@@ -873,7 +859,6 @@ class ConnectionTest extends DbalTestCase ...@@ -873,7 +859,6 @@ class ConnectionTest extends DbalTestCase
$connectionParams['platform'] = $this->createMock(AbstractPlatform::class); $connectionParams['platform'] = $this->createMock(AbstractPlatform::class);
$driver = $this->createMock(Driver::class); $driver = $this->createMock(Driver::class);
assert($driver instanceof Driver);
(new Connection($connectionParams, $driver))->executeCacheQuery($query, [], [], $queryCacheProfileMock); (new Connection($connectionParams, $driver))->executeCacheQuery($query, [], [], $queryCacheProfileMock);
} }
...@@ -887,7 +872,6 @@ class ConnectionTest extends DbalTestCase ...@@ -887,7 +872,6 @@ class ConnectionTest extends DbalTestCase
$connectionParams['platform'] = new stdClass(); $connectionParams['platform'] = new stdClass();
$driver = $this->createMock(Driver::class); $driver = $this->createMock(Driver::class);
assert($driver instanceof Driver);
$this->expectException(DBALException::class); $this->expectException(DBALException::class);
...@@ -900,7 +884,6 @@ class ConnectionTest extends DbalTestCase ...@@ -900,7 +884,6 @@ class ConnectionTest extends DbalTestCase
public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase() : void public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase() : void
{ {
$driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]); $driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]);
assert($driverMock instanceof Driver || $driverMock instanceof VersionAwarePlatformDriver || $driverMock instanceof MockObject);
$connection = new Connection(['dbname' => 'foo'], $driverMock); $connection = new Connection(['dbname' => 'foo'], $driverMock);
$originalException = new Exception('Original exception'); $originalException = new Exception('Original exception');
...@@ -925,16 +908,12 @@ class ConnectionTest extends DbalTestCase ...@@ -925,16 +908,12 @@ class ConnectionTest extends DbalTestCase
public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGeneratingCacheKeys() : void public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGeneratingCacheKeys() : void
{ {
$driver = $this->createMock(Driver::class); $driver = $this->createMock(Driver::class);
assert($driver instanceof Driver || $driver instanceof MockObject);
$platform = $this->createMock(AbstractPlatform::class); $platform = $this->createMock(AbstractPlatform::class);
assert($platform instanceof AbstractPlatform || $platform instanceof MockObject);
$queryCacheProfile = $this->createMock(QueryCacheProfile::class); $queryCacheProfile = $this->createMock(QueryCacheProfile::class);
assert($queryCacheProfile instanceof QueryCacheProfile || $queryCacheProfile instanceof MockObject);
$resultCacheDriver = $this->createMock(Cache::class); $resultCacheDriver = $this->createMock(Cache::class);
assert($resultCacheDriver instanceof Cache || $resultCacheDriver instanceof MockObject);
$queryCacheProfile $queryCacheProfile
->expects($this->any()) ->expects($this->any())
......
...@@ -9,7 +9,6 @@ use Doctrine\DBAL\Exception\DriverException; ...@@ -9,7 +9,6 @@ use Doctrine\DBAL\Exception\DriverException;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use Exception; use Exception;
use stdClass; use stdClass;
use function assert;
use function chr; use function chr;
use function fopen; use function fopen;
use function sprintf; use function sprintf;
...@@ -19,26 +18,22 @@ class DBALExceptionTest extends DbalTestCase ...@@ -19,26 +18,22 @@ class DBALExceptionTest extends DbalTestCase
public function testDriverExceptionDuringQueryAcceptsBinaryData() : void public function testDriverExceptionDuringQueryAcceptsBinaryData() : void
{ {
$driver = $this->createMock(Driver::class); $driver = $this->createMock(Driver::class);
assert($driver instanceof Driver); $e = DBALException::driverExceptionDuringQuery($driver, new Exception(), '', ['ABC', chr(128)]);
$e = DBALException::driverExceptionDuringQuery($driver, new Exception(), '', ['ABC', chr(128)]);
self::assertStringContainsString('with params ["ABC", "\x80"]', $e->getMessage()); self::assertStringContainsString('with params ["ABC", "\x80"]', $e->getMessage());
} }
public function testDriverExceptionDuringQueryAcceptsResource() : void public function testDriverExceptionDuringQueryAcceptsResource() : void
{ {
$driver = $this->createMock(Driver::class); $driver = $this->createMock(Driver::class);
assert($driver instanceof Driver); $e = DBALException::driverExceptionDuringQuery($driver, new Exception(), 'INSERT INTO file (`content`) VALUES (?)', [1 => fopen(__FILE__, 'r')]);
$e = DBALException::driverExceptionDuringQuery($driver, new Exception(), 'INSERT INTO file (`content`) VALUES (?)', [1 => fopen(__FILE__, 'r')]);
self::assertStringContainsString('Resource', $e->getMessage()); self::assertStringContainsString('Resource', $e->getMessage());
} }
public function testAvoidOverWrappingOnDriverException() : void public function testAvoidOverWrappingOnDriverException() : void
{ {
$driver = $this->createMock(Driver::class); $driver = $this->createMock(Driver::class);
assert($driver instanceof Driver);
$inner = $this->createMock(InnerDriverException::class); $inner = $this->createMock(InnerDriverException::class);
assert($inner instanceof InnerDriverException);
$ex = new DriverException('', $inner); $ex = new DriverException('', $inner);
$e = DBALException::driverExceptionDuringQuery($driver, $ex, ''); $e = DBALException::driverExceptionDuringQuery($driver, $ex, '');
......
...@@ -28,10 +28,8 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; ...@@ -28,10 +28,8 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\DBAL\VersionAwarePlatformDriver;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionProperty; use ReflectionProperty;
use function array_merge; use function array_merge;
use function assert;
use function get_class; use function get_class;
use function sprintf; use function sprintf;
...@@ -83,7 +81,6 @@ abstract class AbstractDriverTest extends DbalTestCase ...@@ -83,7 +81,6 @@ abstract class AbstractDriverTest extends DbalTestCase
$driverException = $this->getMockBuilder(DriverExceptionInterface::class) $driverException = $this->getMockBuilder(DriverExceptionInterface::class)
->setConstructorArgs([$message]) ->setConstructorArgs([$message])
->getMock(); ->getMock();
assert($driverException instanceof DriverExceptionInterface || $driverException instanceof MockObject);
$driverException->method('getErrorCode') $driverException->method('getErrorCode')
->willReturn($errorCode); ->willReturn($errorCode);
$driverException->method('getSQLState') $driverException->method('getSQLState')
......
...@@ -11,10 +11,8 @@ use Doctrine\DBAL\Driver\Statement; ...@@ -11,10 +11,8 @@ use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\Portability\Statement as PortabilityStatement; use Doctrine\DBAL\Portability\Statement as PortabilityStatement;
use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\DbalTestCase;
use IteratorAggregate;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Traversable; use Traversable;
use function assert;
use function extension_loaded; use function extension_loaded;
class StatementIteratorTest extends DbalTestCase class StatementIteratorTest extends DbalTestCase
...@@ -25,7 +23,6 @@ class StatementIteratorTest extends DbalTestCase ...@@ -25,7 +23,6 @@ class StatementIteratorTest extends DbalTestCase
public function testGettingIteratorDoesNotCallFetch(string $class) : void public function testGettingIteratorDoesNotCallFetch(string $class) : void
{ {
$stmt = $this->createPartialMock($class, ['fetch', 'fetchAll', 'fetchColumn']); $stmt = $this->createPartialMock($class, ['fetch', 'fetchAll', 'fetchColumn']);
assert($stmt instanceof IteratorAggregate || $stmt instanceof MockObject);
$stmt->expects($this->never())->method('fetch'); $stmt->expects($this->never())->method('fetch');
$stmt->expects($this->never())->method('fetchAll'); $stmt->expects($this->never())->method('fetchAll');
$stmt->expects($this->never())->method('fetchColumn'); $stmt->expects($this->never())->method('fetchColumn');
......
...@@ -22,7 +22,6 @@ use PDO; ...@@ -22,7 +22,6 @@ use PDO;
use function array_change_key_case; use function array_change_key_case;
use function array_filter; use function array_filter;
use function array_keys; use function array_keys;
use function assert;
use function count; use function count;
use function date; use function date;
use function implode; use function implode;
...@@ -955,7 +954,7 @@ class DataAccessTest extends DbalFunctionalTestCase ...@@ -955,7 +954,7 @@ class DataAccessTest extends DbalFunctionalTestCase
} }
$connection = $this->connection->getWrappedConnection(); $connection = $this->connection->getWrappedConnection();
assert($connection instanceof PDOConnection); self::assertInstanceOf(PDOConnection::class, $connection);
$connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); $connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
} }
} }
......
...@@ -9,7 +9,6 @@ use Doctrine\DBAL\Schema\Table; ...@@ -9,7 +9,6 @@ use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalFunctionalTestCase; use Doctrine\Tests\DbalFunctionalTestCase;
use Throwable; use Throwable;
use function array_change_key_case; use function array_change_key_case;
use function assert;
use function sprintf; use function sprintf;
use function strlen; use function strlen;
use function strtolower; use function strtolower;
...@@ -85,7 +84,7 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase ...@@ -85,7 +84,7 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
} }
$conn = DriverManager::getConnection($params); $conn = DriverManager::getConnection($params);
assert($conn instanceof MasterSlaveConnection); self::assertInstanceOf(MasterSlaveConnection::class, $conn);
$conn->connect('slave'); $conn->connect('slave');
self::assertFalse($conn->isConnectedToMaster()); self::assertFalse($conn->isConnectedToMaster());
......
...@@ -10,7 +10,6 @@ use Doctrine\DBAL\Schema\Table; ...@@ -10,7 +10,6 @@ use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use function assert;
class SchemaDiffTest extends TestCase class SchemaDiffTest extends TestCase
{ {
...@@ -44,7 +43,6 @@ class SchemaDiffTest extends TestCase ...@@ -44,7 +43,6 @@ class SchemaDiffTest extends TestCase
private function createPlatform(bool $unsafe) private function createPlatform(bool $unsafe)
{ {
$platform = $this->createMock(AbstractPlatform::class); $platform = $this->createMock(AbstractPlatform::class);
assert($platform instanceof AbstractPlatform || $platform instanceof MockObject);
$platform->expects($this->exactly(1)) $platform->expects($this->exactly(1))
->method('getCreateSchemaSQL') ->method('getCreateSchemaSQL')
->with('foo_ns') ->with('foo_ns')
......
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