Enable PHPStan in tests#3203
Enable PHPStan in tests#3203carusogabriel wants to merge 1 commit intodoctrine:masterfrom carusogabriel:phpstan-tests
Conversation
morozov
left a comment
There was a problem hiding this comment.
@carusogabriel as for the remaining
------ ----------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php
------ ----------------------------------------------------------------------
72 Call to an undefined method
Doctrine\DBAL\Driver\Connection::getAttribute().
------ ----------------------------------------------------------------------
You can add a type hint like @var \PDO $connection.
|
|
||
| public function testConnectDispatchEvent() | ||
| { | ||
| /** @var \PHPUnit_Framework_MockObject_MockObject $listenerMock */ |
There was a problem hiding this comment.
Is there a problem detecting the type here? The code looks straightforward. AFAIK, PHPUnit will use namespaced class names if future versions, so it makes sense to use \PHPUnit\Framework\... instead.
There was a problem hiding this comment.
Looks like it still PHPUnit_... https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/MockObject/MockObject.php#L21
There was a problem hiding this comment.
|
|
||
| public function testExecutionErrorsAreNotSuppressed() | ||
| { | ||
| /** @var \Doctrine\DBAL\Statement $stmt */ |
There was a problem hiding this comment.
This looks redundant. The @return annotation on the method declares the type.
| { | ||
| /** | ||
| * @var \Doctrine\DBAL\Schema\AbstractSchemaManager | ||
| * @var mixed |
There was a problem hiding this comment.
Is it supposed to be anything else than a schema manager?
|
|
||
| $this->_sm->dropAndCreateTable($table); | ||
|
|
||
| /** @var \PHPUnit_Framework_MockObject_MockObject $listenerMock */ |
There was a problem hiding this comment.
I tried to remove, but, no success 😢
There was a problem hiding this comment.
It still doesn't look right. PhpStorm unambiguously detects the $listenerMockType as PHPUnit\Framework\MockObject\MockObject based on the @return annotation of PHPUnit\Framework\MockObject\MockBuilder::getMock(). So should do PHPStan. Instead of annotating every call like this, we need to find what the underlying problem is and fix it.
|
|
||
| $this->_sm->dropAndCreateTable($table); | ||
|
|
||
| /** @var \PHPUnit_Framework_MockObject_MockObject $listenerMock */ |
|
|
||
| public function testConvertsDateTimeImmutableInstanceToDatabaseValue() | ||
| { | ||
| /** @var \DateTimeImmutable|\Prophecy\Prophecy\ObjectProphecy $date */ |
There was a problem hiding this comment.
Does phpstan/phpstan-phpunit handle prophecy mocks? Or there's a separate extension for them? In any event, it's better to have this type detection automated rather than manually entered every time.
|
|
||
| /** | ||
| * @var \Doctrine\DBAL\Types\DateIntervalType | ||
| * @var \Doctrine\DBAL\Types\Type |
|
|
||
| /** | ||
| * @var DateTimeImmutableType | ||
| * @var Type |
There was a problem hiding this comment.
Should this parent/child issue be reported to upstream?
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
26 Property Doctrine\Tests\DBAL\Types\DateTimeImmutableTypeTest::$type (Doctrine\DBAL\Types\DateTimeImmutableType) does not accept Doctrine\DBAL\Types\Type.
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
There was a problem hiding this comment.
No. Please try using new DateTimeImmutableType() instead of the factory.
|
|
||
| /** | ||
| * @var \Doctrine\DBAL\Connection | ||
| * @var mixed |
There was a problem hiding this comment.
It breaks a lot of places:
------ ------------------------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php
------ ------------------------------------------------------------------------------------
32 Call to an undefined method Doctrine\DBAL\Driver\Statement::getWrappedStatement().
------ ------------------------------------------------------------------------------------
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
29 Property Doctrine\Tests\DBAL\Functional\Driver\OCI8\OCI8ConnectionTest::$driverConnection (Doctrine\DBAL\Driver\OCI8\OCI8Connection) does not accept Doctrine\DBAL\Driver\Connection.
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
27 Property Doctrine\Tests\DBAL\Functional\Driver\PDOConnectionTest::$driverConnection (Doctrine\DBAL\Driver\PDOConnection) does not accept Doctrine\DBAL\Driver\Connection.
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php
------ ------------------------------------------------------------------------------
41 Call to an undefined method Doctrine\DBAL\Driver\Connection::setAttribute().
75 Call to an undefined method Doctrine\DBAL\Driver\Connection::setAttribute().
99 Call to an undefined method Doctrine\DBAL\Driver\Connection::setAttribute().
123 Call to an undefined method Doctrine\DBAL\Driver\Connection::setAttribute().
------ ------------------------------------------------------------------------------
There was a problem hiding this comment.
Those breakages look valid though, looks PDO related. Explicitly mixed only disables some checks (so better to avoid mixed).
| { | ||
| /** | ||
| * @var DatabasePlatformMock | ||
| * @var AbstractPlatform|DatabasePlatformMock |
There was a problem hiding this comment.
DatabasePlatformMock extends AbstractPlatform. The former is enough.
|
|
|
@morozov Some comments that now are folded but I'd like your reply to continue to fix: |
|
@carusogabriel Hi, any progress? |
|
Closing as I won't be able to finish it. Anyone is encouraged to finish it 😊 |
|
Great job. |
Summary
Enable PHPStan on test at level 3.