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

Lines changed: 8 additions & 1 deletion
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

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

phpstan.neon.dist

Lines changed: 9 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 7 additions & 1 deletion
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
/**

0 commit comments

Comments
 (0)