Skip to content

Commit

Permalink
Enable PHPStan in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Majkl578 committed Aug 18, 2018
1 parent f65cd05 commit 385b730
Show file tree
Hide file tree
Showing 33 changed files with 334 additions and 126 deletions.
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"doctrine/coding-standard": "^4.0",
"jetbrains/phpstorm-stubs": "^2018.1.2",
"phpstan/phpstan": "^0.10.1",
"phpstan/phpstan-phpunit": "dev-GetMockBuilderDynamicReturnTypeExtension-with-undefined-class as 0.10.0.999",
"phpunit/phpunit": "^7.1.2",
"phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5",
"symfony/console": "^2.0.5|^3.0|^4.0",
Expand All @@ -44,5 +45,11 @@
"dev-master": "2.9.x-dev",
"dev-develop": "3.0.x-dev"
}
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Majkl578/phpstan-phpunit"
}
]
}
72 changes: 69 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ parameters:
level: 3
paths:
- %currentWorkingDirectory%/lib
- %currentWorkingDirectory%/tests
autoload_files:
- %currentWorkingDirectory%/tests/phpstan-polyfill.php
reportUnmatchedIgnoredErrors: false
earlyTerminatingMethodCalls:
PHPUnit\Framework\Assert:
- markTestSkipped
- markTestIncomplete
ignoreErrors:
# extension not available
- '~^(Used )?(Function|Constant) sasql_\S+ not found\.\z~i'
Expand Down Expand Up @@ -44,3 +49,11 @@ parameters:

# weird class name, doesn't exist in stubs either
- '~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~'
- '~^Property Doctrine\\Tests\\DBAL\\Tools\\Console\\RunSqlCommandTest::\$command \(Doctrine\\DBAL\\Tools\\Console\\Command\\RunSqlCommand\) does not accept Symfony\\Component\\Console\\Command\\Command\.\z~'

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class QueryCacheProfileTest extends DbalTestCase
private $params = [666];

/**
* @var string[]
* @var int[]
*/
private $types = [ParameterType::INTEGER];

Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getSQLState()
$message = 'DBAL exception message';

foreach ($data as $item) {
/** @var $driverException \Doctrine\DBAL\Driver\DriverException */
/** @var DriverException $driverException */
list($driverException, $convertedExceptionClassName) = $item;

$convertedException = $this->driver->convertException($message, $driverException);
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PDOExceptionTest extends DbalTestCase
/**
* The wrapped PDO exception mock.
*
* @var \PDOException|\PHPUnit_Framework_MockObject_MockObject
* @var \PDOException
*/
private $wrappedException;

Expand Down
3 changes: 0 additions & 3 deletions tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ protected function createDriver()
return new Driver();
}

/**
* @throws \PHPUnit_Framework_SkippedTestError
*/
private function skipWhenNotUsingPhp56AndPdoPgsql()
{
if (! defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')) {
Expand Down
12 changes: 6 additions & 6 deletions tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,11 @@ public function testFetchAllSupportFetchClass()

$results = $stmt->fetchAll(
FetchMode::CUSTOM_OBJECT,
__NAMESPACE__.'\\MyFetchClass'
MyFetchClass::class
);

self::assertCount(1, $results);
self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]);
self::assertInstanceOf(MyFetchClass::class, $results[0]);

self::assertEquals(1, $results[0]->test_int);
self::assertEquals('foo', $results[0]->test_string);
Expand Down Expand Up @@ -781,12 +781,12 @@ public function testSetFetchModeClassFetchAll()

$sql = "SELECT * FROM fetch_table";
$stmt = $this->_conn->query($sql);
$stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass');
$stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, MyFetchClass::class);

$results = $stmt->fetchAll();

self::assertCount(1, $results);
self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]);
self::assertInstanceOf(MyFetchClass::class, $results[0]);

self::assertEquals(1, $results[0]->test_int);
self::assertEquals('foo', $results[0]->test_string);
Expand All @@ -803,15 +803,15 @@ public function testSetFetchModeClassFetch()

$sql = "SELECT * FROM fetch_table";
$stmt = $this->_conn->query($sql);
$stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass');
$stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, MyFetchClass::class);

$results = array();
while ($row = $stmt->fetch()) {
$results[] = $row;
}

self::assertCount(1, $results);
self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]);
self::assertInstanceOf(MyFetchClass::class, $results[0]);

self::assertEquals(1, $results[0]->test_int);
self::assertEquals('foo', $results[0]->test_string);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace Doctrine\Tests\DBAL\Functional\Driver\IBMDB2;

use Doctrine\DBAL\Driver\IBMDB2\DB2Driver;
use Doctrine\DBAL\Statement;
use Doctrine\Tests\DbalFunctionalTestCase;
use PHPUnit\Framework\Error\Notice;
use function assert;
use function extension_loaded;

class DB2StatementTest extends DbalFunctionalTestCase
Expand All @@ -27,6 +29,7 @@ protected function setUp()
public function testExecutionErrorsAreNotSuppressed()
{
$stmt = $this->_conn->prepare('SELECT * FROM SYSIBM.SYSDUMMY1 WHERE \'foo\' = ?');
assert($stmt instanceof Statement);

// unwrap the statement to prevent the wrapper from handling the PHPUnit-originated exception
$wrappedStmt = $stmt->getWrappedStatement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Doctrine\Tests\DBAL\Functional\Driver\OCI8;

use Doctrine\DBAL\Driver\OCI8\Driver;
use Doctrine\DBAL\Driver\OCI8\OCI8Connection;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalFunctionalTestCase;
use function assert;
use function extension_loaded;

class OCI8ConnectionTest extends DbalFunctionalTestCase
Expand All @@ -26,7 +28,11 @@ protected function setUp()
$this->markTestSkipped('oci8 only test.');
}

$this->driverConnection = $this->_conn->getWrappedConnection();

$wrappedConnection = $this->_conn->getWrappedConnection();
assert($wrappedConnection instanceof OCI8Connection);

$this->driverConnection = $wrappedConnection;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ protected function setUp()

parent::setUp();

$this->driverConnection = $this->_conn->getWrappedConnection();
$wrappedConnection = $this->_conn->getWrappedConnection();

if ( ! $this->driverConnection instanceof PDOConnection) {
if (! $wrappedConnection instanceof PDOConnection) {
$this->markTestSkipped('PDO connection only test.');
}

$this->driverConnection = $wrappedConnection;
}

protected function tearDown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Doctrine\Tests\DBAL\Functional\Driver\PDOSqlsrv;

use Doctrine\DBAL\Driver\Connection as Connection;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver;
use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest;
use PDO;
use function assert;
use function extension_loaded;

class DriverTest extends AbstractDriverTest
Expand Down Expand Up @@ -68,6 +70,7 @@ public function testConnectionOptions() : void
public function testDriverOptions() : void
{
$connection = $this->getConnection([PDO::ATTR_CASE => PDO::CASE_UPPER]);
assert($connection instanceof PDOConnection);

self::assertSame(PDO::CASE_UPPER, $connection->getAttribute(PDO::ATTR_CASE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Tests\DbalFunctionalTestCase;
use const CASE_LOWER;
use function array_change_key_case;
use function assert;
use function sprintf;
use function strlen;
use function strtolower;
Expand Down Expand Up @@ -47,7 +48,10 @@ protected function setUp()

private function createMasterSlaveConnection(bool $keepSlave = false) : MasterSlaveConnection
{
return DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave));
$connection = DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave));
assert($connection instanceof MasterSlaveConnection);

return $connection;
}

private function createMasterSlaveConnectionParams(bool $keepSlave = false) : array
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function testPortabilityPdoSqlServer()

$connection = new ConnectionPortability($params, $driverMock);

$connection->connect($params);
$connection->connect();

self::assertEquals($portability, $connection->getPortability());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\DBAL\Types\Type;
use function array_map;
use function array_pop;
use function assert;
use function count;
use function strtolower;

Expand Down Expand Up @@ -43,6 +44,8 @@ public function testGetSearchPath()
*/
public function testGetSchemaNames()
{
assert($this->_sm instanceof Schema\PostgreSqlSchemaManager);

$names = $this->_sm->getSchemaNames();

self::assertInternalType('array', $names);
Expand Down
Loading

0 comments on commit 385b730

Please sign in to comment.