Skip to content

Commit 9742200

Browse files
committed
Enable PHPStan in tests
1 parent 6daf933 commit 9742200

33 files changed

+318
-121
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"doctrine/coding-standard": "^6.0",
3131
"jetbrains/phpstorm-stubs": "^2018.1.2",
3232
"phpstan/phpstan": "^0.11.3",
33+
"phpstan/phpstan-phpunit": "^0.11.0",
3334
"phpunit/phpunit": "^8.0",
3435
"symfony/console": "^2.0.5|^3.0|^4.0",
3536
"symfony/phpunit-bridge": "^3.4.5|^4.0.5"

composer.lock

Lines changed: 57 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ parameters:
22
level: 7
33
paths:
44
- %currentWorkingDirectory%/lib
5+
- %currentWorkingDirectory%/tests
56
autoload_files:
67
- %currentWorkingDirectory%/tests/phpstan-polyfill.php
78
reportUnmatchedIgnoredErrors: false
@@ -69,3 +70,21 @@ parameters:
6970
-
7071
message: '~^Strict comparison using === between string|false and null will always evaluate to false\.~'
7172
path: %currentWorkingDirectory%/lib/Doctrine/DBAL/Driver/PDOStatement.php
73+
74+
# impossible inference for covariance
75+
- '~^Property Doctrine\\Tests\\DBAL\\Types\\\S+Test::\$type \(Doctrine\\DBAL\\Types\\\S+Type\) does not accept Doctrine\\DBAL\\Types\\Type\.\z~'
76+
- '~^Property Doctrine\\Tests\\DBAL\\Tools\\Console\\RunSqlCommandTest::\$command \(Doctrine\\DBAL\\Tools\\Console\\Command\\RunSqlCommand\) does not accept Symfony\\Component\\Console\\Command\\Command\.\z~'
77+
78+
# https://github.com/phpstan/phpstan-phpunit/pull/28
79+
-
80+
message: '~Call to method expects\(\) on an unknown class \S+~'
81+
path: %currentWorkingDirectory%/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
82+
-
83+
message: '~Call to method expects\(\) on an unknown class \S+~'
84+
path: %currentWorkingDirectory%/tests/Doctrine/Tests/DBAL/ConnectionTest.php
85+
-
86+
message: '~Call to method expects\(\) on an unknown class \S+~'
87+
path: %currentWorkingDirectory%/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
88+
includes:
89+
- vendor/phpstan/phpstan-phpunit/extension.neon
90+
- vendor/phpstan/phpstan-phpunit/rules.neon

tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class QueryCacheProfileTest extends DbalTestCase
2323
/** @var int[] */
2424
private $params = [666];
2525

26-
/** @var string[] */
26+
/** @var int[] */
2727
private $types = [ParameterType::INTEGER];
2828

2929
/** @var string[] */

tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function getSQLState() : ?string
108108
$message = 'DBAL exception message';
109109

110110
foreach ($data as $item) {
111-
/** @var $driverException \Doctrine\DBAL\Driver\DriverException */
111+
/** @var DriverException $driverException */
112112
[$driverException, $convertedExceptionClassName] = $item;
113113

114114
$convertedException = $this->driver->convertException($message, $driverException);

tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class PDOExceptionTest extends DbalTestCase
2727
/**
2828
* The wrapped PDO exception mock.
2929
*
30-
* @var \PDOException|MockObject
30+
* @var \PDOException
3131
*/
3232
private $wrappedException;
3333

tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest;
1010
use PDO;
1111
use PDOException;
12-
use PHPUnit_Framework_SkippedTestError;
12+
use PHPUnit\Framework\SkippedTestError;
1313
use function defined;
1414

1515
class DriverTest extends AbstractPostgreSQLDriverTest
@@ -111,7 +111,7 @@ protected function createDriver()
111111
}
112112

113113
/**
114-
* @throws PHPUnit_Framework_SkippedTestError
114+
* @throws SkippedTestError
115115
*/
116116
private function skipWhenNotUsingPhp56AndPdoPgsql()
117117
{

tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
namespace Doctrine\Tests\DBAL\Functional\Driver\IBMDB2;
66

77
use Doctrine\DBAL\Driver\IBMDB2\DB2Driver;
8+
use Doctrine\DBAL\Statement;
89
use Doctrine\Tests\DbalFunctionalTestCase;
910
use PHPUnit\Framework\Error\Notice;
11+
use function assert;
1012
use function extension_loaded;
1113

1214
class DB2StatementTest extends DbalFunctionalTestCase
@@ -29,6 +31,7 @@ protected function setUp() : void
2931
public function testExecutionErrorsAreNotSuppressed()
3032
{
3133
$stmt = $this->connection->prepare('SELECT * FROM SYSIBM.SYSDUMMY1 WHERE \'foo\' = ?');
34+
assert($stmt instanceof Statement);
3235

3336
// unwrap the statement to prevent the wrapper from handling the PHPUnit-originated exception
3437
$wrappedStmt = $stmt->getWrappedStatement();

tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\DBAL\Driver\OCI8\OCI8Connection;
99
use Doctrine\DBAL\Schema\Table;
1010
use Doctrine\Tests\DbalFunctionalTestCase;
11+
use function assert;
1112
use function extension_loaded;
1213

1314
class OCI8ConnectionTest extends DbalFunctionalTestCase
@@ -27,7 +28,10 @@ protected function setUp() : void
2728
$this->markTestSkipped('oci8 only test.');
2829
}
2930

30-
$this->driverConnection = $this->connection->getWrappedConnection();
31+
$wrappedConnection = $this->connection->getWrappedConnection();
32+
assert($wrappedConnection instanceof OCI8Connection);
33+
34+
$this->driverConnection = $wrappedConnection;
3135
}
3236

3337
/**

tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ protected function setUp() : void
2828

2929
parent::setUp();
3030

31-
$this->driverConnection = $this->connection->getWrappedConnection();
3231

33-
if ($this->driverConnection instanceof PDOConnection) {
34-
return;
32+
$wrappedConnection = $this->connection->getWrappedConnection();
33+
34+
if (! $wrappedConnection instanceof PDOConnection) {
35+
$this->markTestSkipped('PDO connection only test.');
3536
}
3637

37-
$this->markTestSkipped('PDO connection only test.');
38+
$this->driverConnection = $wrappedConnection;
3839
}
3940

4041
protected function tearDown() : void

0 commit comments

Comments
 (0)