Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes from PHPStan l1 for tests #3063

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Doctrine\DBAL\Driver\IBMDB2\DB2Driver;
use Doctrine\Tests\DBAL\Driver\AbstractDB2DriverTest;

class DriverTest extends AbstractDB2DriverTest
class DB2DriverTest extends AbstractDB2DriverTest
{
public function testReturnsName()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Doctrine\Tests\DBAL;
namespace Doctrine\Tests\DBAL\Driver\OCI8;

use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
use Doctrine\DBAL\Driver\OCI8\OCI8Statement;
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/DriverManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Doctrine\Tests\DBAL\Functional\Ticket;
namespace Doctrine\Tests\DBAL\Functional;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\FetchMode;
Expand Down
7 changes: 6 additions & 1 deletion tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,11 +1252,9 @@ public function testThrowsExceptionOnGeneratingInlineColumnCommentSQLIfUnsupport
$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');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Doctrine\DBAL\Platforms\PostgreSQL91Platform;
use Doctrine\DBAL\Schema\Table;

class PostgreSql91PlatformTest extends PostgreSqlPlatformTest
class PostgreSQL91PlatformTest extends PostgreSqlPlatformTest
{
public function createPlatform()
{
Expand Down
13 changes: 6 additions & 7 deletions tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public function testSetMaxResults()
$qb->setMaxResults(10);

self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
self::assertEQuals(10, $qb->getMaxResults());
self::assertEquals(10, $qb->getMaxResults());
}

public function testSetFirstResult()
Expand All @@ -574,7 +574,7 @@ public function testSetFirstResult()
$qb->setFirstResult(10);

self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState());
self::assertEQuals(10, $qb->getFirstResult());
self::assertEquals(10, $qb->getFirstResult());
}

public function testResetQueryPart()
Expand Down Expand Up @@ -652,7 +652,8 @@ public function testReferenceJoinFromJoin()
->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());
}

Expand Down Expand Up @@ -894,10 +895,8 @@ public function testJoinWithNonUniqueAliasThrowsException()
->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();
}
Expand Down
6 changes: 2 additions & 4 deletions tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,8 @@ public function dataQueryWithMissingParameters()
*/
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);
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public function createPlatform($unsafe = false)
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')
Expand All @@ -76,7 +76,7 @@ public function createPlatform($unsafe = false)
$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'));
Expand Down
24 changes: 16 additions & 8 deletions tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public function testConnect()

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',
Expand All @@ -78,7 +79,8 @@ public function testNoGlobalServerException()

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',
Expand All @@ -90,7 +92,8 @@ public function testNoShardsServersException()

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',
Expand All @@ -105,7 +108,8 @@ public function testNoShardsChoserException()

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',
Expand All @@ -121,7 +125,8 @@ public function testShardChoserWrongInstance()

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',
Expand All @@ -136,7 +141,8 @@ public function testShardNonNumericId()

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',
Expand All @@ -151,7 +157,8 @@ public function testShardMissingId()

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',
Expand Down Expand Up @@ -179,7 +186,8 @@ public function testSwitchShardWithOpenTransactionException()

$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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testSelectGlobal()
$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());
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testGetShards()
)
);

$shardManager = new PoolingShardManager($conn, $this->createPassthroughShardChoser());
$shardManager = new PoolingShardManager($conn);
$shards = $shardManager->getShards();

self::assertEquals(array(array('id' => 1), array('id' => 2)), $shards);
Expand Down Expand Up @@ -111,7 +111,7 @@ public function testQueryAll()
->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);
Expand Down Expand Up @@ -141,10 +141,9 @@ public function testQueryAllWithStaticShardChoser()
->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);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ 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);
}

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);
Expand All @@ -43,7 +45,8 @@ public function testSelectGlobalTransactionActive()
$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();
Expand All @@ -64,7 +67,8 @@ public function testSelectShard()
$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);
Expand All @@ -77,7 +81,8 @@ public function testSelectShardNoDistributionValue()
$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);
Expand All @@ -93,4 +98,3 @@ private function createConnection(array $params)
return $conn;
}
}

2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Types/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testDateConvertsToPHPValue()
{
// 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)
);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

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
Expand Down
Loading