Skip to content

Commit 6fd682b

Browse files
committed
Enable PHPStan in tests
1 parent 8c1424c commit 6fd682b

33 files changed

+324
-114
lines changed

composer.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"doctrine/coding-standard": "^4.0",
2222
"jetbrains/phpstorm-stubs": "^2018.1.2",
2323
"phpstan/phpstan": "^0.10.1",
24+
"phpstan/phpstan-phpunit": "dev-GetMockBuilderDynamicReturnTypeExtension-with-undefined-class as 0.10.0.999",
2425
"phpunit/phpunit": "^7.1.2",
2526
"phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5",
2627
"symfony/console": "^2.0.5|^3.0|^4.0",
@@ -47,5 +48,11 @@
4748
},
4849
"archive": {
4950
"exclude": ["!vendor", "tests", "*phpunit.xml", ".appveyor.yml", ".travis.yml", "build.xml", "build.properties", "composer.phar"]
50-
}
51+
},
52+
"repositories": [
53+
{
54+
"type": "vcs",
55+
"url": "https://github.com/Majkl578/phpstan-phpunit"
56+
}
57+
]
5158
}

composer.lock

+69-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon.dist

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ parameters:
22
level: 3
33
paths:
44
- %currentWorkingDirectory%/lib
5+
- %currentWorkingDirectory%/tests
56
autoload_files:
67
- %currentWorkingDirectory%/tests/phpstan-polyfill.php
78
reportUnmatchedIgnoredErrors: false
@@ -44,3 +45,11 @@ parameters:
4445

4546
# weird class name, doesn't exist in stubs either
4647
- '~unknown class OCI-(Lob|Collection)~'
48+
49+
# impossible inference for covariance
50+
- '~^Property Doctrine\\Tests\\DBAL\\Types\\\S+Test::\$type \(Doctrine\\DBAL\\Types\\\S+Type\) does not accept Doctrine\\DBAL\\Types\\Type\.\z~'
51+
- '~^Property Doctrine\\Tests\\DBAL\\Tools\\Console\\RunSqlCommandTest::\$command \(Doctrine\\DBAL\\Tools\\Console\\Command\\RunSqlCommand\) does not accept Symfony\\Component\\Console\\Command\\Command\.\z~'
52+
53+
includes:
54+
- vendor/phpstan/phpstan-phpunit/extension.neon
55+
- vendor/phpstan/phpstan-phpunit/rules.neon

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class QueryCacheProfileTest extends DbalTestCase
2828
private $params = [666];
2929

3030
/**
31-
* @var string[]
31+
* @var int[]
3232
*/
3333
private $types = [ParameterType::INTEGER];
3434

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getSQLState()
9191
$message = 'DBAL exception message';
9292

9393
foreach ($data as $item) {
94-
/** @var $driverException \Doctrine\DBAL\Driver\DriverException */
94+
/** @var DriverException $driverException */
9595
list($driverException, $convertedExceptionClassName) = $item;
9696

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class PDOExceptionTest extends DbalTestCase
2424
/**
2525
* The wrapped PDO exception mock.
2626
*
27-
* @var \PDOException|\PHPUnit_Framework_MockObject_MockObject
27+
* @var \PDOException
2828
*/
2929
private $wrappedException;
3030

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

-3
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ protected function createDriver()
103103
return new Driver();
104104
}
105105

106-
/**
107-
* @throws \PHPUnit_Framework_SkippedTestError
108-
*/
109106
private function skipWhenNotUsingPhp56AndPdoPgsql()
110107
{
111108
if (! defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')) {

tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -743,11 +743,11 @@ public function testFetchAllSupportFetchClass()
743743

744744
$results = $stmt->fetchAll(
745745
FetchMode::CUSTOM_OBJECT,
746-
__NAMESPACE__.'\\MyFetchClass'
746+
MyFetchClass::class
747747
);
748748

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

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

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

786786
$results = $stmt->fetchAll();
787787

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

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

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

808808
$results = array();
809809
while ($row = $stmt->fetch()) {
810810
$results[] = $row;
811811
}
812812

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

816816
self::assertEquals(1, $results[0]->test_int);
817817
self::assertEquals('foo', $results[0]->test_string);

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

+3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Doctrine\Tests\DBAL\Functional\Driver\IBMDB2;
66

7+
use function assert;
78
use Doctrine\DBAL\Driver\IBMDB2\DB2Driver;
9+
use Doctrine\DBAL\Statement;
810
use Doctrine\Tests\DbalFunctionalTestCase;
911
use PHPUnit\Framework\Error\Notice;
1012
use function extension_loaded;
@@ -27,6 +29,7 @@ protected function setUp()
2729
public function testExecutionErrorsAreNotSuppressed()
2830
{
2931
$stmt = $this->_conn->prepare('SELECT * FROM SYSIBM.SYSDUMMY1 WHERE \'foo\' = ?');
32+
assert($stmt instanceof Statement);
3033

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

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace Doctrine\Tests\DBAL\Functional\Driver\OCI8;
44

55
use Doctrine\DBAL\Driver\OCI8\Driver;
6+
use Doctrine\DBAL\Driver\OCI8\OCI8Connection;
67
use Doctrine\DBAL\Schema\Table;
78
use Doctrine\Tests\DbalFunctionalTestCase;
9+
use function assert;
810
use function extension_loaded;
911

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

29-
$this->driverConnection = $this->_conn->getWrappedConnection();
31+
32+
$wrappedConnection = $this->_conn->getWrappedConnection();
33+
assert($wrappedConnection instanceof OCI8Connection);
34+
35+
$this->driverConnection = $wrappedConnection;
3036
}
3137

3238
/**

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\DBAL\Driver\PDOConnection;
66
use Doctrine\Tests\DbalFunctionalTestCase;
7+
use function assert;
78
use function extension_loaded;
89
use function sprintf;
910

@@ -24,7 +25,10 @@ protected function setUp()
2425

2526
parent::setUp();
2627

27-
$this->driverConnection = $this->_conn->getWrappedConnection();
28+
$wrappedConnection = $this->_conn->getWrappedConnection();
29+
assert($wrappedConnection instanceof PDOConnection);
30+
31+
$this->driverConnection = $wrappedConnection;
2832

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

tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Doctrine\Tests\DBAL\Functional\Driver\PDOSqlsrv;
44

55
use Doctrine\DBAL\Driver\Connection as Connection;
6+
use Doctrine\DBAL\Driver\PDOConnection;
67
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver;
78
use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest;
89
use PDO;
@@ -68,6 +69,7 @@ public function testConnectionOptions() : void
6869
public function testDriverOptions() : void
6970
{
7071
$connection = $this->getConnection([PDO::ATTR_CASE => PDO::CASE_UPPER]);
72+
assert($connection instanceof PDOConnection);
7173

7274
self::assertSame(PDO::CASE_UPPER, $connection->getAttribute(PDO::ATTR_CASE));
7375
}

tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Doctrine\Tests\DBAL\Functional;
44

5+
use function assert;
56
use Doctrine\DBAL\Connections\MasterSlaveConnection;
67
use Doctrine\DBAL\DriverManager;
78
use Doctrine\Tests\DbalFunctionalTestCase;
@@ -47,7 +48,10 @@ protected function setUp()
4748

4849
private function createMasterSlaveConnection(bool $keepSlave = false) : MasterSlaveConnection
4950
{
50-
return DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave));
51+
$connection = DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave));
52+
assert($connection instanceof MasterSlaveConnection);
53+
54+
return $connection;
5155
}
5256

5357
private function createMasterSlaveConnectionParams(bool $keepSlave = false) : array

tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function testPortabilityPdoSqlServer()
155155

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

158-
$connection->connect($params);
158+
$connection->connect();
159159

160160
self::assertEquals($portability, $connection->getPortability());
161161
}

tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Doctrine\Tests\DBAL\Functional\Schema;
44

5+
use function assert;
56
use Doctrine\DBAL\Platforms\AbstractPlatform;
67
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
78
use Doctrine\DBAL\Schema;
@@ -43,6 +44,8 @@ public function testGetSearchPath()
4344
*/
4445
public function testGetSchemaNames()
4546
{
47+
assert($this->_sm instanceof Schema\PostgreSqlSchemaManager);
48+
4649
$names = $this->_sm->getSchemaNames();
4750

4851
self::assertInternalType('array', $names);

0 commit comments

Comments
 (0)