Unverified Commit 89a52c28 authored by Marco Pivetta's avatar Marco Pivetta Committed by GitHub

Merge pull request #3063 from carusogabriel/phpstan-tests

Fixes from PHPStan l1 for tests
parents 62fe3fe4 311a7c28
......@@ -5,7 +5,7 @@ namespace Doctrine\Tests\DBAL\Driver\IBMDB2;
use Doctrine\DBAL\Driver\IBMDB2\DB2Driver;
use Doctrine\Tests\DBAL\Driver\AbstractDB2DriverTest;
class DriverTest extends AbstractDB2DriverTest
class DB2DriverTest extends AbstractDB2DriverTest
{
public function testReturnsName()
{
......
<?php
namespace Doctrine\Tests\DBAL;
namespace Doctrine\Tests\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
use Doctrine\DBAL\Driver\OCI8\OCI8Statement;
......
......@@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver as DrizzlePDOMySqlDriver;
use Doctrine\DBAL\Driver\PDOMySQL\Driver as PDOMySQLDriver;
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;
......
<?php
namespace Doctrine\Tests\DBAL\Functional\Ticket;
namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\FetchMode;
......
......@@ -2,11 +2,16 @@
namespace Doctrine\Tests\DBAL\Logging;
use Doctrine\DBAL\Logging\DebugStack;
class DebugStackTest extends \Doctrine\Tests\DbalTestCase
{
/** @var DebugStack */
private $logger;
protected function setUp()
{
$this->logger = new \Doctrine\DBAL\Logging\DebugStack();
$this->logger = new DebugStack();
}
protected function tearDown()
......
......@@ -1252,11 +1252,9 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->markTestSkipped(sprintf('%s supports inline column comments.', get_class($this->_platform)));
}
$this->expectException(
'Doctrine\DBAL\DBALException',
"Operation 'Doctrine\\DBAL\\Platforms\\AbstractPlatform::getInlineColumnCommentSQL' is not supported by platform.",
0
);
$this->expectException('Doctrine\DBAL\DBALException');
$this->expectExceptionMessage("Operation 'Doctrine\\DBAL\\Platforms\\AbstractPlatform::getInlineColumnCommentSQL' is not supported by platform.");
$this->expectExceptionCode(0);
$this->_platform->getInlineColumnCommentSQL('unsupported');
}
......
......@@ -5,7 +5,7 @@ namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\PostgreSQL91Platform;
use Doctrine\DBAL\Schema\Table;
class PostgreSql91PlatformTest extends PostgreSqlPlatformTest
class PostgreSQL91PlatformTest extends PostgreSqlPlatformTest
{
public function createPlatform()
{
......
......@@ -565,7 +565,7 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$qb->setMaxResults(10);
self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
self::assertEQuals(10, $qb->getMaxResults());
self::assertEquals(10, $qb->getMaxResults());
}
public function testSetFirstResult()
......@@ -574,7 +574,7 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$qb->setFirstResult(10);
self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
self::assertEQuals(10, $qb->getFirstResult());
self::assertEquals(10, $qb->getFirstResult());
}
public function testResetQueryPart()
......@@ -652,7 +652,8 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
->innerJoin('nt', 'node', 'n', 'nt.node = n.id')
->where('nt.lang = :lang AND n.deleted != 1');
$this->expectException('Doctrine\DBAL\Query\QueryException', "The given alias 'invalid' is not part of any FROM or JOIN clause table. The currently registered aliases are: news, nv.");
$this->expectException('Doctrine\DBAL\Query\QueryException');
$this->expectExceptionMessage("The given alias 'invalid' is not part of any FROM or JOIN clause table. The currently registered aliases are: news, nv.");
self::assertEquals('', $qb->getSQL());
}
......@@ -894,10 +895,8 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
->from('table_a', 'a')
->join('a', 'table_b', 'a', 'a.fk_b = a.id');
$this->expectException(
'Doctrine\DBAL\Query\QueryException',
"The given alias 'a' is not unique in FROM and JOIN clause table. The currently registered aliases are: a."
);
$this->expectException('Doctrine\DBAL\Query\QueryException');
$this->expectExceptionMessage("The given alias 'a' is not unique in FROM and JOIN clause table. The currently registered aliases are: a.");
$qb->getSQL();
}
......
......@@ -452,10 +452,8 @@ SQLDATA
*/
public function testExceptionIsThrownForMissingParam($query, $params, $types = array())
{
$this->expectException(
'Doctrine\DBAL\SQLParserUtilsException',
'Value for :param not found in params array. Params array key should be "param"'
);
$this->expectException('Doctrine\DBAL\SQLParserUtilsException');
$this->expectExceptionMessage('Value for :param not found in params array. Params array key should be "param"');
SQLParserUtils::expandListParameters($query, $params, $types);
}
......
......@@ -4,17 +4,20 @@ namespace Doctrine\Tests\DBAL\Schema;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\MySqlSchemaManager;
use function array_map;
class MySqlSchemaManagerTest extends \PHPUnit\Framework\TestCase
{
/**
*
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager
*/
private $manager;
/** @var Connection */
private $conn;
protected function setUp()
{
$eventManager = new EventManager();
......
......@@ -2,14 +2,14 @@
namespace Doctrine\Tests\DBAL\Schema\Platforms;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Table;
class MySQLSchemaTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Comparator
*/
/** @var Comparator */
private $comparator;
/**
*
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
......@@ -18,7 +18,7 @@ class MySQLSchemaTest extends \PHPUnit\Framework\TestCase
protected function setUp()
{
$this->comparator = new \Doctrine\DBAL\Schema\Comparator;
$this->comparator = new Comparator();
$this->platform = new \Doctrine\DBAL\Platforms\MySqlPlatform;
}
......
......@@ -57,12 +57,12 @@ class SchemaDiffTest extends \PHPUnit\Framework\TestCase
if ($unsafe) {
$platform->expects($this->exactly(1))
->method('getDropTableSql')
->with($this->isInstanceof('Doctrine\DBAL\Schema\Table'))
->with($this->isInstanceOf('Doctrine\DBAL\Schema\Table'))
->will($this->returnValue('drop_table'));
}
$platform->expects($this->exactly(1))
->method('getCreateTableSql')
->with($this->isInstanceof('Doctrine\DBAL\Schema\Table'))
->with($this->isInstanceOf('Doctrine\DBAL\Schema\Table'))
->will($this->returnValue(array('create_table')));
$platform->expects($this->exactly(1))
->method('getCreateForeignKeySQL')
......@@ -76,7 +76,7 @@ class SchemaDiffTest extends \PHPUnit\Framework\TestCase
$platform->expects($this->exactly(1))
->method('getDropForeignKeySql')
->with(
$this->isInstanceof('Doctrine\DBAL\Schema\ForeignKeyConstraint'),
$this->isInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint'),
$this->isInstanceOf('Doctrine\DBAL\Schema\Table')
)
->will($this->returnValue('drop_orphan_fk'));
......
......@@ -63,7 +63,8 @@ class PoolingShardConnectionTest extends \PHPUnit\Framework\TestCase
public function testNoGlobalServerException()
{
$this->expectException('InvalidArgumentException', "Connection Parameters require 'global' and 'shards' configurations.");
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations.");
DriverManager::getConnection(array(
'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection',
......@@ -78,7 +79,8 @@ class PoolingShardConnectionTest extends \PHPUnit\Framework\TestCase
public function testNoShardsServersException()
{
$this->expectException('InvalidArgumentException', "Connection Parameters require 'global' and 'shards' configurations.");
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations.");
DriverManager::getConnection(array(
'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection',
......@@ -90,7 +92,8 @@ class PoolingShardConnectionTest extends \PHPUnit\Framework\TestCase
public function testNoShardsChoserException()
{
$this->expectException('InvalidArgumentException', "Missing Shard Choser configuration 'shardChoser'");
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("Missing Shard Choser configuration 'shardChoser'");
DriverManager::getConnection(array(
'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection',
......@@ -105,7 +108,8 @@ class PoolingShardConnectionTest extends \PHPUnit\Framework\TestCase
public function testShardChoserWrongInstance()
{
$this->expectException('InvalidArgumentException', "The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser");
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser");
DriverManager::getConnection(array(
'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection',
......@@ -121,7 +125,8 @@ class PoolingShardConnectionTest extends \PHPUnit\Framework\TestCase
public function testShardNonNumericId()
{
$this->expectException('InvalidArgumentException', "Shard Id has to be a non-negative number.");
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Shard Id has to be a non-negative number.');
DriverManager::getConnection(array(
'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection',
......@@ -136,7 +141,8 @@ class PoolingShardConnectionTest extends \PHPUnit\Framework\TestCase
public function testShardMissingId()
{
$this->expectException('InvalidArgumentException', "Missing 'id' for one configured shard. Please specify a unique shard-id.");
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("Missing 'id' for one configured shard. Please specify a unique shard-id.");
DriverManager::getConnection(array(
'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection',
......@@ -151,7 +157,8 @@ class PoolingShardConnectionTest extends \PHPUnit\Framework\TestCase
public function testDuplicateShardId()
{
$this->expectException('InvalidArgumentException', "Shard 1 is duplicated in the configuration.");
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Shard 1 is duplicated in the configuration.');
DriverManager::getConnection(array(
'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection',
......@@ -179,7 +186,8 @@ class PoolingShardConnectionTest extends \PHPUnit\Framework\TestCase
$conn->beginTransaction();
$this->expectException('Doctrine\DBAL\Sharding\ShardingException', 'Cannot switch shard when transaction is active.');
$this->expectException('Doctrine\DBAL\Sharding\ShardingException');
$this->expectExceptionMessage('Cannot switch shard when transaction is active.');
$conn->connect(1);
}
......
......@@ -53,7 +53,7 @@ class PoolingShardManagerTest extends \PHPUnit\Framework\TestCase
$conn = $this->createConnectionMock();
$conn->expects($this->once())->method('connect')->with($this->equalTo(0));
$shardManager = new PoolingShardManager($conn, $this->createPassthroughShardChoser());
$shardManager = new PoolingShardManager($conn);
$shardManager->selectGlobal();
self::assertNull($shardManager->getCurrentDistributionValue());
......@@ -81,7 +81,7 @@ class PoolingShardManagerTest extends \PHPUnit\Framework\TestCase
)
);
$shardManager = new PoolingShardManager($conn, $this->createPassthroughShardChoser());
$shardManager = new PoolingShardManager($conn);
$shards = $shardManager->getShards();
self::assertEquals(array(array('id' => 1), array('id' => 2)), $shards);
......@@ -111,7 +111,7 @@ class PoolingShardManagerTest extends \PHPUnit\Framework\TestCase
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types))
->will($this->returnValue(array( array('id' => 2) ) ));
$shardManager = new PoolingShardManager($conn, $this->createPassthroughShardChoser());
$shardManager = new PoolingShardManager($conn);
$result = $shardManager->queryAll($sql, $params, $types);
self::assertEquals(array(array('id' => 1), array('id' => 2)), $result);
......@@ -141,10 +141,9 @@ class PoolingShardManagerTest extends \PHPUnit\Framework\TestCase
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types))
->will($this->returnValue(array( array('id' => 2) ) ));
$shardManager = new PoolingShardManager($conn, $this->createStaticShardChoser());
$shardManager = new PoolingShardManager($conn);
$result = $shardManager->queryAll($sql, $params, $types);
self::assertEquals(array(array('id' => 1), array('id' => 2)), $result);
}
}
......@@ -8,7 +8,8 @@ class SQLAzureShardManagerTest extends \PHPUnit\Framework\TestCase
{
public function testNoFederationName()
{
$this->expectException('Doctrine\DBAL\Sharding\ShardingException', 'SQLAzure requires a federation name to be set during sharding configuration.');
$this->expectException('Doctrine\DBAL\Sharding\ShardingException');
$this->expectExceptionMessage('SQLAzure requires a federation name to be set during sharding configuration.');
$conn = $this->createConnection(array('sharding' => array('distributionKey' => 'abc', 'distributionType' => 'integer')));
$sm = new SQLAzureShardManager($conn);
......@@ -16,7 +17,8 @@ class SQLAzureShardManagerTest extends \PHPUnit\Framework\TestCase
public function testNoDistributionKey()
{
$this->expectException('Doctrine\DBAL\Sharding\ShardingException', 'SQLAzure requires a distribution key to be set during sharding configuration.');
$this->expectException('Doctrine\DBAL\Sharding\ShardingException');
$this->expectExceptionMessage('SQLAzure requires a distribution key to be set during sharding configuration.');
$conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionType' => 'integer')));
$sm = new SQLAzureShardManager($conn);
......@@ -43,7 +45,8 @@ class SQLAzureShardManagerTest extends \PHPUnit\Framework\TestCase
$conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer')));
$conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true));
$this->expectException('Doctrine\DBAL\Sharding\ShardingException', 'Cannot switch shard during an active transaction.');
$this->expectException('Doctrine\DBAL\Sharding\ShardingException');
$this->expectExceptionMessage('Cannot switch shard during an active transaction.');
$sm = new SQLAzureShardManager($conn);
$sm->selectGlobal();
......@@ -64,7 +67,8 @@ class SQLAzureShardManagerTest extends \PHPUnit\Framework\TestCase
$conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer')));
$conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true));
$this->expectException('Doctrine\DBAL\Sharding\ShardingException', 'Cannot switch shard during an active transaction.');
$this->expectException('Doctrine\DBAL\Sharding\ShardingException');
$this->expectExceptionMessage('Cannot switch shard during an active transaction.');
$sm = new SQLAzureShardManager($conn);
$sm->selectShard(1234);
......@@ -77,7 +81,8 @@ class SQLAzureShardManagerTest extends \PHPUnit\Framework\TestCase
$conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer')));
$conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false));
$this->expectException('Doctrine\DBAL\Sharding\ShardingException', 'You have to specify a string or integer as shard distribution value.');
$this->expectException('Doctrine\DBAL\Sharding\ShardingException');
$this->expectExceptionMessage('You have to specify a string or integer as shard distribution value.');
$sm = new SQLAzureShardManager($conn);
$sm->selectShard(null);
......@@ -93,4 +98,3 @@ class SQLAzureShardManagerTest extends \PHPUnit\Framework\TestCase
return $conn;
}
}
......@@ -21,7 +21,7 @@ class DateTest extends BaseDateTypeTestCase
{
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
self::assertInstanceOf(
\Datetime::class,
\DateTime::class,
$this->type->convertToPHPValue('1985-09-01', $this->platform)
);
}
......
......@@ -4,9 +4,10 @@ namespace Doctrine\Tests\DBAL\Types;
use Doctrine\DBAL\Types\Type;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase;
use function get_class;
class GuidTest extends \Doctrine\Tests\DbalTestCase
class GuidTypeTest extends DbalTestCase
{
/**
* @var MockPlatform
......
......@@ -25,9 +25,6 @@ class ConnectionMock extends \Doctrine\DBAL\Connection
$this->_platformMock = new DatabasePlatformMock();
parent::__construct($params, $driver, $config, $eventManager);
// Override possible assignment of platform to database platform mock
$this->_platform = $this->_platformMock;
}
/**
......
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